- terraform
- hosting
- knowledge-backup
I recently encountered an issue with an outdated Terraform configuration. When I attempted to run terraform plan
, I was notified of the need to upgrade my configuration. The challenge was that the Terraform version I have installed on my desktop no longer supported the 0.13upgrade
command. Thankfully, Docker came to the rescue. After some experimentation, I successfully executed the upgrade using this command:
docker run -v $(pwd):/ -i -t hashicorp/terraform:0.13.0 0.13upgrade
Feeling confident, I proceeded to update a CNAME entry. However, I encountered an error due to an outdated attribute from my AWS provider. The error message indicated an unsupported attribute vpc_id
.
My solution involved a few steps. First, I retrieved the state file from my S3 remote backend:
docker run -e AWS_ACCESS_KEY_ID=xxx -e AWS_SECRET_ACCESS_KEY=xxx -v $(pwd):/src -w /src -i -t hashicorp/terraform:0.13.0 state pull > state.json
Next, I edited the JSON file. For me, this meant removing a vpc_id from a Route53 zone and incrementing the top-level serial value to avoid push failures.
After fixing the JSON file, I pushed the updated state back:
docker run -e AWS_ACCESS_KEY_ID=xxx -e AWS_SECRET_ACCESS_KEY=xxx -v $(pwd):/src -w /src -i -t hashicorp/terraform:0.13.0 state push state.json
Success
Initially, I continued using Terraform 0.13 via Docker to plan and apply my updates:
docker run -e AWS_ACCESS_KEY_ID=xxx -e AWS_SECRET_ACCESS_KEY=xxx -v $(pwd):/src -w /src -i -t hashicorp/terraform:0.13.0 plan --out new.tfplan
docker run -e AWS_ACCESS_KEY_ID=xxx -e AWS_SECRET_ACCESS_KEY=xxx -v $(pwd):/src -w /src -i -t hashicorp/terraform:0.13.0 apply new.tfplan
Eventually, I was able to revert to using my locally installed Terraform. While updating another CNAME, I confirmed that everything was functioning correctly.
This experience highlighted one of the potential drawbacks of infrastructure as code. Had I used AWS tooling or the console directly, this update would have taken significantly less time. However, I still believe the benefits of using Terraform justify its use in certain scenarios and using it for simpler tasks help pressure test it and keep my knowledge a bit fresher.