From 55a0431cf2b23a8dcc90f1fe044cf4825964c1d8 Mon Sep 17 00:00:00 2001 From: Jazel Canseco Date: Wed, 17 Feb 2021 13:59:01 -0800 Subject: [PATCH] Fix bug: artifact_registry_repository update always failing (#4482) This fixes a bug where trying to update an artifact_registry_repository always failed due to the fact that the resource's Update logic was hitting the wrong API endpoint. --- mmv1/products/artifactregistry/api.yaml | 3 + ...e_artifact_registry_repository_test.go.erb | 77 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 mmv1/third_party/terraform/tests/resource_artifact_registry_repository_test.go.erb diff --git a/mmv1/products/artifactregistry/api.yaml b/mmv1/products/artifactregistry/api.yaml index ae8627a9b161..0f55490cb524 100644 --- a/mmv1/products/artifactregistry/api.yaml +++ b/mmv1/products/artifactregistry/api.yaml @@ -25,6 +25,7 @@ apis_required: name: Artifact Registry API url: https://console.cloud.google.com/apis/library/artifactregistry.googleapis.com/ async: !ruby/object:Api::OpAsync + actions: ['create', 'delete'] operation: !ruby/object:Api::OpAsync::Operation path: 'name' base_url: '{{op_id}}' @@ -47,6 +48,8 @@ objects: base_url: projects/{{project}}/locations/{{location}}/repositories create_url: projects/{{project}}/locations/{{location}}/repositories?repository_id={{repository_id}} self_link: projects/{{project}}/locations/{{location}}/repositories/{{repository_id}} + update_verb: :PATCH + update_mask: true min_version: beta description: A repository for storing artifacts references: !ruby/object:Api::Resource::ReferenceLinks diff --git a/mmv1/third_party/terraform/tests/resource_artifact_registry_repository_test.go.erb b/mmv1/third_party/terraform/tests/resource_artifact_registry_repository_test.go.erb new file mode 100644 index 000000000000..ed73bef446bc --- /dev/null +++ b/mmv1/third_party/terraform/tests/resource_artifact_registry_repository_test.go.erb @@ -0,0 +1,77 @@ +<% autogen_exception -%> +package google +<% unless version == 'ga' -%> + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccArtifactRegistryRepository_update(t *testing.T) { + t.Parallel() + + repositoryID := fmt.Sprintf("tf-test-%d", randInt(t)) + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProvidersOiCS, + CheckDestroy: testAccCheckArtifactRegistryRepositoryDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccArtifactRegistryRepository_update(repositoryID), + }, + { + ResourceName: "google_artifact_registry_repository.test", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccArtifactRegistryRepository_update2(repositoryID), + }, + { + ResourceName: "google_artifact_registry_repository.test", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccArtifactRegistryRepository_update(repositoryID string) string { + return fmt.Sprintf(` +resource "google_artifact_registry_repository" "test" { + provider = google-beta + + repository_id = "%s" + location = "us-central1" + description = "pre-update" + format = "DOCKER" + + labels = { + my_key = "my_val" + other_key = "other_val" + } +} +`, repositoryID) +} + +func testAccArtifactRegistryRepository_update2(repositoryID string) string { + return fmt.Sprintf(` +resource "google_artifact_registry_repository" "test" { + provider = google-beta + + repository_id = "%s" + location = "us-central1" + description = "post-update" + format = "DOCKER" + + labels = { + my_key = "my_val" + other_key = "new_val" + } +} +`, repositoryID) +} +<% end -%>