Skip to content

Commit 5804f22

Browse files
[FIX] Use workload identity while enabling secret manager (#12257) (#20215)
[upstream:2e085f2aa60800cf0f72d10a96423d3c5bcf55a9] Signed-off-by: Modular Magician <[email protected]>
1 parent c11a600 commit 5804f22

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

.changelog/12257.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note: none
2+
Use workload identity while enabling secret manager
3+
```

google/services/container/resource_container_cluster_test.go

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3522,13 +3522,14 @@ func TestAccContainerCluster_withSecretManagerConfig(t *testing.T) {
35223522
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
35233523
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
35243524
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
3525+
pid := envvar.GetTestProjectFromEnv()
35253526
acctest.VcrTest(t, resource.TestCase{
35263527
PreCheck: func() { acctest.AccTestPreCheck(t) },
35273528
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
35283529
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
35293530
Steps: []resource.TestStep{
35303531
{
3531-
Config: testAccContainerCluster_basic(clusterName, networkName, subnetworkName),
3532+
Config: testAccContainerCluster_forSecretManagerConfig(pid, clusterName, networkName, subnetworkName),
35323533
},
35333534
{
35343535
ResourceName: "google_container_cluster.primary",
@@ -3537,7 +3538,7 @@ func TestAccContainerCluster_withSecretManagerConfig(t *testing.T) {
35373538
ImportStateVerifyIgnore: []string{"deletion_protection"},
35383539
},
35393540
{
3540-
Config: testAccContainerCluster_withSecretManagerConfigEnabled(clusterName, networkName, subnetworkName),
3541+
Config: testAccContainerCluster_withSecretManagerConfigEnabled(pid, clusterName, networkName, subnetworkName),
35413542
},
35423543
{
35433544
ResourceName: "google_container_cluster.primary",
@@ -3546,16 +3547,7 @@ func TestAccContainerCluster_withSecretManagerConfig(t *testing.T) {
35463547
ImportStateVerifyIgnore: []string{"deletion_protection"},
35473548
},
35483549
{
3549-
Config: testAccContainerCluster_withSecretManagerConfigUpdated(clusterName, networkName, subnetworkName),
3550-
},
3551-
{
3552-
ResourceName: "google_container_cluster.primary",
3553-
ImportState: true,
3554-
ImportStateVerify: true,
3555-
ImportStateVerifyIgnore: []string{"deletion_protection"},
3556-
},
3557-
{
3558-
Config: testAccContainerCluster_basic(clusterName, networkName, subnetworkName),
3550+
Config: testAccContainerCluster_withSecretManagerConfigUpdated(pid, clusterName, networkName, subnetworkName),
35593551
},
35603552
{
35613553
ResourceName: "google_container_cluster.primary",
@@ -5440,6 +5432,26 @@ resource "google_container_cluster" "primary" {
54405432
`, name, networkName, subnetworkName)
54415433
}
54425434

5435+
func testAccContainerCluster_forSecretManagerConfig(projectID, name, networkName, subnetworkName string) string {
5436+
return fmt.Sprintf(`
5437+
data "google_project" "project" {
5438+
project_id = "%s"
5439+
}
5440+
resource "google_container_cluster" "primary" {
5441+
name = "%s"
5442+
location = "us-central1-a"
5443+
initial_node_count = 1
5444+
network = "%s"
5445+
subnetwork = "%s"
5446+
5447+
deletion_protection = false
5448+
workload_identity_config {
5449+
workload_pool = "${data.google_project.project.project_id}.svc.id.goog"
5450+
}
5451+
}
5452+
`, projectID, name, networkName, subnetworkName)
5453+
}
5454+
54435455
func testAccContainerCluster_networkingModeRoutes(firstName, secondName string) string {
54445456
return fmt.Sprintf(`
54455457
resource "google_container_cluster" "primary" {
@@ -9591,8 +9603,11 @@ resource "google_container_cluster" "primary" {
95919603
`, name, networkName, subnetworkName)
95929604
}
95939605

9594-
func testAccContainerCluster_withSecretManagerConfigEnabled(name, networkName, subnetworkName string) string {
9606+
func testAccContainerCluster_withSecretManagerConfigEnabled(projectID, name, networkName, subnetworkName string) string {
95959607
return fmt.Sprintf(`
9608+
data "google_project" "project" {
9609+
project_id = "%s"
9610+
}
95969611
resource "google_container_cluster" "primary" {
95979612
name = "%s"
95989613
location = "us-central1-a"
@@ -9603,12 +9618,18 @@ resource "google_container_cluster" "primary" {
96039618
deletion_protection = false
96049619
network = "%s"
96059620
subnetwork = "%s"
9621+
workload_identity_config {
9622+
workload_pool = "${data.google_project.project.project_id}.svc.id.goog"
9623+
}
96069624
}
9607-
`, name, networkName, subnetworkName)
9625+
`, projectID, name, networkName, subnetworkName)
96089626
}
96099627

9610-
func testAccContainerCluster_withSecretManagerConfigUpdated(name, networkName, subnetworkName string) string {
9628+
func testAccContainerCluster_withSecretManagerConfigUpdated(projectID, name, networkName, subnetworkName string) string {
96119629
return fmt.Sprintf(`
9630+
data "google_project" "project" {
9631+
project_id = "%s"
9632+
}
96129633
resource "google_container_cluster" "primary" {
96139634
name = "%s"
96149635
location = "us-central1-a"
@@ -9620,8 +9641,11 @@ resource "google_container_cluster" "primary" {
96209641
deletion_protection = false
96219642
network = "%s"
96229643
subnetwork = "%s"
9644+
workload_identity_config {
9645+
workload_pool = "${data.google_project.project.project_id}.svc.id.goog"
9646+
}
96239647
}
9624-
`, name, networkName, subnetworkName)
9648+
`, projectID, name, networkName, subnetworkName)
96259649
}
96269650

96279651
func testAccContainerCluster_withLoggingConfigEnabled(name, networkName, subnetworkName string) string {

0 commit comments

Comments
 (0)