diff --git a/main.tf b/main.tf index 053d611..2b258fb 100644 --- a/main.tf +++ b/main.tf @@ -1,4 +1,12 @@ locals { + template_cluster_sync_files = [ + for rel_path in var.template_cluster_file_paths : { + path = "${var.environment}/${var.region}/vpc/cluster/${rel_path}" + content = data.github_repository_file.template_cluster_files[rel_path].content + } + if lookup(var.template_enabled_modules, split(rel_path, "/")[0], false) + ] + managed_extra_files = concat([ { path = "_envcommon/default-versions.hcl" @@ -89,6 +97,14 @@ data "github_repository" "existing_repo" { full_name = "${var.organization}/${var.name}" } +data "github_repository_file" "template_cluster_files" { + for_each = toset(var.template_cluster_file_paths) + + repository = var.template_repo_name + branch = var.template_repo_ref + file = "environment/region/vpc/cluster/${each.value}" +} + resource "github_branch" "files_branch" { count = !var.create_repository && var.files_branch != null ? 1 : 0 repository = data.github_repository.existing_repo[0].name @@ -122,6 +138,7 @@ module "github_repo" { path = path content = content }], + local.template_cluster_sync_files, local.managed_extra_files, var.github_actions_workflows) diff --git a/variables.tf b/variables.tf index 59d81d7..27f556b 100644 --- a/variables.tf +++ b/variables.tf @@ -265,4 +265,63 @@ variable "files_branch_source_branch" { description = "Source branch used when creating files_branch for existing repositories. Defaults to the repository default branch." type = string default = null +} + +variable "template_repo_name" { + description = "Name of the template repository used as authoritative source for cluster-level terragrunt files." + type = string + default = "template-eks-cluster" +} + +variable "template_repo_ref" { + description = "Branch, tag, or SHA to read from template_repo_name when syncing cluster-level terragrunt files." + type = string + default = "main" +} + +variable "template_cluster_file_paths" { + description = "List of file paths under environment/region/vpc/cluster in template_repo_name to sync into environment/region-resolved cluster path." + type = list(string) + default = [ + "eks/terragrunt.hcl", + "eks-config/terragrunt.hcl", + "eks-cribl/terragrunt.hcl", + "eks-dns/terragrunt.hcl", + "eks-gatekeeper/terragrunt.hcl", + "eks-grafana/terragrunt.hcl", + "eks-istio/terragrunt.hcl", + "eks-karpenter/terragrunt.hcl", + "eks-keycloak/terragrunt.hcl", + "eks-kiali/terragrunt.hcl", + "eks-loki/terragrunt.hcl", + "eks-otel/terragrunt.hcl", + "eks-prometheus/terragrunt.hcl", + "eks-tempo/terragrunt.hcl", + ] +} + +variable "template_enabled_modules" { + description = "Enablement map used to decide which template_cluster_file_paths are synced. Key must match the first path segment, for example eks-grafana in eks-grafana/terragrunt.hcl." + type = map(bool) + default = { + eks = true + eks-config = true + eks-dns = true + eks-istio = true + eks-karpenter = true + eks-arcgis = false + eks-cribl = false + eks-gatekeeper = true + eks-grafana = true + eks-keycloak = true + eks-kiali = true + eks-loki = true + eks-otel = true + eks-pipeline = false + eks-postgresql = false + eks-prometheus = true + eks-tempo = true + eks-cert-manager = false + eks-k8s-dashboard = false + } } \ No newline at end of file