96 lines
2.7 KiB
HCL
96 lines
2.7 KiB
HCL
terraform {
|
|
backend "local" {}
|
|
required_version = ">= 1.0"
|
|
required_providers {
|
|
kubernetes = {
|
|
source = "hashicorp/kubernetes"
|
|
version = "~> 2.26"
|
|
}
|
|
}
|
|
}
|
|
|
|
provider "kubernetes" {
|
|
config_path = var.kubeconfig_path
|
|
}
|
|
|
|
locals {
|
|
application_sources = {
|
|
for name, application in var.applications : name => merge(
|
|
{
|
|
repoURL = var.gitops_repo_url
|
|
targetRevision = application.target_revision
|
|
path = application.path
|
|
},
|
|
name == "website-production" && var.website_image_ref != "" ? {
|
|
kustomize = {
|
|
images = ["php-website=${var.website_image_ref}"]
|
|
}
|
|
} : {},
|
|
name == "demos-static" && var.demos_image_ref != "" ? {
|
|
kustomize = {
|
|
images = ["${var.registry_endpoint}/demos-static=${var.demos_image_ref}"]
|
|
}
|
|
} : {},
|
|
name == "container-registry" ? {
|
|
kustomize = {
|
|
patches = [
|
|
{
|
|
target = { kind = "Deployment", name = "local-registry" }
|
|
patch = yamlencode([
|
|
{
|
|
op = "replace"
|
|
path = "/spec/template/spec/affinity/nodeAffinity/requiredDuringSchedulingIgnoredDuringExecution/nodeSelectorTerms/0/matchExpressions/0/values"
|
|
value = [var.registry_placement.node]
|
|
},
|
|
])
|
|
},
|
|
{
|
|
target = { kind = "PersistentVolume", name = "registry-data-pimox-worker-01" }
|
|
patch = yamlencode([
|
|
{ op = "replace", path = "/spec/local/path", value = var.registry_placement.path },
|
|
{
|
|
op = "replace"
|
|
path = "/spec/nodeAffinity/required/nodeSelectorTerms/0/matchExpressions/0/values"
|
|
value = [var.registry_placement.node]
|
|
},
|
|
])
|
|
},
|
|
]
|
|
}
|
|
} : {}
|
|
)
|
|
}
|
|
}
|
|
|
|
resource "kubernetes_manifest" "argocd_application" {
|
|
for_each = var.applications
|
|
|
|
field_manager {
|
|
force_conflicts = true
|
|
}
|
|
|
|
manifest = {
|
|
apiVersion = "argoproj.io/v1alpha1"
|
|
kind = "Application"
|
|
metadata = {
|
|
name = each.key
|
|
namespace = var.argocd_namespace
|
|
}
|
|
spec = {
|
|
project = each.value.project
|
|
source = local.application_sources[each.key]
|
|
destination = {
|
|
server = "https://kubernetes.default.svc"
|
|
namespace = each.value.namespace
|
|
}
|
|
syncPolicy = {
|
|
automated = {
|
|
prune = each.value.prune
|
|
selfHeal = each.value.self_heal
|
|
}
|
|
syncOptions = each.value.create_namespace ? ["CreateNamespace=true"] : []
|
|
}
|
|
}
|
|
}
|
|
}
|