Search code examples
azureterraforminfrastructure-as-code

Terraform - Error: Provider configuration not present


When I was trying to provision my Azure resources via running the Terraform script in Azure DevOps pipelines, I encountered the following error:

│ Error: Provider configuration not present
│ 
│ To work with
│ module.xxxxxxxxx its
│ original provider configuration at
│ module.xxxxxx.provider["registry.terraform.io/hashicorp/azurerm"].some_name
│ 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
│ module.xxxxxxxxx, after
│ which you can remove the provider configuration again.

I don't understand why even I deleted the state file from the Azure storage account, it still fails.

Appreciate for any solutions.


Solution

  • Provider configuration not present issue terraform

    In error it was clearly mentioned as per the description you tried to remove the provider from the configuration which you used to provision the resources.

    Which means you creating some resources using a provider which is updated in state file. Now later on you removed the same provider block you used to provision from the configuration and its not reflected in statefile since youre getting the error while executing commands. Now after removing the provider configuration, you try to make some changes or delete in the rest of the resource configuration that are provisioned using that provider without provider block present in the configuration which will make you end blocker missing provider configuration.

    Even you removed the entire statefile sometimes it doesn’t necessarily remove all references to the provider configuration, especially if there are dependent resources that still exist in the cloud

    We can do two things here

    • Try deleting the resources that are present under azure and run it again from terrafrom init .
    • Include the provider configuration that you used while provisioning the resource.

    configuration:

    terraform {
      backend "azurerm" {
        resource_group_name   = "example-rg"
        storage_account_name  = "examplestorageacc"
        container_name        = "tfstate"
        key                   = "terraform.tfstate"
      }
    }
    
    
    provider "azurerm" {
      features {}
    }
    

    Refer:

    GitHub - hashicorp/terraform-provider-azurerm: Terraform provider for Azure Resource Manager

    Backend Type: azurerm | Terraform | HashiCorp Developer