Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create google_cloudfunctions2_function without providing the location attribute #12487

Closed
AlfatahB opened this issue Sep 7, 2022 · 10 comments

Comments

@AlfatahB
Copy link
Contributor

AlfatahB commented Sep 7, 2022

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment or link the pull request to this issue.

Terraform Version

Terraform v1.2.8

  • provider registry.terraform.io/hashicorp/google v4.34.0

Affected Resource(s)

  • google_cloudfunctions2_function

Terraform Configuration Files (if applicable)

resource "google_storage_bucket" "bucket" {
  name     = "tf-gcf-source"  # Every bucket name must be globally unique
  location = "US"
  uniform_bucket_level_access = true
}

resource "google_storage_bucket_object" "object" {
  name   = "function-source.zip"
  bucket = google_storage_bucket.bucket.name
  source = "function-source.zip"  # Add path to the zipped function source code
}

resource "google_cloudfunctions2_function" "function" {
  name = "function-v2"
  description = "a new function"

  build_config {
    runtime = "nodejs16"
    entry_point = "helloHttp"  # Set the entry point 
    source {
      storage_source {
        bucket = google_storage_bucket.bucket.name
        object = google_storage_bucket_object.object.name
      }
    }
  }

  service_config {
    max_instance_count  = 1
    available_memory    = "256M"
    timeout_seconds     = 60
  }
}

Issue Description

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

Error: Error creating function: googleapi: Error 400: Malformed name: 'projects/projectname/locations//functions/function-v2'

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.

References

@edwardmedia edwardmedia self-assigned this Sep 7, 2022
@edwardmedia edwardmedia added the bug label Sep 7, 2022
@edwardmedia
Copy link
Contributor

@AlfatahB the location is required for this resource. Do you set it like other common attributes like project, zone etc. in the provider, or environment variables? Once you provide defaults for them, they thus become optional for most of resources/data source. Does this make sense?

https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#region

@AlfatahB
Copy link
Contributor Author

AlfatahB commented Sep 8, 2022

@edwardmedia I've provided a region in the provider block. Even after providing region in the provider block, I get the same error i.e. Malformed URL error. Yes we can explore your approach of providing location in the provider block itself and support location via the environment too. For now we have kept the location required for the new data-source.

@edwardmedia
Copy link
Contributor

edwardmedia commented Sep 8, 2022

@melinath shouldn't location be a required field for this resource?

@edwardmedia edwardmedia assigned melinath and unassigned edwardmedia Sep 8, 2022
@melinath
Copy link
Collaborator

It seems like location should probably be a required field.

@melinath melinath assigned edwardmedia and unassigned melinath Sep 12, 2022
@melinath
Copy link
Collaborator

Or we should allow a way to specify a default, like we do for project and some other fields.

@edwardmedia
Copy link
Contributor

Changing the label from bug to enhancement for triage
Should make the location to be a required field?

@toandm
Copy link

toandm commented Feb 1, 2023

Same issue for me. I provided the region in providers config. This resource should get location field from that.

@rileykarson
Copy link
Collaborator

Same issue for me. I provided the region in providers config. This resource should get location field from that.

Locations and regions are not always the same thing, so we're now avoiding inferring location fields based on the provider fields. Unfortunately, while region and zone come from a common list of GCE regions/zones, location is product, specific and often-but-not-always aligns.

@ScottSuarez
Copy link
Collaborator

Implemented this change for the 5.0 release.
GoogleCloudPlatform/magic-modules#8928

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants