hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.29k stars 1.72k forks source link

Cannot create google_artifact_registry_repository without providing the location attribute #13294

Open sanghaniJ opened 1 year ago

sanghaniJ commented 1 year ago

Community Note

Description

While I was creating the data source for google_artifact_registry_repository, I found out that we cannot read the artifact_registry_repository using the read function of resource file without providing the location attribute. When I dig down into this, I also get the same error while making the create calls without providing the location attribute:

 Error: Error creating Repository: googleapi: Error 400: Request contains an invalid argument.
│ Details:
│ [
│   {
│     "@type": "type.googleapis.com/google.rpc.DebugInfo",
│     "detail": "Fail to resolve resource 'projects/crest-359621/locations/' extracted from request field 'parent'.;  while enforcing CPE to generate new SecurityContext."
│   }
│ ]

It's working fine if I provide the location attribute in the configuration file.

I think the replaceVars function in the resource files doesn't deal with {{location}} in the string provided and hence if we don't provide location explicitly, than we get the error for the malformed url.

As of now, the probable fix should be to keep the location attribute required.

New or Affected Resource(s)

Potential Terraform Configuration

resource "google_artifact_registry_repository" "my-repo" {
  repository_id = "my-repository"
  description   = "example docker repository"
  format        = "DOCKER"
}

References

12487 Similar Issue

b/272797520

wyardley commented 3 weeks ago

I think this can be closed now? It appears to work, however, I've noticed a different issue on importing when the location is specified, but is a multi-region location.