Skip to content

Commit

Permalink
Use region from provider as default location in Artifact Registry (#7497
Browse files Browse the repository at this point in the history
) (#5637)

* Use region from provider as default location.

* Fix indentation and properly merge custom code.

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored May 12, 2023
1 parent bd4d121 commit 2f34f92
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/7497.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
artifactregistry: fixed new repositories ignoring the provider region if location is unset.
```
24 changes: 24 additions & 0 deletions google-beta/resource_artifact_registry_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ func resourceArtifactRegistryRepositoryCreate(d *schema.ResourceData, meta inter
obj["remoteRepositoryConfig"] = remoteRepositoryConfigProp
}

obj, err = resourceArtifactRegistryRepositoryEncoder(d, meta, obj)
if err != nil {
return err
}

url, err := tpgresource.ReplaceVars(d, config, "{{ArtifactRegistryBasePath}}projects/{{project}}/locations/{{location}}/repositories?repository_id={{repository_id}}")
if err != nil {
return err
Expand Down Expand Up @@ -554,6 +559,11 @@ func resourceArtifactRegistryRepositoryUpdate(d *schema.ResourceData, meta inter
obj["virtualRepositoryConfig"] = virtualRepositoryConfigProp
}

obj, err = resourceArtifactRegistryRepositoryEncoder(d, meta, obj)
if err != nil {
return err
}

url, err := tpgresource.ReplaceVars(d, config, "{{ArtifactRegistryBasePath}}projects/{{project}}/locations/{{location}}/repositories/{{repository_id}}")
if err != nil {
return err
Expand Down Expand Up @@ -1189,3 +1199,17 @@ func expandArtifactRegistryRepositoryRemoteRepositoryConfigPythonRepository(v in
func expandArtifactRegistryRepositoryRemoteRepositoryConfigPythonRepositoryPublicRepository(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func resourceArtifactRegistryRepositoryEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
config := meta.(*transport_tpg.Config)
if _, ok := d.GetOk("location"); !ok {
location, err := getRegionFromSchema("region", "zone", d, config)
if err != nil {
return nil, fmt.Errorf("Cannot determine location: set in this resource, or set provider-level 'region' or 'zone'.")
}
if err := d.Set("location", location); err != nil {
return nil, fmt.Errorf("Error setting location: %s", err)
}
}
return obj, nil
}

0 comments on commit 2f34f92

Please sign in to comment.