Skip to content

Commit 27d7a24

Browse files
jingjia-pengNA2047
authored andcommitted
fix: compute instance internal ipv6 prefix length is not set in creation and read in syncing (GoogleCloudPlatform#13133)
1 parent 21233a5 commit 27d7a24

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

mmv1/third_party/terraform/services/compute/compute_instance_helpers.go.tmpl

+2
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ func flattenNetworkInterfaces(d *schema.ResourceData, config *transport_tpg.Conf
508508
"ipv6_access_config": flattenIpv6AccessConfigs(iface.Ipv6AccessConfigs),
509509
"ipv6_address": iface.Ipv6Address,
510510
"queue_count": iface.QueueCount,
511+
"internal_ipv6_prefix_length": iface.InternalIpv6PrefixLength,
511512
}
512513
// Instance template interfaces never have names, so they're absent
513514
// in the instance template network_interface schema. We want to use the
@@ -627,6 +628,7 @@ func expandNetworkInterfaces(d tpgresource.TerraformResourceData, config *transp
627628
QueueCount: int64(data["queue_count"].(int)),
628629
Ipv6AccessConfigs: expandIpv6AccessConfigs(data["ipv6_access_config"].([]interface{})),
629630
Ipv6Address: data["ipv6_address"].(string),
631+
InternalIpv6PrefixLength: int64(data["internal_ipv6_prefix_length"].(int)),
630632
}
631633
}
632634
return ifaces, nil

mmv1/third_party/terraform/services/compute/resource_compute_instance_test.go.tmpl

+64
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,30 @@ func TestAccComputeInstance_internalIPv6(t *testing.T) {
587587
})
588588
}
589589

590+
func TestAccComputeInstance_internalIPv6PrefixLength(t *testing.T) {
591+
t.Parallel()
592+
593+
var instance compute.Instance
594+
var instanceName = fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
595+
596+
acctest.VcrTest(t, resource.TestCase{
597+
PreCheck: func() { acctest.AccTestPreCheck(t) },
598+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
599+
CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t),
600+
Steps: []resource.TestStep{
601+
{
602+
Config: testAccComputeInstance_internalIpv6PrefixLength("96", instanceName),
603+
Check: resource.ComposeTestCheckFunc(
604+
testAccCheckComputeInstanceExists(
605+
t, "google_compute_instance.foobar", &instance),
606+
testAccCheckComputeInstanceIpv6AccessConfigHasInternalIPv6(&instance),
607+
),
608+
},
609+
computeInstanceImportStep("us-west2-a", instanceName, []string{"allow_stopping_for_update"}),
610+
},
611+
})
612+
}
613+
590614
func TestAccComputeInstance_PTRRecord(t *testing.T) {
591615
t.Parallel()
592616

@@ -6224,6 +6248,46 @@ func testAccComputeInstance_internalIpv6(ip, instance string) string {
62246248
`, instance, instance, ip, instance)
62256249
}
62266250

6251+
func testAccComputeInstance_internalIpv6PrefixLength(length, instance string) string {
6252+
return fmt.Sprintf(`
6253+
resource "google_compute_network" "vpc" {
6254+
name = "%s-network"
6255+
auto_create_subnetworks = "false"
6256+
enable_ula_internal_ipv6 = true
6257+
}
6258+
6259+
resource "google_compute_subnetwork" "subnetwork" {
6260+
name = "%s-subnetwork"
6261+
ip_cidr_range = "10.0.0.0/22"
6262+
region = "us-west2"
6263+
stack_type = "IPV4_IPV6"
6264+
ipv6_access_type = "INTERNAL"
6265+
network = google_compute_network.vpc.id
6266+
}
6267+
6268+
resource "google_compute_instance" "foobar" {
6269+
name = "%s"
6270+
machine_type = "e2-micro"
6271+
allow_stopping_for_update = true
6272+
zone = "us-west2-a"
6273+
boot_disk {
6274+
auto_delete = false
6275+
initialize_params {
6276+
image = "debian-cloud/debian-11"
6277+
}
6278+
}
6279+
network_interface {
6280+
network = google_compute_network.vpc.self_link
6281+
subnetwork = google_compute_subnetwork.subnetwork.self_link
6282+
stack_type = "IPV4_IPV6"
6283+
access_config {
6284+
network_tier = "STANDARD"
6285+
}
6286+
internal_ipv6_prefix_length = %s
6287+
}
6288+
}
6289+
`, instance, instance, instance, length)
6290+
}
62276291
func testAccComputeInstance_ipv6ExternalReservation(instance string) string {
62286292
return fmt.Sprintf(`
62296293
resource "google_compute_address" "ipv6-address" {

0 commit comments

Comments
 (0)