|
| 1 | +--- |
| 2 | +subcategory: "S2S VPN" |
| 3 | +page_title: "Scaleway: scaleway_s2s_vpn_connection" |
| 4 | +--- |
| 5 | + |
| 6 | +# Resource: scaleway_s2s_vpn_connection |
| 7 | + |
| 8 | +Creates and manages Scaleway Site-to-Site VPN Connections. |
| 9 | +A connection links a Scaleway VPN Gateway to a Customer Gateway and establishes an IPSec tunnel with BGP routing. |
| 10 | + |
| 11 | +For more information, see [the main documentation](https://www.scaleway.com/en/docs/site-to-site-vpn/reference-content/understanding-s2svpn/). |
| 12 | + |
| 13 | +## Example Usage |
| 14 | + |
| 15 | +### Basic Connection |
| 16 | + |
| 17 | +```terraform |
| 18 | +resource "scaleway_vpc" "vpc" { |
| 19 | + name = "my-vpc" |
| 20 | +} |
| 21 | +
|
| 22 | +resource "scaleway_vpc_private_network" "pn" { |
| 23 | + name = "my-private-network" |
| 24 | + vpc_id = scaleway_vpc.vpc.id |
| 25 | + ipv4_subnet { |
| 26 | + subnet = "10.0.1.0/24" |
| 27 | + } |
| 28 | +} |
| 29 | +
|
| 30 | +resource "scaleway_s2s_vpn_gateway" "gateway" { |
| 31 | + name = "my-vpn-gateway" |
| 32 | + gateway_type = "VGW-S" |
| 33 | + private_network_id = scaleway_vpc_private_network.pn.id |
| 34 | +} |
| 35 | +
|
| 36 | +resource "scaleway_s2s_vpn_customer_gateway" "customer_gw" { |
| 37 | + name = "my-customer-gateway" |
| 38 | + ipv4_public = "203.0.113.1" |
| 39 | + asn = 65000 |
| 40 | +} |
| 41 | +
|
| 42 | +resource "scaleway_s2s_vpn_routing_policy" "policy" { |
| 43 | + name = "my-routing-policy" |
| 44 | + prefix_filter_in = ["10.0.2.0/24"] |
| 45 | + prefix_filter_out = ["10.0.1.0/24"] |
| 46 | +} |
| 47 | +
|
| 48 | +resource "scaleway_s2s_vpn_connection" "main" { |
| 49 | + name = "my-vpn-connection" |
| 50 | + vpn_gateway_id = scaleway_s2s_vpn_gateway.gateway.id |
| 51 | + customer_gateway_id = scaleway_s2s_vpn_customer_gateway.customer_gw.id |
| 52 | + initiation_policy = "customer_gateway" |
| 53 | + enable_route_propagation = true |
| 54 | +
|
| 55 | + bgp_config_ipv4 { |
| 56 | + routing_policy_id = scaleway_s2s_vpn_routing_policy.policy.id |
| 57 | + private_ip = "169.254.0.1/30" |
| 58 | + peer_private_ip = "169.254.0.2/30" |
| 59 | + } |
| 60 | +
|
| 61 | + ikev2_ciphers { |
| 62 | + encryption = "aes256" |
| 63 | + integrity = "sha256" |
| 64 | + dh_group = "modp2048" |
| 65 | + } |
| 66 | +
|
| 67 | + esp_ciphers { |
| 68 | + encryption = "aes256" |
| 69 | + integrity = "sha256" |
| 70 | + dh_group = "modp2048" |
| 71 | + } |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +## Argument Reference |
| 76 | + |
| 77 | +The following arguments are supported: |
| 78 | + |
| 79 | +- `vpn_gateway_id` - (Required) The ID of the VPN gateway to attach to the connection. |
| 80 | +- `customer_gateway_id` - (Required) The ID of the customer gateway to attach to the connection. |
| 81 | +- `initiation_policy` - (Optional) Defines who initiates the IPSec tunnel. |
| 82 | +- `enable_route_propagation` - (Optional) Defines whether route propagation is enabled or not. |
| 83 | +- `bgp_config_ipv4` - (Optional) BGP configuration for IPv4. See [BGP Config](#bgp-config) below. |
| 84 | +- `bgp_config_ipv6` - (Optional) BGP configuration for IPv6. See [BGP Config](#bgp-config) below. |
| 85 | +- `ikev2_ciphers` - (Optional) IKEv2 cipher configuration for Phase 1 (tunnel establishment). See [Cipher Config](#cipher-config) below. |
| 86 | +- `esp_ciphers` - (Optional) ESP cipher configuration for Phase 2 (data encryption). See [Cipher Config](#cipher-config) below. |
| 87 | +- `name` - (Optional) The name of the connection. |
| 88 | +- `tags` - (Optional) The list of tags to apply to the connection. |
| 89 | +- `is_ipv6` - (Optional) Defines IP version of the IPSec Tunnel. Defaults to `false` (IPv4). |
| 90 | +- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#regions) in which the connection should be created. |
| 91 | +- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the connection is associated with. |
| 92 | + |
| 93 | +### BGP Config |
| 94 | + |
| 95 | +The `bgp_config_ipv4` and `bgp_config_ipv6` blocks support: |
| 96 | + |
| 97 | +- `routing_policy_id` - (Required) The ID of the routing policy to use for BGP route filtering. |
| 98 | +- `private_ip` - (Optional) The BGP peer IP on Scaleway side (within the IPSec tunnel), in CIDR notation (e.g., `169.254.0.1/30`). If not provided, Scaleway will assign it automatically. |
| 99 | +- `peer_private_ip` - (Optional) The BGP peer IP on customer side (within the IPSec tunnel), in CIDR notation (e.g., `169.254.0.2/30`). If not provided, Scaleway will assign it automatically. |
| 100 | + |
| 101 | +### Cipher Config |
| 102 | + |
| 103 | +The `ikev2_ciphers` and `esp_ciphers` blocks support: |
| 104 | + |
| 105 | +- `encryption` - (Required) The encryption algorithm. |
| 106 | +- `integrity` - (Optional) The integrity/hash algorithm. |
| 107 | +- `dh_group` - (Optional) The Diffie-Hellman group. |
| 108 | + |
| 109 | +## Attributes Reference |
| 110 | + |
| 111 | +In addition to all arguments above, the following attributes are exported: |
| 112 | + |
| 113 | +- `id` - The ID of the connection. |
| 114 | +- `status` - The status of the connection. |
| 115 | +- `tunnel_status` - The status of the IPSec tunnel. |
| 116 | +- `bgp_status_ipv4` - The status of the BGP IPv4 session. |
| 117 | +- `bgp_status_ipv6` - The status of the BGP IPv6 session. |
| 118 | +- `bgp_session_ipv4` - The BGP IPv4 session information. See [BGP Session](#bgp-session) below. |
| 119 | +- `bgp_session_ipv6` - The BGP IPv6 session information. See [BGP Session](#bgp-session) below. |
| 120 | +- `secret_id` - The ID of the secret containing the pre-shared key (PSK) for the connection. |
| 121 | +- `secret_version` - The version of the secret containing the PSK. |
| 122 | +- `route_propagation_enabled` - Whether route propagation is enabled. |
| 123 | +- `created_at` - The date and time of the creation of the connection (RFC 3339 format). |
| 124 | +- `updated_at` - The date and time of the last update of the connection (RFC 3339 format). |
| 125 | +- `organization_id` - The Organization ID the connection is associated with. |
| 126 | + |
| 127 | +### BGP Session |
| 128 | + |
| 129 | +The `bgp_session_ipv4` and `bgp_session_ipv6` blocks contain (read-only): |
| 130 | + |
| 131 | +- `routing_policy_id` - The routing policy ID used for this BGP session. |
| 132 | +- `private_ip` - The BGP peer IP on Scaleway side (within the tunnel). |
| 133 | +- `peer_private_ip` - The BGP peer IP on customer side (within the tunnel). |
| 134 | + |
| 135 | +~> **Important:** Connections' IDs are [regional](../guides/regions_and_zones.md#resource-ids), which means they are of the form `{region}/{id}`, e.g. `fr-par/11111111-1111-1111-1111-111111111111` |
| 136 | + |
| 137 | +~> **Important:** The pre-shared key (PSK) is auto-generated when the connection is created and stored in Scaleway Secret Manager. You can retrieve it using the `scaleway_secret_version` datasource or via the API. |
| 138 | + |
| 139 | +## Retrieving the Pre-Shared Key (PSK) |
| 140 | + |
| 141 | +The PSK is stored in Secret Manager and can be retrieved using: |
| 142 | + |
| 143 | +```terraform |
| 144 | +data "scaleway_secret_version" "s2s_psk" { |
| 145 | + secret_id = scaleway_s2s_vpn_connection.main.secret_id |
| 146 | + revision = tostring(scaleway_s2s_vpn_connection.main.secret_version) |
| 147 | +} |
| 148 | +
|
| 149 | +# The PSK is available as base64-encoded data |
| 150 | +output "psk" { |
| 151 | + value = data.scaleway_secret_version.s2s_psk.data |
| 152 | + sensitive = true |
| 153 | +} |
| 154 | +``` |
| 155 | + |
| 156 | +## Import |
| 157 | + |
| 158 | +Connections can be imported using `{region}/{id}`, e.g. |
| 159 | + |
| 160 | +```bash |
| 161 | +terraform import scaleway_s2s_vpn_connection.main fr-par/11111111-1111-1111-1111-111111111111 |
| 162 | +``` |
0 commit comments