Skip to content

Commit d666200

Browse files
Allow setting both enable_autopilot and workload_identity_config in google_container_cluster resource (#10691) (#18166)
[upstream:432c55f6cacb487e8bf9a17a9460f6a1bc17af48] Signed-off-by: Modular Magician <[email protected]>
1 parent befd4e8 commit d666200

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

google/services/container/resource_container_cluster.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1616,9 +1616,8 @@ func ResourceContainerCluster() *schema.Resource {
16161616
// Computed is unsafe to remove- this API may return `"workloadIdentityConfig": {},` or omit the key entirely
16171617
// and both will be valid. Note that we don't handle the case where the API returns nothing & the user has defined
16181618
// workload_identity_config today.
1619-
Computed: true,
1620-
Description: `Configuration for the use of Kubernetes Service Accounts in GCP IAM policies.`,
1621-
ConflictsWith: []string{"enable_autopilot"},
1619+
Computed: true,
1620+
Description: `Configuration for the use of Kubernetes Service Accounts in GCP IAM policies.`,
16221621
Elem: &schema.Resource{
16231622
Schema: map[string]*schema.Schema{
16241623
"workload_pool": {

google/services/container/resource_container_cluster_test.go

+44
Original file line numberDiff line numberDiff line change
@@ -2725,6 +2725,30 @@ func TestAccContainerCluster_withWorkloadIdentityConfig(t *testing.T) {
27252725
})
27262726
}
27272727

2728+
func TestAccContainerCluster_withWorkloadIdentityConfigAutopilot(t *testing.T) {
2729+
t.Parallel()
2730+
2731+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
2732+
pid := envvar.GetTestProjectFromEnv()
2733+
2734+
acctest.VcrTest(t, resource.TestCase{
2735+
PreCheck: func() { acctest.AccTestPreCheck(t) },
2736+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
2737+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
2738+
Steps: []resource.TestStep{
2739+
{
2740+
Config: testAccContainerCluster_withWorkloadIdentityConfigEnabledAutopilot(pid, clusterName),
2741+
},
2742+
{
2743+
ResourceName: "google_container_cluster.with_workload_identity_config",
2744+
ImportState: true,
2745+
ImportStateVerify: true,
2746+
ImportStateVerifyIgnore: []string{"remove_default_node_pool", "deletion_protection"},
2747+
},
2748+
},
2749+
})
2750+
}
2751+
27282752
func TestAccContainerCluster_withIdentityServiceConfig(t *testing.T) {
27292753
t.Parallel()
27302754

@@ -7328,6 +7352,26 @@ resource "google_container_cluster" "with_workload_identity_config" {
73287352
`, projectID, clusterName, networkName, subnetworkName)
73297353
}
73307354

7355+
func testAccContainerCluster_withWorkloadIdentityConfigEnabledAutopilot(projectID string, clusterName string) string {
7356+
return fmt.Sprintf(`
7357+
data "google_project" "project" {
7358+
project_id = "%s"
7359+
}
7360+
7361+
resource "google_container_cluster" "with_workload_identity_config" {
7362+
name = "%s"
7363+
location = "us-central1"
7364+
initial_node_count = 1
7365+
7366+
workload_identity_config {
7367+
workload_pool = "${data.google_project.project.project_id}.svc.id.goog"
7368+
}
7369+
enable_autopilot = true
7370+
deletion_protection = false
7371+
}
7372+
`, projectID, clusterName)
7373+
}
7374+
73317375
func testAccContainerCluster_updateWorkloadIdentityConfig(projectID, clusterName, networkName, subnetworkName string, enable bool) string {
73327376
workloadIdentityConfig := ""
73337377
if enable {

0 commit comments

Comments
 (0)