Skip to content

Commit dc5e1f2

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

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-beta/services/container/resource_container_cluster_test.go

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3744,13 +3744,14 @@ func TestAccContainerCluster_withSecretManagerConfig(t *testing.T) {
37443744
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
37453745
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
37463746
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
3747+
pid := envvar.GetTestProjectFromEnv()
37473748
acctest.VcrTest(t, resource.TestCase{
37483749
PreCheck: func() { acctest.AccTestPreCheck(t) },
37493750
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
37503751
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
37513752
Steps: []resource.TestStep{
37523753
{
3753-
Config: testAccContainerCluster_basic(clusterName, networkName, subnetworkName),
3754+
Config: testAccContainerCluster_forSecretManagerConfig(pid, clusterName, networkName, subnetworkName),
37543755
},
37553756
{
37563757
ResourceName: "google_container_cluster.primary",
@@ -3759,7 +3760,7 @@ func TestAccContainerCluster_withSecretManagerConfig(t *testing.T) {
37593760
ImportStateVerifyIgnore: []string{"deletion_protection"},
37603761
},
37613762
{
3762-
Config: testAccContainerCluster_withSecretManagerConfigEnabled(clusterName, networkName, subnetworkName),
3763+
Config: testAccContainerCluster_withSecretManagerConfigEnabled(pid, clusterName, networkName, subnetworkName),
37633764
},
37643765
{
37653766
ResourceName: "google_container_cluster.primary",
@@ -3768,16 +3769,7 @@ func TestAccContainerCluster_withSecretManagerConfig(t *testing.T) {
37683769
ImportStateVerifyIgnore: []string{"deletion_protection"},
37693770
},
37703771
{
3771-
Config: testAccContainerCluster_withSecretManagerConfigUpdated(clusterName, networkName, subnetworkName),
3772-
},
3773-
{
3774-
ResourceName: "google_container_cluster.primary",
3775-
ImportState: true,
3776-
ImportStateVerify: true,
3777-
ImportStateVerifyIgnore: []string{"deletion_protection"},
3778-
},
3779-
{
3780-
Config: testAccContainerCluster_basic(clusterName, networkName, subnetworkName),
3772+
Config: testAccContainerCluster_withSecretManagerConfigUpdated(pid, clusterName, networkName, subnetworkName),
37813773
},
37823774
{
37833775
ResourceName: "google_container_cluster.primary",
@@ -5942,6 +5934,26 @@ resource "google_container_cluster" "primary" {
59425934
`, name, networkName, subnetworkName)
59435935
}
59445936

5937+
func testAccContainerCluster_forSecretManagerConfig(projectID, name, networkName, subnetworkName string) string {
5938+
return fmt.Sprintf(`
5939+
data "google_project" "project" {
5940+
project_id = "%s"
5941+
}
5942+
resource "google_container_cluster" "primary" {
5943+
name = "%s"
5944+
location = "us-central1-a"
5945+
initial_node_count = 1
5946+
network = "%s"
5947+
subnetwork = "%s"
5948+
5949+
deletion_protection = false
5950+
workload_identity_config {
5951+
workload_pool = "${data.google_project.project.project_id}.svc.id.goog"
5952+
}
5953+
}
5954+
`, projectID, name, networkName, subnetworkName)
5955+
}
5956+
59455957
func testAccContainerCluster_networkingModeRoutes(firstName, secondName string) string {
59465958
return fmt.Sprintf(`
59475959
resource "google_container_cluster" "primary" {
@@ -10473,8 +10485,11 @@ resource "google_container_cluster" "primary" {
1047310485
`, name, networkName, subnetworkName)
1047410486
}
1047510487

10476-
func testAccContainerCluster_withSecretManagerConfigEnabled(name, networkName, subnetworkName string) string {
10488+
func testAccContainerCluster_withSecretManagerConfigEnabled(projectID, name, networkName, subnetworkName string) string {
1047710489
return fmt.Sprintf(`
10490+
data "google_project" "project" {
10491+
project_id = "%s"
10492+
}
1047810493
resource "google_container_cluster" "primary" {
1047910494
name = "%s"
1048010495
location = "us-central1-a"
@@ -10485,12 +10500,18 @@ resource "google_container_cluster" "primary" {
1048510500
deletion_protection = false
1048610501
network = "%s"
1048710502
subnetwork = "%s"
10503+
workload_identity_config {
10504+
workload_pool = "${data.google_project.project.project_id}.svc.id.goog"
10505+
}
1048810506
}
10489-
`, name, networkName, subnetworkName)
10507+
`, projectID, name, networkName, subnetworkName)
1049010508
}
1049110509

10492-
func testAccContainerCluster_withSecretManagerConfigUpdated(name, networkName, subnetworkName string) string {
10510+
func testAccContainerCluster_withSecretManagerConfigUpdated(projectID, name, networkName, subnetworkName string) string {
1049310511
return fmt.Sprintf(`
10512+
data "google_project" "project" {
10513+
project_id = "%s"
10514+
}
1049410515
resource "google_container_cluster" "primary" {
1049510516
name = "%s"
1049610517
location = "us-central1-a"
@@ -10502,8 +10523,11 @@ resource "google_container_cluster" "primary" {
1050210523
deletion_protection = false
1050310524
network = "%s"
1050410525
subnetwork = "%s"
10526+
workload_identity_config {
10527+
workload_pool = "${data.google_project.project.project_id}.svc.id.goog"
10528+
}
1050510529
}
10506-
`, name, networkName, subnetworkName)
10530+
`, projectID, name, networkName, subnetworkName)
1050710531
}
1050810532

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

0 commit comments

Comments
 (0)