feat: add terramate

This commit is contained in:
OG
2024-11-20 00:21:22 +01:00
committed by AJ ONeal
parent afe35f9198
commit cc66f930b0
4 changed files with 229 additions and 0 deletions

100
terramate/README.md Normal file
View File

@@ -0,0 +1,100 @@
---
title: Terramate
homepage: https://github.com/terramate-io/terramate
tagline: |
Terramate simplifies managing large-scale Terraform codebases with a focus on automation and scalability.
---
To update or switch versions, run `webi terramate@stable` (or `@v1.0.0`,
`@beta`, etc).
## Cheat Sheet
The information in this section is a copy of the preflight requirements and
common command-line arguments from Terramate
(https://github.com/terramate-io/terramate).
> `Terramate` enables scalable automation for Terraform by providing a robust
> framework for managing multiple stacks, generating code, and executing
> targeted workflows.
### **1. Create a New Project**
```bash
git init -b main terramate-quickstart
cd terramate-quickstart
git commit --allow-empty -m "Initial empty commit"
```
---
### **2. Create a Stack**
```bash
terramate create \
--name "StackName" \
--description "Description of the stack" \
stacks/stackname
git add stacks/stackname/stack.tm.hcl
git commit -m "Create a stack"
```
---
### **3. List Stacks**
```bash
terramate list
```
---
### **4. Detect Changes**
```bash
terramate list --changed
```
---
### **5. Generate Code**
1. Create a `.tm.hcl` file for code generation:
```bash
cat <<EOF >stacks/backend.tm.hcl
generate_hcl "backend.tf" {
content {
terraform {
backend "local" {}
}
}
}
EOF
```
2. Run the generation command:
```bash
terramate generate
```
---
### **6. Run Terraform Commands**
- **Initialize stacks:**
```bash
terramate run terraform init
```
- **Plan changes:**
```bash
terramate run terraform plan
```
- **Apply changes:**
```bash
terramate run terraform apply -auto-approve
```
- **Run commands only on changed stacks:**
```bash
terramate run --changed terraform init
terramate run --changed terraform plan
terramate run --changed terraform apply -auto-approve
```

56
terramate/install.ps1 Normal file
View File

@@ -0,0 +1,56 @@
#!/usr/bin/env pwsh
###############
# Install terramate #
###############
# Every package should define these variables
$pkg_cmd_name = "terramate"
$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\terramate.exe"
$pkg_dst = "$pkg_dst_cmd"
$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\terramate-v$Env:WEBI_VERSION\bin\terramate.exe"
$pkg_src_bin = "$Env:USERPROFILE\.local\opt\terramate-v$Env:WEBI_VERSION\bin"
$pkg_src_dir = "$Env:USERPROFILE\.local\opt\terramate-v$Env:WEBI_VERSION"
$pkg_src = "$pkg_src_cmd"
New-Item "$Env:USERPROFILE\Downloads\webi" -ItemType Directory -Force | Out-Null
$pkg_download = "$Env:USERPROFILE\Downloads\webi\$Env:WEBI_PKG_FILE"
# Fetch archive
IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\webi\$Env:WEBI_PKG_FILE")) {
Write-Output "Downloading terramate from $Env:WEBI_PKG_URL to $pkg_download"
& curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part"
& Move-Item "$pkg_download.part" "$pkg_download"
}
IF (!(Test-Path -Path "$pkg_src_cmd")) {
Write-Output "Installing terramate"
# TODO: create package-specific temp directory
# Enter tmp
Push-Location .local\tmp
# Remove any leftover tmp cruft
Remove-Item -Path ".\terramate-v*" -Recurse -ErrorAction Ignore
Remove-Item -Path ".\terramate.exe" -Recurse -ErrorAction Ignore
# Unpack archive file into this temporary directory
# Windows BSD-tar handles zip. Imagine that.
Write-Output "Unpacking $pkg_download"
& tar xf "$pkg_download"
# Settle unpacked archive into place
Write-Output "Install Location: $pkg_src_cmd"
New-Item "$pkg_src_bin" -ItemType Directory -Force | Out-Null
Move-Item -Path "terramate.exe" -Destination "$pkg_src_bin"
# Exit tmp
Pop-Location
}
Write-Output "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'"
Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore | Out-Null
Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse
Remove-Item -Path "$pkg_src" -Recurse -ErrorAction Ignore

47
terramate/install.sh Normal file
View File

@@ -0,0 +1,47 @@
#!/bin/sh
set -e
set -u
__init_terramate() {
#####################
# Install terramate #
#####################
# Every package should define these 6 variables
pkg_cmd_name="terramate"
pkg_dst_cmd="$HOME/.local/bin/terramate"
pkg_dst="$pkg_dst_cmd"
pkg_src_cmd="$HOME/.local/opt/terramate-v$WEBI_VERSION/bin/terramate"
pkg_src_dir="$HOME/.local/opt/terramate-v$WEBI_VERSION"
pkg_src="$pkg_src_cmd"
# pkg_install must be defined by every package
pkg_install() {
# ~/.local/opt/terramate-v0.99.9/bin
mkdir -p "$(dirname "$pkg_src_cmd")"
# mv ./terramate-*/terramate ~/.local/opt/terramate-v0.99.9/bin/terramate
mv terramate "$pkg_src_cmd"
}
# pkg_get_current_version is recommended, but (soon) not required
pkg_get_current_version() {
# 'terramate version' has output in this format:
# 0.10.4
# Your version of Terramate is out of date! The latest version
# is 0.11.1 (released on Wed Oct 30 15:37:00 UTC 2024).
# You can update by downloading from https://github.com/mineiros-io/terramate/releases/tag/v0.11.1
# This trims it down to just the version number:
# 0.10.4
terramate version | grep '^[0-9]\+\.[0-9]\+\.[0-9]\+$'
}
}
__init_terramate

26
terramate/releases.js Normal file
View File

@@ -0,0 +1,26 @@
'use strict';
var github = require('../_common/github.js');
var owner = 'terramate-io';
var repo = 'terramate';
module.exports = function () {
return github(null, owner, repo).then(function (all) {
all.releases = all.releases.filter(
(release) => !['checksums.txt', 'cosign.pub'].includes(release.name),
);
return all;
});
};
if (module === require.main) {
module.exports().then(function (all) {
all = require('../_webi/normalize.js')(all);
// just select the first 5 for demonstration
// all.releases = all.releases.slice(0, 5);
// all.releases = all.releases.filter(
// release => !["checksums.txt.sig", "cosign.pub","terramate_0.9.0_windows_x86_64.zip"].includes(release.name)
// );
console.info(JSON.stringify(all, null, 2));
});
}