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"] ["src" "resources"]
:deps :deps
{org.clojure/clojure {:mvn/version "1.11.4"} {org.clojure/clojure {:mvn/version "1.11.1"}
org.clojure/spec.alpha {:mvn/version "0.5.238"} org.clojure/spec.alpha {:mvn/version "0.4.233"}
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.91.1392"}} :extra-deps {lambdaisland/kaocha {:mvn/version "1.87.1366"}}
: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,7 +1,6 @@
(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]))
@ -9,70 +8,58 @@
(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 [config (merge default devops)] (let [final (merge default devops)]
(i/execute! (domain/clean-build-dir-command config) config))) (i/execute! (domain/clean-build-dir-command final) final)))
(defn-spec copy-terragrunt! nil? (defn-spec copy-terragrunt! nil?
[devops ::d/devops] [devops ::d/devops]
(let [config (merge default devops)] (let [final (merge default devops)]
(doseq [c (domain/copy-terragrunt-command config)] (doseq [c (domain/copy-terragrunt-command final)]
(i/execute! c config)))) (i/execute! c final))))
(defn-spec terragrunt-plan! nil? (defn-spec terragrunt-plan! nil?
[devops ::d/devops] [devops ::d/devops]
(let [config (merge default devops)] (let [final (merge default devops)]
(doseq [c (domain/terragrunt-plan-command config)] (doseq [c (domain/terragrunt-plan-command final)]
(i/execute! c config)))) (i/execute! c final))))
(defn-spec terragrunt-apply! nil? (defn-spec terragrunt-apply! nil?
[devops ::d/devops] [devops ::d/devops]
(let [config (merge default devops)] (let [final (merge default devops)]
(doseq [c (domain/terragrunt-apply-command config)] (doseq [c (into (domain/terragrunt-apply-command final)
(i/execute! c config)))) (domain/terragrunt-output-command final))]
(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 [config (merge default devops)] (let [final (merge default devops)]
(doseq [c (domain/terragrunt-destroy-command config)] (doseq [c (domain/terragrunt-destroy-command final)]
(i/execute! c config)))) (i/execute! c final))))
(defn-spec plan! nil? (defn-spec plan! nil?
[devops ::d/devops] [devops ::d/devops]
(let [config (merge default devops)] (clean-build-dir! devops)
(clean-build-dir! config) (d/create-build-dir! devops)
(d/create-build-dir! config) (copy-terragrunt! devops)
(copy-terragrunt! config) (terragrunt-plan! devops))
(terragrunt-plan! config)))
(defn-spec apply! map? (defn-spec apply! nil?
[devops ::d/devops] [devops ::d/devops]
(let [config (merge default devops)] (clean-build-dir! devops)
(clean-build-dir! config) (d/create-build-dir! devops)
(d/create-build-dir! config) (copy-terragrunt! devops)
(copy-terragrunt! config) (terragrunt-apply! devops))
(terragrunt-apply! config)
(terragrunt-output! config)))
(defn-spec destroy! nil? (defn-spec destroy! nil?
[devops ::d/devops] [devops ::d/devops]
(let [config (merge default devops)] (clean-build-dir! devops)
(clean-build-dir! config) (d/create-build-dir! devops)
(d/create-build-dir! config) (copy-terragrunt! devops)
(copy-terragrunt! config) (terragrunt-destroy! devops))
(terragrunt-destroy! config)))
(st/instrument `clean-build-dir!) (st/instrument `clean-build-dir!)
(st/instrument `copy-terragrunt!) (st/instrument `copy-terragrunt!)

View file

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