@@ -12932,6 +12932,208 @@ resource "google_container_cluster" "primary" {
1293212932` , secretID , clusterName , customDomain , networkName , subnetworkName )
1293312933}
1293412934
12935+ func TestAccContainerCluster_writableCgroups (t * testing.T ) {
12936+ t .Parallel ()
12937+
12938+ clusterName := fmt .Sprintf ("tf-test-cluster-%s" , acctest .RandString (t , 10 ))
12939+ nodePoolName := fmt .Sprintf ("tf-test-nodepool-%s" , acctest .RandString (t , 10 ))
12940+ networkName := acctest .BootstrapSharedTestNetwork (t , "gke-cluster" )
12941+ subnetworkName := acctest .BootstrapSubnet (t , "gke-cluster" , networkName )
12942+
12943+ acctest .VcrTest (t , resource.TestCase {
12944+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
12945+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
12946+ CheckDestroy : testAccCheckContainerClusterDestroyProducer (t ),
12947+ Steps : []resource.TestStep {
12948+ // Test enabling writable_cgroups for new node pools via node_pool_defaults.
12949+ {
12950+ Config : testAccContainerCluster_writableCgroupsEnabled (clusterName , networkName , subnetworkName ),
12951+ Check : resource .ComposeAggregateTestCheckFunc (
12952+ resource .TestCheckResourceAttr (
12953+ "google_container_cluster.primary" ,
12954+ "node_pool_defaults.0.node_config_defaults.0.containerd_config.0.writable_cgroups.0.enabled" ,
12955+ "true" ,
12956+ ),
12957+ ),
12958+ },
12959+ {
12960+ ResourceName : "google_container_cluster.primary" ,
12961+ ImportState : true ,
12962+ ImportStateVerify : true ,
12963+ ImportStateVerifyIgnore : []string {"min_master_version" , "deletion_protection" },
12964+ },
12965+ // Test disabling writable_cgroups for new node pools via node_pool_defaults.
12966+ {
12967+ Config : testAccContainerCluster_writableCgroupsDisabled (clusterName , networkName , subnetworkName ),
12968+ ConfigPlanChecks : resource.ConfigPlanChecks {
12969+ PreApply : []plancheck.PlanCheck {
12970+ acctest .ExpectNoDelete (),
12971+ },
12972+ },
12973+ Check : resource .ComposeAggregateTestCheckFunc (
12974+ resource .TestCheckResourceAttr (
12975+ "google_container_cluster.primary" ,
12976+ "node_pool_defaults.0.node_config_defaults.0.containerd_config.0.writable_cgroups.0.enabled" ,
12977+ "false" ,
12978+ ),
12979+ ),
12980+ },
12981+ {
12982+ ResourceName : "google_container_cluster.primary" ,
12983+ ImportState : true ,
12984+ ImportStateVerify : true ,
12985+ ImportStateVerifyIgnore : []string {"min_master_version" , "deletion_protection" },
12986+ },
12987+ // Test configuring writable_cgroups on the cluster's default node pool directly via node_config.
12988+ {
12989+ Config : testAccContainerCluster_withNodeConfigWritableCgroups (clusterName , networkName , subnetworkName ),
12990+ ConfigPlanChecks : resource.ConfigPlanChecks {
12991+ PreApply : []plancheck.PlanCheck {
12992+ acctest .ExpectNoDelete (),
12993+ },
12994+ },
12995+ Check : resource .ComposeAggregateTestCheckFunc (
12996+ resource .TestCheckResourceAttr (
12997+ "google_container_cluster.primary" ,
12998+ "node_config.0.containerd_config.0.writable_cgroups.0.enabled" ,
12999+ "true" ,
13000+ ),
13001+ ),
13002+ },
13003+ {
13004+ ResourceName : "google_container_cluster.primary" ,
13005+ ImportState : true ,
13006+ ImportStateVerify : true ,
13007+ ImportStateVerifyIgnore : []string {"min_master_version" , "deletion_protection" },
13008+ },
13009+ // Test configuring writable_cgroups on a named node pool defined within the cluster.
13010+ // This change from a default to a named node pool is expected to force recreation.
13011+ {
13012+ Config : testAccContainerCluster_withNodePoolWritableCgroups (clusterName , nodePoolName , networkName , subnetworkName ),
13013+ },
13014+ {
13015+ ResourceName : "google_container_cluster.primary" ,
13016+ ImportState : true ,
13017+ ImportStateVerify : true ,
13018+ ImportStateVerifyIgnore : []string {"min_master_version" , "deletion_protection" },
13019+ },
13020+ },
13021+ })
13022+ }
13023+
13024+ func testAccContainerCluster_writableCgroupsEnabled (clusterName , networkName , subnetworkName string ) string {
13025+ return fmt .Sprintf (`
13026+ data "google_container_engine_versions" "central1a" {
13027+ location = "us-central1-a"
13028+ }
13029+
13030+ resource "google_container_cluster" "primary" {
13031+ name = "%s"
13032+ location = "us-central1-a"
13033+ initial_node_count = 1
13034+ min_master_version = data.google_container_engine_versions.central1a.release_channel_latest_version["RAPID"]
13035+ network = "%s"
13036+ subnetwork = "%s"
13037+ deletion_protection = false
13038+
13039+ node_pool_defaults {
13040+ node_config_defaults {
13041+ containerd_config {
13042+ writable_cgroups {
13043+ enabled = true
13044+ }
13045+ }
13046+ }
13047+ }
13048+ }
13049+ ` , clusterName , networkName , subnetworkName )
13050+ }
13051+
13052+ func testAccContainerCluster_writableCgroupsDisabled (clusterName , networkName , subnetworkName string ) string {
13053+ return fmt .Sprintf (`
13054+ data "google_container_engine_versions" "central1a" {
13055+ location = "us-central1-a"
13056+ }
13057+
13058+ resource "google_container_cluster" "primary" {
13059+ name = "%s"
13060+ location = "us-central1-a"
13061+ initial_node_count = 1
13062+ min_master_version = data.google_container_engine_versions.central1a.release_channel_latest_version["RAPID"]
13063+ network = "%s"
13064+ subnetwork = "%s"
13065+ deletion_protection = false
13066+
13067+ node_pool_defaults {
13068+ node_config_defaults {
13069+ containerd_config {
13070+ writable_cgroups {
13071+ enabled = false
13072+ }
13073+ }
13074+ }
13075+ }
13076+ }
13077+ ` , clusterName , networkName , subnetworkName )
13078+ }
13079+
13080+ func testAccContainerCluster_withNodePoolWritableCgroups (clusterName , nodePoolName , networkName , subnetworkName string ) string {
13081+ return fmt .Sprintf (`
13082+ data "google_container_engine_versions" "central1a" {
13083+ location = "us-central1-a"
13084+ }
13085+
13086+ resource "google_container_cluster" "primary" {
13087+ name = "%s"
13088+ location = "us-central1-a"
13089+ min_master_version = data.google_container_engine_versions.central1a.release_channel_latest_version["RAPID"]
13090+ network = "%s"
13091+ subnetwork = "%s"
13092+ deletion_protection = false
13093+
13094+ node_pool {
13095+ name = "%s"
13096+ initial_node_count = 1
13097+ node_config {
13098+ containerd_config {
13099+ writable_cgroups {
13100+ enabled = true
13101+ }
13102+ }
13103+ }
13104+ }
13105+
13106+ }
13107+ ` , clusterName , networkName , subnetworkName , nodePoolName )
13108+ }
13109+
13110+ func testAccContainerCluster_withNodeConfigWritableCgroups (clusterName , networkName , subnetworkName string ) string {
13111+ return fmt .Sprintf (`
13112+ data "google_container_engine_versions" "central1a" {
13113+ location = "us-central1-a"
13114+ }
13115+
13116+ resource "google_container_cluster" "primary" {
13117+ name = "%s"
13118+ location = "us-central1-a"
13119+ initial_node_count = 1
13120+ min_master_version = data.google_container_engine_versions.central1a.release_channel_latest_version["RAPID"]
13121+ network = "%s"
13122+ subnetwork = "%s"
13123+ deletion_protection = false
13124+
13125+ node_config {
13126+ containerd_config {
13127+ writable_cgroups {
13128+ enabled = true
13129+ }
13130+ }
13131+ }
13132+
13133+ }
13134+ ` , clusterName , networkName , subnetworkName )
13135+ }
13136+
1293513137func TestAccContainerCluster_withProviderDefaultLabels (t * testing.T ) {
1293613138 // The test failed if VCR testing is enabled, because the cached provider config is used.
1293713139 // With the cached provider config, any changes in the provider default labels will not be applied.
0 commit comments