Skip to content

Commit

Permalink
add validate option for local deployment with terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
renato-rudnicki committed Sep 6, 2024
1 parent 5417744 commit f6a226f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion 0-bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ The following steps will guide you through deploying without using Cloud Build.
1. Use the helper script [validate-requirements.sh](../scripts/validate-requirements.sh) to validate your environment:

```bash
../terraform-google-enterprise-genai/scripts/validate-requirements.sh -o <ORGANIZATION_ID> -b <BILLING_ACCOUNT_ID> -u <END_USER_EMAIL>
../terraform-google-enterprise-genai/scripts/validate-requirements.sh -o <ORGANIZATION_ID> -b <BILLING_ACCOUNT_ID> -u <END_USER_EMAIL> -t
```

**Note:** The script is not able to validate if the user is in a Cloud Identity or Google Workspace group with the required roles.
Expand Down
27 changes: 24 additions & 3 deletions scripts/validate-requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ END_USER_CREDENTIAL=""
ORGANIZATION_ID=""
BILLING_ACCOUNT=""
EXTERNAL_REPO="false"
TERRAFORM_LOCAL="false"

# Collect the errors
ERRORS=""
Expand Down Expand Up @@ -229,6 +230,21 @@ function validate_bootstrap_step(){
fi
}

# Checks if initial config was done for gcp-bootstrap step in Terraform Local deploy
function validate_bootstrap_terraform_local(){
SCRIPTS_DIR="$( dirname -- "$0"; )"
FILE="$SCRIPTS_DIR/../../gcp-bootstrap/terraform.tfvars"
if [ ! -f "$FILE" ]; then
echo " Rename the file gcp-bootstrap/terraform.example.tfvars to gcp-bootstrap/terraform.tfvars"
ERRORS+=$' terraform.tfvars file must exist for gcp-bootstrap step.\n'
else
if [ "$(grep -c REPLACE_ME "$FILE")" != 0 ]; then
echo " gcp-bootstrap/terraform.tfvars must have required values fulfilled."
ERRORS+=$' terraform.tfvars file must be correctly fulfilled for gcp-bootstrap step.\n'
fi
fi
}

# Checks if initial config was done for 0-bootstrap step in Terraform Cloud deploy
function validate_bootstrap_step_external_repo(){
SCRIPTS_DIR="$( dirname -- "$0"; )"
Expand Down Expand Up @@ -305,9 +321,11 @@ function main(){

echo "Validating 0-bootstrap configuration..."
if [[ "$EXTERNAL_REPO" == "true" ]]; then
validate_bootstrap_step_external_repo
validate_bootstrap_step_external_repo
elif [[ "$TERRAFORM_LOCAL" == "true" ]]; then
validate_bootstrap_terraform_local
else
validate_bootstrap_step
validate_bootstrap_step
fi

echo "......................................."
Expand All @@ -334,7 +352,7 @@ usage() {
}

# Check for input variables
while getopts ":o:b:u:e" OPT; do
while getopts ":o:b:u:e:t" OPT; do
case ${OPT} in
o )
ORGANIZATION_ID=$OPTARG
Expand All @@ -348,6 +366,9 @@ while getopts ":o:b:u:e" OPT; do
e )
EXTERNAL_REPO="true"
;;
t )
TERRAFORM_LOCAL="true"
;;
: )
echo
echo " Error: option -${OPTARG} requires an argument"
Expand Down

0 comments on commit f6a226f

Please sign in to comment.