provider "aws" {
version = "~> 2.0"
region = "us-east-2"
}
terraform {
backend "s3" {
bucket = "hc-lee-force-push-test"
key = "tfstate"
region = "us-east-2"
}
}
resource "random_integer" "rando" {
min = 1
max = 50000
}
tf state pull > state
cat state
{
"version": 4,
"terraform_version": "0.12.24",
"serial": 0,
"lineage": "1aa2c42c-763f-c016-1cd9-7f6167380282",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "random_integer",
"name": "rando",
"provider": "provider[\"registry.terraform.io/hashicorp/random\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"id": "41836",
"keepers": null,
"max": 50000,
"min": 1,
"result": 41836,
"seed": null
},
"private": "bnVsbA=="
}
]
}
]
}
Edit lineage and save and compare with diff:
tf state pull | diff - state
5c5
< "lineage": "1aa2c42c-763f-c016-1cd9-7f6167380282",
---
> "lineage": "1aa2c42c-763f-c016-1cd9-7f6167380283",
Try to push:
tf state push state
Failed to write state: cannot import state with lineage "1aa2c42c-763f-c016-1cd9-7f6167380283" over unrelated state with lineage "1aa2c42c-763f-c016-1cd9-7f6167380282"
Force push and compare again (no output from push):
tf state push -force state
tf state pull | diff - state
4c4
< "serial": 1,
---
> "serial": 0,
Try to push again:
tf state push state
Failed to write state: cannot import state with serial 0 over newer state with serial 1
tf state push -force state
tf state pull | diff - state
4c4
< "serial": 1,
---
> "serial": 0,