providers/google: random resource names in SA test

This commit is contained in:
Evan Brown 2016-11-14 09:42:11 -08:00
parent b12005b247
commit 14069696fd

View File

@ -4,19 +4,19 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
var ( var (
accountId = "tf-test"
accountId2 = "tf-test-2"
displayName = "Terraform Test" displayName = "Terraform Test"
displayName2 = "Terraform Test Update" displayName2 = "Terraform Test Update"
) )
// Test that a service account resource can be created, updated, and destroyed // Test that a service account resource can be created, updated, and destroyed
func TestAccGoogleServiceAccount_basic(t *testing.T) { func TestAccGoogleServiceAccount_basic(t *testing.T) {
accountId := "a" + acctest.RandString(10)
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
@ -42,27 +42,28 @@ func TestAccGoogleServiceAccount_basic(t *testing.T) {
// Test that a service account resource can be created with a policy, updated, // Test that a service account resource can be created with a policy, updated,
// and destroyed. // and destroyed.
func TestAccGoogleServiceAccount_createPolicy(t *testing.T) { func TestAccGoogleServiceAccount_createPolicy(t *testing.T) {
accountId := "a" + acctest.RandString(10)
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
// The first step creates a basic service account with an IAM policy // The first step creates a basic service account with an IAM policy
resource.TestStep{ resource.TestStep{
Config: fmt.Sprintf(testAccGoogleServiceAccount_policy, accountId2, displayName, projectId), Config: fmt.Sprintf(testAccGoogleServiceAccount_policy, accountId, displayName, accountId, projectId),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckGoogleServiceAccountPolicyCount("google_service_account.acceptance", 1), testAccCheckGoogleServiceAccountPolicyCount("google_service_account.acceptance", 1),
), ),
}, },
// The second step updates the service account with no IAM policy // The second step updates the service account with no IAM policy
resource.TestStep{ resource.TestStep{
Config: fmt.Sprintf(testAccGoogleServiceAccount_basic, accountId2, displayName), Config: fmt.Sprintf(testAccGoogleServiceAccount_basic, accountId, displayName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckGoogleServiceAccountPolicyCount("google_service_account.acceptance", 0), testAccCheckGoogleServiceAccountPolicyCount("google_service_account.acceptance", 0),
), ),
}, },
// The final step re-applies the IAM policy // The final step re-applies the IAM policy
resource.TestStep{ resource.TestStep{
Config: fmt.Sprintf(testAccGoogleServiceAccount_policy, accountId2, displayName, projectId), Config: fmt.Sprintf(testAccGoogleServiceAccount_policy, accountId, displayName, accountId, projectId),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckGoogleServiceAccountPolicyCount("google_service_account.acceptance", 1), testAccCheckGoogleServiceAccountPolicyCount("google_service_account.acceptance", 1),
), ),
@ -132,7 +133,7 @@ data "google_iam_policy" "service_account" {
binding { binding {
role = "roles/iam.serviceAccountActor" role = "roles/iam.serviceAccountActor"
members = [ members = [
"serviceAccount:tf-test-2@%v.iam.gserviceaccount.com", "serviceAccount:%v@%v.iam.gserviceaccount.com",
] ]
} }
}` }`