Skip to content

Commit 83f87df

Browse files
Make compute subnetwork ipv6_access_type field updatable (#6928) (#13211)
fixes #12860 Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent 5c2c295 commit 83f87df

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

.changelog/6928.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: Made subnetwork ipv6_access_type field updatable
3+
```

google/resource_compute_subnetwork.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ creation time.`,
111111
"ipv6_access_type": {
112112
Type: schema.TypeString,
113113
Optional: true,
114-
ForceNew: true,
115114
ValidateFunc: validateEnum([]string{"EXTERNAL", "INTERNAL", ""}),
116115
Description: `The access type of IPv6 address this subnet holds. It's immutable and can only be specified during creation
117116
or the first time the subnet is updated into IPV4_IPV6 dual stack. If the ipv6_type is EXTERNAL then this subnet
@@ -661,7 +660,7 @@ func resourceComputeSubnetworkUpdate(d *schema.ResourceData, meta interface{}) e
661660
return err
662661
}
663662
}
664-
if d.HasChange("private_ipv6_google_access") || d.HasChange("stack_type") {
663+
if d.HasChange("private_ipv6_google_access") || d.HasChange("stack_type") || d.HasChange("ipv6_access_type") {
665664
obj := make(map[string]interface{})
666665

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

697702
url, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/subnetworks/{{name}}")
698703
if err != nil {

google/resource_compute_subnetwork_test.go

+65
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,37 @@ func TestAccComputeSubnetwork_flowLogsMigrate(t *testing.T) {
331331
})
332332
}
333333

334+
func TestAccComputeSubnetwork_ipv6(t *testing.T) {
335+
t.Parallel()
336+
337+
cnName := fmt.Sprintf("tf-test-%s", randString(t, 10))
338+
subnetworkName := fmt.Sprintf("tf-test-%s", randString(t, 10))
339+
340+
vcrTest(t, resource.TestCase{
341+
PreCheck: func() { testAccPreCheck(t) },
342+
Providers: testAccProviders,
343+
CheckDestroy: testAccCheckComputeSubnetworkDestroyProducer(t),
344+
Steps: []resource.TestStep{
345+
{
346+
Config: testAccComputeSubnetwork_ipv4(cnName, subnetworkName),
347+
},
348+
{
349+
ResourceName: "google_compute_subnetwork.subnetwork",
350+
ImportState: true,
351+
ImportStateVerify: true,
352+
},
353+
{
354+
Config: testAccComputeSubnetwork_ipv6(cnName, subnetworkName),
355+
},
356+
{
357+
ResourceName: "google_compute_subnetwork.subnetwork",
358+
ImportState: true,
359+
ImportStateVerify: true,
360+
},
361+
},
362+
})
363+
}
364+
334365
func testAccCheckComputeSubnetworkExists(t *testing.T, n string, subnetwork *compute.Subnetwork) resource.TestCheckFunc {
335366
return func(s *terraform.State) error {
336367
rs, ok := s.RootModule().Resources[n]
@@ -728,3 +759,37 @@ resource "google_compute_subnetwork" "network-with-flow-logs" {
728759
}
729760
`, cnName, subnetworkName)
730761
}
762+
763+
func testAccComputeSubnetwork_ipv4(cnName, subnetworkName string) string {
764+
return fmt.Sprintf(`
765+
resource "google_compute_network" "custom-test" {
766+
name = "%s"
767+
auto_create_subnetworks = false
768+
}
769+
770+
resource "google_compute_subnetwork" "subnetwork" {
771+
name = "%s"
772+
ip_cidr_range = "10.0.0.0/16"
773+
region = "us-central1"
774+
network = google_compute_network.custom-test.self_link
775+
}
776+
`, cnName, subnetworkName)
777+
}
778+
779+
func testAccComputeSubnetwork_ipv6(cnName, subnetworkName string) string {
780+
return fmt.Sprintf(`
781+
resource "google_compute_network" "custom-test" {
782+
name = "%s"
783+
auto_create_subnetworks = false
784+
}
785+
786+
resource "google_compute_subnetwork" "subnetwork" {
787+
name = "%s"
788+
ip_cidr_range = "10.0.0.0/16"
789+
region = "us-central1"
790+
network = google_compute_network.custom-test.self_link
791+
stack_type = "IPV4_IPV6"
792+
ipv6_access_type = "EXTERNAL"
793+
}
794+
`, cnName, subnetworkName)
795+
}

0 commit comments

Comments
 (0)