My state files are kept along side the terraform files. (I know this is not ideal, but it is what it is at my workplace at the moment. There are plans to move away from this state management model)
The goal of my branch is to create a new ec2 instance (named
adhoc-ec2) with various policy attachments. The change is tested so the ec2 instance exists in the development environment.
A the end my branch and its associated PR has gone through a PR review process, the state file has already updated in another branch and merged into the
The difference between the two versions of the files are so big it is impossible to reconcile manually.
The root cause is of course that the terraform file contains too many resources, but it is too late to undo this now.
Now I have to resolve all the conflicts before I can merge my branch into
I tried to resolve the conflict this way:
Rebase my branch to master (such that my terraform file will contain all the latest changes)
Overwrite the stale state file in branch with the latest version in the
terraform refresh in an attempt to synchronise the state file and the actual resources of the AWS environment.
However apparently this plan does not work. Because when I run
terraform plan immediately afterwards, the plans shows that terrafrom still wants to create the ec2 instance
adhoc-ec2 (which is already created as I stated earlier in this question)
Alternatively I can destroy the ec2 instances with all the dependent roles and policies, but it is time consuming.
Is there a easier way to resolve this kind of state file conflict? Why
refresh did not work in the first place?