Skip to content

Commit

Permalink
Added tests for updating workload identity config
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeepsukhani committed Jul 19, 2019
1 parent cb315c0 commit 254eab1
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions google-beta/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,33 @@ func TestAccContainerCluster_withWorkloadIdentityConfig(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccContainerCluster_updateWorkloadMetadataConfig(pid, clusterName, "SECURE"),
},
{
ResourceName: "google_container_cluster.with_workload_identity_config",
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccContainerCluster_updateWorkloadIdentityConfig(pid, clusterName, false),
},
{
ResourceName: "google_container_cluster.with_workload_identity_config",
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccContainerCluster_updateWorkloadIdentityConfig(pid, clusterName, true),
},
{
ResourceName: "google_container_cluster.with_workload_identity_config",
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
},
},
})

Expand Down Expand Up @@ -2695,6 +2722,30 @@ resource "google_container_cluster" "with_workload_metadata_config" {
`, acctest.RandString(10))
}

func testAccContainerCluster_updateWorkloadMetadataConfig(projectID string, clusterName string, workloadMetadataConfig string) string {
return fmt.Sprintf(`
data "google_project" "project" {
project_id = "%s"
}
resource "google_container_cluster" "with_workload_identity_config" {
name = "%s"
zone = "us-central1-a"
initial_node_count = 1
node_config {
oauth_scopes = [
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring"
]
workload_metadata_config {
node_metadata = "%s"
}
}
}`, projectID, clusterName, workloadMetadataConfig)
}

func testAccContainerCluster_withSandboxConfig() string {
return fmt.Sprintf(`
data "google_container_engine_versions" "central1a" {
Expand Down Expand Up @@ -3488,6 +3539,28 @@ resource "google_container_cluster" "with_workload_identity_config" {
`, projectID, clusterName)
}

func testAccContainerCluster_updateWorkloadIdentityConfig(projectID string, clusterName string, enable bool) string {
workloadIdentityConfig := ""
if enable {
workloadIdentityConfig = `
workload_identity_config {
identity_namespace = "${data.google_project.project.project_id}.svc.id.goog"
}`
}
return fmt.Sprintf(`
data "google_project" "project" {
project_id = "%s"
}
resource "google_container_cluster" "with_workload_identity_config" {
name = "%s"
zone = "us-central1-a"
initial_node_count = 1
%s
}`, projectID, clusterName, workloadIdentityConfig)
}

func testAccContainerCluster_withResourceLabels(clusterName string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_resource_labels" {
Expand Down

0 comments on commit 254eab1

Please sign in to comment.