Skip to content

Commit df4d706

Browse files
committed
Fix diff suppress function ignoring additive_vpc_scope_dns_domain in Autopilot clusters
1 parent 3b3cb68 commit df4d706

File tree

2 files changed

+148
-1
lines changed

2 files changed

+148
-1
lines changed

mmv1/third_party/terraform/services/container/resource_container_cluster.go.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ var (
112112
}
113113

114114
suppressDiffForAutopilot = schema.SchemaDiffSuppressFunc(func(k, oldValue, newValue string, d *schema.ResourceData) bool {
115-
if v, _ := d.Get("enable_autopilot").(bool); v {
115+
if v, _ := d.Get("enable_autopilot").(bool); v && k != "dns_config.#" && k != "dns_config.0.additive_vpc_scope_dns_domain" {
116116
return true
117117
}
118118
return false

mmv1/third_party/terraform/services/container/resource_container_cluster_test.go.tmpl

+147
Original file line numberDiff line numberDiff line change
@@ -5798,6 +5798,117 @@ func TestAccContainerCluster_autopilot_minimal(t *testing.T) {
57985798
})
57995799
}
58005800

5801+
func TestAccContainerCluster_autopilot_withDNSConfig(t *testing.T) {
5802+
t.Parallel()
5803+
5804+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
5805+
acctest.VcrTest(t, resource.TestCase{
5806+
PreCheck: func() { acctest.AccTestPreCheck(t) },
5807+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
5808+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
5809+
Steps: []resource.TestStep{
5810+
{
5811+
Config: testAccContainerCluster_autopilot_withDNSConfig(clusterName, true, false, false, ""),
5812+
},
5813+
{
5814+
ResourceName: "google_container_cluster.primary",
5815+
ImportState: true,
5816+
ImportStateVerify: true,
5817+
ImportStateVerifyIgnore: []string{"deletion_protection"},
5818+
},
5819+
{
5820+
Config: testAccContainerCluster_autopilot_withDNSConfig(clusterName, true, true, false, ""),
5821+
},
5822+
{
5823+
ResourceName: "google_container_cluster.primary",
5824+
ImportState: true,
5825+
ImportStateVerify: true,
5826+
ImportStateVerifyIgnore: []string{"deletion_protection"},
5827+
},
5828+
{
5829+
Config: testAccContainerCluster_autopilot_withDNSConfig(clusterName, true, false, true, ""),
5830+
},
5831+
{
5832+
ResourceName: "google_container_cluster.primary",
5833+
ImportState: true,
5834+
ImportStateVerify: true,
5835+
ImportStateVerifyIgnore: []string{"deletion_protection"},
5836+
},
5837+
{
5838+
Config: testAccContainerCluster_autopilot_withDNSConfig(clusterName, true, true, true, ""),
5839+
},
5840+
{
5841+
ResourceName: "google_container_cluster.primary",
5842+
ImportState: true,
5843+
ImportStateVerify: true,
5844+
ImportStateVerifyIgnore: []string{"deletion_protection"},
5845+
},
5846+
},
5847+
})
5848+
}
5849+
5850+
func TestAccContainerCluster_autopilot_withAdditiveVPC(t *testing.T) {
5851+
t.Parallel()
5852+
5853+
domain := "additive.autopilot.example"
5854+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
5855+
acctest.VcrTest(t, resource.TestCase{
5856+
PreCheck: func() { acctest.AccTestPreCheck(t) },
5857+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
5858+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
5859+
Steps: []resource.TestStep{
5860+
{
5861+
Config: testAccContainerCluster_autopilot_withDNSConfig(clusterName, true, false, false, domain),
5862+
Check: resource.ComposeTestCheckFunc(
5863+
resource.TestCheckResourceAttr("google_container_cluster.primary", "dns_config.0.additive_vpc_scope_dns_domain", domain),
5864+
),
5865+
},
5866+
{
5867+
ResourceName: "google_container_cluster.primary",
5868+
ImportState: true,
5869+
ImportStateVerify: true,
5870+
ImportStateVerifyIgnore: []string{"deletion_protection"},
5871+
},
5872+
{
5873+
Config: testAccContainerCluster_autopilot_withDNSConfig(clusterName, true, true, false, domain),
5874+
Check: resource.ComposeTestCheckFunc(
5875+
resource.TestCheckResourceAttr("google_container_cluster.primary", "dns_config.0.additive_vpc_scope_dns_domain", domain),
5876+
),
5877+
},
5878+
{
5879+
ResourceName: "google_container_cluster.primary",
5880+
ImportState: true,
5881+
ImportStateVerify: true,
5882+
ImportStateVerifyIgnore: []string{"deletion_protection"},
5883+
},
5884+
{
5885+
Config: testAccContainerCluster_autopilot_withDNSConfig(clusterName, true, false, true, domain),
5886+
Check: resource.ComposeTestCheckFunc(
5887+
resource.TestCheckResourceAttr("google_container_cluster.primary", "dns_config.0.additive_vpc_scope_dns_domain", domain),
5888+
),
5889+
},
5890+
{
5891+
ResourceName: "google_container_cluster.primary",
5892+
ImportState: true,
5893+
ImportStateVerify: true,
5894+
ImportStateVerifyIgnore: []string{"deletion_protection"},
5895+
},
5896+
{
5897+
Config: testAccContainerCluster_autopilot_withDNSConfig(clusterName, true, true, true, domain),
5898+
Check: resource.ComposeTestCheckFunc(
5899+
resource.TestCheckResourceAttr("google_container_cluster.primary", "dns_config.0.additive_vpc_scope_dns_domain", domain),
5900+
),
5901+
},
5902+
{
5903+
ResourceName: "google_container_cluster.primary",
5904+
ImportState: true,
5905+
ImportStateVerify: true,
5906+
ImportStateVerifyIgnore: []string{"deletion_protection"},
5907+
},
5908+
},
5909+
})
5910+
}
5911+
58015912
func TestAccContainerCluster_autopilot_net_admin(t *testing.T) {
58025913
t.Parallel()
58035914

@@ -11035,6 +11146,42 @@ resource "google_container_cluster" "primary" {
1103511146
}`, name)
1103611147
}
1103711148

11149+
func testAccContainerCluster_autopilot_withDNSConfig(name string, dnsConfigSectionPresent, clusterDnsPresent, clusterDnsScopePresent bool, additiveVpcDnsDomain string) string {
11150+
config := fmt.Sprintf(`
11151+
resource "google_container_cluster" "primary" {
11152+
name = "%s"
11153+
location = "us-central1"
11154+
enable_autopilot = true
11155+
deletion_protection = false
11156+
`, name)
11157+
if dnsConfigSectionPresent {
11158+
config += `
11159+
dns_config {
11160+
`
11161+
if clusterDnsPresent {
11162+
config += `
11163+
cluster_dns = "CLOUD_DNS"
11164+
`
11165+
}
11166+
if clusterDnsScopePresent {
11167+
config += `
11168+
cluster_dns_scope = "CLUSTER_SCOPE"
11169+
`
11170+
}
11171+
if additiveVpcDnsDomain != "" {
11172+
config += fmt.Sprintf(`
11173+
additive_vpc_scope_dns_domain = "%s"
11174+
`, additiveVpcDnsDomain)
11175+
}
11176+
config += `
11177+
}
11178+
`
11179+
}
11180+
config += `
11181+
}`
11182+
return config
11183+
}
11184+
1103811185
func testAccContainerCluster_autopilot_net_admin(name, networkName, subnetworkName string, enabled bool) string {
1103911186
return fmt.Sprintf(`
1104011187
resource "google_container_cluster" "primary" {

0 commit comments

Comments
 (0)