diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 56cea5b6e..c0bb7df59 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,10 +9,16 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - - name: Setup GCP authentication - run: echo "${{ secrets.GCP_JSON }}" | base64 -d > output_file.txt - - run: export GOOGLE_APPLICATION_CREDENTIALS=$(pwd)/output_file.txt - - name: Initiate Terraform + - name: Setup Terraform + uses: hashicorp/setup-terraform@v3 + with: + terraform_version: 1.9.8 + project_id: ${{ secrets.PROJECT_ID }} + - name: Validate Terraform Configuration run: terraform -chdir=terraform init + env: + GOOGLE_CREDENTIALS: ${{ secrets.GCP_JSON }} - name: Dry run Terraform - run: terraform -chdir=terraform plan -var-file=terraform/variables.tfvars \ No newline at end of file + run: terraform -chdir=terraform plan -var-file=terraform/variables.tfvars + env: + GOOGLE_CREDENTIALS: ${{ secrets.GCP_JSON }} \ No newline at end of file diff --git a/terraform/main.tf b/terraform/main.tf index ab8216184..e63a155f8 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -3,6 +3,8 @@ provider "google" { region = var.region } +data "google_compute_default_service_account" "default" {} + data "google_compute_network" "default" { name = "default" } @@ -28,6 +30,11 @@ resource "google_compute_instance" "petclinic" { } metadata_startup_script = "${file("startup-script.sh")}" + + service_account { + email = data.google_compute_default_service_account.default.email + scopes = ["cloud-platform"] + } } resource "google_sql_database_instance" "petclinic" { @@ -48,7 +55,7 @@ resource "google_sql_database_instance" "petclinic" { resource "google_sql_user" "users" { name = var.app instance = google_sql_database_instance.petclinic.name - password = POSTGRES_PASSWORD + password = "changeme" } resource "google_sql_database" "database" { diff --git a/terraform/startup-script.sh b/terraform/startup-script.sh index 0abf1c868..e59a7b449 100644 --- a/terraform/startup-script.sh +++ b/terraform/startup-script.sh @@ -12,4 +12,7 @@ sudo apt-get update sudo apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -grep -qxF "petclinic.local" /etc/hosts || echo "127.0.0.1 petclinic.local" >> /etc/hosts \ No newline at end of file +grep -qxF "petclinic.local" /etc/hosts || echo "127.0.0.1 petclinic.local" >> /etc/hosts + +curl -sSO https://dl.google.com/cloudagents/add-google-cloud-ops-agent-repo.sh +sudo bash add-google-cloud-ops-agent-repo.sh --also-install \ No newline at end of file