Terraform: Terraform 0.13 / Error: Provider configuration not present

Created on 18 Aug 2020  ·  6Comments  ·  Source: hashicorp/terraform

Hi all,

I've an issue since I'm upgrading Terraform 0.13.00, I didn't have this issue before with Terraform 0.12.26
The odd point here, is that I've a terraform project as prefix workspace backend, and it's still work on 1 environnement, and not on antoher one.

The error is specific with azurerm provider, and with azurerm_key_vault_secret ressource. The error is

Error: Provider configuration not present

To work with azurerm_key_vault_secret.kvsecret_xxxx its
original provider configuration at provider["registry.terraform.io/-/azurerm"]
is required, but it has been removed. This occurs when a provider
configuration is removed while objects created by that provider still exist in
the state. Re-add the provider configuration to destroy
azurerm_key_vault_secret.xxxx, after which you can
remove the provider configuration again.

Tried to upgrade init, but it didn't fix anything.
Have to know that I use Terraform Cloud as backend state location, but running is local. Maybe this information can help.

Thank for your help

Terraform Version

Terraform v0.13.0
* -/azurerm: version = "~> 2.23.0"

Terraform Configuration Files

Here the main part of involved code, but unable to repro the issue in new workspace

terraform {
  required_version = ">= 0.13"
  required_providers {
    azuread = {
      source = "hashicorp/azuread"
    }
    azurerm = {
      source = "hashicorp/azurerm"
    }
    random = {
      source = "hashicorp/random"
    }
  }
  backend "remote" {
    hostname = "app.terraform.io"
    organization = "ORG"
    workspaces {
      prefix = "PROJECT-"
    }
  }
}
provider "azurerm" {
  version         = "~> 2"
  subscription_id = local.az_spn.subscription_id
  tenant_id       = local.az_spn.tenant_id
  client_id       = local.az_spn.client_id
  client_secret   = local.az_spn.client_secret

  features {
    key_vault {
      recover_soft_deleted_key_vaults = true
      purge_soft_delete_on_destroy    = true
    }
    virtual_machine {
      delete_os_disk_on_deletion = true
    }
    virtual_machine_scale_set {
      roll_instances_when_required = true
    }
  }
}
resource "azurerm_key_vault_secret" "kvsecret_xxxx" {
  name     = "MySecret"
  value    = "abcdef"
  key_vault_id = azurerm_key_vault.keyvault.id
}

Debug Output

Too long and with many confidential info, if need i can share with PM or noise some info inside

Crash Output

Error: Provider configuration not present
To work with azurerm_key_vault_secret.xxx its
original provider configuration at provider["registry.terraform.io/-/azurerm"]
is required, but it has been removed. This occurs when a provider
configuration is removed while objects created by that provider still exist in
the state. Re-add the provider configuration to destroy
azurerm_key_vault_secret.xxx, after
which you can remove the provider configuration again.

Expected Behavior

I expect that plan is able to run

Actual Behavior

the terraform plan failed

Steps to Reproduce

  1. terraform workspace select XX
  2. terraform init
  3. terraform plan
    -->

Additional Context

We using Terraform Cloud as backend storage, and using prefix workspace. It's work on the same project, but different workspace (with same code so)

Maybe it's not related to terraform 0.13 directly, and so maybe due to azurerm provider, but the issue happend just after upgrade terraform 0.13 on this workspace, and already works before with azurerm 2.23 version.

Thanks for your help
Kind regards
Alex

bug new

Most helpful comment

@alex-3sr It happened to me in the same way and my solution looked like this:

  1. revert changes
  2. terraform init --upgrade=true
  3. terraform apply
  4. terraform 0.13upgrade --> yes
  5. terraform apply
  6. NOW apply intended changes

All 6 comments

OK, finally I was able to fix it !
It's just that I removed some terraform resources (only key vault secrets) before upgrading 0.13, and I didn't update state on all workspace. And now that I update TF 0.13, this ressources was not in config files anymore, and only in a state for a specific workspace. I terraform state rm xxx.yyy the resources, and it's working again ;)

Have to admit that error message is not clearly and was only focus on provider ;)

Thx
Regards
Alex

Moved comment as I realize its another issue

https://github.com/hashicorp/terraform/issues/25909#issuecomment-675689216

@alex-3sr It happened to me in the same way and my solution looked like this:

  1. revert changes
  2. terraform init --upgrade=true
  3. terraform apply
  4. terraform 0.13upgrade --> yes
  5. terraform apply
  6. NOW apply intended changes

For anyone who missed it, the upgrade guide does specify that you should run plan _before_ you upgrade and apply changes before upgrading.

Hi @mildwonkey , that's correct 👍 , thank you for pointing this out.

But things start to become really funny when you discover Terraform 0.13 code with a 0.11 statefile.
Didn't know this was possible, but I guess just some missing terraform apply after upgrading.

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.

Was this page helpful?
0 / 5 - 0 ratings