Skip to content

working terraform scripts from local #2

working terraform scripts from local

working terraform scripts from local #2

Workflow file for this run

name: Deploy GBFS Validator Cloud Function
on:
workflow_dispatch: # Trigger for DEV (on-demand)
inputs:
jar_file_path_override:
description: 'Optional: Override JAR file path for DEV (e.g., target/my-dev-specific.jar)'
required: false
default: 'path/to/your/validator.jar' # Default, same as TF_VAR_jar_file_path
# Add other inputs if needed for dev, like specific branch/commit to build from
push:
branches:
- main # Trigger for QA
release:
types: [published] # Trigger for PROD
env: # Global env vars, can be overridden at job level
# These should be configured based on your function's needs or overridden per environment job
TF_VAR_function_name: "gbfs-validator-function"
TF_VAR_gcp_region: "us-central1" # Change if needed
TF_VAR_function_entry_point: "com.example.YourFunctionEntryPoint" # ** IMPORTANT: User needs to change this **
TF_VAR_jar_file_path: "path/to/your/validator.jar" # ** IMPORTANT: User needs to change this **
TF_VAR_function_runtime: "java11" # Or java17, java21
TF_VAR_function_memory_mb: 256
TF_VAR_function_timeout_s: 60
TERRAFORM_VERSION: "1.2.0" # Specify Terraform version
jobs:
###########################################
# DEV DEPLOYMENT #
###########################################
deploy-dev:
if: github.event_name == 'workflow_dispatch'
name: Deploy to DEV
runs-on: ubuntu-latest
environment: dev # Optional: Link to GitHub environment for protection rules/secrets
env:
TF_VAR_gcp_project_id: ${{ secrets.GCP_PROJECT_ID_DEV }}
TF_VAR_environment: "dev"
TF_VAR_source_bucket_name: "gbfs-validator-src-dev"
# Override JAR path if provided in workflow_dispatch input
TF_VAR_jar_file_path: ${{ github.event.inputs.jar_file_path_override || env.TF_VAR_jar_file_path }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: ${{ env.TF_VAR_function_runtime == 'java11' && '11' || (env.TF_VAR_function_runtime == 'java17' && '17' || '21') }}
# - name: Build JAR for DEV (if needed)
# run: |
# echo "JAR build step for DEV - customize if needed"
# # Ensure TF_VAR_jar_file_path points to the built JAR
- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v1
with:
project_id: ${{ env.TF_VAR_gcp_project_id }}
- name: Authenticate to GCP
id: auth_dev
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Set up Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
- name: Terraform Init (DEV)
run: terraform init -backend-config=bucket=${{ env.TF_VAR_environment }}-gbfs-tf-state -backend-config=prefix=gbfs-validator
- name: Terraform Validate (DEV)
run: terraform validate
- name: Terraform Plan (DEV)
run: terraform plan -input=false -no-color -out=tfplan_dev
- name: Terraform Apply (DEV)
run: terraform apply -auto-approve -input=false tfplan_dev
- name: Show Function URL (DEV)
run: echo "DEV Cloud Function URL: $(terraform output -raw function_url)"

Check failure on line 88 in .github/workflows/deploy.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/deploy.yml

Invalid workflow file

You have an error in your yaml syntax on line 88
###########################################
# QA DEPLOYMENT #
###########################################
deploy-qa:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
name: Deploy to QA
runs-on: ubuntu-latest
needs: [deploy-dev] # Optional: make QA depend on a successful DEV manual run if desired, though typically QA is from main
environment: qa
env:
TF_VAR_gcp_project_id: ${{ secrets.GCP_PROJECT_ID_QA }}
TF_VAR_environment: "qa"
TF_VAR_source_bucket_name: "gbfs-validator-src-qa"
# TF_VAR_jar_file_path: "path/to/qa/validator.jar" # Override if QA uses a different JAR path
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: ${{ env.TF_VAR_function_runtime == 'java11' && '11' || (env.TF_VAR_function_runtime == 'java17' && '17' || '21') }}
# - name: Build JAR for QA (if needed)
# run: |
# echo "JAR build step for QA - customize if needed"
# # Ensure TF_VAR_jar_file_path points to the built JAR
- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v1
with:
project_id: ${{ env.TF_VAR_gcp_project_id }}
- name: Authenticate to GCP
id: auth_qa
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Set up Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
- name: Terraform Init (QA)
run: terraform init -backend-config=bucket=${{ env.TF_VAR_environment }}-gbfs-tf-state -backend-config=prefix=gbfs-validator
- name: Terraform Validate (QA)
run: terraform validate
- name: Terraform Plan (QA)
run: terraform plan -input=false -no-color -out=tfplan_qa
- name: Terraform Apply (QA)
run: terraform apply -auto-approve -input=false tfplan_qa
- name: Show Function URL (QA)
run: echo "QA Cloud Function URL: $(terraform output -raw function_url)"
###########################################
# PROD DEPLOYMENT #
###########################################
deploy-prod:
if: github.event_name == 'release' && github.event.action == 'published'
name: Deploy to PROD
runs-on: ubuntu-latest
needs: [deploy-qa] # Optional: make PROD depend on a successful QA deployment
environment: prod
env:
TF_VAR_gcp_project_id: ${{ secrets.GCP_PROJECT_ID_PROD }}
TF_VAR_environment: "prod"
TF_VAR_source_bucket_name: "gbfs-validator-src-prod"
# For releases, you might want to use a JAR attached to the release or built from the release tag
# TF_VAR_jar_file_path: "path/to/release/validator.jar" # Override for PROD
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.event.release.tag_name }} # Checkout the code from the release tag
# Add step here to download JAR from release assets if that's your strategy
# - name: Download Release JAR
# uses: actions/download-artifact@v3
# with:
# name: validator-jar # Assuming JAR was uploaded as an artifact with this name
# path: path/to/download # Download to a specific path
# Then update TF_VAR_jar_file_path accordingly for this job
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: ${{ env.TF_VAR_function_runtime == 'java11' && '11' || (env.TF_VAR_function_runtime == 'java17' && '17' || '21') }}
# - name: Build JAR for PROD (if needed, typically use release artifact)
# run: |
# echo "JAR build step for PROD - customize if needed"
# # Ensure TF_VAR_jar_file_path points to the built JAR or release artifact
- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v1
with:
project_id: ${{ env.TF_VAR_gcp_project_id }}
- name: Authenticate to GCP
id: auth_prod
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Set up Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
- name: Terraform Init (PROD)
run: terraform init -backend-config=bucket=${{ env.TF_VAR_environment }}-gbfs-tf-state -backend-config=prefix=gbfs-validator
- name: Terraform Validate (PROD)
run: terraform validate
- name: Terraform Plan (PROD)
run: terraform plan -input=false -no-color -out=tfplan_prod
- name: Terraform Apply (PROD)
run: terraform apply -auto-approve -input=false tfplan_prod
- name: Show Function URL (PROD)
run: echo "PROD Cloud Function URL: $(terraform output -raw function_url)"