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

Terraform doesn't show meaningful error-details on http 400 (google_cloudfunctions_function) #8768

Open
elouanKeryell-Even opened this issue Mar 25, 2021 · 2 comments

Comments

@elouanKeryell-Even
Copy link

elouanKeryell-Even commented Mar 25, 2021

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.
  • If an issue is assigned to the modular-magician user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to hashibot, a community member has claimed the issue already.

Terraform Version

  • terraform:
# terraform -version
Terraform v0.13.5

Your version of Terraform is out of date! The latest version
is 0.14.9. You can update by downloading from https://www.terraform.io/downloads.html
  • provider (google):
* hashicorp/google: version = "~> 3.60.0"

Affected Resource(s)

  • google_cloudfunctions_function

Terraform Configuration Files

main.tf

resource "google_cloudfunctions_function" "function" {
  project = var.project
  name    = "redacted"
  runtime = "nodejs12"
  region  = var.region

  source_archive_bucket = local.app_bucket
  source_archive_object = "src.zip"

  event_trigger {
    event_type = "google.pubsub.topic.publish"
    resource   = google_pubsub_topic.redacted.id
  }

  # Name of the method to be called in the source code
  entry_point = "entrypoint"

  environment_variables = {
    SUB_DEQUEUE = local.pubsub_dequeue
    TOPIC_ERROR = local.topic_error
  }

  service_account_email = google_service_account.redacted.email

  vpc_connector = "projects/${var.project}/locations/${var.region}/connectors/redacted"
}

Debug Output

See section Actual Behavior below

Panic Output

N/A

Expected Behavior

terraform apply should fail, but the error message it shows should convey-up every meaningful detail, like this:

{
  "error": {
    "code": 400,
    "message": "The request has errors",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "vpc_connector",
            "description": "A Cloud Function and a Serverless VPC Access connector must be located in the same region."
          }
        ]
      }
    ]
  }
}

The above detailed error response was obtained by manually submitting the request terraform was attempting to make (i.e. PATCH a cloud function), directly through the Cloud Functions API (here).

The payload used to make this manual request was copied from terraform debug logs (see below).

With this more detailed error message, I was able find the error in my terraform config: I was passing the vpc_connector's full id (i.e. projects/<project>/locations/<location>/connectors/<connector>), instead of just its name.

Actual Behavior

terraform apply fails, and the error message it shows does not convey meaningful information:

  • TF_LOGS: default
google_cloudfunctions_function.function: Modifying... [id=projects/redacted/locations/europe-west1/functions/redacted]

Error: Error while updating cloudfunction configuration: %!s(<nil>)

  on main.tf line 77, in resource "google_cloudfunctions_function" "function":
  77: resource "google_cloudfunctions_function" "function" {

the HTTP response terraform shows is the following:

{
  "error": {
    "code": 400,
    "message": "The request has errors",
    "errors": [
      {
        "message": "The request has errors",
        "domain": "global",
        "reason": "badRequest"
      }
    ],
    "status": "INVALID_ARGUMENT"
  }
}

As you can see, it doesn't convey any meaningful detail.

Steps to Reproduce

  • Define a cloud function resource
  • Pass a full self-id for the vpc_connector field (projects/<project>/locations/<location>/connectors/<connector>, which is incorrect), instead of just passing the <connector-name>
  • try to terraform apply

Important Factoids

N/A

References

b/274818664

@ghost ghost added the bug label Mar 25, 2021
@edwardmedia edwardmedia self-assigned this Mar 25, 2021
@edwardmedia
Copy link
Contributor

edwardmedia commented Mar 29, 2021

@elouanKeryell-Even I can repro and see the difference of the responses between these two calls.

By removing User-Agent: google-api-go-client/0.5 Terraform/0.13.5 (+https://www.terraform.io) Terraform-Plugin-SDK/2.4.4 terraform-provider-google/dev from the PATCH request headers, the description will be included in the API response. That Header User-Agent makes difference

To resolve this, we need API's help. Added label upstream

@ScottSuarez
Copy link
Collaborator

I've filed the following ticket with the api https://issuetracker.google.com/184159006

@edwardmedia edwardmedia removed their assignment Apr 24, 2021
modular-magician added a commit to modular-magician/terraform-provider-google that referenced this issue Sep 6, 2023
* Fix import of bigquery transfer config location

* Fix import of bigquery transfer config when name does not contain location

* Fix indentation in bigquery_data_transfer_self_link_as_name_set_location.go.erb

Signed-off-by: Modular Magician <magic-modules@google.com>
modular-magician added a commit that referenced this issue Sep 6, 2023
* Fix import of bigquery transfer config location

* Fix import of bigquery transfer config when name does not contain location

* Fix indentation in bigquery_data_transfer_self_link_as_name_set_location.go.erb

Signed-off-by: Modular Magician <magic-modules@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants