Compare commits
2 commits
cc79a7b0f4
...
bfc6b308cf
Author | SHA1 | Date | |
---|---|---|---|
bfc6b308cf | |||
9253377526 |
4 changed files with 117 additions and 69 deletions
6
deps.edn
6
deps.edn
|
@ -5,8 +5,8 @@
|
|||
["src" "resources"]
|
||||
|
||||
:deps
|
||||
{org.clojure/clojure {:mvn/version "1.11.1"}
|
||||
org.clojure/spec.alpha {:mvn/version "0.4.233"}
|
||||
{org.clojure/clojure {:mvn/version "1.11.4"}
|
||||
org.clojure/spec.alpha {:mvn/version "0.5.238"}
|
||||
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.87.1366"}}
|
||||
:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}}
|
||||
:main-opts ["-m" "kaocha.runner"]
|
||||
:exec-fn kaocha.runner/exec-fn
|
||||
:exec-args {:randomize? false
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
(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]))
|
||||
|
@ -8,58 +9,70 @@
|
|||
(st/instrument `clean-build-dir!)
|
||||
|
||||
(def default
|
||||
(merge d/default {:autoapply false}))
|
||||
(merge d/default {:autoapply false
|
||||
:tg-output-filenname "tg-out.json"}))
|
||||
|
||||
(defn-spec clean-build-dir! nil?
|
||||
[devops ::d/devops]
|
||||
(let [final (merge default devops)]
|
||||
(i/execute! (domain/clean-build-dir-command final) final)))
|
||||
(let [config (merge default devops)]
|
||||
(i/execute! (domain/clean-build-dir-command config) config)))
|
||||
|
||||
(defn-spec copy-terragrunt! nil?
|
||||
[devops ::d/devops]
|
||||
(let [final (merge default devops)]
|
||||
(doseq [c (domain/copy-terragrunt-command final)]
|
||||
(i/execute! c final))))
|
||||
(let [config (merge default devops)]
|
||||
(doseq [c (domain/copy-terragrunt-command config)]
|
||||
(i/execute! c config))))
|
||||
|
||||
(defn-spec terragrunt-plan! nil?
|
||||
[devops ::d/devops]
|
||||
(let [final (merge default devops)]
|
||||
(doseq [c (domain/terragrunt-plan-command final)]
|
||||
(i/execute! c final))))
|
||||
(let [config (merge default devops)]
|
||||
(doseq [c (domain/terragrunt-plan-command config)]
|
||||
(i/execute! c config))))
|
||||
|
||||
(defn-spec terragrunt-apply! nil?
|
||||
[devops ::d/devops]
|
||||
(let [final (merge default devops)]
|
||||
(doseq [c (into (domain/terragrunt-apply-command final)
|
||||
(domain/terragrunt-output-command final))]
|
||||
(i/execute! c final))))
|
||||
(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))))))
|
||||
|
||||
(defn-spec terragrunt-destroy! nil?
|
||||
[devops ::d/devops]
|
||||
(let [final (merge default devops)]
|
||||
(doseq [c (domain/terragrunt-destroy-command final)]
|
||||
(i/execute! c final))))
|
||||
(let [config (merge default devops)]
|
||||
(doseq [c (domain/terragrunt-destroy-command config)]
|
||||
(i/execute! c config))))
|
||||
|
||||
(defn-spec plan! nil?
|
||||
[devops ::d/devops]
|
||||
(clean-build-dir! devops)
|
||||
(d/create-build-dir! devops)
|
||||
(copy-terragrunt! devops)
|
||||
(terragrunt-plan! devops))
|
||||
(let [config (merge default devops)]
|
||||
(clean-build-dir! config)
|
||||
(d/create-build-dir! config)
|
||||
(copy-terragrunt! config)
|
||||
(terragrunt-plan! config)))
|
||||
|
||||
(defn-spec apply! nil?
|
||||
(defn-spec apply! map?
|
||||
[devops ::d/devops]
|
||||
(clean-build-dir! devops)
|
||||
(d/create-build-dir! devops)
|
||||
(copy-terragrunt! devops)
|
||||
(terragrunt-apply! devops))
|
||||
(let [config (merge default devops)]
|
||||
(clean-build-dir! config)
|
||||
(d/create-build-dir! config)
|
||||
(copy-terragrunt! config)
|
||||
(terragrunt-apply! config)
|
||||
(terragrunt-output! config)))
|
||||
|
||||
(defn-spec destroy! nil?
|
||||
[devops ::d/devops]
|
||||
(clean-build-dir! devops)
|
||||
(d/create-build-dir! devops)
|
||||
(copy-terragrunt! devops)
|
||||
(terragrunt-destroy! devops))
|
||||
(let [config (merge default devops)]
|
||||
(clean-build-dir! config)
|
||||
(d/create-build-dir! config)
|
||||
(copy-terragrunt! config)
|
||||
(terragrunt-destroy! config)))
|
||||
|
||||
(st/instrument `clean-build-dir!)
|
||||
(st/instrument `copy-terragrunt!)
|
||||
|
|
|
@ -3,36 +3,46 @@
|
|||
[orchestra.core :refer [defn-spec]]
|
||||
[dda.build.devops.domain :as d]))
|
||||
|
||||
(s/def ::devops
|
||||
(s/keys :req-un [::name ::stage ::project-root-path ::build-dir-name ::debug ::dry-run ::module]
|
||||
(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]
|
||||
:opt-un []))
|
||||
|
||||
(defn-spec clean-build-dir-command seq?
|
||||
[devops ::devops]
|
||||
["rm" "-rf" (d/build-path (dissoc devops :module))])
|
||||
[config ::config]
|
||||
["rm" "-rf" (d/build-path (dissoc config :module))])
|
||||
|
||||
(defn-spec copy-terragrunt-command seq?
|
||||
[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)]]))
|
||||
[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)]]))
|
||||
|
||||
(defn-spec terragrunt-plan-command seq?
|
||||
[devops ::devops]
|
||||
[[{:dir (d/build-path devops)} "terragrunt" "init"]
|
||||
[{:dir (d/build-path devops)} "terragrunt" "plan"]])
|
||||
[config ::config]
|
||||
[[{:dir (d/build-path config)} "terragrunt" "init"]
|
||||
[{:dir (d/build-path config)} "terragrunt" "plan"]])
|
||||
|
||||
(defn-spec terragrunt-apply-command seq?
|
||||
[devops ::devops]
|
||||
[[{:dir (d/build-path devops)} "terragrunt" "init"]
|
||||
[{:dir (d/build-path devops)} "terragrunt" "apply" "-auto-approve"]])
|
||||
[config ::config]
|
||||
[[{:dir (d/build-path config)} "terragrunt" "init"]
|
||||
[{:dir (d/build-path config)} "terragrunt" "apply" "-auto-approve"]])
|
||||
|
||||
(defn-spec terragrunt-destroy-command seq?
|
||||
[devops ::devops]
|
||||
[[{:dir (d/build-path devops)} "terragrunt" "init"]
|
||||
[{:dir (d/build-path devops)} "terragrunt" "destroy"]])
|
||||
[config ::config]
|
||||
[[{:dir (d/build-path config)} "terragrunt" "init"]
|
||||
[{:dir (d/build-path config)} "terragrunt" "destroy"]])
|
||||
|
||||
(defn-spec terragrunt-output-command seq?
|
||||
[devops ::devops]
|
||||
[[{:dir (d/build-path devops)} "bash" "-c" "terragrunt output -json > terraform.json"]])
|
||||
[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)))
|
||||
|
|
|
@ -19,8 +19,10 @@
|
|||
:version "4.11.8-dev"
|
||||
:stage "dev"
|
||||
:debug false
|
||||
:dry-run false}))))
|
||||
|
||||
:dry-run false
|
||||
:autoapply false
|
||||
:tg-output-filenname "tg-out.json"}))))
|
||||
|
||||
(deftest should-calculate-copy-terragrunt-command
|
||||
(is (= [["bash" "-c" "cp *.hcl ../../target/test"]
|
||||
["cp" "-r" "statistics" "../../target/test"]]
|
||||
|
@ -31,7 +33,9 @@
|
|||
:version "4.11.8-dev"
|
||||
:stage "dev"
|
||||
:debug false
|
||||
:dry-run false}))))
|
||||
:dry-run false
|
||||
:autoapply false
|
||||
:tg-output-filenname "tg-out.json"}))))
|
||||
|
||||
(deftest should-calculate-terragrunt-plan-command
|
||||
(is (= [[{:dir "../../../target/test/statistics"} "terragrunt" "init"]
|
||||
|
@ -43,29 +47,50 @@
|
|||
:version "4.11.8-dev"
|
||||
:stage "dev"
|
||||
:debug false
|
||||
:dry-run false}))))
|
||||
:dry-run false
|
||||
:autoapply false
|
||||
:tg-output-filenname "tg-out.json"}))))
|
||||
|
||||
(deftest should-calculate-terragrunt-apply-command
|
||||
(is (= [[{:dir "../../../target/test/statistics"} "terragrunt" "init"]
|
||||
[{:dir "../../../target/test/statistics"} "terragrunt" "apply" "-auto-approve"]]
|
||||
(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"
|
||||
:project-root-path "../../.."
|
||||
:build-dir-name "target"
|
||||
:version "4.11.8-dev"
|
||||
:stage "dev"
|
||||
: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"}))))
|
||||
|
||||
|
|
Loading…
Reference in a new issue