Skip to content

Commit

Permalink
add random suffix to test resource names
Browse files Browse the repository at this point in the history
  • Loading branch information
c2thorn committed Dec 5, 2019
1 parent 781763f commit 2d12228
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion products/sourcerepo/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ overrides: !ruby/object:Overrides::ResourceOverrides
- !ruby/object:Provider::Terraform::Examples
name: "sourcerepo_repository_full"
primary_resource_id: "my-repo"
primary_resource_name: "fmt.Sprintf(\"my-repository%s\", context[\"random_suffix\"])"
vars:
repository_name: "my-repository"
account_id: "my-account"
topic_name: "my-topic"
properties:
name: !ruby/object:Overrides::Terraform::PropertyOverride
custom_expand: templates/terraform/custom_expand/shortname_to_url.go.erb
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
resource "google_service_account" "test-account" {
account_id = "my-service-account"
account_id = "<%= ctx[:vars]['account_id'] %>"
display_name = "Test Service Account"
}

resource "google_pubsub_topic" "topic" {
name = "my-topic"
name = "<%= ctx[:vars]['topic_name'] %>"
}

resource "google_sourcerepo_repository" "<%= ctx[:primary_resource_id] %>" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func TestAccSourceRepoRepository_update(t *testing.T) {
t.Parallel()

repositoryName := fmt.Sprintf("source-repo-repository-test-%s", acctest.RandString(10))
accountId := fmt.Sprintf("account-id-%s", acctest.RandString(10))
topicName := fmt.Sprintf("topic-name-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand All @@ -47,7 +49,7 @@ func TestAccSourceRepoRepository_update(t *testing.T) {
ImportStateVerify: true,
},
{
Config: testAccSourceRepoRepository_extended(repositoryName),
Config: testAccSourceRepoRepository_extended(accountId, topicName, repositoryName),
},
{
ResourceName: "google_sourcerepo_repository.acceptance",
Expand All @@ -66,15 +68,15 @@ resource "google_sourcerepo_repository" "acceptance" {
`, repositoryName)
}

func testAccSourceRepoRepository_extended(repositoryName string) string {
func testAccSourceRepoRepository_extended(accountId string, topicName string, repositoryName string) string {
return fmt.Sprintf(`
resource "google_service_account" "test-account" {
account_id = "service-account-update"
account_id = "%s"
display_name = "Test Service Account"
}
resource "google_pubsub_topic" "topic" {
name = "topic-update"
name = "%s"
}
resource "google_sourcerepo_repository" "acceptance" {
Expand All @@ -85,5 +87,5 @@ func testAccSourceRepoRepository_extended(repositoryName string) string {
service_account_email = google_service_account.test-account.email
}
}
`, repositoryName)
`, accountId, topicName, repositoryName)
}

0 comments on commit 2d12228

Please sign in to comment.