@@ -5798,6 +5798,169 @@ func TestAccContainerCluster_autopilot_minimal(t *testing.T) {
5798
5798
})
5799
5799
}
5800
5800
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
+
5912
+ func TestAccContainerCluster_autopilot_withAdditiveVPCMutation(t *testing.T) {
5913
+ t.Parallel()
5914
+
5915
+ domain := "additive-mutating.autopilot.example"
5916
+ clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
5917
+ acctest.VcrTest(t, resource.TestCase{
5918
+ PreCheck: func() { acctest.AccTestPreCheck(t) },
5919
+ ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
5920
+ CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
5921
+ Steps: []resource.TestStep{
5922
+ {
5923
+ Config: testAccContainerCluster_autopilot_withDNSConfig(clusterName, true, false, false, ""),
5924
+ Check: resource.ComposeTestCheckFunc(
5925
+ resource.TestCheckResourceAttr("google_container_cluster.primary", "dns_config.0.additive_vpc_scope_dns_domain", ""),
5926
+ ),
5927
+ },
5928
+ {
5929
+ ResourceName: "google_container_cluster.primary",
5930
+ ImportState: true,
5931
+ ImportStateVerify: true,
5932
+ ImportStateVerifyIgnore: []string{"deletion_protection"},
5933
+ },
5934
+ {
5935
+ Config: testAccContainerCluster_autopilot_withDNSConfig(clusterName, true, false, false, domain),
5936
+ Check: resource.ComposeTestCheckFunc(
5937
+ resource.TestCheckResourceAttr("google_container_cluster.primary", "dns_config.0.additive_vpc_scope_dns_domain", domain),
5938
+ ),
5939
+ ConfigPlanChecks: resource.ConfigPlanChecks{PreApply: []plancheck.PlanCheck{plancheck.ExpectResourceAction("google_container_cluster.primary", plancheck.ResourceActionReplace)}},
5940
+ },
5941
+ {
5942
+ ResourceName: "google_container_cluster.primary",
5943
+ ImportState: true,
5944
+ ImportStateVerify: true,
5945
+ ImportStateVerifyIgnore: []string{"deletion_protection"},
5946
+ },
5947
+ {
5948
+ Config: testAccContainerCluster_autopilot_withDNSConfig(clusterName, true, false, false, ""),
5949
+ Check: resource.ComposeTestCheckFunc(
5950
+ resource.TestCheckResourceAttr("google_container_cluster.primary", "dns_config.0.additive_vpc_scope_dns_domain", ""),
5951
+ ),
5952
+ ConfigPlanChecks: resource.ConfigPlanChecks{PreApply: []plancheck.PlanCheck{plancheck.ExpectResourceAction("google_container_cluster.primary", plancheck.ResourceActionReplace)}},
5953
+ },
5954
+ {
5955
+ ResourceName: "google_container_cluster.primary",
5956
+ ImportState: true,
5957
+ ImportStateVerify: true,
5958
+ ImportStateVerifyIgnore: []string{"deletion_protection"},
5959
+ },
5960
+ },
5961
+ })
5962
+ }
5963
+
5801
5964
func TestAccContainerCluster_autopilot_net_admin(t *testing.T) {
5802
5965
t.Parallel()
5803
5966
@@ -11035,6 +11198,42 @@ resource "google_container_cluster" "primary" {
11035
11198
}`, name)
11036
11199
}
11037
11200
11201
+ func testAccContainerCluster_autopilot_withDNSConfig(name string, dnsConfigSectionPresent, clusterDnsPresent, clusterDnsScopePresent bool, additiveVpcDnsDomain string) string {
11202
+ config := fmt.Sprintf(`
11203
+ resource "google_container_cluster" "primary" {
11204
+ name = "%s"
11205
+ location = "us-central1"
11206
+ enable_autopilot = true
11207
+ deletion_protection = false
11208
+ `, name)
11209
+ if dnsConfigSectionPresent {
11210
+ config += `
11211
+ dns_config {
11212
+ `
11213
+ if clusterDnsPresent {
11214
+ config += `
11215
+ cluster_dns = "CLOUD_DNS"
11216
+ `
11217
+ }
11218
+ if clusterDnsScopePresent {
11219
+ config += `
11220
+ cluster_dns_scope = "CLUSTER_SCOPE"
11221
+ `
11222
+ }
11223
+ if additiveVpcDnsDomain != "" {
11224
+ config += fmt.Sprintf(`
11225
+ additive_vpc_scope_dns_domain = "%s"
11226
+ `, additiveVpcDnsDomain)
11227
+ }
11228
+ config += `
11229
+ }
11230
+ `
11231
+ }
11232
+ config += `
11233
+ }`
11234
+ return config
11235
+ }
11236
+
11038
11237
func testAccContainerCluster_autopilot_net_admin(name, networkName, subnetworkName string, enabled bool) string {
11039
11238
return fmt.Sprintf(`
11040
11239
resource "google_container_cluster" "primary" {
0 commit comments