Compare commits

..

No commits in common. "bfc6b308cf5cc0f855f8015505277bef424fb6f1" and "cc79a7b0f4712561742487cb7f62ecaac63a8208" have entirely different histories.

4 changed files with 69 additions and 117 deletions

View file

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

View file

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

View file

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

View file

@ -19,9 +19,7 @@
:version "4.11.8-dev"
:stage "dev"
:debug false
:dry-run false
:autoapply false
:tg-output-filenname "tg-out.json"}))))
:dry-run false}))))
(deftest should-calculate-copy-terragrunt-command
(is (= [["bash" "-c" "cp *.hcl ../../target/test"]
@ -33,9 +31,7 @@
:version "4.11.8-dev"
:stage "dev"
:debug false
:dry-run false
:autoapply false
:tg-output-filenname "tg-out.json"}))))
:dry-run false}))))
(deftest should-calculate-terragrunt-plan-command
(is (= [[{:dir "../../../target/test/statistics"} "terragrunt" "init"]
@ -47,9 +43,7 @@
:version "4.11.8-dev"
:stage "dev"
:debug false
:dry-run false
:autoapply false
:tg-output-filenname "tg-out.json"}))))
:dry-run false}))))
(deftest should-calculate-terragrunt-apply-command
(is (= [[{:dir "../../../target/test/statistics"} "terragrunt" "init"]
@ -61,9 +55,7 @@
:version "4.11.8-dev"
:stage "dev"
:debug false
:dry-run false
:autoapply false
:tg-output-filenname "tg-out.json"}))))
:dry-run false}))))
(deftest should-calculate-terragrunt-destroy-command
(is (= [[{:dir "../../../target/test/statistics"} "terragrunt" "init"]
@ -75,22 +67,5 @@
: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"}))))
:dry-run false}))))