Skip to content

Commit 560b613

Browse files
committed
Refactor ArgoCD application management: use dynamic triggers for application creation and destruction
1 parent ffb6b37 commit 560b613

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

Terraform/modules/argocd/applications.tf

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
# Create ArgoCD Applications
21
resource "null_resource" "argocd_applications" {
32
count = length(var.applications)
43

4+
# Store dynamic values in triggers
5+
triggers = {
6+
cluster_name = var.cluster_name
7+
namespace = var.namespace
8+
app_name = var.applications[count.index].name
9+
}
10+
11+
# Creation
512
provisioner "local-exec" {
613
command = <<EOF
714
# Configure kubectl to use EKS cluster
8-
aws eks update-kubeconfig --name ${var.cluster_name} --region us-east-1
15+
aws eks update-kubeconfig --name ${self.triggers.cluster_name} --region us-east-1
916
1017
# Wait for ArgoCD CRDs to be available
1118
kubectl wait --for condition=established --timeout=300s crd/applications.argoproj.io
@@ -15,8 +22,8 @@ kubectl apply -f - <<YAML
1522
apiVersion: argoproj.io/v1alpha1
1623
kind: Application
1724
metadata:
18-
name: ${var.applications[count.index].name}
19-
namespace: ${var.namespace}
25+
name: ${self.triggers.app_name}
26+
namespace: ${self.triggers.namespace}
2027
spec:
2128
project: default
2229
source:
@@ -36,12 +43,13 @@ YAML
3643
EOF
3744
}
3845

46+
# Destroy
3947
provisioner "local-exec" {
40-
when = destroy
41-
command = <<EOF
42-
# Configure kubectl for destroy (using hardcoded values)
43-
aws eks update-kubeconfig --name otel-cluster --region us-east-1 || true
44-
kubectl delete application ${self.triggers.name} -n argocd --ignore-not-found=true
48+
when = destroy
49+
command = <<EOF
50+
# Configure kubectl for destroy (using dynamic triggers)
51+
aws eks update-kubeconfig --name ${self.triggers.cluster_name} --region us-east-1 || true
52+
kubectl delete application ${self.triggers.app_name} -n ${self.triggers.namespace} --ignore-not-found=true
4553
EOF
4654
}
4755

0 commit comments

Comments
 (0)