|
| 1 | +--- |
| 2 | +page_title: "Migrating from Legacy VPC Gateway to v2" |
| 3 | +--- |
| 4 | + |
| 5 | +# Migrating from Legacy VPC Gateway to v2 |
| 6 | + |
| 7 | +This guide explains how to migrate from the legacy VPC gateway configuration (v1) to the new v2 API. |
| 8 | +In the legacy setup, DHCP and DHCP reservations are managed with dedicated resources and referenced in the gateway network. |
| 9 | +In v2, the public gateway is migrated to use IPAM (IP Address Management) mode. |
| 10 | +In 2023, DHCP functionality was moved from Public Gateways to Private Networks, DHCP resources are now no longer needed. |
| 11 | + |
| 12 | +Note: |
| 13 | +During migration, you need to trigger the migration call by setting the `migrate_to_v2` flag on your public gateway resource. |
| 14 | +You can do this via the Terraform configuration or by using the Scaleway CLI/Console. |
| 15 | + |
| 16 | +## Prerequisites |
| 17 | + |
| 18 | +### Ensure the Latest Provider Version |
| 19 | + |
| 20 | +Ensure your Scaleway provider is updated to at least version `2.52.0`. |
| 21 | + |
| 22 | +```hcl |
| 23 | +terraform { |
| 24 | + required_providers { |
| 25 | + scaleway = { |
| 26 | + source = "scaleway/scaleway" |
| 27 | + version = "~> v2.52.0" |
| 28 | + } |
| 29 | + } |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +### Legacy Configuration |
| 34 | + |
| 35 | +A typical legacy configuration might look like this: |
| 36 | + |
| 37 | +```hcl |
| 38 | +resource "scaleway_vpc" "main" { |
| 39 | + name = "foo" |
| 40 | +} |
| 41 | +
|
| 42 | +resource "scaleway_vpc_private_network" "main" { |
| 43 | + name = "bar" |
| 44 | + vpc_id = scaleway_vpc.main.id |
| 45 | +} |
| 46 | +
|
| 47 | +resource "scaleway_vpc_public_gateway_ip" "main" { |
| 48 | +} |
| 49 | +
|
| 50 | +resource "scaleway_vpc_public_gateway" "main" { |
| 51 | + name = "foobar" |
| 52 | + type = "VPC-GW-S" |
| 53 | + ip_id = scaleway_vpc_public_gateway_ip.main.id |
| 54 | +} |
| 55 | +
|
| 56 | +resource "scaleway_vpc_public_gateway_dhcp" "main" { |
| 57 | + subnet = "192.168.1.0/24" |
| 58 | +} |
| 59 | +
|
| 60 | +resource "scaleway_instance_server" "main" { |
| 61 | + image = "ubuntu_focal" |
| 62 | + type = "DEV1-S" |
| 63 | +} |
| 64 | +
|
| 65 | +resource "scaleway_instance_private_nic" "main" { |
| 66 | + server_id = scaleway_instance_server.main.id |
| 67 | + private_network_id = scaleway_vpc_private_network.main.id |
| 68 | +} |
| 69 | +
|
| 70 | +resource "scaleway_vpc_gateway_network" "main" { |
| 71 | + gateway_id = scaleway_vpc_public_gateway.main.id |
| 72 | + private_network_id = scaleway_vpc_private_network.main.id |
| 73 | + dhcp_id = scaleway_vpc_public_gateway_dhcp.main.id |
| 74 | + cleanup_dhcp = true |
| 75 | + enable_masquerade = true |
| 76 | +} |
| 77 | +
|
| 78 | +resource "scaleway_vpc_public_gateway_dhcp_reservation" "main" { |
| 79 | + gateway_network_id = scaleway_vpc_gateway_network.main.id |
| 80 | + mac_address = scaleway_instance_private_nic.main.mac_address |
| 81 | + ip_address = "192.168.1.1" |
| 82 | +} |
| 83 | +``` |
| 84 | + |
| 85 | +### Triggering Migration |
| 86 | + |
| 87 | +Before updating your configuration, you must trigger the migration on the public gateway resource. For example, add the `migrate_to_v2` flag: |
| 88 | + |
| 89 | +```hcl |
| 90 | +resource "scaleway_vpc_public_gateway" "main" { |
| 91 | + name = "foobar" |
| 92 | + type = "VPC-GW-S" |
| 93 | + ip_id = scaleway_vpc_public_gateway_ip.main.id |
| 94 | + migrate_to_v2 = true |
| 95 | +} |
| 96 | +``` |
| 97 | + |
| 98 | +This call updates the gateway on the API side from v1 to v2. The DHCP configuration and reservations remain intact, but the underlying resource is now managed using v2. |
| 99 | + |
| 100 | +### Updated Configuration |
| 101 | + |
| 102 | +After triggering the migration, update your Terraform configuration as follows: |
| 103 | + |
| 104 | +1. **Remove the DHCP and DHCP Reservation Resources** |
| 105 | + |
| 106 | + Since DHCP functionality is built directly into Private Networks, you no longer need the DHCP configuration resources. Delete the following from your config: |
| 107 | + |
| 108 | + `scaleway_vpc_public_gateway_dhcp` |
| 109 | + `scaleway_vpc_public_gateway_dhcp_reservation` |
| 110 | + |
| 111 | +2. **Update the Gateway Network** |
| 112 | + |
| 113 | + Replace the DHCP related attributes with an `ipam_config` block. For example |
| 114 | + |
| 115 | + ```hcl |
| 116 | + resource "scaleway_vpc_gateway_network" "main" { |
| 117 | + gateway_id = scaleway_vpc_public_gateway.main.id |
| 118 | + private_network_id = scaleway_vpc_private_network.main.id |
| 119 | + ipam_config { |
| 120 | + push_default_route = false |
| 121 | + } |
| 122 | + enable_masquerade = true |
| 123 | + } |
| 124 | + ``` |
| 125 | +
|
| 126 | +### Using the IPAM Datasource and Resource for Reservations |
| 127 | +
|
| 128 | +After migrating your public gateway to v2, you no longer manage DHCP reservations with dedicated resources. |
| 129 | +Instead, you remove the legacy DHCP reservation resource and switch to using IPAM to manage your IPs. |
| 130 | +
|
| 131 | +1. **Retrieve an Existing IP with the IPAM Datasource** |
| 132 | + If you have already reserved an IP (for example, via your legacy configuration), even after deleting the DHCP reservation resource the IP is still available. You can reference it using the `scaleway_ipam_ip` datasource. For instance: |
| 133 | +
|
| 134 | + ```hcl |
| 135 | + data "scaleway_ipam_ip" "existing" { |
| 136 | + mac_address = scaleway_instance_private_nic.main.mac_address |
| 137 | + type = "ipv4" |
| 138 | + } |
| 139 | + ``` |
| 140 | + You can now use data.scaleway_ipam_ip.existing.id in your configuration to reference the reserved IP. |
| 141 | + |
| 142 | +2. **Book New IPs Using the IPAM IP Resource** |
| 143 | + If you need to reserve new IPs, use the scaleway_ipam_ip resource. This resource allows you to explicitly book an IP from your private network. For example: |
| 144 | + |
| 145 | + ```hcl |
| 146 | + resource "scaleway_ipam_ip" "new_ip" { |
| 147 | + address = "172.16.64.7" |
| 148 | + source { |
| 149 | + private_network_id = scaleway_vpc_private_network.pn01.id |
| 150 | + } |
| 151 | + } |
| 152 | + ``` |
| 153 | + |
| 154 | +3. **Attach the Reserved IP to Your Resources** |
| 155 | + |
| 156 | + Once you have your IP—whether retrieved via the datasource or booked as a new resource—you can attach it to your server’s private NIC: |
| 157 | + ```hcl |
| 158 | + resource "scaleway_instance_private_nic" "pnic01" { |
| 159 | + private_network_id = scaleway_vpc_private_network.main.id |
| 160 | + server_id = scaleway_instance_server.main.id |
| 161 | + ipam_ip_ids = [scaleway_ipam_ip.new_ip.id] |
| 162 | + } |
| 163 | + ``` |
0 commit comments