Skip to content

Commit

Permalink
feat: Add condition to make creation of network subnet optional (#7)
Browse files Browse the repository at this point in the history
* feat: Add condition to make creation of network subnet optional

* docs: Generate README.md

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
dhoppe and github-actions[bot] authored Jan 17, 2022
1 parent b5a5ce4 commit 2db356d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,30 @@ Terraform module to manage the Hetzner Cloud resources (hcloud_network, hcloud_n

Copy and paste into your Terraform configuration, insert the variables and run ```terraform init```:

**Create a network:**

```hcl
module "hcloud-network" {
source = "dhoppeIT/network/hcloud"
name = "private"
ip_range_network = "10.0.0.0/16"
}
```

**Create a network subnet:**

```hcl
module "hcloud-network" {
source = "dhoppeIT/network/hcloud"
name = "private"
ip_range_network = "10.0.0.0/16"
type = "cloud"
ip_range_subnet = "10.0.0.0/24"
network_zone = "eu-central"
create_network_subnet = true
type = "cloud"
ip_range_subnet = "10.0.0.0/24"
network_zone = "eu-central"
}
```

Expand Down Expand Up @@ -52,13 +66,14 @@ No modules.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_create_network_subnet"></a> [create\_network\_subnet](#input\_create\_network\_subnet) | Whether to create network subnet | `bool` | `false` | no |
| <a name="input_delete_protection"></a> [delete\_protection](#input\_delete\_protection) | Enable or disable delete protection | `bool` | `false` | no |
| <a name="input_ip_range_network"></a> [ip\_range\_network](#input\_ip\_range\_network) | IP Range of the whole Network which must span all included subnets and route destinations | `string` | n/a | yes |
| <a name="input_ip_range_subnet"></a> [ip\_range\_subnet](#input\_ip\_range\_subnet) | Range to allocate IPs from | `string` | n/a | yes |
| <a name="input_ip_range_subnet"></a> [ip\_range\_subnet](#input\_ip\_range\_subnet) | Range to allocate IPs from | `string` | `null` | no |
| <a name="input_labels"></a> [labels](#input\_labels) | User-defined labels (key-value pairs) should be created with | `map(string)` | `{}` | no |
| <a name="input_name"></a> [name](#input\_name) | Name of the Network to create | `string` | n/a | yes |
| <a name="input_network_zone"></a> [network\_zone](#input\_network\_zone) | Name of network zone | `string` | n/a | yes |
| <a name="input_type"></a> [type](#input\_type) | Type of subnet | `string` | n/a | yes |
| <a name="input_network_zone"></a> [network\_zone](#input\_network\_zone) | Name of network zone | `string` | `null` | no |
| <a name="input_type"></a> [type](#input\_type) | Type of subnet | `string` | `null` | no |
| <a name="input_vswitch_id"></a> [vswitch\_id](#input\_vswitch\_id) | ID of the vswitch | `number` | `null` | no |

## Outputs
Expand Down
2 changes: 2 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ resource "hcloud_network" "default" {
}

resource "hcloud_network_subnet" "default" {
count = var.create_network_subnet ? 1 : 0

network_id = hcloud_network.default.id
type = var.type
ip_range = var.ip_range_subnet
Expand Down
4 changes: 2 additions & 2 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ output "ip_range_network" {

output "id_subnet" {
description = "ID of the Network subnet"
value = hcloud_network_subnet.default.id
value = hcloud_network_subnet.default.*.id
}

output "ip_range_subnet" {
description = "Range to allocate IPs from"
value = hcloud_network_subnet.default.ip_range
value = hcloud_network_subnet.default.*.ip_range
}
2 changes: 1 addition & 1 deletion rover.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,27 @@ variable "delete_protection" {
description = "Enable or disable delete protection"
}

variable "create_network_subnet" {
type = bool
default = false
description = "Whether to create network subnet"
}

variable "type" {
type = string
default = null
description = "Type of subnet"
}

variable "ip_range_subnet" {
type = string
default = null
description = "Range to allocate IPs from"
}

variable "network_zone" {
type = string
default = null
description = "Name of network zone"
}

Expand Down

0 comments on commit 2db356d

Please sign in to comment.