# modules/zenml_stack_base/main.tf
terraform {
required_providers {
zenml = {
source = "zenml-io/zenml"
}
google = {
source = "hashicorp/google"
}
}
}
resource "random_id" "suffix" {
# This will generate a string of 12 characters, encoded as base64 which makes
# it 8 characters long
byte_length = 6
}
# Create base infrastructure resources, including a shared object storage,
# and container registry. This module should also create resources used to
# authenticate with the cloud provider and authorize access to the resources
# (e.g. user accounts, service accounts, workload identities, roles,
# permissions etc.)
module "base_infrastructure" {
source = "./modules/base_infra"
environment = var.environment
project_id = var.project_id
region = var.region
# Generate consistent random naming across resources
resource_prefix = "zenml-${var.environment}-${random_id.suffix.hex}"
}
# Create a flexible service connector for authentication
resource "zenml_service_connector" "base_connector" {
name = "${var.environment}-base-connector"
type = "gcp"
auth_method = "service-account"
configuration = {
project_id = var.project_id
region = var.region
service_account_json = module.base_infrastructure.service_account_key
}
labels = {
environment = var.environment
}
}
# Create base stack components
resource "zenml_stack_component" "artifact_store" {
name = "${var.environment}-artifact-store"
type = "artifact_store"
flavor = "gcp"
configuration = {
path = "gs://${module.base_infrastructure.artifact_store_bucket}/artifacts"
}
connector_id = zenml_service_connector.base_connector.id
}
resource "zenml_stack_component" "container_registry" {
name = "${var.environment}-container-registry"
type = "container_registry"
flavor = "gcp"
configuration = {
uri = module.base_infrastructure.container_registry_uri
}
connector_id = zenml_service_connector.base_connector.id
}
resource "zenml_stack_component" "orchestrator" {
name = "${var.environment}-orchestrator"
type = "orchestrator"
flavor = "vertex"
configuration = {
location = var.region
workload_service_account = "${module.base_infrastructure.service_account_email}"
}
connector_id = zenml_service_connector.base_connector.id
}
# Create the base stack
resource "zenml_stack" "base_stack" {
name = "${var.environment}-base-stack"
components = {
artifact_store = zenml_stack_component.artifact_store.id
container_registry = zenml_stack_component.container_registry.id
orchestrator = zenml_stack_component.orchestrator.id
}
labels = {
environment = var.environment
type = "base"
}
}