Skip to content

Commit

Permalink
Fix bug: artifact_registry_repository update always failing (#4482)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jcanseco authored Feb 17, 2021
1 parent 1c35689 commit 55a0431
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mmv1/products/artifactregistry/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}'
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 -%>

0 comments on commit 55a0431

Please sign in to comment.