generated from dxw/terraform-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* When a new service is deployed, if the .env file doesn't exist in the environment files S3 bucket, the initial deployment will fail and terraform stops * This adds a script to create an empty .env file for the service, only if the file doesn't exist (It won't overwrite existing files). The script is then ran when the bucklet or service name changes
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 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 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 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 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,49 @@ | ||
#!/bin/bash | ||
|
||
# exit on failures | ||
set -e | ||
set -o pipefail | ||
|
||
usage() { | ||
echo "Usage: $(basename "$0") [OPTIONS]" 1>&2 | ||
echo " -h - help" | ||
echo " -b - Bucket" | ||
echo " -k - Key" | ||
exit 1 | ||
} | ||
|
||
while getopts "b:k:h" opt; do | ||
case $opt in | ||
b) | ||
BUCKET=$OPTARG | ||
;; | ||
k) | ||
KEY=$OPTARG | ||
;; | ||
h) | ||
usage | ||
;; | ||
*) | ||
usage | ||
;; | ||
esac | ||
done | ||
|
||
if [[ | ||
-z "$BUCKET" || | ||
-z "$KEY" | ||
]] | ||
then | ||
usage | ||
fi | ||
|
||
if ! aws s3api head-object --bucket "$BUCKET" --key "$KEY" 2>/dev/null | ||
then | ||
# If the file does not exist, create an empty file | ||
touch /tmp/empty_file.txt | ||
aws s3api put-object --bucket "$BUCKET" --key "$KEY" --body empty_file.txt | ||
rm /tmp/empty_file.txt | ||
echo "==> Empty file created in S3 bucket" | ||
else | ||
echo "==> File already exists in S3 bucket, skipping creation" | ||
fi |