Skip to content

Commit

Permalink
chore(instance)!: Phased out nat IPs and force use of routed IPs
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit-garcia committed Jan 30, 2025
1 parent 84d8645 commit 3fa0c59
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 16 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ module "my_instance" {
| <a name="input_private_networks"></a> [private_networks](#input_private_networks) | Private networks associated with the server. | `list(string)` | `[]` | no |
| <a name="input_project_id"></a> [project_id](#input_project_id) | ID of the project the namespace is associated with. Ressource will be created in the project set at the provider level if null. | `string` | `null` | no |
| <a name="input_root_volume"></a> [root_volume](#input_root_volume) | Root volume attached to the server on creation. Updates to `root_volume.size_in_gb` will be ignored after the creation of the server. | ```object({ delete_on_termination = bool size_in_gb = number volume_id = optional(string) volume_type = optional(string) })``` | `null` | no |
| <a name="input_routed_ip_enabled"></a> [routed_ip_enabled](#input_routed_ip_enabled) | Determine if the instance will support routed ips only. Changing it to true will migrate the server and its IP to routed type. | `bool` | `true` | no |
| <a name="input_security_group_id"></a> [security_group_id](#input_security_group_id) | ID of the security group the server is attached to. | `string` | `null` | no |
| <a name="input_state"></a> [state](#input_state) | State of the server. Default to 'started'. Possible values are: 'started', 'stopped' or 'standby'. | `string` | `"started"` | no |
| <a name="input_tags"></a> [tags](#input_tags) | Tags associated with the server and dedicated ip address. | `list(string)` | `[]` | no |
Expand Down
2 changes: 1 addition & 1 deletion ipv4.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ resource "scaleway_instance_ip" "public_ipv4" {
count = var.enable_public_ipv4 ? 1 : 0

project_id = var.project_id
type = var.routed_ip_enabled ? "routed_ipv4" : "nat"
type = "routed_ipv4"
zone = var.zone
}

Expand Down
6 changes: 3 additions & 3 deletions ipv6.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ moved {
}

resource "scaleway_instance_ip" "ipv6" {
count = var.enable_ipv6 && var.routed_ip_enabled ? 1 : 0
count = var.enable_ipv6 ? 1 : 0

project_id = var.project_id
type = "routed_ipv6"
zone = var.zone
}

resource "scaleway_instance_ip_reverse_dns" "ipv6" {
count = var.enable_ipv6 && var.routed_ip_enabled && (var.domainname != null) ? 1 : 0
count = var.enable_ipv6 && (var.domainname != null) ? 1 : 0

ip_id = scaleway_instance_ip.ipv6[count.index].id
reverse = local.effective_fqdn
Expand All @@ -22,7 +22,7 @@ resource "scaleway_instance_ip_reverse_dns" "ipv6" {
resource "scaleway_domain_record" "ipv6" {
count = var.domainname != null && var.enable_ipv6 && var.state != "stopped" ? 1 : 0

data = var.routed_ip_enabled ? one([for item in scaleway_instance_server.this.public_ips[*].address : item if can(regex(":", item))]) : scaleway_instance_server.this.ipv6_address
data = one([for item in scaleway_instance_server.this.public_ips[*].address : item if can(regex(":", item))])
dns_zone = var.domainname
name = local.effective_hostname
type = "AAAA"
Expand Down
5 changes: 2 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ resource "scaleway_instance_server" "this" {
}

enable_dynamic_ip = var.enable_public_ipv4
enable_ipv6 = var.routed_ip_enabled ? null : var.enable_ipv6
routed_ip_enabled = var.routed_ip_enabled
enable_ipv6 = null

ip_ids = compact(tolist([
var.enable_public_ipv4 ? scaleway_instance_ip.public_ipv4[0].id : null,
var.enable_ipv6 && var.routed_ip_enabled ? scaleway_instance_ip.ipv6[0].id : null,
var.enable_ipv6 ? scaleway_instance_ip.ipv6[0].id : null,
]))

dynamic "private_network" {
Expand Down
4 changes: 2 additions & 2 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
output "ip4" {
description = "IPv4 address of the intance."
value = var.enable_public_ipv4 ? (var.routed_ip_enabled ? scaleway_instance_ip.public_ipv4[0].address : scaleway_instance_server.this.public_ip) : scaleway_instance_server.this.private_ip
value = var.enable_public_ipv4 ? scaleway_instance_ip.public_ipv4[0].address : scaleway_instance_server.this.private_ip
}

output "ip6" {
description = "IPv6 address of the instance."
value = var.enable_ipv6 && var.routed_ip_enabled ? one([for item in scaleway_instance_server.this.public_ips[*].address : item if can(regex(":", item))]) : scaleway_instance_server.this.ipv6_address
value = var.enable_ipv6 ? one([for item in scaleway_instance_server.this.public_ips[*].address : item if can(regex(":", item))]) : scaleway_instance_server.this.ipv6_address
}

output "name" {
Expand Down
6 changes: 0 additions & 6 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ variable "enable_public_ipv4" {
default = false
}

variable "routed_ip_enabled" {
type = bool
description = "Determine if the instance will support routed ips only. Changing it to true will migrate the server and its IP to routed type."
default = true
}

variable "private_networks" {
type = list(string)
description = "Private networks associated with the server."
Expand Down

0 comments on commit 3fa0c59

Please sign in to comment.