Roman Newaza
Roman Newaza

Reputation: 11690

Terraform: Error: Provider configuration not present

After Terraform upgrade from version 0.11.14 to 0.13.7 I got an error:

Error: Invalid resource name

on .terraform/modules/tflib/alb/main.tf line 53, in resource "aws_alb_listener" "443": 53: resource "aws_alb_listener" "443" {

A name must start with a letter or underscore and may contain only letters, digits, underscores, and dashes.

So I have it renamed to resource "aws_alb_listener" "https", but another error's thrown:

Error: Provider configuration not present

To work with module.tflib.module.alb.aws_alb_listener.443 its original provider configuration at provider["registry.terraform.io/-/aws"] 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.tflib.module.alb.aws_alb_listener.443, after which you can remove the provider configuration again.

AWS Provider config:

provider "aws" {
  region = var.region
}

terraform {
  required_providers {
    aws = {
      version = "~> 3.15"
      source = "hashicorp/aws"
    }
  }
}

How can I fix it?

Upvotes: 3

Views: 6327

Answers (1)

Peter Arboleda
Peter Arboleda

Reputation: 521

I ran into this issue when I was updating TF from 0.11 to 0.13. As other people already suggested I did 11>12>13 but nonetheless I got the same problem.

I think what happened is that the state had the old provider configuration, in this case is aws but it could be any other, so you could update the provider in your state to get the new compatible version like this

terraform state replace-provider 'registry.terraform.io/-/aws' 'registry.terraform.io/hashicorp/aws'

Upvotes: 5

Related Questions