Skip to content

Commit

Permalink
Make compute subnetwork ipv6_access_type field updatable (#6928) (#13211
Browse files Browse the repository at this point in the history
)

fixes #12860

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Dec 9, 2022
1 parent 5c2c295 commit 83f87df
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
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)
}

0 comments on commit 83f87df

Please sign in to comment.