32 lines
893 B
Bash
32 lines
893 B
Bash
|
|
#!/bin/bash
|
||
|
|
|
||
|
|
set -a
|
||
|
|
|
||
|
|
# read environment variables from .env file
|
||
|
|
# for value $PROJECT_NAME
|
||
|
|
. .env
|
||
|
|
|
||
|
|
|
||
|
|
# Check if PROJECT_NAME environment variable is set
|
||
|
|
if [ -z "$PROJECT_NAME" ]; then
|
||
|
|
echo "Error: PROJECT_NAME environment variable is not set."
|
||
|
|
echo "Please set the PROJECT_NAME variable and try again."
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Get the directory where the script is located
|
||
|
|
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
||
|
|
cd "$SCRIPT_DIR" || { echo "Failed to change directory to $SCRIPT_DIR"; exit 1; }
|
||
|
|
# Define the template file path and output file path
|
||
|
|
TEMPLATE_FILE="../terraform.tfvars.template"
|
||
|
|
OUTPUT_FILE="../terraform.tfvars"
|
||
|
|
|
||
|
|
|
||
|
|
# Use envsubst to substitute the PROJECT_NAME variable into the template
|
||
|
|
envsubst < "$TEMPLATE_FILE" > "$OUTPUT_FILE"
|
||
|
|
if [ $? -ne 0 ]; then
|
||
|
|
echo "Error: Failed to substitute variables in the template."
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo "tfvars has been created at $OUTPUT_FILE"
|