Hacker News new | ask | show | jobs
by kstrauser 1891 days ago
I think there's a middle ground if you're not sure how to fix a mistake in Terraform but you know how to do it in the console:

* Make your changes by hand

* Right afterward, run "terraform plan" to see how Terraform would undo your changes

* Edit your Terraform config to reflect those changes, and run "terraform plan" again to make sure you caught everything. Repeat until it's a no-op.

Now you've got a log of what you've done in a Git-ready format, and you can repeat it elsewhere, and you've learned how to make that console change in code.

3 comments

This. I’m surprised at how many folks don’t realize you can do this and capture your changes in terraform by looking at the plan and making tf code changes until the plan doesn’t show a diff
You can also fetch cloud resource state with terraform, without running plan - I can’t remember the exact command. You can use this to import new resources into tf
You can do it that way, but I find the tf docs easier and more concise to use than clicking around the AWS UI.
I do too, but that was an invaluable tool when we were first switching over and learning the ropes.