cloudposse / terraform-aws-tfstate-backend

Terraform module that provision an S3 bucket to store the `terraform.tfstate` file and a DynamoDB table to lock the state file to prevent concurrent modifications and state corruption.
https://cloudposse.com/accelerate
Apache License 2.0
408 stars 177 forks source link

v0.16.0 -> v0.17.0 broken? #47

Closed schollii closed 2 years ago

schollii commented 4 years ago

Found a bug? Maybe our Slack Community can help.

Slack Community

Describe the Bug

When upgrading the backend plugin from 0.16 to 0.17, you get a bunch of errors that look like this:

Error: Provider configuration not present

To work with
module.terraform_state_backend.module.dynamodb_table_label.data.null_data_source.tags_as_list_of_maps[0]
its original provider configuration at
module.terraform_state_backend.module.dynamodb_table_label.provider.null 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.terraform_state_backend.module.dynamodb_table_label.data.null_data_source.tags_as_list_of_maps[0],
after which you can remove the provider configuration again.

Terraform version:

$ terraform -version
Terraform v0.12.24
+ provider.aws v2.62.0
+ provider.local v1.4.0
+ provider.null v2.1.2
+ provider.template v2.1.2

I checked https://github.com/hashicorp/terraform/issues/21416 but it is not obvious how to fix, I think the fix has to be in your module (not in backend.tf).

Expected Behavior

The terraform apply after upgrading backend module to 0.17 should have worked.

Steps to Reproduce

In empty folder, create backend.tf:

provider "aws" {
  region = "us-east-2"
}

module "terraform_state_backend" {
  source        = "git::https://github.com/cloudposse/terraform-aws-tfstate-backend.git?ref=0.16.0"

  environment   = "test-tf-bug"
  stage         = "oliver"
  name          = null
  # force_destroy = true
  attributes    = ["terraform-state"]
  region        = "us-east-2"
}

Then

terraform init
terraform apply

Everything works.

Now edit the backend.tf file to point to 0.17 of terraform-aws-tfstate-backend module, then repeat:

terraform init
terraform apply 

This time the apply causes a dozen identical errors (but about different elements). The error is shown in the Description above.

tvjg commented 4 years ago

Is it possible/safe to downgrade? I just blundered into this while trying to upgrade a different plugin.

schollii commented 4 years ago

I don't recall a problem downgrading. Pin the version, init, apply (check the plan before yes)

osterman commented 4 years ago

I think the only way to fix this is to destroy and recreate the resource. Basically, terraform fails to correctly compute the required steps to perform the operation.

I have encountered this with other modules when we do big changes.

I'm not sure what has changed recently to cause this. We'll review any PRs though to fix it =)

jamengual commented 4 years ago

I just had this problem and I fixed it bu running :

terraform state rm module.terraform_state_backend.module.s3_bucket_label.data.null_data_source.tags_as_list_of_maps
 terraform state rm module.terraform_state_backend.module.base_label.data.null_data_source.tags_as_list_of_maps
 terraform state rm module.terraform_state_backend.module.dynamodb_table_label.data.null_data_source.tags_as_list_of_maps
dfuentes77 commented 4 years ago

I just had this problem and I fixed it bu running :

terraform state rm module.terraform_state_backend.module.s3_bucket_label.data.null_data_source.tags_as_list_of_maps
 terraform state rm module.terraform_state_backend.module.base_label.data.null_data_source.tags_as_list_of_maps
 terraform state rm module.terraform_state_backend.module.dynamodb_table_label.data.null_data_source.tags_as_list_of_maps

This worked for me. Thanks.

nitrocode commented 2 years ago

Ok I will close this since a workaround has been found.