Open rocketnova opened 4 months ago
@lorenyu @doshitan Thoughts on approach?
If we come up with a solution to this sentence from this ticket:
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.
then that might work here too
unfortunately I'm not sure if the jq .backend.config solution I proposed works. may need to dig into it more.
Issue
All of the following make targets call
/bin/create-tfbackend
:infra-configure-network
infra-configure-app-build-repository
infra-configure-app-database
infra-configure-app-service
If you run any of these commands again accidentally after the layer has already been configured, you get a confusing terraform message without clear instructions about what's wrong.
For example, if you have already previously run
make infra-configure-app-build-repository
and you run it again, you will receive the following error:What's actually happening is that this line is causing an error: https://github.com/navapbc/template-infra/blob/71f2cd419a36e296ca9799d3c4b329625affc486/bin/create-tfbackend.sh#L29
The message is confusing and doesn't provide helpful advice to the user. Running
terraform init
in the root dir or in the build-repository dir, and then trying to re-runmake infra-configure-app-build-repository
is incorrect, even if it seems intuitive based on the error message.The correct next step for the user is actually to move on to run
make infra-update-app-build-repository
OR to run something liketerraform -chdir=infra/accounts init -backend-config=$(./bin/current-account-config-name).s3.tfbackend
to re-initialize the account before re-runningmake infra-configure-app-build-repository
.Resolution Ideas
Perhaps we can:
/bin/create-tfbackend
to check to check to see if the account needs to be re-initialized