Skip to content

Terraform

BigConfig main idea is that it is better to write Clojure to generate JSON instead of HCL.

(ns core
(:require
[big-config.utils :refer [deep-merge sort-nested-map]]
[big-tofu.core :refer [add-suffix construct]]
[big-tofu.create :as create]
[cheshire.core :as json]))
(let [{:keys [aws-account-id
region] :as data} {:aws-account-id "111111111111"
:region "eu-west-1"
:module "example"}
queues (->> (for [n (range 2)]
(create/sqs (add-suffix :alpha/big-sqs (str "-" n))))
flatten
(map construct))
kms (->> (create/kms :alpha/big-kms)
(map construct))
bucket (format "tf-state-%s-%s" aws-account-id region)
provider (create/provider (assoc data :bucket bucket))
m (->> [provider]
(into kms)
(into queues)
(apply deep-merge)
sort-nested-map)]
(json/generate-string m {:pretty true}))

BigConfig requires Clojure and Babashka. You should also configure dirvenv for your shell.

Terminal window
brew install clojure/tools/clojure
brew install borkdude/brew/babashka
brew install direnv
  1. Create the Terraform project
    Terminal window
    # Add big-config as tool to Clojure
    clojure -Ttools install-latest :lib io.github.amiorin/big-config :as big-config
    # Invoke the terraform template
    clojure -Tbig-config terraform
  2. Configure git
    Terminal window
    git init
    git add
    git commit
    git push
  3. Shows the Babashka tasks
    Terminal window
    bb tasks
  4. Show the BigConfig DSL manual.
    Terminal window
    bb show-help

Terraform supports both HCL and JSON files. Instead of learning a new language (HCL) you can use Clojure to generate the JSON files.