infra_snippets/terraform/basic_gke/main.tf

138 lines
3.1 KiB
Terraform
Raw Normal View History

2021-07-09 01:54:20 +00:00
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "3.74.0"
}
2021-07-09 05:54:13 +00:00
google-beta = {
source = "hashicorp/google-beta"
version = "3.74.0"
}
2021-07-09 01:54:20 +00:00
random = {
source = "hashicorp/random"
version = "3.1.0"
}
}
}
2021-07-09 00:30:19 +00:00
variable "project" {
description = "Project ID."
type = string
2021-07-09 04:50:48 +00:00
default = "hip-wharf-319304"
2021-07-09 00:30:19 +00:00
}
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
}
2021-07-09 01:54:20 +00:00
data "google_project" "project" {
2021-07-09 04:50:48 +00:00
project_id = var.project
2021-07-09 01:54:20 +00:00
}
#################### Networking ###########################
module "networking" {
source = "../modules/networking"
project = var.project
region = var.region
}
2021-07-09 05:54:13 +00:00
#################### 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 ##################################
2021-07-13 05:10:23 +00:00
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
2021-07-18 22:27:24 +00:00
machine_type = "e2-standard-2"
2021-07-09 00:30:19 +00:00
depends_on = [
module.networking
]
2021-07-09 00:30:19 +00:00
}
2021-07-09 04:50:48 +00:00
output "gke_connect_command" {
2021-07-13 05:10:23 +00:00
# description = "Command to run to connect to the kubernetes cluster."
value = module.gke.gke_connect_command
2021-07-09 04:50:48 +00:00
}
2021-07-12 04:06:49 +00:00
#################### SQL ##################################
module "cloudsql" {
source = "../modules/cloudsql"
project = var.project
region = var.region
private_network_id = module.networking.private_network_id
depends_on = [
module.networking
]
2021-07-12 04:06:49 +00:00
}
2021-07-13 03:15:54 +00:00
# Create a workload identity service account for IAM authentication to
# cloudsql
module "cloudsql_test_sa" {
2021-07-18 21:03:14 +00:00
source = "../modules/workload_identity_account"
project = var.project
k8s_service_account = "test-sa"
}
2021-07-13 03:15:54 +00:00
#################### 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
}