@@ -14118,6 +14118,208 @@ resource "google_container_cluster" "primary" {
1411814118`, secretID, clusterName, customDomain, networkName, subnetworkName)
1411914119}
1412014120
14121+ func TestAccContainerCluster_writableCgroups(t *testing.T) {
14122+ t.Parallel()
14123+
14124+ clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
14125+ nodePoolName := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10))
14126+ networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
14127+ subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
14128+
14129+ acctest.VcrTest(t, resource.TestCase{
14130+ PreCheck: func() { acctest.AccTestPreCheck(t) },
14131+ ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
14132+ CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
14133+ Steps: []resource.TestStep{
14134+ // Test enabling writable_cgroups for new node pools via node_pool_defaults.
14135+ {
14136+ Config: testAccContainerCluster_writableCgroupsEnabled(clusterName, networkName, subnetworkName),
14137+ Check: resource.ComposeAggregateTestCheckFunc(
14138+ resource.TestCheckResourceAttr(
14139+ "google_container_cluster.primary",
14140+ "node_pool_defaults.0.node_config_defaults.0.containerd_config.0.writable_cgroups.0.enabled",
14141+ "true",
14142+ ),
14143+ ),
14144+ },
14145+ {
14146+ ResourceName: "google_container_cluster.primary",
14147+ ImportState: true,
14148+ ImportStateVerify: true,
14149+ ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
14150+ },
14151+ // Test disabling writable_cgroups for new node pools via node_pool_defaults.
14152+ {
14153+ Config: testAccContainerCluster_writableCgroupsDisabled(clusterName, networkName, subnetworkName),
14154+ ConfigPlanChecks: resource.ConfigPlanChecks{
14155+ PreApply: []plancheck.PlanCheck{
14156+ acctest.ExpectNoDelete(),
14157+ },
14158+ },
14159+ Check: resource.ComposeAggregateTestCheckFunc(
14160+ resource.TestCheckResourceAttr(
14161+ "google_container_cluster.primary",
14162+ "node_pool_defaults.0.node_config_defaults.0.containerd_config.0.writable_cgroups.0.enabled",
14163+ "false",
14164+ ),
14165+ ),
14166+ },
14167+ {
14168+ ResourceName: "google_container_cluster.primary",
14169+ ImportState: true,
14170+ ImportStateVerify: true,
14171+ ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
14172+ },
14173+ // Test configuring writable_cgroups on the cluster's default node pool directly via node_config.
14174+ {
14175+ Config: testAccContainerCluster_withNodeConfigWritableCgroups(clusterName, networkName, subnetworkName),
14176+ ConfigPlanChecks: resource.ConfigPlanChecks{
14177+ PreApply: []plancheck.PlanCheck{
14178+ acctest.ExpectNoDelete(),
14179+ },
14180+ },
14181+ Check: resource.ComposeAggregateTestCheckFunc(
14182+ resource.TestCheckResourceAttr(
14183+ "google_container_cluster.primary",
14184+ "node_config.0.containerd_config.0.writable_cgroups.0.enabled",
14185+ "true",
14186+ ),
14187+ ),
14188+ },
14189+ {
14190+ ResourceName: "google_container_cluster.primary",
14191+ ImportState: true,
14192+ ImportStateVerify: true,
14193+ ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
14194+ },
14195+ // Test configuring writable_cgroups on a named node pool defined within the cluster.
14196+ // This change from a default to a named node pool is expected to force recreation.
14197+ {
14198+ Config: testAccContainerCluster_withNodePoolWritableCgroups(clusterName, nodePoolName, networkName, subnetworkName),
14199+ },
14200+ {
14201+ ResourceName: "google_container_cluster.primary",
14202+ ImportState: true,
14203+ ImportStateVerify: true,
14204+ ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
14205+ },
14206+ },
14207+ })
14208+ }
14209+
14210+ func testAccContainerCluster_writableCgroupsEnabled(clusterName, networkName, subnetworkName string) string {
14211+ return fmt.Sprintf(`
14212+ data "google_container_engine_versions" "central1a" {
14213+ location = "us-central1-a"
14214+ }
14215+
14216+ resource "google_container_cluster" "primary" {
14217+ name = "%s"
14218+ location = "us-central1-a"
14219+ initial_node_count = 1
14220+ min_master_version = data.google_container_engine_versions.central1a.release_channel_latest_version["RAPID"]
14221+ network = "%s"
14222+ subnetwork = "%s"
14223+ deletion_protection = false
14224+
14225+ node_pool_defaults {
14226+ node_config_defaults {
14227+ containerd_config {
14228+ writable_cgroups {
14229+ enabled = true
14230+ }
14231+ }
14232+ }
14233+ }
14234+ }
14235+ `, clusterName, networkName, subnetworkName)
14236+ }
14237+
14238+ func testAccContainerCluster_writableCgroupsDisabled(clusterName, networkName, subnetworkName string) string {
14239+ return fmt.Sprintf(`
14240+ data "google_container_engine_versions" "central1a" {
14241+ location = "us-central1-a"
14242+ }
14243+
14244+ resource "google_container_cluster" "primary" {
14245+ name = "%s"
14246+ location = "us-central1-a"
14247+ initial_node_count = 1
14248+ min_master_version = data.google_container_engine_versions.central1a.release_channel_latest_version["RAPID"]
14249+ network = "%s"
14250+ subnetwork = "%s"
14251+ deletion_protection = false
14252+
14253+ node_pool_defaults {
14254+ node_config_defaults {
14255+ containerd_config {
14256+ writable_cgroups {
14257+ enabled = false
14258+ }
14259+ }
14260+ }
14261+ }
14262+ }
14263+ `, clusterName, networkName, subnetworkName)
14264+ }
14265+
14266+ func testAccContainerCluster_withNodePoolWritableCgroups(clusterName, nodePoolName, networkName, subnetworkName string) string {
14267+ return fmt.Sprintf(`
14268+ data "google_container_engine_versions" "central1a" {
14269+ location = "us-central1-a"
14270+ }
14271+
14272+ resource "google_container_cluster" "primary" {
14273+ name = "%s"
14274+ location = "us-central1-a"
14275+ min_master_version = data.google_container_engine_versions.central1a.release_channel_latest_version["RAPID"]
14276+ network = "%s"
14277+ subnetwork = "%s"
14278+ deletion_protection = false
14279+
14280+ node_pool {
14281+ name = "%s"
14282+ initial_node_count = 1
14283+ node_config {
14284+ containerd_config {
14285+ writable_cgroups {
14286+ enabled = true
14287+ }
14288+ }
14289+ }
14290+ }
14291+
14292+ }
14293+ `, clusterName, networkName, subnetworkName, nodePoolName)
14294+ }
14295+
14296+ func testAccContainerCluster_withNodeConfigWritableCgroups(clusterName, networkName, subnetworkName string) string {
14297+ return fmt.Sprintf(`
14298+ data "google_container_engine_versions" "central1a" {
14299+ location = "us-central1-a"
14300+ }
14301+
14302+ resource "google_container_cluster" "primary" {
14303+ name = "%s"
14304+ location = "us-central1-a"
14305+ initial_node_count = 1
14306+ min_master_version = data.google_container_engine_versions.central1a.release_channel_latest_version["RAPID"]
14307+ network = "%s"
14308+ subnetwork = "%s"
14309+ deletion_protection = false
14310+
14311+ node_config {
14312+ containerd_config {
14313+ writable_cgroups {
14314+ enabled = true
14315+ }
14316+ }
14317+ }
14318+
14319+ }
14320+ `, clusterName, networkName, subnetworkName)
14321+ }
14322+
1412114323func TestAccContainerCluster_withProviderDefaultLabels(t *testing.T) {
1412214324 // The test failed if VCR testing is enabled, because the cached provider config is used.
1412314325 // With the cached provider config, any changes in the provider default labels will not be applied.
@@ -15734,4 +15936,4 @@ resource "google_container_cluster" "with_kubelet_config" {
1573415936 }
1573515937}
1573615938`, clusterName, networkName, subnetworkName, npName, npName)
15737- }
15939+ }
0 commit comments