Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
refactor non-common TF workflows to be used behind arbitrary _bin rule
Browse files Browse the repository at this point in the history
  • Loading branch information
VJftw committed Mar 4, 2021
1 parent 77707ac commit 507df01
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
15 changes: 4 additions & 11 deletions terraform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,10 @@ terraform {
The above will result in a terraform state tree consistent with the structure of your repository.

This build rule generates the following subrules which perform the Terraform workflows:
* `terraform init`
* `terraform console`
* `terraform graph`
* `terraform import`
* `terraform output`
* `terraform providers`
* `terraform taint`
* `terraform untaint`
* `terraform plan`
* `terraform apply`
* `terraform destroy`
* `_plan`
* `_apply`
* `_destroy`
* `_bin` for all other workflows e.g. `plz run //my_infrastructure_tf_bin -- init && plz run //my_infrastructure_tf_bin -- console`

For all of these workflows, we support passing in flags via please as expected, e.g.:
```
Expand Down
5 changes: 5 additions & 0 deletions terraform/scripts/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ for i in "${!TERRAFORM_CMDS[@]}"; do
echo ""
done

# if there's no TERRAFORM_CMDS given, we assume that we just want to run Terraform directly with the given args.
if [ "${#TERRAFORM_CMDS[@]}" == "0" ]; then
"${TERRAFORM_BIN}" "${@}"
fi

for bin in "${POST_BINARIES[@]}"; do
"${ABS}/${bin}"
done
10 changes: 1 addition & 9 deletions terraform/terraform.build_defs
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,10 @@ def terraform_root(
post_binary_bash_array = _to_bash_array("POST_BINARIES", [f"$(out_exe {b})" for b in post_binaries])

cmds = {
"init": ["init"],
"console": ["init", "console"],
"graph": ["init", "graph"],
"import": ["init", "import"],
"output": ["init", "output"],
"providers": ["init", "providers"],
"refresh": ["init", "refresh"],
"taint": ["init", "taint"],
"untaint": ["init", "untaint"],
"plan": ["init", "plan"],
"apply": ["init", "apply"],
"destroy": ["init", "destroy"],
"bin": [],
}
for k in cmds.keys():
commands = cmds[k]
Expand Down

0 comments on commit 507df01

Please sign in to comment.