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

Support IPV6 for HA VPN. #5395

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/7525.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added stack_type to resource `ha_vpn_gateway`
```
26 changes: 26 additions & 0 deletions google-beta/resource_compute_ha_vpn_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ character, which cannot be a dash.`,
DiffSuppressFunc: compareSelfLinkOrResourceName,
Description: `The region this gateway should sit in.`,
},
"stack_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validateEnum([]string{"IPV4_ONLY", "IPV4_IPV6", ""}),
Description: `The stack type for this VPN gateway to identify the IP protocols that are enbaled.
If not specified, IPV4_ONLY will be used. Default value: "IPV4_ONLY" Possible values: ["IPV4_ONLY", "IPV4_IPV6"]`,
Default: "IPV4_ONLY",
},
"vpn_interfaces": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -149,6 +158,12 @@ func resourceComputeHaVpnGatewayCreate(d *schema.ResourceData, meta interface{})
} else if v, ok := d.GetOkExists("network"); !isEmptyValue(reflect.ValueOf(networkProp)) && (ok || !reflect.DeepEqual(v, networkProp)) {
obj["network"] = networkProp
}
stackTypeProp, err := expandComputeHaVpnGatewayStackType(d.Get("stack_type"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("stack_type"); !isEmptyValue(reflect.ValueOf(stackTypeProp)) && (ok || !reflect.DeepEqual(v, stackTypeProp)) {
obj["stackType"] = stackTypeProp
}
vpnInterfacesProp, err := expandComputeHaVpnGatewayVpnInterfaces(d.Get("vpn_interfaces"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -251,6 +266,9 @@ func resourceComputeHaVpnGatewayRead(d *schema.ResourceData, meta interface{}) e
if err := d.Set("network", flattenComputeHaVpnGatewayNetwork(res["network"], d, config)); err != nil {
return fmt.Errorf("Error reading HaVpnGateway: %s", err)
}
if err := d.Set("stack_type", flattenComputeHaVpnGatewayStackType(res["stackType"], d, config)); err != nil {
return fmt.Errorf("Error reading HaVpnGateway: %s", err)
}
if err := d.Set("vpn_interfaces", flattenComputeHaVpnGatewayVpnInterfaces(res["vpnInterfaces"], d, config)); err != nil {
return fmt.Errorf("Error reading HaVpnGateway: %s", err)
}
Expand Down Expand Up @@ -345,6 +363,10 @@ func flattenComputeHaVpnGatewayNetwork(v interface{}, d *schema.ResourceData, co
return ConvertSelfLinkToV1(v.(string))
}

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

func flattenComputeHaVpnGatewayVpnInterfaces(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -416,6 +438,10 @@ func expandComputeHaVpnGatewayNetwork(v interface{}, d TerraformResourceData, co
return f.RelativeLink(), nil
}

func expandComputeHaVpnGatewayStackType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeHaVpnGatewayVpnInterfaces(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
req := make([]interface{}, 0, len(l))
Expand Down
41 changes: 41 additions & 0 deletions google-beta/resource_compute_ha_vpn_gateway_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,47 @@ resource "google_compute_network" "network1" {
`, context)
}

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

context := map[string]interface{}{
"random_suffix": RandString(t, 10),
}

VcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeHaVpnGatewayDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeHaVpnGateway_haVpnGatewayIpv6Example(context),
},
{
ResourceName: "google_compute_ha_vpn_gateway.ha_gateway1",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "region"},
},
},
})
}

func testAccComputeHaVpnGateway_haVpnGatewayIpv6Example(context map[string]interface{}) string {
return Nprintf(`
resource "google_compute_ha_vpn_gateway" "ha_gateway1" {
region = "us-central1"
name = "tf-test-ha-vpn-1%{random_suffix}"
network = google_compute_network.network1.id
stack_type = "IPV4_IPV6"
}

resource "google_compute_network" "network1" {
name = "network1%{random_suffix}"
auto_create_subnetworks = false
}
`, context)
}

func testAccCheckComputeHaVpnGatewayDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
28 changes: 28 additions & 0 deletions website/docs/r/compute_ha_vpn_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ resource "google_compute_ha_vpn_gateway" "ha_gateway1" {
network = google_compute_network.network1.id
}

resource "google_compute_network" "network1" {
name = "network1"
auto_create_subnetworks = false
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=ha_vpn_gateway_ipv6&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Ha Vpn Gateway Ipv6


```hcl
resource "google_compute_ha_vpn_gateway" "ha_gateway1" {
region = "us-central1"
name = "ha-vpn-1"
network = google_compute_network.network1.id
stack_type = "IPV4_IPV6"
}

resource "google_compute_network" "network1" {
name = "network1"
auto_create_subnetworks = false
Expand Down Expand Up @@ -150,6 +171,13 @@ The following arguments are supported:
(Optional)
An optional description of this resource.

* `stack_type` -
(Optional)
The stack type for this VPN gateway to identify the IP protocols that are enbaled.
If not specified, IPV4_ONLY will be used.
Default value is `IPV4_ONLY`.
Possible values are `IPV4_ONLY` and `IPV4_IPV6`.

* `vpn_interfaces` -
(Optional)
A list of interfaces on this VPN gateway.
Expand Down