Terraform: -force flag on terraform remote push does not work

Created on 16 Mar 2016  ยท  12Comments  ยท  Source: hashicorp/terraform

Hey,

I have an issue where I am attempting to push my local state over the remote state using the command:

# terraform remote push -force                                          

results in the error

Failed to read state: Unknown refresh result: Local and remote state conflict, manual resolution required

Shouldn't the "-force" overwrite the remote anyway, or am I not understanding something?

I am on v0.6.13

Thanks!

bug core

Most helpful comment

For anyone else that happens upon this, it's serial that needs to be bumped, not version

All 12 comments

One additional note is that I first did a

terraform remote config -backend=S3 -backend-config="bucket=xxxxxx" -backend-config="key=terraform.tfstate" -backend-config="region=us-east-1" -pull=false

(notice the "-pull=false" on the end. This was an attempt to fix up an issue)

Thanks for the report, @dansteen it does indeed look like the -force flag is not working as intended here!

The workaround in the meantime is to manually bump the serial number in your local state cache (.terraform/terraform.tfstate) to exceed the number held remotely. Then terraform remote push should succeed.

thanks!

Hitting a frustrating issue with the -force flag as well. I have some state in an S3 bucket that is old. Like @dansteen, I did a terraform remote config with a -pull=false. I then tried a terraform push -force to overwrite the old state. However, instead, the old state gets merged into my current state, which messes things up. I'll try the serial number fix to see if that helps.

Update: looks like bumping the version number in the .terraform/terraform.tfstate file did the trick. Thanks for the workaround.

@phinze Also ran into this, thanks for the workaround.

It's terraform 0.7.3 and the issue is still there.

For anyone else that happens upon this, it's serial that needs to be bumped, not version

I haven't tried it out myself but this appears to have been significantly reworked in master. I wouldn't be surprised if it's been fixed by some of those changes.

If bumping the serial number is how one confirms this bug still exists, then I can confirm it is still there as of 0.8.8.

Hi all! Sorry for this issue and sorry for letting it sit here for so long.

In Terraform 0.9 we significantly redesigned the remote state system, eliminating the local cache of state and along with it the terraform remote push command. Therefore the code that was causing this bug no longer exists: Terraform just immediately writes state to the backend, skipping the local/remote syncing that used to happen.

Therefore I'm going to close this issue. If anyone still has issues with remote state, I recommend to open a fresh new issue for it since the relevant parts of Terraform have changed a lot since v0.6.3 (and v0.8.8, for that matter) so any new issues are likely to have a different root-cause and need fresh investigation. Thanks everyone for the discussion here!

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.

Was this page helpful?
0 / 5 - 0 ratings