You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a module named "s3_bucket" that encapsulated the bucket itself, CloudWatch alarms, Cloudfront distributions, Route53 records, etc. My configuration looks like this:
I set this up for 10 or so buckets. However, I noticed after doing the import + setup that I got one of the bucket's names wrong. We had an empty bucket with a similar name, and I substituted that instead. I would like to keep all of the resources in the module the same, but point them at the correct bucket.
Right now, the naive change (changing the id of the import and the bucket name in the module var), forces recreation of the bucket:
Instead of forcing recreation, I would like to re-import the correct bucket into management and drop the old incorrect bucket from terraform management.
Attempted Solutions
My first attempted solution was to use the removed block, since I know removed is the declarative version of terraform state rm:
However, this had no effect. Unlike terraform state rm, removed blocks do not seem to do anything when the resource still exists in the configuration:
Initializing plugins and modules...
╷
│ Error: Removed resource still exists
│
│ on ../modules/s3_bucket/s3_bucket.tf line 8:
│ 8: resource "aws_s3_bucket" "bucket" {
│
│ This statement declares that
│ module.rehosted_images_bucket.aws_s3_bucket.bucket was removed, but it is
│ still declared in configuration.
╵
Operation failed: failed running terraform plan (exit 1)
Then, I had the idea of using a moved block. I would move the bucket to an "ignored" address, and then the old address would be free to import the new resource:
moved {
from=module.rehosted_images_bucket.aws_s3_bucket.bucketto=aws_s3_bucket.ignored_images_bucket
}
This had a similar issue:
╷
│ Error: Moved object still exists
│
│ on s3_buckets.tf line 37:
│ 37: moved {
│
│ This statement declares a move from
│ module.rehosted_images_bucket.aws_s3_bucket.bucket, but that resource is
│ still declared at ../modules/s3_bucket/s3_bucket.tf:8,1.
│
│ Change your configuration so that this resource will be declared as
│ aws_s3_bucket.ignored_images_bucket instead.
╵
Proposal
Allow either (or both!) "removed" or "moved" blocks to reference existing configuration, since there are obviously very valid use-cases for it.
This would also have the benefit of simplifying the checks these blocks need to do, and (at least to a first glance) only involve removing code, not adding new code.
References
No response
The text was updated successfully, but these errors were encountered:
Terraform Version
Use Cases
I have a module named "s3_bucket" that encapsulated the bucket itself, CloudWatch alarms, Cloudfront distributions, Route53 records, etc. My configuration looks like this:
I set this up for 10 or so buckets. However, I noticed after doing the import + setup that I got one of the bucket's names wrong. We had an empty bucket with a similar name, and I substituted that instead. I would like to keep all of the resources in the module the same, but point them at the correct bucket.
Right now, the naive change (changing the
id
of the import and the bucket name in the module var), forces recreation of the bucket:Instead of forcing recreation, I would like to re-import the correct bucket into management and drop the old incorrect bucket from terraform management.
Attempted Solutions
My first attempted solution was to use the
removed
block, since I knowremoved
is the declarative version ofterraform state rm
:However, this had no effect. Unlike
terraform state rm
, removed blocks do not seem to do anything when the resource still exists in the configuration:Then, I had the idea of using a
moved
block. I would move the bucket to an "ignored" address, and then the old address would be free to import the new resource:This had a similar issue:
Proposal
Allow either (or both!) "removed" or "moved" blocks to reference existing configuration, since there are obviously very valid use-cases for it.
This would also have the benefit of simplifying the checks these blocks need to do, and (at least to a first glance) only involve removing code, not adding new code.
References
No response
The text was updated successfully, but these errors were encountered: