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

Flatten TF module structure via .tfvars/.tfbackend #980

Closed
wants to merge 5 commits into from

Conversation

GaryGSC
Copy link
Member

@GaryGSC GaryGSC commented Jul 12, 2023

Using .tfvars and .tfbackend files, we can flatten our TF modules.

Before After
82d1b3e4-9e8d-49cd-b573-4642ec7badbb 37774ebc-685d-4ce6-9f19-81e3f7a18d4a

@GaryGSC GaryGSC force-pushed the simplify-tf-module-structure branch 2 times, most recently from a8bdd8d to 2f0e09c Compare July 12, 2023 19:06
@github-actions

This comment was marked as outdated.

@GaryGSC
Copy link
Member Author

GaryGSC commented Jul 12, 2023

This module restructuring clobbers the existing state, but I don't really want to fill up the template with a bunch of moved blocks.

@GaryGSC GaryGSC requested a review from a team July 12, 2023 19:12
@GaryGSC
Copy link
Member Author

GaryGSC commented Jul 12, 2023

As an example of how to use these environments, navigate to the terraform/app directory and then:

  • aws sso login
  • terraform init -backend-config=dev.s3.tfbackend
  • terraform plan -var-file=dev.tfvars

If you then try switch to production (not that you should really be doing that outside of CI/CD), the CLI will instruct you to call terraform init with either the -migrate-state or -reconfigure. -reconfigure is the correct option here because you're not trying to migrate our dev state to prd. So, it'd look like:

  • aws sso login (but to the prd account this time)
  • terraform init -backend-config=prd.s3.tfbackend -reconfigure
  • terraform plan -var-file=prd.tfvars

@GaryGSC
Copy link
Member Author

GaryGSC commented Aug 9, 2023

Rebased on dev.

@stuft2
Copy link
Contributor

stuft2 commented Aug 15, 2023

@jvisker have we talk about this in the cloud guild yet? Are we still discussing it? Do we need to update an ADR before merging?

@GaryGSC
Copy link
Member Author

GaryGSC commented Aug 16, 2023

Updated docs. That needed to happen.

Also renamed terraform-iac/ to terraform/. We're restructuring our TF stuff anyways, so this seemed like a good opportunity to also rename the directory. Why? Calling the directory terraform/ is common enough in the industry that themes can pick up on that (e.g. in VSCode or Chrome):
image

@GaryGSC
Copy link
Member Author

GaryGSC commented Nov 20, 2023

Another tiny reason to rename terraform-iac to terraform: editors treat kebab-case as multiple "words" and so the directory name can't be selected by double-clicking.

@GaryGSC GaryGSC force-pushed the simplify-tf-module-structure branch from 570809e to f27ecde Compare June 24, 2024 21:52
@GaryGSC GaryGSC changed the title Flatten TF module structure via .tfvars/.tfbackend, update to TF v1.5.3 Flatten TF module structure via .tfvars/.tfbackend Jun 24, 2024
@GaryGSC
Copy link
Member Author

GaryGSC commented Jun 24, 2024

Rebased on dev.

GaryGSC added 4 commits June 24, 2024 15:59
… local backend

This makes it harder to do the wrong thing. With this change, we avoid
a potential footgun when developers use `terraform init` instead of
`terraform init -backend-config=dev.s3.tfbackend`.

This isn't a functional change because we were already using encryption
on everything in our state buckets.
Docs needed to be updated either way.

I know we've done some bikeshedding on the directory name before. I
didn't previously care whether it was called terraform/, iac/,
terraform-iac/ or anything else. Nowadays, I have a tiny reason to
prefer the name terraform/: it plays nicely with automatic folder
icons. The other options don't.
@GaryGSC GaryGSC force-pushed the simplify-tf-module-structure branch from f27ecde to 0bc6d66 Compare June 24, 2024 22:02
@GaryGSC
Copy link
Member Author

GaryGSC commented Jun 25, 2024

Closing in favor of #1247.

@GaryGSC GaryGSC closed this Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants