Skip to content

Commit

Permalink
feat: add custom routes variable
Browse files Browse the repository at this point in the history
  • Loading branch information
KoLiBer committed Jul 26, 2022
1 parent 7847124 commit 736cdde
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
20 changes: 15 additions & 5 deletions network.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
resource "hcloud_network" "this" {
name = var.name
ip_range = var.cidr
name = var.name
ip_range = var.cidr
delete_protection = var.protection
labels = var.labels
}

resource "hcloud_network_subnet" "this" {
count = length(var.subnets)
for_each = var.subnets

network_id = hcloud_network.this.id
network_zone = var.zone
ip_range = var.subnets[count.index]
type = "cloud"
type = each.value.type
ip_range = each.value.cidr
}

resource "hcloud_network_route" "this" {
for_each = var.routes

network_id = hcloud_network.this.id
destination = each.value.destination
gateway = each.value.gateway
}
2 changes: 1 addition & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ output "network_id" {
}

output "subnet_ids" {
value = { for idx, val in var.subnets : val => hcloud_network_subnet.this[idx].id }
value = { for key, val in var.subnets : key => hcloud_network_subnet.this[key].id }
sensitive = true
description = "Network Subnet IDs"
}
31 changes: 29 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,36 @@ variable "cidr" {
description = "Network CIDR"
}

variable "protection" {
type = bool
default = false
sensitive = false
description = "Network Protection"
}

variable "labels" {
type = map(string)
default = {}
sensitive = false
description = "Network Labels"
}

variable "subnets" {
type = list(string)
default = []
type = list(object({
type = string
cidr = string
}))
default = {}
sensitive = false
description = "Network Subnets"
}

variable "routes" {
type = list(object({
destination = string
gateway = string
}))
default = {}
sensitive = false
description = "Network Routes"
}

0 comments on commit 736cdde

Please sign in to comment.