diff --git a/README.md b/README.md index bc71f6b..0457d85 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Terraform module to manage the Hetzner Cloud resource (hcloud_server, hcloud_ser Copy and paste into your Terraform configuration, insert the variables and run ```terraform init```: -**Create one server:** +**Create one server (only public IP):** ```hcl module "hcloud-server" { @@ -22,6 +22,22 @@ module "hcloud-server" { } ``` +**Create one server (plus private IP):** + +```hcl +module "hcloud-server" { + source = "dhoppeIT/server/hcloud" + + name = "debian" + server_type = "cx11" + image = "debian-10" + + create_server_network = true + network_id = 1331495 + ip = cidrhost("10.0.0.0/24", 2) +} +``` + **Create multiple servers:** ```hcl @@ -32,6 +48,10 @@ module "hcloud-server" { name = format("debian%02d", count.index + 1) server_type = "cx11" image = "debian-10" + + create_server_network = true + subnet_id = "1331495-10.0.0.0/24" + ip = cidrhost("10.0.0.0/24", 10 + count.index) } ``` @@ -90,7 +110,8 @@ No modules. | Name | Description | |------|-------------| | [id](#output\_id) | Unique ID of the server | -| [ipv4\_address](#output\_ipv4\_address) | The IPv4 address | +| [ipv4\_address\_private](#output\_ipv4\_address\_private) | The private IPv4 address | +| [ipv4\_address\_public](#output\_ipv4\_address\_public) | The public IPv4 address | | [name](#output\_name) | Name of the server | diff --git a/outputs.tf b/outputs.tf index 4801d7d..d3dded9 100644 --- a/outputs.tf +++ b/outputs.tf @@ -8,7 +8,12 @@ output "name" { value = hcloud_server.default.name } -output "ipv4_address" { - description = "The IPv4 address" +output "ipv4_address_public" { + description = "The public IPv4 address" value = hcloud_server.default.ipv4_address } + +output "ipv4_address_private" { + description = "The private IPv4 address" + value = try(hcloud_server_network.default[0].ip, "") +} diff --git a/rover.svg b/rover.svg index b73c185..9778323 100644 --- a/rover.svg +++ b/rover.svg @@ -1 +1 @@ -.main.tfoutputs.tfvariables.tfhcloud_serverdefaultidnameipv4_addresslabelsnameimagedatacenterserver_typekeep_diskssh_keysuser_datanetwork_idfirewall_idslocationrescueipsubnet_idcreate_server_networkdelete_protectionrebuild_protectionisoalias_ipsbackups \ No newline at end of file +.outputs.tfvariables.tfmain.tfhcloud_serverhcloud_server_networkdefaultidnameipv4_address_publicipv4_address_privatedelete_protectionrescuealias_ipsssh_keysrebuild_protectionbackupsipserver_typesubnet_idcreate_server_networklabelsimageisofirewall_idskeep_diskuser_datanetwork_idlocationdatacenternamedefaultdefault[0] \ No newline at end of file