Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for removed block #34402

Closed
nevelis opened this issue Dec 12, 2023 · 3 comments
Closed

Add support for removed block #34402

nevelis opened this issue Dec 12, 2023 · 3 comments
Labels
enhancement new new issue not yet triaged

Comments

@nevelis
Copy link

nevelis commented Dec 12, 2023

Terraform Version

Terraform v1.6.5
on linux_amd64
+ provider registry.terraform.io/hashicorp/aws v5.28.0
+ provider registry.terraform.io/hashicorp/external v2.3.1
+ provider registry.terraform.io/hashicorp/null v3.2.1

Use Cases

The proposal is to add a block to mark state to be removed from the state file.

The last few major Terraform releases has been good to us. We had moved, we got import, we got for_each over import blocks. With these, and the -replace flag, we can now prepare plans that encapsulate the entire transition of the infrastructure state, instead of doing:

  • Use terraform apply -replace=x over terraform taint x
  • Use import { from = x, to = y } over terraform import x y
  • Use moved { from = x, to = y } over terraform state mv x y

... but we have nothing for terraform state rm x

We support moving objects around, we support importing, but we cannot support un-importing. Being able to detach an object from being managed by Terraform during the application of a plan would prevent the last of our remaining needs to manually manipulate the state file. For now. :)

Attempted Solutions

Initial condition:

# main.tf:

resource "aws_vpc" "myvpc" {
   ...
}

resource "aws_vpc" "theirvpc" {
   ...
}

import {
  id = "xxx"
  to = aws_vpc.othervpc
}

moved {
  from = aws_vpc.othervpc
  to   = aws_vpc.theirvpc
}

Now lets say that we have released this, and we either decide we've imported the wrong othervpc that has been moved to theirvpc. If we remove aws_vpc.their_vpc from main.tf, the object will be removed. In order to prevent this, we would do terraform state rm aws_vpc.theirvpc before applying these changes.

Proposal

# main.tf:

resource "aws_vpc" "myvpc" {
   ...
}

removed {
  from = aws_vpc.theirvpc
}

terraform apply

References

No response

@nevelis nevelis added enhancement new new issue not yet triaged labels Dec 12, 2023
@jbardin
Copy link
Member

jbardin commented Dec 12, 2023

Hi @nevelis,

A removed block feature will be available in v1.7. You can see the first beta release notes here: https://github.com/hashicorp/terraform/releases/tag/v1.7.0-beta1

Thanks!

@jbardin jbardin closed this as completed Dec 12, 2023
@nevelis
Copy link
Author

nevelis commented Dec 13, 2023

YOU ARE AMAZING. Love your work! 😁

Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement new new issue not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants