Skip to main content

consolidate some of the terraform scripts

ID
84d5502
date
2023-02-17 09:32:18+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
f2bb9b2
message
consolidate some of the terraform scripts
changed files
4 files, 23 additions, 55 deletions

Changed files

terraform/tf (0) → terraform/tf (562)

diff --git a/terraform/tf b/terraform/tf
new file mode 100755
index 0000000..9adc777
--- /dev/null
+++ b/terraform/tf
@@ -0,0 +1,18 @@
+#!/usr/bin/env bash
+# In some of the Wellcome Terraform projects, we invoke Terraform via
+# a wrapper script.  This fetches extra credentials from Secrets Manager,
+# e.g. our Auth0 API tokens, and passes them to Terraform as env vars.
+#
+# This script does the boring work of checking whether a project uses
+# a wrapper script, or whether to invoke Terraform directly.
+#
+# All arguments are then passed to the underlying `terraform` command.
+
+_ensure_aws_credentials_are_fresh
+
+if [[ -f run_terraform.sh ]]
+then
+  ./run_terraform.sh "$@"
+else
+  terraform "$@"
+fi

terraform/tfa (1554) → terraform/tfa (919)

diff --git a/terraform/tfa b/terraform/tfa
index db571e5..f8a81ed 100755
--- a/terraform/tfa
+++ b/terraform/tfa
@@ -1,15 +1,7 @@
 #!/usr/bin/env bash
-# In some of the Wellcome Terraform projects, we invoke Terraform via
-# a wrapper script.  This fetches extra credentials from Secrets Manager,
-# e.g. our Auth0 API tokens, and passes them to Terraform as env vars.
-#
-# This is one of three scripts (`tfi`, `tfp`, `tfa`) which do the
-# boring work of checking whether a project uses a wrapper script, or
-# whether to invoke Terraform directly.
-#
 # This is an alias for "terraform apply".
 
-# Handle refresh-only changes.
+# == Handle refresh-only changes ==
 #
 # If Terraform doesn't want to make any changes, it will give you
 # a message:
@@ -32,23 +24,11 @@
 #
 # which doesn't make any sense!
 #
-_ensure_aws_credentials_are_fresh
-
 if [[ "$@" == "-refresh-only" ]]
 then
-  if [[ -f run_terraform.sh ]]
-  then
-    ./run_terraform.sh apply -refresh-only
-  else
-    terraform apply -refresh-only
-  fi
+  tf apply -refresh-only
 
 # All other Terraform operations
 else
-  if [[ -f run_terraform.sh ]]
-  then
-    ./run_terraform.sh apply terraform.plan "$@"
-  else
-    terraform apply terraform.plan "$@"
-  fi
+  tf apply terraform.plan "$@"
 fi

terraform/tfi (618) → terraform/tfi (106)

diff --git a/terraform/tfi b/terraform/tfi
index a58e5c5..0b83005 100755
--- a/terraform/tfi
+++ b/terraform/tfi
@@ -1,22 +1,7 @@
 #!/usr/bin/env bash
-# In some of the Wellcome Terraform projects, we invoke Terraform via
-# a wrapper script.  This fetches extra credentials from Secrets Manager,
-# e.g. our Auth0 API tokens, and passes them to Terraform as env vars.
-#
-# This is one of three scripts (`tfi`, `tfp`, `tfa`) which do the
-# boring work of checking whether a project uses a wrapper script, or
-# whether to invoke Terraform directly.
-#
 # This is an alias for "terraform init".
 
 set -o errexit
 set -o nounset
 
-_ensure_aws_credentials_are_fresh
-
-if [[ -f run_terraform.sh ]]
-then
-  ./run_terraform.sh init "$@"
-else
-  terraform init "$@"
-fi
+tf init "$@"

terraform/tfp (627) → terraform/tfp (95)

diff --git a/terraform/tfp b/terraform/tfp
index 996f258..4ac2eed 100755
--- a/terraform/tfp
+++ b/terraform/tfp
@@ -1,19 +1,4 @@
 #!/usr/bin/env bash
-# In some of the Wellcome Terraform projects, we invoke Terraform via
-# a wrapper script.  This fetches extra credentials from Secrets Manager,
-# e.g. our Auth0 API tokens, and passes them to Terraform as env vars.
-#
-# This is one of three scripts (`tfi`, `tfp`, `tfa`) which do the
-# boring work of checking whether a project uses a wrapper script, or
-# whether to invoke Terraform directly.
-#
 # This is an alias for "terraform plan".
 
-_ensure_aws_credentials_are_fresh
-
-if [[ -f run_terraform.sh ]]
-then
-  ./run_terraform.sh plan -out=terraform.plan "$@"
-else
-  terraform plan -out=terraform.plan "$@"
-fi
+tf plan -out=terraform.plan "$@"