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

Incorrect `Provider Configuration Not Present` Removing google_compute_global_address #7303

Closed samhumphreys-2sixty closed 3 years ago

samhumphreys-2sixty commented 3 years ago

Community Note

Terraform Version

Terraform v0.13.2

Affected Resource(s)

google_compute_global_address

Terraform Configuration Files

# BEFORE CHANGE
terraform {
  required_providers {
      google-beta = {
        source  = "hashicorp/google-beta"
        version = "3.39.0"
      }

      google = {
        source  = "hashicorp/google"
        version = "3.39.0"
      }
  }
}

resource "google_project" "project" {
  name            = "Testing"
  project_id      = OMITTED
  folder_id       = OMITTED
  billing_account = OMITTED
}

resource "google_project_service" "cloudbilling-googleapis-com" {
  project             = google_project.project.project_id
  service             = "cloudbilling.googleapis.com"
  disable_on_destroy  = false
}

resource "google_project_service" "compute-googleapis-com" {
  project             = google_project.project.project_id
  service             = "compute.googleapis.com"
  disable_on_destroy  = false
}

resource "google_compute_global_address" "testing-ip" {
  depends_on  = [
    google_project_service.cloudbilling-googleapis-com,
    google_project_service.compute-googleapis-com
  ]
  provider    = google-beta
  project     = google_project.project.project_id
  name        = "testing-ip"
  description = ""
  ip_version  = "IPV4"

  labels = {
    "foo" = "bar"
  }
}

# AFTER CHANGE
terraform {
  required_providers {
      google-beta = {
        source  = "hashicorp/google-beta"
        version = "3.39.0"
      }

      google = {
        source  = "hashicorp/google"
        version = "3.39.0"
      }
  }
}

resource "google_project" "project" {
  name            = "Testing"
  project_id      = OMITTED
  folder_id       = OMITTED
  billing_account = OMITTED
}

resource "google_project_service" "cloudbilling-googleapis-com" {
  project             = google_project.project.project_id
  service             = "cloudbilling.googleapis.com"
  disable_on_destroy  = false
}

resource "google_project_service" "compute-googleapis-com" {
  project             = google_project.project.project_id
  service             = "compute.googleapis.com"
  disable_on_destroy  = false
}

Debug Output

https://gist.github.com/samhumphreys-2sixty/9ebe6895172bc72b740f7a052d8e4e92

Expected Behavior

google_compute_global_address should have been destroyed.

Actual Behavior

Error raised that provider configuration not present, despite still being in the Terraform file. Also this wasn't an upgrade to Terraform 13, which is where this issue usually arises (mapping legacy providers).

Error - Error: Provider configuration not present

Steps to Reproduce

  1. terraform apply - using the full initial config
  2. Remove the google_compute_global_address resource
  3. terraform apply

Important Factoids

samhumphreys-2sixty commented 3 years ago

I have also just encountered this same issue, with both google_container_cluster and google_container_node_pool. Both resources declared with provider = google-beta, and using the same Terraform version and provider versions as stated in the issue above.

It seems this is not limited to just a single resource. It is also not the case for all google-beta resources, as mentioned above, removing google_compute_address worked as expected.

edwardmedia commented 3 years ago

I can repro this issue. It appears me an Terraform issue. What do you think @c2thorn?

c2thorn commented 3 years ago

Hi @samhumphreys-2sixty, you are experiencing behavior specific to Terraform in general, and not the Google provider. Terraform notices a reference to the google-beta provider in state, but your configuration doesn't have a reference to it (It would be nice if the required_providers block was enough).

I believe you are seeing inconsistent behavior for removing resources based on whether or not it was the last reference to google-beta in your config. If you add a provider block to your config like:

provider "google-beta" {
}

and try removing any google-beta resources, you should not see this error any more. I will close this for now, but please try this out and let us know.

samhumphreys-2sixty commented 3 years ago

@c2thorn thanks, you're right. The provider configuration is still necessary to destroy the resources, though as you say it would be nice if the required_providers block was authoritative. Not an issue though, thanks!

ghost commented 3 years ago

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!