From 781763f21f23a25156bd711faaadcefcd9c131ff Mon Sep 17 00:00:00 2001 From: Cameron Thornton Date: Tue, 3 Dec 2019 16:08:36 -0800 Subject: [PATCH] modify fields, added update test --- products/sourcerepo/api.yaml | 1 + products/sourcerepo/terraform.yaml | 2 + .../resource_sourcerepo_repository_test.go | 51 +++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/products/sourcerepo/api.yaml b/products/sourcerepo/api.yaml index 5394d2241f93..e4d9cf53f02a 100644 --- a/products/sourcerepo/api.yaml +++ b/products/sourcerepo/api.yaml @@ -78,6 +78,7 @@ objects: values: - :PROTOBUF - :JSON + required: true - !ruby/object:Api::Type::String name: 'serviceAccountEmail' description: | diff --git a/products/sourcerepo/terraform.yaml b/products/sourcerepo/terraform.yaml index b2443755dde5..bb74126cfa97 100644 --- a/products/sourcerepo/terraform.yaml +++ b/products/sourcerepo/terraform.yaml @@ -39,6 +39,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides description: | Resource name of the repository, of the form `{{repo}}`. The repo name may contain slashes. eg, `name/with/slash` + pubsubConfigs.serviceAccountEmail: !ruby/object:Overrides::Terraform::PropertyOverride + default_from_api: true custom_code: !ruby/object:Provider::Terraform::CustomCode update_encoder: templates/terraform/update_encoder/source_repo_repository.erb post_create: templates/terraform/post_create/source_repo_repository_update.go.erb diff --git a/third_party/terraform/tests/resource_sourcerepo_repository_test.go b/third_party/terraform/tests/resource_sourcerepo_repository_test.go index cdb35bb6af46..5114971a4d69 100644 --- a/third_party/terraform/tests/resource_sourcerepo_repository_test.go +++ b/third_party/terraform/tests/resource_sourcerepo_repository_test.go @@ -29,6 +29,35 @@ func TestAccSourceRepoRepository_basic(t *testing.T) { }) } +func TestAccSourceRepoRepository_update(t *testing.T) { + t.Parallel() + + repositoryName := fmt.Sprintf("source-repo-repository-test-%s", acctest.RandString(10)) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckSourceRepoRepositoryDestroy, + Steps: []resource.TestStep{ + { + Config: testAccSourceRepoRepository_basic(repositoryName), + }, + { + ResourceName: "google_sourcerepo_repository.acceptance", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccSourceRepoRepository_extended(repositoryName), + }, + { + ResourceName: "google_sourcerepo_repository.acceptance", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccSourceRepoRepository_basic(repositoryName string) string { return fmt.Sprintf(` resource "google_sourcerepo_repository" "acceptance" { @@ -36,3 +65,25 @@ resource "google_sourcerepo_repository" "acceptance" { } `, repositoryName) } + +func testAccSourceRepoRepository_extended(repositoryName string) string { + return fmt.Sprintf(` + resource "google_service_account" "test-account" { + account_id = "service-account-update" + display_name = "Test Service Account" + } + + resource "google_pubsub_topic" "topic" { + name = "topic-update" + } + + resource "google_sourcerepo_repository" "acceptance" { + name = "%s" + pubsub_configs { + topic = google_pubsub_topic.topic.id + message_format = "JSON" + service_account_email = google_service_account.test-account.email + } + } +`, repositoryName) +}