From 01c9c53d073bcde562809f0ad175fc3ba4447612 Mon Sep 17 00:00:00 2001 From: Sean Date: Sun, 14 Apr 2024 10:38:29 -0400 Subject: [PATCH] (chore) Move and update configs, scripts and terraform to new folders --- 010-scripts/build | 5 --- 010-scripts/generate_configs | 4 -- 010-scripts/getconfigs | 17 -------- 010-scripts/terraform | 43 ------------------- {000-configs => configs}/inventory.yaml | 0 .../templates/cluster-build.tfvars.tmpl | 4 +- .../templates/external.tfvars.tmpl | 0 .../templates/machineconfig.yaml.tmpl | 4 +- scripts/build | 5 +++ scripts/generate_configs | 4 ++ scripts/getconfigs | 17 ++++++++ scripts/terraform | 43 +++++++++++++++++++ .../cloudflare.tf | 0 .../cloudflared.tf | 0 .../external-cluster-dependencies}/secrets.tf | 0 .../variables.tf | 0 .../versions.tf | 0 .../talos}/main.tf | 2 +- .../talos}/providers.tf | 0 .../talos}/variables.tf | 0 .../talos}/versions.tf | 0 21 files changed, 74 insertions(+), 74 deletions(-) delete mode 100644 010-scripts/build delete mode 100644 010-scripts/generate_configs delete mode 100644 010-scripts/getconfigs delete mode 100644 010-scripts/terraform rename {000-configs => configs}/inventory.yaml (100%) rename {000-configs => configs}/templates/cluster-build.tfvars.tmpl (84%) rename {000-configs => configs}/templates/external.tfvars.tmpl (100%) rename {000-configs => configs}/templates/machineconfig.yaml.tmpl (95%) create mode 100644 scripts/build create mode 100644 scripts/generate_configs create mode 100644 scripts/getconfigs create mode 100644 scripts/terraform rename {310-external-cluster-dependencies => terraform/external-cluster-dependencies}/cloudflare.tf (100%) rename {310-external-cluster-dependencies => terraform/external-cluster-dependencies}/cloudflared.tf (100%) rename {310-external-cluster-dependencies => terraform/external-cluster-dependencies}/secrets.tf (100%) rename {310-external-cluster-dependencies => terraform/external-cluster-dependencies}/variables.tf (100%) rename {310-external-cluster-dependencies => terraform/external-cluster-dependencies}/versions.tf (100%) rename {100-cluster-build => terraform/talos}/main.tf (97%) rename {100-cluster-build => terraform/talos}/providers.tf (100%) rename {100-cluster-build => terraform/talos}/variables.tf (100%) rename {100-cluster-build => terraform/talos}/versions.tf (100%) diff --git a/010-scripts/build b/010-scripts/build deleted file mode 100644 index e08d6e18..00000000 --- a/010-scripts/build +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -./010-scripts/generate_configs -./010-scripts/terraform -c -a -./010-scripts/getconfigs diff --git a/010-scripts/generate_configs b/010-scripts/generate_configs deleted file mode 100644 index 4a5d111b..00000000 --- a/010-scripts/generate_configs +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -gomplate -f 000-configs/templates/machineconfig.yaml.tmpl -gomplate -f 000-configs/templates/cluster-build.tfvars.tmpl diff --git a/010-scripts/getconfigs b/010-scripts/getconfigs deleted file mode 100644 index acc87f24..00000000 --- a/010-scripts/getconfigs +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh - -overwrite=false - -while getopts "o" arg; do - case $arg in - o) overwrite=true - esac -done - -terraform -chdir="./100-cluster-build" output -raw talos_config > 000-configs/generated_configs/TALOS_CONFIG -terraform -chdir="./100-cluster-build" output -raw kube_config > 000-configs/generated_configs/KUBE_CONFIG - -if $overwrite; then - cp 000-configs/generated_configs/TALOS_CONFIG ~/.talos/config - cp 000-configs/generated_configs/KUBE_CONFIG ~/.kube/config -fi diff --git a/010-scripts/terraform b/010-scripts/terraform deleted file mode 100644 index d34c44e7..00000000 --- a/010-scripts/terraform +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh - -apply=false -upgrade=false -init=false -cluster=false -external=false -while getopts "auice" arg; do - case $arg in - a) apply=true;; - u) upgrade=true;; - i) init=true;; - c) cluster=true;; - e) external=true;; - esac -done - -if $external; then - if $upgrade; then - terraform -chdir="./310-external-cluster-dependencies" init -upgrade - elif $init; then - terraform -chdir="./310-external-cluster-dependencies" - fi - if $apply; then - terraform -chdir="./310-external-cluster-dependencies" apply -var-file=../000-configs/generated_configs/external.tfvars -auto-approve - else - terraform -chdir="./310-external-cluster-dependencies" plan -var-file=../000-configs/generated_configs/external.tfvars -no-color > 000-configs/generated_configs/310.tfplan - cat 000-configs/generated_configs/310.tfplan - fi -fi -if $cluster; then - if $upgrade; then - terraform -chdir="./100-cluster-build" init -upgrade - elif $init; then - terraform -chdir="./100-cluster-build" init - fi - if $apply; then - terraform -chdir="./100-cluster-build" apply -var-file=../000-configs/generated_configs/cluster-build.tfvars -auto-approve - else - terraform -chdir="./100-cluster-build" plan -var-file=../000-configs/generated_configs/cluster-build.tfvars -no-color > 000-configs/generated_configs/100.tfplan - cat 000-configs/generated_configs/100.tfplan - fi -fi diff --git a/000-configs/inventory.yaml b/configs/inventory.yaml similarity index 100% rename from 000-configs/inventory.yaml rename to configs/inventory.yaml diff --git a/000-configs/templates/cluster-build.tfvars.tmpl b/configs/templates/cluster-build.tfvars.tmpl similarity index 84% rename from 000-configs/templates/cluster-build.tfvars.tmpl rename to configs/templates/cluster-build.tfvars.tmpl index a36b2538..1f344b4b 100644 --- a/000-configs/templates/cluster-build.tfvars.tmpl +++ b/configs/templates/cluster-build.tfvars.tmpl @@ -21,6 +21,6 @@ kubernetes_version = "{{ (datasource "inventory").kubernetes_version }}" talos_version = "{{ (datasource "inventory").talos_version }}" {{ end -}} -{{ defineDatasource "inventory" "000-configs/inventory.yaml" }} -{{- $outPath := "000-configs/generated_configs/cluster-build.tfvars" }} +{{ defineDatasource "inventory" "configs/inventory.yaml" }} +{{- $outPath := "configs/generated_configs/cluster-build.tfvars" }} {{- tmpl.Exec "talostfvars" | file.Write $outPath }} diff --git a/000-configs/templates/external.tfvars.tmpl b/configs/templates/external.tfvars.tmpl similarity index 100% rename from 000-configs/templates/external.tfvars.tmpl rename to configs/templates/external.tfvars.tmpl diff --git a/000-configs/templates/machineconfig.yaml.tmpl b/configs/templates/machineconfig.yaml.tmpl similarity index 95% rename from 000-configs/templates/machineconfig.yaml.tmpl rename to configs/templates/machineconfig.yaml.tmpl index 020c3caf..df346db1 100644 --- a/000-configs/templates/machineconfig.yaml.tmpl +++ b/configs/templates/machineconfig.yaml.tmpl @@ -98,9 +98,9 @@ cluster: {{ end }} {{ end }} -{{ defineDatasource "inventory" "000-configs/inventory.yaml" }} +{{ defineDatasource "inventory" "configs/inventory.yaml" }} {{- range $node := (datasource "inventory").nodes}} {{- $ctx := dict "node" $node }} -{{- $outPath := printf "000-configs/generated_configs/%s.yaml" $node.name }} +{{- $outPath := printf "configs/generated_configs/%s.yaml" $node.name }} {{- tmpl.Exec "machineconfigtemplate" $ctx | file.Write $outPath }} {{- end -}} diff --git a/scripts/build b/scripts/build new file mode 100644 index 00000000..5d7407b6 --- /dev/null +++ b/scripts/build @@ -0,0 +1,5 @@ +#!/bin/sh + +./scripts/generate_configs +./scripts/terraform -c -a +./scripts/getconfigs diff --git a/scripts/generate_configs b/scripts/generate_configs new file mode 100644 index 00000000..8c8f066c --- /dev/null +++ b/scripts/generate_configs @@ -0,0 +1,4 @@ +#!/bin/sh + +gomplate -f configs/templates/machineconfig.yaml.tmpl +gomplate -f configs/templates/cluster-build.tfvars.tmpl diff --git a/scripts/getconfigs b/scripts/getconfigs new file mode 100644 index 00000000..7e5f9e63 --- /dev/null +++ b/scripts/getconfigs @@ -0,0 +1,17 @@ +#!/bin/sh + +overwrite=false + +while getopts "o" arg; do + case $arg in + o) overwrite=true + esac +done + +terraform -chdir="./terraform/talos" output -raw talos_config > configs/generated_configs/TALOS_CONFIG +terraform -chdir="./terraform/talos" output -raw kube_config > configs/generated_configs/KUBE_CONFIG + +if $overwrite; then + cp configs/generated_configs/TALOS_CONFIG ~/.talos/config + cp configs/generated_configs/KUBE_CONFIG ~/.kube/config +fi diff --git a/scripts/terraform b/scripts/terraform new file mode 100644 index 00000000..e5221c28 --- /dev/null +++ b/scripts/terraform @@ -0,0 +1,43 @@ +#!/bin/sh + +apply=false +upgrade=false +init=false +cluster=false +external=false +while getopts "auice" arg; do + case $arg in + a) apply=true;; + u) upgrade=true;; + i) init=true;; + c) cluster=true;; + e) external=true;; + esac +done + +if $external; then + if $upgrade; then + terraform -chdir="./terraform/external-cluster-dependencies" init -upgrade + elif $init; then + terraform -chdir="./terraform/external-cluster-dependencies" + fi + if $apply; then + terraform -chdir="./terraform/external-cluster-dependencies" apply -var-file=../../configs/generated_configs/external.tfvars -auto-approve + else + terraform -chdir="./terraform/external-cluster-dependencies" plan -var-file=../../configs/generated_configs/external.tfvars -no-color > configs/generated_configs/310.tfplan + cat configs/generated_configs/310.tfplan + fi +fi +if $cluster; then + if $upgrade; then + terraform -chdir="./terraform/talos" init -upgrade + elif $init; then + terraform -chdir="./terraform/talos" init + fi + if $apply; then + terraform -chdir="./terraform/talos" apply -var-file=../../configs/generated_configs/cluster-build.tfvars -auto-approve + else + terraform -chdir="./terraform/talos" plan -var-file=../../configs/generated_configs/cluster-build.tfvars -no-color > configs/generated_configs/100.tfplan + cat configs/generated_configs/100.tfplan + fi +fi diff --git a/310-external-cluster-dependencies/cloudflare.tf b/terraform/external-cluster-dependencies/cloudflare.tf similarity index 100% rename from 310-external-cluster-dependencies/cloudflare.tf rename to terraform/external-cluster-dependencies/cloudflare.tf diff --git a/310-external-cluster-dependencies/cloudflared.tf b/terraform/external-cluster-dependencies/cloudflared.tf similarity index 100% rename from 310-external-cluster-dependencies/cloudflared.tf rename to terraform/external-cluster-dependencies/cloudflared.tf diff --git a/310-external-cluster-dependencies/secrets.tf b/terraform/external-cluster-dependencies/secrets.tf similarity index 100% rename from 310-external-cluster-dependencies/secrets.tf rename to terraform/external-cluster-dependencies/secrets.tf diff --git a/310-external-cluster-dependencies/variables.tf b/terraform/external-cluster-dependencies/variables.tf similarity index 100% rename from 310-external-cluster-dependencies/variables.tf rename to terraform/external-cluster-dependencies/variables.tf diff --git a/310-external-cluster-dependencies/versions.tf b/terraform/external-cluster-dependencies/versions.tf similarity index 100% rename from 310-external-cluster-dependencies/versions.tf rename to terraform/external-cluster-dependencies/versions.tf diff --git a/100-cluster-build/main.tf b/terraform/talos/main.tf similarity index 97% rename from 100-cluster-build/main.tf rename to terraform/talos/main.tf index f2827dcb..01d16c44 100644 --- a/100-cluster-build/main.tf +++ b/terraform/talos/main.tf @@ -1,5 +1,5 @@ locals { - config_directory = "../000-configs/generated_configs" + config_directory = "../../configs/generated_configs" node_identities = merge(var.controlplane, var.worker) nodes = keys(local.node_identities) apply_mode = "staged" diff --git a/100-cluster-build/providers.tf b/terraform/talos/providers.tf similarity index 100% rename from 100-cluster-build/providers.tf rename to terraform/talos/providers.tf diff --git a/100-cluster-build/variables.tf b/terraform/talos/variables.tf similarity index 100% rename from 100-cluster-build/variables.tf rename to terraform/talos/variables.tf diff --git a/100-cluster-build/versions.tf b/terraform/talos/versions.tf similarity index 100% rename from 100-cluster-build/versions.tf rename to terraform/talos/versions.tf