Skip to content

Commit

Permalink
Fix diff suppress function ignoring additive_vpc_scope_dns_domain in …
Browse files Browse the repository at this point in the history
…Autopilot clusters
  • Loading branch information
Michcioperz committed Dec 13, 2024
1 parent 3b3cb68 commit df4d706
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ var (
}

suppressDiffForAutopilot = schema.SchemaDiffSuppressFunc(func(k, oldValue, newValue string, d *schema.ResourceData) bool {
if v, _ := d.Get("enable_autopilot").(bool); v {
if v, _ := d.Get("enable_autopilot").(bool); v && k != "dns_config.#" && k != "dns_config.0.additive_vpc_scope_dns_domain" {
return true
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5798,6 +5798,117 @@ func TestAccContainerCluster_autopilot_minimal(t *testing.T) {
})
}

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

clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_autopilot_withDNSConfig(clusterName, true, false, false, ""),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
{
Config: testAccContainerCluster_autopilot_withDNSConfig(clusterName, true, true, false, ""),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
{
Config: testAccContainerCluster_autopilot_withDNSConfig(clusterName, true, false, true, ""),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
{
Config: testAccContainerCluster_autopilot_withDNSConfig(clusterName, true, true, true, ""),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
},
})
}

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

domain := "additive.autopilot.example"
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_autopilot_withDNSConfig(clusterName, true, false, false, domain),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("google_container_cluster.primary", "dns_config.0.additive_vpc_scope_dns_domain", domain),
),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
{
Config: testAccContainerCluster_autopilot_withDNSConfig(clusterName, true, true, false, domain),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("google_container_cluster.primary", "dns_config.0.additive_vpc_scope_dns_domain", domain),
),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
{
Config: testAccContainerCluster_autopilot_withDNSConfig(clusterName, true, false, true, domain),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("google_container_cluster.primary", "dns_config.0.additive_vpc_scope_dns_domain", domain),
),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
{
Config: testAccContainerCluster_autopilot_withDNSConfig(clusterName, true, true, true, domain),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("google_container_cluster.primary", "dns_config.0.additive_vpc_scope_dns_domain", domain),
),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
},
})
}

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

Expand Down Expand Up @@ -11035,6 +11146,42 @@ resource "google_container_cluster" "primary" {
}`, name)
}

func testAccContainerCluster_autopilot_withDNSConfig(name string, dnsConfigSectionPresent, clusterDnsPresent, clusterDnsScopePresent bool, additiveVpcDnsDomain string) string {
config := fmt.Sprintf(`
resource "google_container_cluster" "primary" {
name = "%s"
location = "us-central1"
enable_autopilot = true
deletion_protection = false
`, name)
if dnsConfigSectionPresent {
config += `
dns_config {
`
if clusterDnsPresent {
config += `
cluster_dns = "CLOUD_DNS"
`
}
if clusterDnsScopePresent {
config += `
cluster_dns_scope = "CLUSTER_SCOPE"
`
}
if additiveVpcDnsDomain != "" {
config += fmt.Sprintf(`
additive_vpc_scope_dns_domain = "%s"
`, additiveVpcDnsDomain)
}
config += `
}
`
}
config += `
}`
return config
}

func testAccContainerCluster_autopilot_net_admin(name, networkName, subnetworkName string, enabled bool) string {
return fmt.Sprintf(`
resource "google_container_cluster" "primary" {
Expand Down

0 comments on commit df4d706

Please sign in to comment.