Skip to content

Commit

Permalink
[FIX] Use workload identity while enabling secret manager (#12257) (#…
Browse files Browse the repository at this point in the history
…20215)

[upstream:2e085f2aa60800cf0f72d10a96423d3c5bcf55a9]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Nov 6, 2024
1 parent c11a600 commit 5804f22
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .changelog/12257.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note: none
Use workload identity while enabling secret manager
```
56 changes: 40 additions & 16 deletions google/services/container/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3522,13 +3522,14 @@ func TestAccContainerCluster_withSecretManagerConfig(t *testing.T) {
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
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_basic(clusterName, networkName, subnetworkName),
Config: testAccContainerCluster_forSecretManagerConfig(pid, clusterName, networkName, subnetworkName),
},
{
ResourceName: "google_container_cluster.primary",
Expand All @@ -3537,7 +3538,7 @@ func TestAccContainerCluster_withSecretManagerConfig(t *testing.T) {
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
{
Config: testAccContainerCluster_withSecretManagerConfigEnabled(clusterName, networkName, subnetworkName),
Config: testAccContainerCluster_withSecretManagerConfigEnabled(pid, clusterName, networkName, subnetworkName),
},
{
ResourceName: "google_container_cluster.primary",
Expand All @@ -3546,16 +3547,7 @@ func TestAccContainerCluster_withSecretManagerConfig(t *testing.T) {
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
{
Config: testAccContainerCluster_withSecretManagerConfigUpdated(clusterName, networkName, subnetworkName),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
{
Config: testAccContainerCluster_basic(clusterName, networkName, subnetworkName),
Config: testAccContainerCluster_withSecretManagerConfigUpdated(pid, clusterName, networkName, subnetworkName),
},
{
ResourceName: "google_container_cluster.primary",
Expand Down Expand Up @@ -5440,6 +5432,26 @@ resource "google_container_cluster" "primary" {
`, name, networkName, subnetworkName)
}

func testAccContainerCluster_forSecretManagerConfig(projectID, name, networkName, subnetworkName string) string {
return fmt.Sprintf(`
data "google_project" "project" {
project_id = "%s"
}
resource "google_container_cluster" "primary" {
name = "%s"
location = "us-central1-a"
initial_node_count = 1
network = "%s"
subnetwork = "%s"
deletion_protection = false
workload_identity_config {
workload_pool = "${data.google_project.project.project_id}.svc.id.goog"
}
}
`, projectID, name, networkName, subnetworkName)
}

func testAccContainerCluster_networkingModeRoutes(firstName, secondName string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "primary" {
Expand Down Expand Up @@ -9591,8 +9603,11 @@ resource "google_container_cluster" "primary" {
`, name, networkName, subnetworkName)
}

func testAccContainerCluster_withSecretManagerConfigEnabled(name, networkName, subnetworkName string) string {
func testAccContainerCluster_withSecretManagerConfigEnabled(projectID, name, networkName, subnetworkName string) string {
return fmt.Sprintf(`
data "google_project" "project" {
project_id = "%s"
}
resource "google_container_cluster" "primary" {
name = "%s"
location = "us-central1-a"
Expand All @@ -9603,12 +9618,18 @@ resource "google_container_cluster" "primary" {
deletion_protection = false
network = "%s"
subnetwork = "%s"
workload_identity_config {
workload_pool = "${data.google_project.project.project_id}.svc.id.goog"
}
}
`, name, networkName, subnetworkName)
`, projectID, name, networkName, subnetworkName)
}

func testAccContainerCluster_withSecretManagerConfigUpdated(name, networkName, subnetworkName string) string {
func testAccContainerCluster_withSecretManagerConfigUpdated(projectID, name, networkName, subnetworkName string) string {
return fmt.Sprintf(`
data "google_project" "project" {
project_id = "%s"
}
resource "google_container_cluster" "primary" {
name = "%s"
location = "us-central1-a"
Expand All @@ -9620,8 +9641,11 @@ resource "google_container_cluster" "primary" {
deletion_protection = false
network = "%s"
subnetwork = "%s"
workload_identity_config {
workload_pool = "${data.google_project.project.project_id}.svc.id.goog"
}
}
`, name, networkName, subnetworkName)
`, projectID, name, networkName, subnetworkName)
}

func testAccContainerCluster_withLoggingConfigEnabled(name, networkName, subnetworkName string) string {
Expand Down

0 comments on commit 5804f22

Please sign in to comment.