Skip to content

Commit

Permalink
container: add support for autopilot to set gcp_filestore_csi_driver_…
Browse files Browse the repository at this point in the history
…config in addons config (GoogleCloudPlatform#11748)
  • Loading branch information
philipsabri authored Sep 23, 2024
1 parent 99c4ab8 commit d43e652
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,7 @@ func ResourceContainerCluster() *schema.Resource {
Computed: true,
AtLeastOneOf: addonsConfigKeys,
MaxItems: 1,
Description: `The status of the Filestore CSI driver addon, which allows the usage of filestore instance as volumes. Defaults to disabled; set enabled = true to enable.`,
ConflictsWith: []string{"enable_autopilot"},
Description: `The status of the Filestore CSI driver addon, which allows the usage of filestore instance as volumes. Defaults to disabled for Standard clusters; set enabled = true to enable. It is enabled by default for Autopilot clusters; set enabled = true to enable it explicitly.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ func resourceContainerClusterResourceV1() *schema.Resource {
Computed: true,
AtLeastOneOf: addonsConfigKeys,
MaxItems: 1,
Description: `The status of the Filestore CSI driver addon, which allows the usage of filestore instance as volumes. Defaults to disabled; set enabled = true to enable.`,
ConflictsWith: []string{"enable_autopilot"},
Description: `The status of the Filestore CSI driver addon, which allows the usage of filestore instance as volumes. Defaults to disabled for Standard clusters; set enabled = true to enable. It is enabled by default for Autopilot clusters; set enabled = true to enable it explicitly.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11816,3 +11816,69 @@ func extractSPName(url string) (string, error) {
}
}

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

randomSuffix := acctest.RandString(t, 10)
clusterName := fmt.Sprintf("tf-test-cluster-%s", randomSuffix)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
ExternalProviders: map[string]resource.ExternalProvider{
"time": {},
},
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withAutopilotGcpFilestoreCsiDriverDefault(clusterName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("google_container_cluster.with_autopilot_gcp_filestore", "addons_config.0.gcp_filestore_csi_driver_config.0.enabled", "true"),
),
},
{
ResourceName: "google_container_cluster.with_autopilot_gcp_filestore",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
{
Config: testAccContainerCluster_withAutopilotGcpFilestoreCsiDriverUpdated(clusterName),
},
{
ResourceName: "google_container_cluster.with_autopilot_gcp_filestore",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{ "deletion_protection"},
},
},
})
}

func testAccContainerCluster_withAutopilotGcpFilestoreCsiDriverDefault(name string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_autopilot_gcp_filestore" {
name = "%s"
location = "us-central1"
enable_autopilot = true
deletion_protection = false
}
`, name)
}

func testAccContainerCluster_withAutopilotGcpFilestoreCsiDriverUpdated(name string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_autopilot_gcp_filestore" {
name = "%s"
location = "us-central1"
enable_autopilot = true
deletion_protection = false

addons_config {
gcp_filestore_csi_driver_config {
enabled = false
}
}
}
`, name)
}

0 comments on commit d43e652

Please sign in to comment.