Closed rymir closed 4 years ago
This is related to https://github.com/hashicorp/terraform/issues/24078
We saw that the GCS backend performs the initialisation as expected: https://github.com/hashicorp/terraform/blob/79d74c9ba0753000caafaef11700e10bcedda003/backend/remote-state/gcs/backend_state.go#L103
As there are different consistency guarantees between S3 and GCS we were unsure of the correct fix. Happy to work on a PR if there is a proposed solution.
FYI, our current workaround immediately after terraform init
is the following:
# on first-time tfstate creation, it prevents pre-computed plans from over-writing the s3 state when
# the pre-computed plans have been created with no initial-state in s3 to compute a lineage on.
# "terraform state push" might raise an error if an s3 tfstate is already in place
# in this case we swallow the error and continue
if [ "$(aws dynamodb get-item --table-name "${TFSTATE_DYNAMO_TABLE_NAME}" --key "{\"LockID\": {\"S\": \"${TFSTATE_S3_BUCKET_NAME}/${TFSTATE_FILE}-md5\"}}" | jq -r .Item.LockID.S)" != "${TFSTATE_S3_BUCKET_NAME}/${TFSTATE_FILE}-md5" ]; then
echo "[INFO] No s3 tfstate detected. Ensuring an initial empty tfstate written in s3."
terraform state push ".terraform/terraform.tfstate" || true
fi
Thank for the report and additional information @rymir! We are tracking this issue in #24078
Closing as duplicate of #24078
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.
Terraform Version
Terraform Configuration Files
Debug Output
Crash Output
no crash
Expected Behavior
terraform plan -out=plan1.out
andterraform plan -out=plan2.out
Actual Behavior
terraform plan -out=plan1.out
andterraform plan -out=plan2.out
Steps to Reproduce
Additional Context
References