Skip to content

Commit

Permalink
Add new tests for new GCE role specific attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
petems committed Nov 2, 2018
1 parent 8bc7c50 commit b47f958
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions vault/resource_gcp_auth_backend_role_test.go
Expand Up @@ -32,6 +32,24 @@ func TestGCPAuthBackendRole_basic(t *testing.T) {
})
}

func TestGCPAuthBackendRole_gce(t *testing.T) {
backend := acctest.RandomWithPrefix("tf-test-gcp-backend")
name := acctest.RandomWithPrefix("tf-test-gcp-role")
projectId := acctest.RandomWithPrefix("tf-test-gcp-project-id")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testProviders,
CheckDestroy: testGCPAuthBackendRoleDestroy,
Steps: []resource.TestStep{
{
Config: testGCPAuthBackendRoleConfig_gce(backend, name, projectId),
Check: testGCPAuthBackendRoleCheck_attrs(backend, name),
},
},
})
}

func testGCPAuthBackendRoleDestroy(s *terraform.State) error {
client := testProvider.Meta().(*api.Client)

Expand Down Expand Up @@ -95,6 +113,9 @@ func testGCPAuthBackendRoleCheck_attrs(backend, name string) resource.TestCheckF
"period": "period",
"policies": "policies",
"bound_service_accounts": "bound_service_accounts",
"bound_regions": "bound_regions",
"bound_zones": "bound_zones",
"bound_labels": "bound_labels",
}

for stateAttr, apiAttr := range attrs {
Expand Down Expand Up @@ -192,3 +213,28 @@ resource "vault_gcp_auth_backend_role" "test" {
`, backend, name, serviceAccount, projectId)

}

func testGCPAuthBackendRoleConfig_gce(backend, name, projectId string) string {

return fmt.Sprintf(`
resource "vault_auth_backend" "gcp" {
path = "%s"
type = "gcp"
}
resource "vault_gcp_auth_backend_role" "test" {
backend = "${vault_auth_backend.gcp.path}"
role = "%s"
type = "gce"
project_id = "%s"
ttl = 300
max_ttl = 600
policies = ["policy_a", "policy_b"]
bound_regions = ["eu-west2"]
bound_zones = ["europe-west2-c"]
bound_labels = ["foo"]
}
`, backend, name, projectId)

}

0 comments on commit b47f958

Please sign in to comment.