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

Deprecate the tfmigrate plan --out=tfplan option #63

Merged
merged 1 commit into from
Dec 10, 2021

Conversation

minamijoyo
Copy link
Owner

Closes #62

The tfmigrate plan --out=tfplan option was originally requested in #36, and added in #37.
While testing Terraform 1.1 support, I found it no longer work with Terraform 1.1. #62
After debugging, the tfmigrate plan --out=tfplan option was based on a bug prior to Terraform 1.1.

Since terraform state push increments the serial of tfstate, a saved plan file in tfmigrate plan phase should not be able to terraform apply. However, prior to Terraform 1.1, there was no proper validation and terraform apply allows a such case incorrectly. Starting from Terraform 1.1, it now rejects the plan as stale, which seems to be a correct behavior.

That is, the tfmigrate plan --out=tfplan option doesn't work with Terraform 1.1 or later. There is no way to do this.
Fortunately, Terraform 1.1 added a new moved block feature, so some use-cases could be covered by the moved block.
So, I decided to deprecate the tfmigrate plan --out=tfplan option without replacement and it will be removed in a future release.

Closes #62

The tfmigrate plan --out=tfplan option was originally requested in #36,
and added in #37.

While testing Terraform 1.1 support, I found it no longer work with
Terraform 1.1. #62

After debugging, the tfmigrate plan --out=tfplan option was based on a
bug prior to Terraform 1.1.

Since terraform state push increments the serial of tfstate, a saved
plan file in tfmigrate plan phase should not be able to terraform apply.
However, prior to Terraform 1.1, there was no proper validation and
terraform apply allows a such case incorrectly. Starting from Terraform
1.1, it now rejects the plan as stale, which seems to be a correct
behavior.

That is, the tfmigrate plan --out=tfplan option doesn't work with
Terraform 1.1 or later. There is no way to do this.

Fortunately, Terraform 1.1 added a new `moved` block feature, so some
use-cases could be covered by the `moved` block.

So, I decided to deprecate the tfmigrate plan --out=tfplan option
without replacement and it will be removed in a future release.
@minamijoyo minamijoyo merged commit 738ef56 into master Dec 10, 2021
@minamijoyo minamijoyo deleted the deprecate-plan-out branch December 10, 2021 07:41
minamijoyo added a commit that referenced this pull request Dec 10, 2021
A notable change is only #63.
@joestump
Copy link

@minamijoyo wondering if we should we run tfmigrate apply then run terraform plan and terraform apply? Also, the moved block has some serious limitations for now: https://discuss.hashicorp.com/t/error-cross-package-move-statement/33127/12

@minamijoyo
Copy link
Owner Author

Hi @joestump,

Yes. If resource drift remains after tfmigrate apply with a force flag, then you need to run terraform plan and terraform apply. I'm also aware of the current limitation of the moved block, which does not cover all cases. At the time of this writing, there is no simple perfect solution.

minamijoyo added a commit that referenced this pull request Sep 14, 2022
The `tfmigrate plan --out=tfplan` option was initially implemented in
tfmigrate v0.2.7 and deprecated in v0.3.0 because the feature was based
on a bug before Terraform v1.1. This means that the saved plan file is
no longer applicable in Terraform v1.1+.
#63

Even though, we found the plan file would still be useful for static
analysis such as Conftest.
#106

Let’s revert the deprecation and clarify it's intended to use only for
static analysis.

Note that the old terraform show command before Terraform v1.1.3 rejects
a plan file generated by `tfmigrate plan —out=tfplan` as stale. It works
after this change.
hashicorp/terraform#30205

Use Terraform v1.1.3+ for this feature. I think this limitation is
acceptable as long as it works with the latest Terraform.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed to terraform apply with tfplan generated by tfmigrate plan --out=tfplan in Terraform 1.1
2 participants