Created
October 28, 2024 21:52
-
-
Save rgeraskin/88c895e393aa8727464401980482f4e0 to your computer and use it in GitHub Desktop.
Mise confing for terramate and terraform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [tools] | |
| terraform = "1.9" | |
| terramate = "0.9" | |
| pre-commit = "3" | |
| awscli = "2" | |
| "pipx:detect-secrets" = "1.4" # for pre-commit | |
| "go:github.com/containerscrew/tftools" = "0.9.0" # for mise tm.summarize task | |
| [settings] | |
| experimental = true | |
| legacy_version_file = false | |
| [tasks."tm.generate"] | |
| alias = "tmg" | |
| description = "`terramate generate` for all states and envs" | |
| run = "terramate generate" | |
| [tasks.sso] | |
| alias = "s" | |
| description = "`aws sso login` if necessary" | |
| run = """ | |
| #!/usr/bin/env bash | |
| sso_session_name=XXX | |
| sso_session_name_sha1=$(echo -n $sso_session_name | shasum | awk '{print $1}') | |
| sso_expires="$(jq -r .expiresAt ~/.aws/sso/cache/${sso_session_name_sha1}.json)" | |
| date_now=$(date +"%s") | |
| if [[ "$OSTYPE" == "darwin"* ]]; then | |
| date_expires=$(date -u -j -f "%FT%TZ" "$sso_expires" +"%s") | |
| else | |
| date_expires=$(date -d "$sso_expires" +"%s") | |
| fi | |
| if [[ $date_now -gt $date_expires ]]; then | |
| echo "Session <$sso_session_name> has expired, logging in" | |
| aws sso login --sso-session $sso_session_name | |
| else | |
| echo "Session <$sso_session_name> is still valid" | |
| fi | |
| """ | |
| [tasks."tm.init"] | |
| alias = "tmi" | |
| depends = ["tm.generate", "sso"] | |
| description = "`terraform init`" | |
| run = "terramate run -j 10 --tags=${tags:-$t} terraform init" | |
| [tasks."tm.validate"] | |
| alias = "tmv" | |
| depends = ["tm.init"] | |
| description = "`terraform validate`" | |
| run = "terramate run -j 10 --tags=${tags:-$t} terraform validate" | |
| [tasks."tm.plan"] | |
| alias = "tmp" | |
| depends = ["tm.init"] | |
| description = "`terraform plan`" | |
| run = """ | |
| #!/usr/bin/env bash | |
| terramate run -j 10 --tags=${tags:-$t} terraform plan -out=tfplan $@ | |
| echo terramate run -j 10 --tags=${tags:-$t} terraform plan -out=tfplan $@ | |
| tput bel | |
| """ | |
| [tasks."tm.summarize"] | |
| alias = "tms" | |
| description = "`tftools summarize` with pre-generated plan file (terraform plan should be generated in advance)" | |
| run = """ | |
| #!/usr/bin/env bash | |
| terramate run --tags=${tags:-$t} bash -c "\ | |
| if [ -f tfplan ]; then \ | |
| terraform show -json tfplan > plan.json; \ | |
| tftools summarize < plan.json; \ | |
| else \ | |
| echo tfplan not found; \ | |
| fi \ | |
| " | |
| """ | |
| [tasks."tm.apply"] | |
| alias = "tma" | |
| description = "`terraform apply` with pre-generated plan file (terraform plan should be generated in advance)" | |
| run = """ | |
| #!/usr/bin/env bash | |
| cmd="terramate run --tags=${tags:-$t} terraform apply tfplan $@" | |
| read -p "$cmd\n\nAre you sure? (Y/n) " choice | |
| [ "$choice" = "n" ] || ($cmd; tput bel) | |
| """ | |
| [tasks."tm.lock"] | |
| depends = ["tm.init"] | |
| description = "`terraform providers lock` with predefined platform list" | |
| run = "terramate run -j 10 --tags=${tags:-$t} terraform providers lock -platform=linux_amd64 -platform=darwin_amd64 -platform=darwin_arm64 ; tput bel" | |
| [tasks."tm.console"] | |
| alias = "tmc" | |
| depends = ["tm.init"] | |
| description = "`terraform console`" | |
| raw = true | |
| run = "terramate run --tags=${tags:-$t} terraform console" | |
| [tasks."tm.run"] | |
| alias = "r" | |
| description = "`terramate run` (run shell command in stack dir)" | |
| run = "terramate run -j 10 --tags=${tags:-$t}" | |
| [tasks.lint] | |
| alias = "l" | |
| description = "`pre-commit run` to lint all files staged for commit" | |
| run = "pre-commit run" |
Author
Thanks for sharing this!
cmd="terramate run --tags=${tags:-$t} terraform apply tfplan $@"
read -p "$cmd\n\nAre you sure? (Y/n) " choice
[ "$choice" = "n" ] || ($cmd; tput bel)
BTW, mise has confirm parameter exactly for that.
It also became possible to manage aliases! So, you can setup alias mr from within mise config!
In some cases, it's possible to type mise foo instead of mise run foo and it would work unless there is mise own command for that.
Author
Yes, there are a lot of new features that have arrived to mise after the initial blog post (and this gist) publication. Thanks for the comment @php-coder !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dev env prepare:

Tasks:
