Skip to content

Commit

Permalink
Allow setting both enable_autopilot and workload_identity_config in g…
Browse files Browse the repository at this point in the history
…oogle_container_cluster resource (#10691) (#18166)

[upstream:432c55f6cacb487e8bf9a17a9460f6a1bc17af48]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed May 16, 2024
1 parent befd4e8 commit d666200
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
5 changes: 2 additions & 3 deletions google/services/container/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1616,9 +1616,8 @@ func ResourceContainerCluster() *schema.Resource {
// Computed is unsafe to remove- this API may return `"workloadIdentityConfig": {},` or omit the key entirely
// and both will be valid. Note that we don't handle the case where the API returns nothing & the user has defined
// workload_identity_config today.
Computed: true,
Description: `Configuration for the use of Kubernetes Service Accounts in GCP IAM policies.`,
ConflictsWith: []string{"enable_autopilot"},
Computed: true,
Description: `Configuration for the use of Kubernetes Service Accounts in GCP IAM policies.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"workload_pool": {
Expand Down
44 changes: 44 additions & 0 deletions google/services/container/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2725,6 +2725,30 @@ func TestAccContainerCluster_withWorkloadIdentityConfig(t *testing.T) {
})
}

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

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

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withWorkloadIdentityConfigEnabledAutopilot(pid, clusterName),
},
{
ResourceName: "google_container_cluster.with_workload_identity_config",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"remove_default_node_pool", "deletion_protection"},
},
},
})
}

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

Expand Down Expand Up @@ -7328,6 +7352,26 @@ resource "google_container_cluster" "with_workload_identity_config" {
`, projectID, clusterName, networkName, subnetworkName)
}

func testAccContainerCluster_withWorkloadIdentityConfigEnabledAutopilot(projectID string, clusterName string) string {
return fmt.Sprintf(`
data "google_project" "project" {
project_id = "%s"
}
resource "google_container_cluster" "with_workload_identity_config" {
name = "%s"
location = "us-central1"
initial_node_count = 1
workload_identity_config {
workload_pool = "${data.google_project.project.project_id}.svc.id.goog"
}
enable_autopilot = true
deletion_protection = false
}
`, projectID, clusterName)
}

func testAccContainerCluster_updateWorkloadIdentityConfig(projectID, clusterName, networkName, subnetworkName string, enable bool) string {
workloadIdentityConfig := ""
if enable {
Expand Down

0 comments on commit d666200

Please sign in to comment.