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: could not find default credentials when deleting module #23567

Closed
zagr0 opened this issue Dec 5, 2019 · 9 comments
Closed

google: could not find default credentials when deleting module #23567

zagr0 opened this issue Dec 5, 2019 · 9 comments
Assignees
Labels
bug core v0.12 Issues (primarily bugs) reported against v0.12 releases

Comments

@zagr0
Copy link

zagr0 commented Dec 5, 2019

Terraform Version

Terraform v0.12.17

Terraform Configuration Files

Initial configuration

variable "gcp_credentials" {
}
variable "gcp_project_name" {
}

provider "google" {
  credentials = file(var.gcp_credentials)
  project     = var.gcp_project_name
  region      = "us-west2"
  alias       = "us-west2"
}

module "module-gcp" {
  source  = "./modules/gcp-resources"
  providers = {
    google = google.us-west2
  }
  some_var = "some_value"
}

modules/gcp-resources/main.tf

variable "some_var" {
}

resource "google_compute_network" "network" {
  name = var.some_var
  auto_create_subnetworks = "false"
}

updated configuration to remove module resources

variable "gcp_credentials" {
}
variable "gcp_project_name" {
}

provider "google" {
  credentials = file(var.gcp_credentials)
  project     = var.gcp_project_name
  region      = "us-west2"
  alias       = "us-west2"
}

#module "module-gcp" {
#  source  = "./modules/gcp-resources"
#  providers = {
#    google = google.us-west2
#  }
#  some_var = "some_value"
#}

Expected Behavior

Terraform should destroy resources from module and exit with success

Actual Behavior

Terraform apply failed, exit code 1
STDERR:

Error: google: could not find default credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.

  on <empty> line 0:
  (source code not available)

Steps to Reproduce

  1. Use initial plan to create resources
  2. terraform init
  3. terraform apply -var 'gcp_project_name=project_name' -var 'gcp_credentials=gcp-credentials.json' - SUCCESS
  4. Use plan with removed module to remove resources
  5. terraform init
  6. terraform apply 'gcp_project_name=project_name' -var 'gcp_credentials=gcp-credentials.json' - FAILURE

Additional Context

there is already opened ticket for the google provider, but they said this is core issue
hashicorp/terraform-provider-google#4272

@jbardin
Copy link
Member

jbardin commented Dec 5, 2019

Hi @zagr0,

Is it possible to share the source of the module as well? If not, are you certain that you don't have another google provider defined somewhere within that module?

Thanks!

@zagr0
Copy link
Author

zagr0 commented Dec 5, 2019

sure
modules/gcp-resources/main.tf

variable "some_var" {
}

resource "google_compute_network" "network" {
  name = var.some_var
  auto_create_subnetworks = "false"
}

@jbardin jbardin added bug core v0.12 Issues (primarily bugs) reported against v0.12 releases and removed question waiting-response An issue/pull request is waiting for a response from the community labels Dec 5, 2019
@jbardin
Copy link
Member

jbardin commented Dec 5, 2019

Thanks @zagr0,

It appears that the module resources are being removed correctly, and are using the correct provider. The error is coming from terraform trying to also configure a default google provider, which does not have any credentials defined.

@pselle
Copy link
Contributor

pselle commented Jan 7, 2020

@zagr0 Thank you for providing your replication case! I ran through this on the current master branch of Terraform (deploying soon) and was unable to reproduce. I followed both your steps of init/apply/remove module+apply/init/apply again as well as init/apply/remove module/init/apply. In both cases the removed module+resource was removed.

@jbardin
Copy link
Member

jbardin commented Jan 7, 2020

Thanks for verifying this @pselle!
This was fixed by #23696

@jbardin jbardin closed this as completed Jan 7, 2020
@zagr0
Copy link
Author

zagr0 commented Jan 9, 2020

hi @jbardin , @pselle

Looks like there is some regression, just tested on 0.12.19 and got error:

  STDERR:

Error: leftover module module.gcp_module in state that should have been removed; this is a bug in Terraform and should be reported

@jbardin
Copy link
Member

jbardin commented Jan 9, 2020

Hi @zagr0,

We have that issue recorded at #22579.
The simple example above does not seem to reproduce the issue. If you have a good reproduction, or even the resulting state if there is no sensitive data, please add it to that issue.

Thanks!

@jbardin
Copy link
Member

jbardin commented Jan 9, 2020

Sorry, this does look like a regression, but I cannot reproduce it with the config above. It's hard to reproduce in some cases, because the problem is with non-deterministic ordering of operations. I'm going to take care of it with #23821.

@ghost
Copy link

ghost commented Feb 7, 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 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.

@ghost ghost locked and limited conversation to collaborators Feb 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug core v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

No branches or pull requests

4 participants