Skip to content

Commit

Permalink
VAST-260 first terraform draft
Browse files Browse the repository at this point in the history
  • Loading branch information
swisstxtsokol committed Oct 25, 2024
1 parent 8b9ba4b commit 8464bf3
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Deploy to Google Cloud Run

on:
push:
branches:
- main
- dev

jobs:
terraform:
name: Apply Terraform Configuration
runs-on: ubuntu-latest

steps:

deploy:
name: Deploy to Google Cloud Run
needs: terraform
runs-on: ubuntu-latest

steps:
87 changes: 87 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
provider "google" {
project = var.project_id
region = var.region
}

locals {
registry_name = "${var.project_id}-registry"
}

# activated services in cloud-platform-iac
# services:
# - secretmanager.googleapis.com
# - sqladmin.googleapis.com
# - run.googleapis.com
# - compute.googleapis.com
# - artifactregistry.googleapis.com

resource "google_project_service" "secret_manager" {
project = var.project_id
service = "secretmanager.googleapis.com"
}

resource "google_project_service" "sqladmin" {
project = var.project_id
service = "sqladmin.googleapis.com"
}

resource "google_project_service" "cloud_run" {
project = var.project_id
service = "run.googleapis.com"
}

resource "google_project_service" "compute" {
project = var.project_id
service = "compute.googleapis.com"
}

resource "google_project_service" "artifact_registry" {
project = var.project_id
service = "artifactregistry.googleapis.com"
}

resource "google_artifact_registry_repository" "keycloak_repo" {
project = var.project_id
location = var.region
repository_id = local.registry_name # Current https://console.cloud.google.com/artifacts/docker/keycloak-dev-399613/europe-west6/keycloak/keycloak?project=keycloak-dev-399613
format = "DOCKER" # @todo is it right?
description = "Docker repository for Keycloak images"
}

resource "google_sql_database_instance" "keycloak_db_instance" {
project = var.project_id
region = var.region
name = "keycloak-dev-db" # Current https://console.cloud.google.com/sql/instances/keycloak-dev/overview?project=keycloak-dev-399613
database_version = "POSTGRES_15"

settings {
tier = var.tier # @todo the other setting like in sous-titrage?
}
}

resource "google_sql_database" "keycloak_db" {
instance = google_sql_database_instance.keycloak_db_instance.name
name = "keycloakdb" # @or should it be keycloak-dev-db?
}

resource "google_cloud_run_service" "keycloak_service" {
name = "keycloak-service"
location = var.region

template {
spec {
containers {
image = "${module.docker_artifact_registry.image_path}/${var.backend_image_tag}"
# image = "europe-west6-docker.pkg.dev/keycloak-dev-399613/keycloak/keycloak@sha256:0eeed2228ff032040510f2b478f1bb475693179018cfd5587d9a0cc1d7c5716e"

env { # took it from the docker file
name = "KC_DB_KIND"
value = "postgres"
}

}
}
}

autogenerate_revision_name = true #took from the official docs
}
22 changes: 22 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
variable "project_id" {
description = "Google Cloud Project ID"
type = string
default = "ast-d-keycloak"
}

variable "region" {
description = "Google Cloud Region"
type = string
default = "europe-west1"
}

variable "env" {
description = "Deployment environment (dev or prod)"
type = string
default = "dev" # temporarily dev
}

variable "tier" {
description = "The machine type to use for the instances."
type = string
}

0 comments on commit 8464bf3

Please sign in to comment.