Skip to content

Add support for IPv6 addresses with the google_compute_external_vpn_gateway terraform resource #8552

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

Merged
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
3 changes: 3 additions & 0 deletions .changelog/11982.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added `interface.ipv6-address` field in `google_compute_external_vpn_gateway` resource
```
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ Only IPv4 is supported. This IP address can be either from
your on-premise gateway or another Cloud provider's VPN gateway,
it cannot be an IP address from Google Compute Engine.`,
},
"ipv6_address": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `IPv6 address of the interface in the external VPN gateway. This IPv6
address can be either from your on-premise gateway or another Cloud
provider's VPN gateway, it cannot be an IP address from Google Compute
Engine. Must specify an IPv6 address (not IPV4-mapped) using any format
described in RFC 4291 (e.g. 2001:db8:0:0:2d9:51:0:0). The output format
is RFC 5952 format (e.g. 2001:db8::2d9:51:0:0).`,
},
},
},
},
Expand Down Expand Up @@ -520,8 +531,9 @@ func flattenComputeExternalVpnGatewayInterface(v interface{}, d *schema.Resource
continue
}
transformed = append(transformed, map[string]interface{}{
"id": flattenComputeExternalVpnGatewayInterfaceId(original["id"], d, config),
"ip_address": flattenComputeExternalVpnGatewayInterfaceIpAddress(original["ipAddress"], d, config),
"id": flattenComputeExternalVpnGatewayInterfaceId(original["id"], d, config),
"ip_address": flattenComputeExternalVpnGatewayInterfaceIpAddress(original["ipAddress"], d, config),
"ipv6_address": flattenComputeExternalVpnGatewayInterfaceIpv6Address(original["ipv6Address"], d, config),
})
}
return transformed
Expand All @@ -547,6 +559,10 @@ func flattenComputeExternalVpnGatewayInterfaceIpAddress(v interface{}, d *schema
return v
}

func flattenComputeExternalVpnGatewayInterfaceIpv6Address(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenComputeExternalVpnGatewayTerraformLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -606,6 +622,13 @@ func expandComputeExternalVpnGatewayInterface(v interface{}, d tpgresource.Terra
transformed["ipAddress"] = transformedIpAddress
}

transformedIpv6Address, err := expandComputeExternalVpnGatewayInterfaceIpv6Address(original["ipv6_address"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedIpv6Address); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["ipv6Address"] = transformedIpv6Address
}

req = append(req, transformed)
}
return req, nil
Expand All @@ -619,6 +642,10 @@ func expandComputeExternalVpnGatewayInterfaceIpAddress(v interface{}, d tpgresou
return v, nil
}

func expandComputeExternalVpnGatewayInterfaceIpv6Address(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandComputeExternalVpnGatewayEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,42 @@ resource "google_compute_external_vpn_gateway" "external_gateway" {
}
`, suffix, key, value)
}

func TestAccComputeExternalVPNGateway_insertIpv6Address(t *testing.T) {
t.Parallel()

rnd := acctest.RandString(t, 10)
resourceName := "google_compute_external_vpn_gateway.external_gateway"

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Steps: []resource.TestStep{
{
Config: computeExternalVPNGatewayIpv6AddressConfig(rnd, "2001:db8:abcd:1234:5678:90ab:cdef:1234"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "interface.0.ipv6_address", "2001:db8:abcd:1234:5678:90ab:cdef:1234"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func computeExternalVPNGatewayIpv6AddressConfig(suffix, ipv6_address string) string {
return fmt.Sprintf(`
resource "google_compute_external_vpn_gateway" "external_gateway" {
name = "tf-test-external-gateway-%s"
redundancy_type = "SINGLE_IP_INTERNALLY_REDUNDANT"
description = "An externally managed VPN gateway"
interface {
id = 0
ipv6_address = "%s"
}
}
`, suffix, ipv6_address)
}
9 changes: 9 additions & 0 deletions website/docs/r/compute_external_vpn_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,15 @@ The following arguments are supported:
your on-premise gateway or another Cloud provider's VPN gateway,
it cannot be an IP address from Google Compute Engine.

* `ipv6_address` -
(Optional)
IPv6 address of the interface in the external VPN gateway. This IPv6
address can be either from your on-premise gateway or another Cloud
provider's VPN gateway, it cannot be an IP address from Google Compute
Engine. Must specify an IPv6 address (not IPV4-mapped) using any format
described in RFC 4291 (e.g. 2001:db8:0:0:2d9:51:0:0). The output format
is RFC 5952 format (e.g. 2001:db8::2d9:51:0:0).

## Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:
Expand Down