forked from HHS/simpler-grants-gov
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathterraform-init.sh
More file actions
executable file
·27 lines (23 loc) · 1.29 KB
/
terraform-init.sh
File metadata and controls
executable file
·27 lines (23 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash
# -----------------------------------------------------------------------------
# Convenience script for running terraform init for the specified module and configuration name.
# The configuration name is used to determine which .tfbackend file to use for the -backend-config
# option of terraform init.
#
# Positional parameters:
# MODULE_DIR (required) – The location of the root module to initialize and apply
# CONFIG_NAME (required) – The name of the backend config. For accounts, the config name is the AWS account alias.
# For application modules the config name is the name of the environment (e.g. "dev", "staging", "prod").
# For application modules that are shared across environments, the config name is "shared".
# For example if a backend config file is named "myaccount.s3.tfbackend", then the CONFIG_NAME would be "myaccount"
# -----------------------------------------------------------------------------
set -euo pipefail
MODULE_DIR="$1"
CONFIG_NAME="$2"
# Run terraform init with the named backend config file
BACKEND_CONFIG_FILE="$CONFIG_NAME.s3.tfbackend"
# Note that the BACKEND_CONFIG_FILE path is relative to MODULE_DIR, not the current working directory
terraform -chdir="$MODULE_DIR" init \
-input=false \
-reconfigure \
-backend-config="$BACKEND_CONFIG_FILE"