TF complaints about deleted module's provider

Hello!

I’ve deleted a 3rd party module from my TF code , but TF still complaints about missing external provider (used by that module).

The error that I get is:

Error: failed to read schema for module.notify_slack.module.lambda.data.external.archive_prepare in registry.terraform.io/hashicorp/external: failed to instantiate provider "registry.terraform.io/hashicorp/external" to obtain schema: unavailable provider "registry.terraform.io/hashicorp/external"

I’ve run terraform init but the issue remains. My .terraform.lock.hcl file which is commited on my source control does not have the external provider setting.

provider "registry.terraform.io/hashicorp/aws" {
  version     = "4.47.0"
  constraints = "~> 4.0"
  hashes = [

  ]
}

provider "registry.terraform.io/hashicorp/random" {
  version     = "3.4.3"
  constraints = "~> 3.0, ~> 3.1"
  hashes = [

 ]
}

If I get .terraform.lock.hcl from main, which has all the previous providers (including external), I can make it work locally but then my CI fails.

Do you guys have any suggestions, please?

Seems to be similar to AWS provider issue on MAC M1 · Issue #29993 · hashicorp/terraform · GitHub

Hi @manu.nz,

Terraform remembers all of the resources that were present at the most recent terraform apply in the new state snapshot it creates.

After you remove a provider from your configuration you must run terraform apply once more to allow Terraform to remove any leftover objects that belonged to that provider. The terraform init command will install that provider so that Terraform is still able to interpret the previous state snapshot which still refers to that provider.

This means that you should also retain the entry in your .terraform.lock.hcl file until you’ve run terraform apply to remove the state file records of that provider.

Once you’ve run terraform apply at least once without the provider mentioned in your configuration there will no longer be any mention of the provider in your latest state snapshot and so terraform init (and other commands) will no longer need to install that provider.

1 Like