63 lines
1.4 KiB
HCL
63 lines
1.4 KiB
HCL
terraform {
|
|
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}"]
|
|
}
|
|
} : {}
|
|
)
|
|
}
|
|
}
|
|
|
|
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"] : []
|
|
}
|
|
}
|
|
}
|
|
}
|