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 16, 2024
1 parent 5e6616b commit 5fc163d
Show file tree
Hide file tree
Showing 2 changed files with 207 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ var (

suppressDiffForAutopilot = schema.SchemaDiffSuppressFunc(func(k, oldValue, newValue string, d *schema.ResourceData) bool {
if v, _ := d.Get("enable_autopilot").(bool); v {
if k == "dns_config.0.additive_vpc_scope_dns_domain" {
return false
}
if k == "dns_config.#" {
if avpcDomain, _ := d.Get("dns_config.0.additive_vpc_scope_dns_domain").(string); avpcDomain != "" || d.HasChange("dns_config.0.additive_vpc_scope_dns_domain") {
return false
}
}
return true
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5798,6 +5798,169 @@ 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_withAdditiveVPCMutation(t *testing.T) {
t.Parallel()

domain := "additive-mutating.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, ""),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("google_container_cluster.primary", "dns_config.0.additive_vpc_scope_dns_domain", ""),
),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
{
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),
),
ConfigPlanChecks: resource.ConfigPlanChecks{PreApply: []plancheck.PlanCheck{plancheck.ExpectResourceAction("google_container_cluster.primary", plancheck.ResourceActionReplace)}},
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
{
Config: testAccContainerCluster_autopilot_withDNSConfig(clusterName, true, false, false, ""),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("google_container_cluster.primary", "dns_config.0.additive_vpc_scope_dns_domain", ""),
),
ConfigPlanChecks: resource.ConfigPlanChecks{PreApply: []plancheck.PlanCheck{plancheck.ExpectResourceAction("google_container_cluster.primary", plancheck.ResourceActionReplace)}},
},
{
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 +11198,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 5fc163d

Please sign in to comment.