138 lines
3.1 KiB
HCL
138 lines
3.1 KiB
HCL
terraform {
|
|
required_providers {
|
|
google = {
|
|
source = "hashicorp/google"
|
|
version = "3.74.0"
|
|
}
|
|
google-beta = {
|
|
source = "hashicorp/google-beta"
|
|
version = "3.74.0"
|
|
}
|
|
random = {
|
|
source = "hashicorp/random"
|
|
version = "3.1.0"
|
|
}
|
|
}
|
|
}
|
|
|
|
variable "project" {
|
|
description = "Project ID."
|
|
type = string
|
|
default = "hip-wharf-319304"
|
|
}
|
|
|
|
variable "region" {
|
|
description = "Region."
|
|
type = string
|
|
default = "us-central1"
|
|
}
|
|
|
|
variable "zone" {
|
|
description = "Zone."
|
|
type = string
|
|
default = "us-central1-c"
|
|
}
|
|
|
|
provider "google" {
|
|
project = var.project
|
|
region = var.region
|
|
zone = var.zone
|
|
}
|
|
|
|
data "google_project" "project" {
|
|
project_id = var.project
|
|
}
|
|
|
|
#################### Networking ###########################
|
|
|
|
module "networking" {
|
|
source = "../modules/networking"
|
|
project = var.project
|
|
region = var.region
|
|
}
|
|
|
|
#################### Workload Identity ####################
|
|
|
|
resource "random_id" "identity_pool" {
|
|
byte_length = 4
|
|
}
|
|
|
|
resource "google_iam_workload_identity_pool" "identity_pool" {
|
|
provider = google-beta
|
|
project = var.project
|
|
workload_identity_pool_id = "identity-pool-${random_id.identity_pool.hex}"
|
|
}
|
|
|
|
#################### KMS ##################################
|
|
|
|
resource "google_project_service" "cloudkms" {
|
|
project = var.project
|
|
service = "cloudkms.googleapis.com"
|
|
disable_dependent_services = true
|
|
}
|
|
|
|
#################### GKE ##################################
|
|
|
|
module "gke" {
|
|
source = "../modules/gke"
|
|
project = var.project
|
|
region = var.region
|
|
private_network_id = module.networking.private_network_id
|
|
private_subnetwork_id = module.networking.private_subnetwork_id
|
|
service_cloudkms = google_project_service.cloudkms
|
|
machine_type = "e2-standard-2"
|
|
|
|
depends_on = [
|
|
module.networking
|
|
]
|
|
}
|
|
|
|
output "gke_connect_command" {
|
|
# description = "Command to run to connect to the kubernetes cluster."
|
|
value = module.gke.gke_connect_command
|
|
}
|
|
|
|
#################### SQL ##################################
|
|
|
|
module "cloudsql" {
|
|
source = "../modules/cloudsql"
|
|
project = var.project
|
|
region = var.region
|
|
private_network_id = module.networking.private_network_id
|
|
|
|
depends_on = [
|
|
module.networking
|
|
]
|
|
}
|
|
|
|
# Create a workload identity service account for IAM authentication to
|
|
# cloudsql
|
|
module "cloudsql_test_sa" {
|
|
source = "../modules/workload_identity_account"
|
|
project = var.project
|
|
k8s_service_account = "test-sa"
|
|
}
|
|
|
|
#################### Redis ################################
|
|
|
|
module "redis" {
|
|
source = "../modules/redis"
|
|
project = var.project
|
|
region = var.region
|
|
private_network_id = module.networking.private_network_id
|
|
|
|
depends_on = [
|
|
module.networking
|
|
]
|
|
}
|
|
|
|
output "redis_host" {
|
|
description = "Hostname/IP Address for redis database."
|
|
value = module.redis.redis_host
|
|
}
|
|
|
|
output "redis_port" {
|
|
description = "Port for redis database."
|
|
value = module.redis.redis_port
|
|
}
|