Compare commits

...

2 commits

Author SHA1 Message Date
bfc6b308cf parse output 2024-08-14 20:06:47 +02:00
9253377526 upgrade versions 2024-08-14 19:23:00 +02:00
4 changed files with 117 additions and 69 deletions

View file

@ -5,8 +5,8 @@
["src" "resources"] ["src" "resources"]
:deps :deps
{org.clojure/clojure {:mvn/version "1.11.1"} {org.clojure/clojure {:mvn/version "1.11.4"}
org.clojure/spec.alpha {:mvn/version "0.4.233"} org.clojure/spec.alpha {:mvn/version "0.5.238"}
orchestra/orchestra {:mvn/version "2021.01.01-1"}} orchestra/orchestra {:mvn/version "2021.01.01-1"}}
:aliases :aliases
@ -27,7 +27,7 @@
;; call with :watch? true to start file watcher and re-run tests on saved changes ;; call with :watch? true to start file watcher and re-run tests on saved changes
:test/run :test/run
{:extra-paths ["test"] {:extra-paths ["test"]
:extra-deps {lambdaisland/kaocha {:mvn/version "1.87.1366"}} :extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}}
:main-opts ["-m" "kaocha.runner"] :main-opts ["-m" "kaocha.runner"]
:exec-fn kaocha.runner/exec-fn :exec-fn kaocha.runner/exec-fn
:exec-args {:randomize? false :exec-args {:randomize? false

View file

@ -1,6 +1,7 @@
(ns dda.build.terragrunt (ns dda.build.terragrunt
(:require [orchestra.core :refer [defn-spec]] (:require [orchestra.core :refer [defn-spec]]
[clojure.spec.test.alpha :as st] [clojure.spec.test.alpha :as st]
[cheshire.core :refer [parse-string]]
[dda.build.devops :as d] [dda.build.devops :as d]
[dda.build.terragrunt.domain :as domain] [dda.build.terragrunt.domain :as domain]
[dda.build.infrastructure :as i])) [dda.build.infrastructure :as i]))
@ -8,58 +9,70 @@
(st/instrument `clean-build-dir!) (st/instrument `clean-build-dir!)
(def default (def default
(merge d/default {:autoapply false})) (merge d/default {:autoapply false
:tg-output-filenname "tg-out.json"}))
(defn-spec clean-build-dir! nil? (defn-spec clean-build-dir! nil?
[devops ::d/devops] [devops ::d/devops]
(let [final (merge default devops)] (let [config (merge default devops)]
(i/execute! (domain/clean-build-dir-command final) final))) (i/execute! (domain/clean-build-dir-command config) config)))
(defn-spec copy-terragrunt! nil? (defn-spec copy-terragrunt! nil?
[devops ::d/devops] [devops ::d/devops]
(let [final (merge default devops)] (let [config (merge default devops)]
(doseq [c (domain/copy-terragrunt-command final)] (doseq [c (domain/copy-terragrunt-command config)]
(i/execute! c final)))) (i/execute! c config))))
(defn-spec terragrunt-plan! nil? (defn-spec terragrunt-plan! nil?
[devops ::d/devops] [devops ::d/devops]
(let [final (merge default devops)] (let [config (merge default devops)]
(doseq [c (domain/terragrunt-plan-command final)] (doseq [c (domain/terragrunt-plan-command config)]
(i/execute! c final)))) (i/execute! c config))))
(defn-spec terragrunt-apply! nil? (defn-spec terragrunt-apply! nil?
[devops ::d/devops] [devops ::d/devops]
(let [final (merge default devops)] (let [config (merge default devops)]
(doseq [c (into (domain/terragrunt-apply-command final) (doseq [c (domain/terragrunt-apply-command config)]
(domain/terragrunt-output-command final))] (i/execute! c config))))
(i/execute! c final))))
(defn-spec terragrunt-output! map?
[devops ::d/devops]
(let [config (merge default devops)]
(doseq [c (domain/terragrunt-output-command config)]
(i/execute! c config))
(parse-string (slurp (domain/output-path config))
(fn [k] (keyword (.toLowerCase k))))))
(defn-spec terragrunt-destroy! nil? (defn-spec terragrunt-destroy! nil?
[devops ::d/devops] [devops ::d/devops]
(let [final (merge default devops)] (let [config (merge default devops)]
(doseq [c (domain/terragrunt-destroy-command final)] (doseq [c (domain/terragrunt-destroy-command config)]
(i/execute! c final)))) (i/execute! c config))))
(defn-spec plan! nil? (defn-spec plan! nil?
[devops ::d/devops] [devops ::d/devops]
(clean-build-dir! devops) (let [config (merge default devops)]
(d/create-build-dir! devops) (clean-build-dir! config)
(copy-terragrunt! devops) (d/create-build-dir! config)
(terragrunt-plan! devops)) (copy-terragrunt! config)
(terragrunt-plan! config)))
(defn-spec apply! nil? (defn-spec apply! map?
[devops ::d/devops] [devops ::d/devops]
(clean-build-dir! devops) (let [config (merge default devops)]
(d/create-build-dir! devops) (clean-build-dir! config)
(copy-terragrunt! devops) (d/create-build-dir! config)
(terragrunt-apply! devops)) (copy-terragrunt! config)
(terragrunt-apply! config)
(terragrunt-output! config)))
(defn-spec destroy! nil? (defn-spec destroy! nil?
[devops ::d/devops] [devops ::d/devops]
(clean-build-dir! devops) (let [config (merge default devops)]
(d/create-build-dir! devops) (clean-build-dir! config)
(copy-terragrunt! devops) (d/create-build-dir! config)
(terragrunt-destroy! devops)) (copy-terragrunt! config)
(terragrunt-destroy! config)))
(st/instrument `clean-build-dir!) (st/instrument `clean-build-dir!)
(st/instrument `copy-terragrunt!) (st/instrument `copy-terragrunt!)

View file

@ -3,36 +3,46 @@
[orchestra.core :refer [defn-spec]] [orchestra.core :refer [defn-spec]]
[dda.build.devops.domain :as d])) [dda.build.devops.domain :as d]))
(s/def ::devops (s/def ::tg-output-filenname string?)
(s/keys :req-un [::name ::stage ::project-root-path ::build-dir-name ::debug ::dry-run ::module] (s/def ::autoapply boolean?)
(s/def ::config
(s/keys :req-un [::d/name ::d/stage ::d/project-root-path ::d/build-dir-name ::d/debug
::d/dry-run ::d/module ::tg-output-filenname ::autoapply]
:opt-un [])) :opt-un []))
(defn-spec clean-build-dir-command seq? (defn-spec clean-build-dir-command seq?
[devops ::devops] [config ::config]
["rm" "-rf" (d/build-path (dissoc devops :module))]) ["rm" "-rf" (d/build-path (dissoc config :module))])
(defn-spec copy-terragrunt-command seq? (defn-spec copy-terragrunt-command seq?
[devops ::devops] [config ::config]
(let [{:keys [module]} devops (let [{:keys [module]} config
devops-wo-module (dissoc devops :module)] config-wo-module (dissoc config :module)]
[["bash" "-c" (str "cp *.hcl " (d/build-path devops-wo-module))] [["bash" "-c" (str "cp *.hcl " (d/build-path config-wo-module))]
["cp" "-r" module (d/build-path devops-wo-module)]])) ["cp" "-r" module (d/build-path config-wo-module)]]))
(defn-spec terragrunt-plan-command seq? (defn-spec terragrunt-plan-command seq?
[devops ::devops] [config ::config]
[[{:dir (d/build-path devops)} "terragrunt" "init"] [[{:dir (d/build-path config)} "terragrunt" "init"]
[{:dir (d/build-path devops)} "terragrunt" "plan"]]) [{:dir (d/build-path config)} "terragrunt" "plan"]])
(defn-spec terragrunt-apply-command seq? (defn-spec terragrunt-apply-command seq?
[devops ::devops] [config ::config]
[[{:dir (d/build-path devops)} "terragrunt" "init"] [[{:dir (d/build-path config)} "terragrunt" "init"]
[{:dir (d/build-path devops)} "terragrunt" "apply" "-auto-approve"]]) [{:dir (d/build-path config)} "terragrunt" "apply" "-auto-approve"]])
(defn-spec terragrunt-destroy-command seq? (defn-spec terragrunt-destroy-command seq?
[devops ::devops] [config ::config]
[[{:dir (d/build-path devops)} "terragrunt" "init"] [[{:dir (d/build-path config)} "terragrunt" "init"]
[{:dir (d/build-path devops)} "terragrunt" "destroy"]]) [{:dir (d/build-path config)} "terragrunt" "destroy"]])
(defn-spec terragrunt-output-command seq? (defn-spec terragrunt-output-command seq?
[devops ::devops] [config ::config]
[[{:dir (d/build-path devops)} "bash" "-c" "terragrunt output -json > terraform.json"]]) (let [{:keys [tg-output-filenname]} config]
[[{:dir (d/build-path config)} "bash" "-c" (str "terragrunt output -json > " tg-output-filenname)]]))
(defn-spec output-path string?
[config ::config]
(let [{:keys [tg-output-filenname]} config]
(str (d/build-path config) "/" tg-output-filenname)))

View file

@ -19,7 +19,9 @@
:version "4.11.8-dev" :version "4.11.8-dev"
:stage "dev" :stage "dev"
:debug false :debug false
:dry-run false})))) :dry-run false
:autoapply false
:tg-output-filenname "tg-out.json"}))))
(deftest should-calculate-copy-terragrunt-command (deftest should-calculate-copy-terragrunt-command
(is (= [["bash" "-c" "cp *.hcl ../../target/test"] (is (= [["bash" "-c" "cp *.hcl ../../target/test"]
@ -31,7 +33,9 @@
:version "4.11.8-dev" :version "4.11.8-dev"
:stage "dev" :stage "dev"
:debug false :debug false
:dry-run false})))) :dry-run false
:autoapply false
:tg-output-filenname "tg-out.json"}))))
(deftest should-calculate-terragrunt-plan-command (deftest should-calculate-terragrunt-plan-command
(is (= [[{:dir "../../../target/test/statistics"} "terragrunt" "init"] (is (= [[{:dir "../../../target/test/statistics"} "terragrunt" "init"]
@ -43,29 +47,50 @@
:version "4.11.8-dev" :version "4.11.8-dev"
:stage "dev" :stage "dev"
:debug false :debug false
:dry-run false})))) :dry-run false
:autoapply false
:tg-output-filenname "tg-out.json"}))))
(deftest should-calculate-terragrunt-apply-command (deftest should-calculate-terragrunt-apply-command
(is (= [[{:dir "../../../target/test/statistics"} "terragrunt" "init"] (is (= [[{:dir "../../../target/test/statistics"} "terragrunt" "init"]
[{:dir "../../../target/test/statistics"} "terragrunt" "apply" "-auto-approve"]] [{:dir "../../../target/test/statistics"} "terragrunt" "apply" "-auto-approve"]]
(cut/terragrunt-apply-command {:name "test" (cut/terragrunt-apply-command {:name "test"
:module "statistics"
:project-root-path "../../.."
:build-dir-name "target"
:version "4.11.8-dev"
:stage "dev"
:debug false
:dry-run false}))))
(deftest should-calculate-terragrunt-destroy-command
(is (= [[{:dir "../../../target/test/statistics"} "terragrunt" "init"]
[{:dir "../../../target/test/statistics"} "terragrunt" "destroy"]]
(cut/terragrunt-destroy-command {:name "test"
:module "statistics" :module "statistics"
:project-root-path "../../.." :project-root-path "../../.."
:build-dir-name "target" :build-dir-name "target"
:version "4.11.8-dev" :version "4.11.8-dev"
:stage "dev" :stage "dev"
:debug false :debug false
:dry-run false})))) :dry-run false
:autoapply false
:tg-output-filenname "tg-out.json"}))))
(deftest should-calculate-terragrunt-destroy-command
(is (= [[{:dir "../../../target/test/statistics"} "terragrunt" "init"]
[{:dir "../../../target/test/statistics"} "terragrunt" "destroy"]]
(cut/terragrunt-destroy-command {:name "test"
:module "statistics"
:project-root-path "../../.."
:build-dir-name "target"
:version "4.11.8-dev"
:stage "dev"
:debug false
:dry-run false
:autoapply false
:tg-output-filenname "tg-out.json"}))))
(deftest should-calculate-terragrunt-output-command
(is (= [[{:dir "../../../target/test/statistics"} "bash"
"-c"
"terragrunt output -json > tg-out.json"]]
(cut/terragrunt-output-command {:name "test"
:module "statistics"
:project-root-path "../../.."
:build-dir-name "target"
:version "4.11.8-dev"
:stage "dev"
:debug false
:dry-run false
:autoapply false
:tg-output-filenname "tg-out.json"}))))