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
  • Loading branch information
dargudear-google authored Nov 6, 2024
1 parent 3850a58 commit 2e085f2
Showing 1 changed file with 40 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3760,13 +3760,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 @@ -3775,7 +3776,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 @@ -3784,16 +3785,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 @@ -5965,6 +5957,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 @@ -10518,8 +10530,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 @@ -10530,12 +10545,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 @@ -10547,8 +10568,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 2e085f2

Please sign in to comment.