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

Make compute subnetwork ipv6_access_type field updatable #13211

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/6928.txt
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: Made subnetwork ipv6_access_type field updatable
```
9 changes: 7 additions & 2 deletions google/resource_compute_subnetwork.go
Expand Up @@ -111,7 +111,6 @@ creation time.`,
"ipv6_access_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validateEnum([]string{"EXTERNAL", "INTERNAL", ""}),
Description: `The access type of IPv6 address this subnet holds. It's immutable and can only be specified during creation
or the first time the subnet is updated into IPV4_IPV6 dual stack. If the ipv6_type is EXTERNAL then this subnet
Expand Down Expand Up @@ -661,7 +660,7 @@ func resourceComputeSubnetworkUpdate(d *schema.ResourceData, meta interface{}) e
return err
}
}
if d.HasChange("private_ipv6_google_access") || d.HasChange("stack_type") {
if d.HasChange("private_ipv6_google_access") || d.HasChange("stack_type") || d.HasChange("ipv6_access_type") {
obj := make(map[string]interface{})

getUrl, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/subnetworks/{{name}}")
Expand Down Expand Up @@ -693,6 +692,12 @@ func resourceComputeSubnetworkUpdate(d *schema.ResourceData, meta interface{}) e
} else if v, ok := d.GetOkExists("stack_type"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, stackTypeProp)) {
obj["stackType"] = stackTypeProp
}
ipv6AccessTypeProp, err := expandComputeSubnetworkIpv6AccessType(d.Get("ipv6_access_type"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("ipv6_access_type"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, ipv6AccessTypeProp)) {
obj["ipv6AccessType"] = ipv6AccessTypeProp
}

url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/subnetworks/{{name}}")
if err != nil {
Expand Down
65 changes: 65 additions & 0 deletions google/resource_compute_subnetwork_test.go
Expand Up @@ -331,6 +331,37 @@ func TestAccComputeSubnetwork_flowLogsMigrate(t *testing.T) {
})
}

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

cnName := fmt.Sprintf("tf-test-%s", randString(t, 10))
subnetworkName := fmt.Sprintf("tf-test-%s", randString(t, 10))

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeSubnetworkDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeSubnetwork_ipv4(cnName, subnetworkName),
},
{
ResourceName: "google_compute_subnetwork.subnetwork",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeSubnetwork_ipv6(cnName, subnetworkName),
},
{
ResourceName: "google_compute_subnetwork.subnetwork",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckComputeSubnetworkExists(t *testing.T, n string, subnetwork *compute.Subnetwork) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -728,3 +759,37 @@ resource "google_compute_subnetwork" "network-with-flow-logs" {
}
`, cnName, subnetworkName)
}

func testAccComputeSubnetwork_ipv4(cnName, subnetworkName string) string {
return fmt.Sprintf(`
resource "google_compute_network" "custom-test" {
name = "%s"
auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "subnetwork" {
name = "%s"
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
network = google_compute_network.custom-test.self_link
}
`, cnName, subnetworkName)
}

func testAccComputeSubnetwork_ipv6(cnName, subnetworkName string) string {
return fmt.Sprintf(`
resource "google_compute_network" "custom-test" {
name = "%s"
auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "subnetwork" {
name = "%s"
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
network = google_compute_network.custom-test.self_link
stack_type = "IPV4_IPV6"
ipv6_access_type = "EXTERNAL"
}
`, cnName, subnetworkName)
}