-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
120 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -Eexo pipefail | ||
|
||
# Read in args from command line | ||
|
||
POSITIONAL=() | ||
while [[ $# -gt 0 ]] | ||
do | ||
key="$1" | ||
|
||
case $key in | ||
--ticket) | ||
ticket="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
--app-version) | ||
app_version="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
--lambda_container_image_uri) | ||
lambda_container_image_uri="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
-v|--tf-venue) | ||
tf_venue="$2" | ||
case $tf_venue in | ||
sit|uat|ops) ;; | ||
*) | ||
echo "tf_venue must be sit, uat, or ops" | ||
exit 1;; | ||
esac | ||
shift # past argument | ||
shift # past value | ||
;; | ||
*) # unknown option | ||
POSITIONAL+=("$1") # save it in an array for later | ||
shift # past argument | ||
;; | ||
esac | ||
done | ||
set -- "${POSITIONAL[@]}" # restore positional parameters | ||
|
||
# https://www.terraform.io/docs/commands/environment-variables.html#tf_in_automation | ||
TF_IN_AUTOMATION=true | ||
|
||
# Terraform initialization | ||
terraform init -reconfigure -input=false -backend-config="bucket=podaac-services-${tf_venue}-terraform" -backend-config="profile=ngap-service-${tf_venue}" | ||
|
||
if [[ "${ticket}" ]]; then | ||
set +e | ||
terraform workspace new "${ticket}" | ||
set -e | ||
terraform workspace select "${ticket}" | ||
else | ||
terraform workspace select default | ||
fi | ||
|
||
terraform plan -input=false -var-file=tfvars/"${tf_venue}".tfvars -var="credentials=~/.aws/credentials" -var="profile=ngap-service-${tf_venue}" -var="app_version=${app_version}" -var="lambda_container_image_uri"=${lambda_container_image_uri} -out="tfplan" | ||
|
||
# Apply the plan that was created | ||
terraform apply -input=false -auto-approve tfplan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -Eexo pipefail | ||
|
||
POSITIONAL=() | ||
while [[ $# -gt 0 ]] | ||
do | ||
key="$1" | ||
|
||
case $key in | ||
--ticket) | ||
ticket="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
--app-version) | ||
app_version="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
-v|--tf-venue) | ||
tf_venue="$2" | ||
case $tf_venue in | ||
sit|uat|ops) ;; | ||
*) | ||
echo "tf_venue must be sit, uat, or ops" | ||
exit 1;; | ||
esac | ||
shift # past argument | ||
shift # past value | ||
;; | ||
*) # unknown option | ||
POSITIONAL+=("$1") # save it in an array for later | ||
shift # past argument | ||
;; | ||
esac | ||
done | ||
set -- "${POSITIONAL[@]}" # restore positional parameters | ||
|
||
# https://www.terraform.io/docs/commands/environment-variables.html#tf_in_automation | ||
TF_IN_AUTOMATION=true | ||
|
||
# Verify that you are in test workspace | ||
current_workspace=$(terraform workspace show) | ||
|
||
if [ $current_workspace == ${ticket} ]; then | ||
# Terraform initialization | ||
terraform init -reconfigure -input=false -backend-config="bucket=podaac-services-${tf_venue}-terraform" -backend-config="profile=ngap-service-${tf_venue}" | ||
terraform destroy -auto-approve -var-file=tfvars/"${tf_venue}".tfvars -var="credentials=~/.aws/credentials" -var="profile=ngap-service-${tf_venue}" -var="app_version=${app_version}" | ||
terraform workspace select default | ||
terraform workspace delete ${ticket} | ||
else | ||
exit 1 | ||
fi |