navapbc / template-infra

A template to set up foundational infrastructure for your application in AWS
Apache License 2.0
9 stars 2 forks source link

Create more flexible terraform wrapper script #614

Open lorenyu opened 1 month ago

lorenyu commented 1 month ago

The Makefile commands that wrap terraform are nice but pretty limited which forces devs to use the terraform commands sometimes. This makes it a leaky abstraction and also not as convenient. It would be nice to have a more flexible wrapper that can handle most or all of terraform's functionality.

Design and implementation notes

Adding all of it to Makefile would probably make the Makefile unweildy as Make isn't designed for that. Consider something like a bin/infra script that can be used like:

infra <layer> <command>

# Examples

# Accounts layer
# infra account <account_name> plan/apply

# update dev account
infra account dev apply

# Networks layer
# infra network <network_name> plan/apply

# update dev network
infra network dev apply

# Service layer
# infra service <app_name> <environment_name> apply

# update service layer
infra service app dev apply

# change workspace
infra service app dev workspace new my_workspace

Speeding up terraform by skipping initialization when possible

it would be nice if the script checked .terraform/terraform.tfstate | jq .backend.config to see if it is already the correct backend config and skip initialization if so to speed up terraform commands.

Autocomplete

autocomplete would be nice too:

rocketnova commented 1 month ago

Somewhat related, but should ultimately be split into a separate issue:

The script should check .terraform/terraform.tfstate | jq .backend.config to see if it is already the correct backend config and skip initialization if so to speed up terraform commands.

Can we make jq a requirement for working with the platform templates? It would simplify a lot of our scripts.

lorenyu commented 1 month ago

Can we make jq a requirement for working with the platform templates? It would simplify a lot of our scripts.

Yeah I was avoiding adding dependencies at first but I realize now that it's a light, common, and robust enough dependency that it's worth it at this point given how much it'd simplify things