Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added ipam config : push default route true to prevent legacy mode #8

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,16 @@ No modules.
| [scaleway_vpc_gateway_network.main](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/vpc_gateway_network) | resource |
| [scaleway_vpc_private_network.main](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/vpc_private_network) | resource |
| [scaleway_vpc_public_gateway.main](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/vpc_public_gateway) | resource |
| [scaleway_vpc_public_gateway_dhcp.main](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/vpc_public_gateway_dhcp) | resource |
| [scaleway_vpc_public_gateway_ip.main](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/vpc_public_gateway_ip) | resource |
| [scaleway_vpc_public_gateway_ip_reverse_dns.main](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/vpc_public_gateway_ip_reverse_dns) | resource |
| [scaleway_vpc_public_gateway_dhcp_reservation.reservations](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/data-sources/vpc_public_gateway_dhcp_reservation) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_gateway_dhcp_address"></a> [gateway\_dhcp\_address](#input\_gateway\_dhcp\_address) | IP address of the DHCP server. This will be the gateway's address in the Private Network. Defaults to the first address of the subnet. (IP address) | `string` | `"192.168.0.1"` | no |
| <a name="input_gateway_dhcp_dns_search"></a> [gateway\_dhcp\_dns\_search](#input\_gateway\_dhcp\_dns\_search) | Array of DNS server IP addresses used to override the DNS server list pushed to DHCP clients, instead of the gateway itself | `list(string)` | `null` | no |
| <a name="input_gateway_dhcp_dns_server_servers_override"></a> [gateway\_dhcp\_dns\_server\_servers\_override](#input\_gateway\_dhcp\_dns\_server\_servers\_override) | A list of additional Array of DNS server IP addresses used to override the DNS server list pushed to DHCP clients, instead of the gateway itself. Default the `gateway_dhcp_address` | `list(string)` | `[]` | no |
| <a name="input_gateway_dhcp_enable_dynamic"></a> [gateway\_dhcp\_enable\_dynamic](#input\_gateway\_dhcp\_enable\_dynamic) | Defines whether to enable dynamic pooling of IPs. When false, only pre-existing DHCP reservations will be handed out. Defaults to true | `bool` | `true` | no |
| <a name="input_gateway_dhcp_pool_high"></a> [gateway\_dhcp\_pool\_high](#input\_gateway\_dhcp\_pool\_high) | High IP (inclusive) of the dynamic address pool. Must be in the config's subnet. Defaults to the last address of the subnet. (IP address) | `string` | `"192.168.0.254"` | no |
| <a name="input_gateway_dhcp_pool_low"></a> [gateway\_dhcp\_pool\_low](#input\_gateway\_dhcp\_pool\_low) | Low IP (inclusive) of the dynamic address pool. Must be in the config's subnet. Defaults to the second address of the subnet. (IP address) | `string` | `"192.168.0.2"` | no |
| <a name="input_gateway_dhcp_push_default_route"></a> [gateway\_dhcp\_push\_default\_route](#input\_gateway\_dhcp\_push\_default\_route) | Defines whether the gateway should push a default route to DHCP clients or only hand out IPs. Defaults to true | `bool` | `true` | no |
| <a name="input_gateway_dhcp_push_dns_server"></a> [gateway\_dhcp\_push\_dns\_server](#input\_gateway\_dhcp\_push\_dns\_server) | Defines whether the gateway should push custom DNS servers to clients. This allows for Instance hostname -> IP resolution. Defaults to true. | `bool` | `true` | no |
| <a name="input_gateway_dhcp_rebind_timer"></a> [gateway\_dhcp\_rebind\_timer](#input\_gateway\_dhcp\_rebind\_timer) | After how long a DHCP client will query for a new lease if previous renews fail. Must be 30s lower than `valid_lifetime`. Defaults to 51m (3060s). (in seconds) | `number` | `3060` | no |
| <a name="input_gateway_dhcp_renew_timer"></a> [gateway\_dhcp\_renew\_timer](#input\_gateway\_dhcp\_renew\_timer) | After how long a renew will be attempted. Must be 30s lower than `rebind_timer`. Defaults to 50m (3000s). (in seconds) | `number` | `3000` | no |
| <a name="input_gateway_dhcp_subnet"></a> [gateway\_dhcp\_subnet](#input\_gateway\_dhcp\_subnet) | Subnet for the DHCP server. | `string` | `"192.168.0.0/24"` | no |
| <a name="input_gateway_dhcp_valid_lifetime"></a> [gateway\_dhcp\_valid\_lifetime](#input\_gateway\_dhcp\_valid\_lifetime) | How long DHCP entries will be valid for. Defaults to 1h (3600s). (in seconds | `number` | `3600` | no |
| <a name="input_gateway_network_cleanup_dhcp"></a> [gateway\_network\_cleanup\_dhcp](#input\_gateway\_network\_cleanup\_dhcp) | Defines whether to clean up attached DHCP configurations (if any, and if not attached to another Gateway Network) | `bool` | `true` | no |
| <a name="input_gateway_network_enable_masquerade"></a> [gateway\_network\_enable\_masquerade](#input\_gateway\_network\_enable\_masquerade) | Defines whether the gateway should masquerade traffic for the attached Private Network (i.e. whether to enable dynamic NAT) | `bool` | `true` | no |
| <a name="input_gateway_reverse_dns"></a> [gateway\_reverse\_dns](#input\_gateway\_reverse\_dns) | Create (reserve) a new flexible IP address that can be used for a Public Gateway in a specified Scaleway Project | `bool` | `false` | no |
| <a name="input_instances"></a> [instances](#input\_instances) | A map of interface and/or instance mac addresses containing their properties | `any` | `{}` | no |
| <a name="input_list_reservations"></a> [list\_reservations](#input\_list\_reservations) | Defines whether to list reservations addresses) | `bool` | `false` | no |
| <a name="input_name"></a> [name](#input\_name) | Name to be used on all the resources as identifier | `string` | `""` | no |
| <a name="input_private_network_ipv4_subnet"></a> [private\_network\_ipv4\_subnet](#input\_private\_network\_ipv4\_subnet) | IPv4 subnet to be used on private network resource | `string` | `"192.168.0.0/24"` | no |
| <a name="input_private_network_name"></a> [private\_network\_name](#input\_private\_network\_name) | Name to be used on private network resource as identifier | `string` | `""` | no |
Expand All @@ -80,14 +64,12 @@ No modules.
| <a name="input_timeouts"></a> [timeouts](#input\_timeouts) | Define maximum timeout for creating, updating, and deleting VPC resources | `map(string)` | `{}` | no |
| <a name="input_vpc_public_gateway_type"></a> [vpc\_public\_gateway\_type](#input\_vpc\_public\_gateway\_type) | Type to be used on gateway resource as default | `string` | `"VPC-GW-S"` | no |
| <a name="input_vpc_tags"></a> [vpc\_tags](#input\_vpc\_tags) | Additional tags for the VPC | `list(string)` | `[]` | no |
| <a name="input_wait_reservations"></a> [wait\_reservations](#input\_wait\_reservations) | Determines whether wait reservations are available | `bool` | `true` | no |
| <a name="input_zones"></a> [zones](#input\_zones) | A list of availability zones in the region | `list(string)` | `[]` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_dhcp_reservations"></a> [dhcp\_reservations](#output\_dhcp\_reservations) | ID of VPC Gateway DHCP reservations. |
| <a name="output_private_network_id"></a> [private\_network\_id](#output\_private\_network\_id) | ID of private networks. |
| <a name="output_public_gateway_id"></a> [public\_gateway\_id](#output\_public\_gateway\_id) | ID of public gateways. |
| <a name="output_public_gateway_ip_address"></a> [public\_gateway\_ip\_address](#output\_public\_gateway\_ip\_address) | Address of the public gateway IP. |
Expand Down
13 changes: 6 additions & 7 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ No inputs.

## Outputs

| Name | Description |
|-------------------------------------|------------------------------------------------------------------------------|
| default_public_gateway_ip_addresses | List of Address of the public gateway IP. |
| default_public_gateway_ip_id | List of IDs of gateway IP. |
| default_public_gateway_id | List of IDs of public gateway. |
| default_private_network_id | List of IDs of private networks. |
| dhcp_reservations | List containing the full resource object and attributes for all reservations |
| Name | Description |
| ----------------------------------- | ----------------------------------------- |
| default_public_gateway_ip_addresses | List of Address of the public gateway IP. |
| default_public_gateway_ip_id | List of IDs of gateway IP. |
| default_public_gateway_id | List of IDs of public gateway. |
| default_private_network_id | List of IDs of private networks. |
5 changes: 0 additions & 5 deletions examples/basic/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,3 @@ output "default_private_network_ids" {
description = "IDs of private networks."
value = module.vpc.private_network_id
}

output "reservations" {
description = "IPs address of reservations"
value = module.vpc.dhcp_reservations
}
42 changes: 4 additions & 38 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
################################################################################
# VPC
################################################################################
locals {
instances = { for k, v in var.instances : k => v if var.list_reservations }
}

### IP for Public Gateway
resource "scaleway_vpc_public_gateway_ip" "main" {
count = length(var.zones)
Expand Down Expand Up @@ -63,50 +59,20 @@ resource "scaleway_vpc_private_network" "main" {
}
}

### DHCP Space of VPC Public Gateway
resource "scaleway_vpc_public_gateway_dhcp" "main" {
count = length(var.zones)
subnet = var.gateway_dhcp_subnet
address = var.gateway_dhcp_address
pool_low = var.gateway_dhcp_pool_low
pool_high = var.gateway_dhcp_pool_high
enable_dynamic = var.gateway_dhcp_enable_dynamic
push_default_route = var.gateway_dhcp_push_default_route
push_dns_server = var.gateway_dhcp_push_dns_server
dns_servers_override = concat([
var.gateway_dhcp_address
], var.gateway_dhcp_dns_server_servers_override)
dns_local_name = replace(scaleway_vpc_private_network.main[count.index].name, "_", "-")
valid_lifetime = var.gateway_dhcp_valid_lifetime
renew_timer = var.gateway_dhcp_renew_timer
rebind_timer = var.gateway_dhcp_rebind_timer
dns_search = var.gateway_dhcp_dns_search
depends_on = [scaleway_vpc_private_network.main]
zone = length(regexall("^[a-z]{2}-", element(var.zones, count.index))) > 0 ? element(var.zones, count.index) : null
}

### VPC Gateway Network
resource "scaleway_vpc_gateway_network" "main" {
count = length(var.zones)
gateway_id = scaleway_vpc_public_gateway.main[count.index].id
private_network_id = scaleway_vpc_private_network.main[count.index].id
dhcp_id = scaleway_vpc_public_gateway_dhcp.main[count.index].id
cleanup_dhcp = var.gateway_network_cleanup_dhcp
enable_masquerade = var.gateway_network_enable_masquerade
depends_on = [
scaleway_vpc_public_gateway.main, scaleway_vpc_private_network.main,
scaleway_vpc_public_gateway_dhcp.main
]
zone = length(regexall("^[a-z]{2}-", element(var.zones, count.index))) > 0 ? element(var.zones, count.index) : null
zone = length(regexall("^[a-z]{2}-", element(var.zones, count.index))) > 0 ? element(var.zones, count.index) : null
ipam_config {
push_default_route = true
}
timeouts {
create = lookup(var.timeouts, "create", "10m")
update = lookup(var.timeouts, "update", "10m")
delete = lookup(var.timeouts, "delete", "10m")
}
}

data "scaleway_vpc_public_gateway_dhcp_reservation" "reservations" {
for_each = local.instances
mac_address = lookup(each.value, "mac_address", null)
wait_for_dhcp = var.wait_reservations
}
5 changes: 0 additions & 5 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,3 @@ output "private_network_id" {
description = "ID of private networks."
value = scaleway_vpc_private_network.main[*].id
}

output "dhcp_reservations" {
description = "ID of VPC Gateway DHCP reservations."
value = data.scaleway_vpc_public_gateway_dhcp_reservation.reservations[*]
}
94 changes: 0 additions & 94 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ variable "zones" {
default = []
}

variable "list_reservations" {
type = bool
default = false
description = "Defines whether to list reservations addresses)"
}


################################################################################
# PUBLIC GATEWAY
################################################################################
Expand Down Expand Up @@ -109,90 +102,3 @@ variable "private_network_ipv4_subnet" {
default = "192.168.0.0/24"
description = "IPv4 subnet to be used on private network resource"
}

################################################################################
# DHCP
################################################################################
variable "gateway_dhcp_subnet" {
type = string
default = "192.168.0.0/24"
description = "Subnet for the DHCP server."
}

variable "gateway_dhcp_address" {
type = string
default = "192.168.0.1"
description = "IP address of the DHCP server. This will be the gateway's address in the Private Network. Defaults to the first address of the subnet. (IP address)"
}

variable "gateway_dhcp_pool_low" {
type = string
default = "192.168.0.2"
description = "Low IP (inclusive) of the dynamic address pool. Must be in the config's subnet. Defaults to the second address of the subnet. (IP address)"
}

variable "gateway_dhcp_pool_high" {
type = string
default = "192.168.0.254"
description = "High IP (inclusive) of the dynamic address pool. Must be in the config's subnet. Defaults to the last address of the subnet. (IP address)"
}

variable "gateway_dhcp_enable_dynamic" {
type = bool
default = true
description = "Defines whether to enable dynamic pooling of IPs. When false, only pre-existing DHCP reservations will be handed out. Defaults to true"
}

variable "gateway_dhcp_push_default_route" {
type = bool
default = true
description = "Defines whether the gateway should push a default route to DHCP clients or only hand out IPs. Defaults to true"
}

variable "gateway_dhcp_push_dns_server" {
type = bool
default = true
description = "Defines whether the gateway should push custom DNS servers to clients. This allows for Instance hostname -> IP resolution. Defaults to true."
}

variable "gateway_dhcp_dns_server_servers_override" {
type = list(string)
default = []
description = "A list of additional Array of DNS server IP addresses used to override the DNS server list pushed to DHCP clients, instead of the gateway itself. Default the `gateway_dhcp_address` "
}

variable "gateway_dhcp_valid_lifetime" {
default = 3600
type = number
description = "How long DHCP entries will be valid for. Defaults to 1h (3600s). (in seconds"
}

variable "gateway_dhcp_renew_timer" {
default = 3000
type = number
description = "After how long a renew will be attempted. Must be 30s lower than `rebind_timer`. Defaults to 50m (3000s). (in seconds)"
}

variable "gateway_dhcp_rebind_timer" {
default = 3060
type = number
description = "After how long a DHCP client will query for a new lease if previous renews fail. Must be 30s lower than `valid_lifetime`. Defaults to 51m (3060s). (in seconds)"
}

variable "gateway_dhcp_dns_search" {
type = list(string)
default = null
description = "Array of DNS server IP addresses used to override the DNS server list pushed to DHCP clients, instead of the gateway itself"
}

variable "instances" {
description = "A map of interface and/or instance mac addresses containing their properties"
type = any
default = {}
}

variable "wait_reservations" {
description = "Determines whether wait reservations are available"
type = bool
default = true
}
Loading