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

google provider returning 0 exit code on error #5181

Closed
marcb1 opened this issue Dec 16, 2019 · 3 comments
Closed

google provider returning 0 exit code on error #5181

marcb1 opened this issue Dec 16, 2019 · 3 comments
Assignees

Comments

@marcb1
Copy link

marcb1 commented Dec 16, 2019

Terraform version info:

$ terraform version
Terraform v0.12.16
+ provider.google v2.20.1
+ provider.google-beta v3.2.0
+ provider.null v2.1.2
+ provider.random v2.2.1
+ provider.template v2.1.2
+ provider.tls v2.1.1

We are creating the following resource via the google provider:

resource "google_kms_key_ring" "slack-reporter-keyring" {
  project  = "project_id"
  name     = "slack-reporter-keyring"
  location = "us-central1"
}

resource "google_kms_crypto_key" "slack-reporter-cryptokey" {
  name     = "slack-reporter-cryptokey"
  key_ring = google_kms_key_ring.slack-reporter-keyring.self_link
}

When running terraform apply, we get the following error:

Error: Error creating KeyRing: googleapi: Error 400: Google Cloud KMS API has not been used in this project before, or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudkms.googleapis.com/overview?project=[project_id] then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.

  on slack_reporter.tf line 27, in resource "google_kms_key_ring" "slack-reporter-keyring":
  27: resource "google_kms_key_ring" "slack-reporter-keyring" {
$ echo $?
0

However the exit code returned by terraform is 0. Our automation relies on an error exit code (non-zero) being returned.
Is this a terraform bug, or a google provider bug? Let me know I can close and re-open this on terraform's main github repo.

@danawillow danawillow added the bug label Dec 16, 2019
@venkykuberan venkykuberan self-assigned this Dec 28, 2019
@venkykuberan
Copy link
Contributor

@marcb1 Its not a bug working as expected. If you haven't used that service before in your project, GCP expects you to enable it before you use it. It can be done in 2 ways

  1. On the Cloud Console, Search for the API Google Cloud KMS API under Api & Services side bar
  2. run the command on terminal gcloud services enable cloudkms.googleapis.com

@marcb1
Copy link
Author

marcb1 commented Dec 31, 2019

@venkykuberan thanks for the info. I think this was a bug in the main terraform core and the google provider. We've upgraded from 0.12.16 to 0.12.18 and the issue went away.
(terraform now returns a 1 exit code on errors, before this was inconsistent as sometimes an error will be printed by terraform but the shell exit code would be 0- we rely on exit codes for our terraform automation)

@marcb1 marcb1 closed this as completed Dec 31, 2019
@ghost ghost removed the waiting-response label Dec 31, 2019
@ghost
Copy link

ghost commented Jan 30, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Jan 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants