Provider configuration in nested modules

Hi,

I have a problem similar to

provider["registry.terraform.io/hashicorp/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.foo.aws_acm_certificate.cert (orphan),
│ after which you can remove the provider configuration again

The nested module in question has providers defined and now I am wondering how I could fix that.

So I am trying to get rid of this bit in a nested module:

provider “aws” {
region = “us-east-1”
}

I did not catch it in the PR review and now I have multiple environments with this applied. :frowning:

After some research, I currently see no other way than to destroy and recreate the aws resources.

refactoring it so that the provider configuration this module uses is in the root module and passed down explicitly to the child module

I don’t comprehend how this will help. Will this not just push the problem upstairs?

I have read Providers Within Modules - Configuration Language | Terraform | HashiCorp Developer

Am I missing something?

So it would be cascading downward until I reach the problematic moduleB
root → moduleA → moduleB

root

moduleA (
providers = {
aws = aws
})

moduleB
providers = {
aws = aws
})

ah last bit we wrap our deployment via terragrunt

It looks like this is why I am not getting the idea.

Ah I got it.

You can move it upwards and then you do an apply, after which you can remove the explicit provider again

provider “aws” {
alias = “remove_me”
region = “us-east-1”
}

module B {
source = …/
providers = {
aws = aws.remove_me
}
}

I hope this helps others. I don’t find it easy to explain.
And so on … tortoises all the way
apply when you reached root
then you can remove the explicit providers again and apply once more

(I only had one level, so bare in mind you might have to add more steps)