11resource "terraform_data" "flux_namespace" {
22 provisioner "local-exec" {
33 interpreter = [" /bin/bash" , " -c" ]
4- command = join (
5- " " ,
6- [
7- " kubectl" , " create" , " namespace" , " flux-system" ,
8- " --context" , var . k8s_cluster_context ,
9- ]
10- )
4+ # `kubectl create namespace` fails with AlreadyExists on re-runs, making it
5+ # non-retryable. Piping through `--dry-run=client -o yaml | kubectl apply`
6+ # produces an idempotent apply that succeeds whether the namespace exists or not.
7+ # The pipe requires a shell, so the inner command is passed as a bash -c string.
8+ command = join (" " , [
9+ " ${ path . module } /../scripts/retry.sh" , " --" , " bash" , " -c" ,
10+ " 'kubectl create namespace flux-system --context ${ var . k8s_cluster_context } --dry-run=client -o yaml" ,
11+ " | kubectl apply --context ${ var . k8s_cluster_context } -f -'" ,
12+ ])
1113 }
1214 triggers_replace = {
1315 first_run = " true"
@@ -21,6 +23,7 @@ resource "terraform_data" "flux2" {
2123 command = join (
2224 " " ,
2325 [
26+ " ${ path . module } /../scripts/retry.sh" , " --" ,
2427 " kubectl" , " --context" , var . k8s_cluster_context ,
2528 " apply" , " -f" , " https://github.com/fluxcd/flux2/releases/download/${ var . flux_version } /install.yaml" ,
2629 ]
0 commit comments