fix: Add create_tfvars script and update pipeline configuration
This commit is contained in:
parent
2ab7872af1
commit
e0891f6c09
3 changed files with 54 additions and 0 deletions
|
|
@ -17,6 +17,15 @@
|
|||
"retryCount": 0,
|
||||
"shouldAbort": true
|
||||
},
|
||||
{
|
||||
"name": "create tfvars",
|
||||
"function": "RunCommand",
|
||||
"params": [
|
||||
"./gcloud/tf/scripts/create_tfvars.sh"
|
||||
],
|
||||
"retryCount": 0,
|
||||
"shouldAbort": true
|
||||
},
|
||||
{
|
||||
"name": "run tofu",
|
||||
"function": "RunCommand",
|
||||
|
|
|
|||
32
gcloud/tf/scripts/create_tfvars.sh
Executable file
32
gcloud/tf/scripts/create_tfvars.sh
Executable file
|
|
@ -0,0 +1,32 @@
|
|||
#!/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"
|
||||
13
gcloud/tf/terraform.tfvars.template
Normal file
13
gcloud/tf/terraform.tfvars.template
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// Your GCP project name
|
||||
// it will be refererred as the project id
|
||||
// in Google Cloud
|
||||
// ----------------------------------
|
||||
project_name = "${PROJECT_NAME}"
|
||||
|
||||
// where to deploy to
|
||||
// region
|
||||
region = "us-central1"
|
||||
zone = "us-central1-a"
|
||||
|
||||
// application name
|
||||
app_name = "${PROJECT_NAME}-k3s-cluster"
|
||||
Loading…
Add table
Add a link
Reference in a new issue