-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add terraform files for hcloud server setup * add tests for public IPv4, IPv6, and private IPv4 * add test to check for location filter * add circleci entry for hcloud provider Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
- Loading branch information
1 parent
032f476
commit cddebf3
Showing
5 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package hcloud_test | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"testing" | ||
|
||
discover "github.com/hashicorp/go-discover" | ||
"github.com/hashicorp/go-discover/provider/hcloud" | ||
) | ||
|
||
var _ discover.Provider = (*hcloud.Provider)(nil) | ||
var addrTests = map[string]struct { | ||
addrType string | ||
location string | ||
outLen int | ||
}{ | ||
"public ipv4 all locations": {"public_v4", "", 2}, | ||
"public ipv6 all locations": {"public_v6", "", 2}, | ||
"private ipv4 all locations": {"private_v4", "", 2}, | ||
"private ipv4 fsn1 datacenter": {"private_v4", "fsn1", 1}, | ||
"public ipv6 nbg1 datacenter": {"public_v6", "nbg1", 1}, | ||
"public ipv4 hel1 datacenter": {"public_v4", "hel1", 0}, | ||
} | ||
|
||
func TestAddrs(t *testing.T) { | ||
l := log.New(os.Stderr, "", log.LstdFlags) | ||
for name, at := range addrTests { | ||
t.Run(name, func(t *testing.T) { | ||
args := discover.Config{ | ||
"provider": "hcloud", | ||
"label_selector": "go-discover-test-tag", | ||
"address_type": at.addrType, | ||
} | ||
p := &hcloud.Provider{} | ||
addrs, err := p.Addrs(args, l) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if len(addrs) != at.outLen { | ||
t.Fatalf("expected: %d, got: %d", at.outLen, len(addrs)) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
variable "prefix" { | ||
default = "go-discover" | ||
} | ||
|
||
variable "hcloud_image" { | ||
default = "ubuntu-20.04" | ||
} | ||
|
||
variable "hcloud_location_nbg" { | ||
default = "nbg1" | ||
} | ||
|
||
variable "hcloud_location_fsn" { | ||
default = "fsn1" | ||
} | ||
|
||
variable "hcloud_size" { | ||
default = "cx11" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
provider "hcloud" { | ||
} | ||
|
||
resource "hcloud_server" "test-01" { | ||
count = 2 | ||
image = var.hcloud_image | ||
name = "${var.prefix}-01-${count.index + 1}" | ||
server_type = var.hcloud_size | ||
location = var.hcloud_location_nbg | ||
labels = { | ||
"${var.prefix}-test-tag" : "" | ||
} | ||
} | ||
|
||
resource "hcloud_server" "test-02" { | ||
image = var.hcloud_image | ||
name = "${var.prefix}-02" | ||
server_type = var.hcloud_size | ||
location = var.hcloud_location_fsn | ||
} | ||
|
||
resource "hcloud_network" "internal" { | ||
name = "${var.prefix}-internal" | ||
ip_range = "10.0.0.0/8" | ||
labels = { | ||
"${var.prefix}-test-tag" : "" | ||
} | ||
} | ||
|
||
resource "hcloud_network_subnet" "subnet" { | ||
network_id = hcloud_network.internal.id | ||
type = "cloud" | ||
network_zone = "eu-central" | ||
ip_range = "10.0.1.0/24" | ||
} | ||
|
||
resource "hcloud_server_network" "test-01" { | ||
count = 2 | ||
server_id = hcloud_server.test-01[count.index].id | ||
subnet_id = hcloud_network_subnet.subnet.id | ||
} | ||
|
||
resource "hcloud_server_network" "test-02" { | ||
server_id = hcloud_server.test-02.id | ||
subnet_id = hcloud_network_subnet.subnet.id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
terraform { | ||
required_providers { | ||
hcloud = { | ||
source = "hetznercloud/hcloud" | ||
version = "1.24.1" | ||
} | ||
} | ||
|
||
required_version = ">=0.12" | ||
} |