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

Terraform state out of sync #14

Closed
joverlee521 opened this issue Jun 6, 2024 · 10 comments
Closed

Terraform state out of sync #14

joverlee521 opened this issue Jun 6, 2024 · 10 comments
Assignees
Labels
bug Something isn't working

Comments

@joverlee521
Copy link
Contributor

Previously discussed in #10 (comment)

I'm seeing changes in the Terraform plan even though I'm starting with a fresh clone of the repo and on the main branch.

AWS_PROFILE=admin envdir ~/Repos/env.d/infra-github-token/ terraform -chdir=env/production init
AWS_PROFILE=admin envdir ~/Repos/env.d/infra-github-token/ terraform -chdir=env/production plan -out=plan
...
Plan: 38 to add, 0 to change, 4 to destroy.

plan.txt

@victorlin
Copy link
Member

victorlin commented Jun 6, 2024

I can't read the file linked in the issue description. Here's my output with terraform plan -no-color:

plan.txt

@joverlee521
Copy link
Contributor Author

@victorlin Weird, I can't read your file either

$ terraform show ~/Downloads/plan.txt
╷
│ Error: Failed to read the given file as a state or plan file
│ 
│ State read error: Error reading /Users/joverlee/Downloads/plan.txt as a statefile: 2 problems:
│ 
│ - Unsupported state file format: The state file could not be parsed as JSON: syntax error at byte offset 1.
│ - Unsupported state file format: The state file does not have a "version" attribute, which is required to identify the format version.
│ 
│ Plan read error: couldn't load the provided path as either a local plan file (zip: not a valid zip file) or a saved cloud plan (invalid
│ character 'd' looking for beginning of value)

@victorlin
Copy link
Member

Oh... I didn't realize plan.txt referred to the actual plan file used for terraform show, I thought it was just the full output. Now we have both – mine is the console output of terraform plan and yours is the plan file.

@joverlee521
Copy link
Contributor Author

joverlee521 commented Jun 6, 2024

Terraform reading...

The "add" plans are resources that rely on Terraform state:

When Terraform creates a new infrastructure object represented by a resource block, the identifier for that real object is saved in Terraform's state, allowing it to be updated and destroyed in response to future changes.

Terraform state:

This state is stored by default in a local file named "terraform.tfstate", but we recommend storing it in HCP Terraform to version, encrypt, and securely share it with your team.

We are currently excluding the local state file from version control in the .gitignore

OH, but we do have a backend defined in terraform.tf

@joverlee521 joverlee521 changed the title Terraform plan out of sync? Terraform state out of sync? Jun 6, 2024
@joverlee521
Copy link
Contributor Author

joverlee521 commented Jun 6, 2024

$ AWS_PROFILE=admin aws s3 ls s3://nextstrain-terraform/infra/production/tfstate
2024-04-08 17:28:45      16127 tfstate

The remote tfstate file was last updated in April...which doesn't sound right considering all of the activity in this repo over the past month.

Ah, but there's been a lot of updates to s3://nextstrain-terraform/workspace/trs/infra/production/tfstate.

@tsibley, are you working from a temporary workspace?

@tsibley
Copy link
Member

tsibley commented Jun 7, 2024

Ugh, I am.

$ envd aws/blab/trs-admin-read-only github/tsibley/nextstrain-admin -- terraform -chdir=env/production workspace list
  default
* trs

Dammit. I'll move the state over (tonight or tomorrow morning) and ping here when I do.

@tsibley tsibley changed the title Terraform state out of sync? Terraform state out of sync Jun 7, 2024
@tsibley
Copy link
Member

tsibley commented Jun 7, 2024

Moved with envd aws/blab/trs github/tsibley/nextstrain-admin -- bash -c 'cd env/production; terraform state pull | (terraform workspace select default && terraform state push -)'.

@joverlee521 @victorlin What does plan say for you now?

@joverlee521
Copy link
Contributor Author

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

🎉

@tsibley
Copy link
Member

tsibley commented Jun 7, 2024

Excellent. Sorry for the hiccups!

@tsibley
Copy link
Member

tsibley commented Jun 7, 2024

(Need to get the current Terraform workspace into my prompt, since "try not to use them much and be careful" hasn't been enough…)

@tsibley tsibley self-assigned this Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants