Skip to content

Commit 61160cb

Browse files
committed
Add new Template block, and clean up a bunch of stuff in the process.
- Introduce <Template> block - Retire <BoilerplateInputs> - Retire <BoilerplateTemplate> - Update the variable propagation system - Consolidate layout components under a new layout/ folder - Rename shared to _shared for shared components - Add a new test runbook, demo-runbook-3
1 parent 573a26a commit 61160cb

79 files changed

Lines changed: 1683 additions & 1573 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

testdata/demo-runbook-2/runbook.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ variables:
118118
failMessage="Failed to create the pull request."
119119
/>
120120

121-
<BoilerplateInputs id="mise-config-inputs" templatePath="templates/mise-config" />
121+
<Template id="mise-config-inputs" path="templates/mise-config" />
122122

123123
We just created the `.mise.toml` file. We're going to use this shortly in your new repo!
124124

@@ -154,7 +154,7 @@ jobs:
154154

155155
Now let's generate a bunch of files that will lay a solid foundation for your new repo with Terragrunt.
156156

157-
<BoilerplateInputs id="infra-live-elements-inputs" templatePath="templates/infra-live-elements" />
157+
<Template id="infra-live-elements-inputs" path="templates/infra-live-elements" />
158158

159159
### Create a pull request with the changes
160160

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
# Check if Mise is installed
4+
if ! command -v gh &> /dev/null; then
5+
echo "❌ gh is not installed"
6+
exit 1
7+
fi
8+
9+
echo "✅ gh is installed"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
# Check if Mise is installed
4+
if ! command -v mise &> /dev/null; then
5+
echo "❌ Mise is not installed"
6+
exit 1
7+
fi
8+
9+
echo "✅ Mise is installed"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Demo Runbook 3
2+
3+
## Test 1
4+
5+
First, let's test that a standalone `<Template>` block works:
6+
7+
<Template id="test1" path="templates/infra-live-elements" />
8+
9+
## Test 2
10+
11+
Now let's create a standalone inputs
12+
13+
<Inputs id="test2">
14+
```yaml
15+
variables:
16+
- name: GithubOrgName
17+
type: string
18+
description: The GitHub organization name where the repository is hosted
19+
default: "gruntwork-io"
20+
validations: "required"
21+
- name: GithubRepoName
22+
type: string
23+
description: The name of the GitHub repository for infrastructure code
24+
default: "runbooks-infrastructure-live-example"
25+
validations: "required"
26+
```
27+
</Inputs>
28+
29+
## Test 3
30+
31+
Now let's render an inline template based on both test1 and test2
32+
33+
<TemplatePreview inputsId="test2">
34+
```yaml
35+
orgName: {{ .GithubOrgName }}
36+
```
37+
</TemplatePreview>
38+
39+
## Test 4
40+
41+
Now let's render an inline template that pulls from both test1 and test2
42+
43+
<TemplatePreview inputsId={["test1", "test2"]}>
44+
```yaml
45+
orgName: {{ .GithubOrgName }}
46+
orgNamePrefix: {{ .OrgNamePrefix }}
47+
```
48+
</TemplatePreview>
49+
50+
## Test 5
51+
52+
Let's render a standard template with inputs from test1 and test2
53+
54+
This template:
55+
56+
| Variable | Declares | Inherits |
57+
| ----------- | -------- | -------- |
58+
| GithubOrgName | Yes | Yes |
59+
| OrgNamePrefix | No | Yes |
60+
| FirstName | Yes | No
61+
62+
<Template id="test5" path="templates/temp1" inputsId={["test1", "test2"]} />
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#!/usr/bin/env bash
2+
#
3+
# This script creates a pull request with all the files from the generated folder.
4+
# It handles the complete workflow of cloning the repo, adding files, committing,
5+
# pushing, and creating a PR.
6+
#
7+
# This script is designed to be called from the runbook Command block, which
8+
# automatically passes values from the boilerplate input block with id
9+
# "infrastructure-live-root-repo-inputs" as command-line arguments:
10+
# - GithubOrgName -> $1
11+
# - GithubRepoName -> $2
12+
13+
set -e
14+
15+
# Save the original directory before any cd commands
16+
ORIGINAL_DIR=$(pwd)
17+
18+
# Parse arguments (automatically passed from boilerplate inputs in the runbook)
19+
GITHUB_ORG="{{ .GithubOrgName }}"
20+
REPO_NAME="{{ .GithubRepoName }}"
21+
22+
if [ -z "$GITHUB_ORG" ] || [ -z "$REPO_NAME" ]; then
23+
echo "Error: Missing required arguments"
24+
echo "Usage: $0 <github-org> <repo-name>"
25+
echo "Example: $0 acme-corp infrastructure-live-root"
26+
exit 1
27+
fi
28+
29+
# Configuration
30+
BRANCH_NAME="add-terragrunt-foundations"
31+
GENERATED_DIR="generated"
32+
TEMP_DIR=$(mktemp -d)
33+
34+
echo "🚀 Starting pull request creation process..."
35+
echo " Repository: ${GITHUB_ORG}/${REPO_NAME}"
36+
echo " Branch: ${BRANCH_NAME}"
37+
echo ""
38+
39+
# Check if generated directory exists
40+
if [ ! -d "${ORIGINAL_DIR}/${GENERATED_DIR}" ]; then
41+
echo "❌ Error: Generated directory not found at ${ORIGINAL_DIR}/${GENERATED_DIR}"
42+
echo " Please make sure you've generated the files first."
43+
exit 1
44+
fi
45+
46+
# Check if there are any files in the generated directory
47+
if [ -z "$(ls -A ${ORIGINAL_DIR}/${GENERATED_DIR})" ]; then
48+
echo "❌ Error: Generated directory is empty"
49+
echo " Please generate files before running this script."
50+
exit 1
51+
fi
52+
53+
echo "📦 Cloning repository..."
54+
cd "$TEMP_DIR"
55+
gh repo clone "${GITHUB_ORG}/${REPO_NAME}" repo
56+
cd repo
57+
58+
# Check if the repository is empty (no commits on main)
59+
REPO_IS_EMPTY=false
60+
if ! git rev-parse --verify main >/dev/null 2>&1; then
61+
REPO_IS_EMPTY=true
62+
echo "📝 Repository is empty (no main branch yet)"
63+
echo " Creating initial commit on main to establish base branch..."
64+
65+
# Ensure we're on main branch (in case default branch isn't main)
66+
git checkout -b main 2>/dev/null || git checkout main
67+
68+
# Create a minimal README for the initial commit
69+
echo "# ${REPO_NAME}" > README.md
70+
echo "" >> README.md
71+
echo "Infrastructure repository managed with Terragrunt." >> README.md
72+
73+
git add README.md
74+
git commit -m "Initial commit"
75+
76+
echo "⬆️ Pushing initial commit to main..."
77+
git push -u origin main
78+
79+
echo "✅ Base branch established"
80+
fi
81+
82+
# Check if the branch already exists remotely
83+
if git ls-remote --heads origin "$BRANCH_NAME" | grep -q "$BRANCH_NAME"; then
84+
echo "🌿 Branch '$BRANCH_NAME' already exists, checking it out..."
85+
git fetch origin "$BRANCH_NAME"
86+
git checkout "$BRANCH_NAME"
87+
git pull origin "$BRANCH_NAME"
88+
else
89+
echo "🌿 Creating new branch '$BRANCH_NAME'..."
90+
git checkout -b "$BRANCH_NAME"
91+
fi
92+
93+
echo "📁 Copying generated files..."
94+
cp -r "${ORIGINAL_DIR}/${GENERATED_DIR}"/* .
95+
96+
echo "➕ Adding files to git..."
97+
git add .
98+
99+
# Check if there are any changes to commit
100+
if git diff --staged --quiet; then
101+
echo "⚠️ Warning: No changes detected. The generated files may already exist in the repo."
102+
echo " Cleaning up and exiting..."
103+
cd "$ORIGINAL_DIR"
104+
rm -rf "$TEMP_DIR"
105+
exit 0
106+
fi
107+
108+
echo "💾 Committing changes..."
109+
git commit -m "Add Terragrunt foundations
110+
111+
This commit adds the foundational Terragrunt configuration files including:
112+
- Root terragrunt.hcl configuration
113+
- Common configuration files
114+
- Account definitions
115+
- Tags configuration
116+
- README documentation"
117+
118+
echo "⬆️ Pushing to GitHub..."
119+
git push origin "$BRANCH_NAME"
120+
121+
# Check if PR already exists
122+
PR_EXISTS=$(gh pr list --head "$BRANCH_NAME" --json number --jq 'length')
123+
124+
if [ "$PR_EXISTS" -gt 0 ]; then
125+
PR_NUMBER=$(gh pr list --head "$BRANCH_NAME" --json number --jq '.[0].number')
126+
echo "🔀 Pull request #${PR_NUMBER} already exists, updated with new commits!"
127+
echo " View it at: https://github.com/${GITHUB_ORG}/${REPO_NAME}/pull/${PR_NUMBER}"
128+
else
129+
echo "🔀 Creating pull request..."
130+
gh pr create \
131+
--base main \
132+
--head "$BRANCH_NAME" \
133+
--title "Add Terragrunt foundations" \
134+
--body "This PR adds the Terragrunt foundations to the repo.
135+
136+
## Changes included:
137+
- Root terragrunt.hcl configuration
138+
- Common configuration files
139+
- Account definitions
140+
- Tags configuration
141+
- README documentation
142+
143+
These files provide the foundation for managing infrastructure with Terragrunt."
144+
145+
echo ""
146+
echo "✅ Pull request created successfully!"
147+
echo " View it at: https://github.com/${GITHUB_ORG}/${REPO_NAME}/pulls"
148+
fi
149+
150+
# Cleanup
151+
cd "$ORIGINAL_DIR"
152+
rm -rf "$TEMP_DIR"
153+
154+
echo ""
155+
echo "🎉 Done! Your pull request is ready for review."
156+
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Script to upgrade GitHub CLI (gh) to the latest version
5+
# Detects how gh is installed and uses the appropriate upgrade method
6+
7+
echo "Checking current gh version..."
8+
if ! command -v gh &> /dev/null; then
9+
echo "Error: gh is not installed on this system"
10+
exit 1
11+
fi
12+
13+
current_version=$(gh --version | head -n 1)
14+
echo "Current version: $current_version"
15+
echo ""
16+
17+
# Function to check if a command exists
18+
command_exists() {
19+
command -v "$1" &> /dev/null
20+
}
21+
22+
# Try gh upgrade first (self-update)
23+
if gh upgrade --help &> /dev/null; then
24+
echo "Upgrading gh using built-in 'gh upgrade' command..."
25+
gh upgrade
26+
exit 0
27+
fi
28+
29+
# Detect and use the appropriate package manager
30+
if command_exists brew && brew list gh &> /dev/null; then
31+
echo "Detected Homebrew installation. Upgrading..."
32+
brew upgrade gh
33+
34+
elif command_exists apt && dpkg -l | grep -q "^ii.*gh "; then
35+
echo "Detected apt installation. Upgrading..."
36+
sudo apt update
37+
sudo apt install gh
38+
39+
elif command_exists dnf && dnf list installed gh &> /dev/null; then
40+
echo "Detected dnf installation. Upgrading..."
41+
sudo dnf upgrade gh
42+
43+
elif command_exists yum && yum list installed gh &> /dev/null; then
44+
echo "Detected yum installation. Upgrading..."
45+
sudo yum upgrade gh
46+
47+
elif command_exists pacman && pacman -Q gh &> /dev/null; then
48+
echo "Detected pacman installation. Upgrading..."
49+
sudo pacman -Syu gh
50+
51+
elif command_exists choco && choco list --local-only | grep -q "^gh "; then
52+
echo "Detected Chocolatey installation. Upgrading..."
53+
choco upgrade gh
54+
55+
elif command_exists scoop && scoop list | grep -q "gh "; then
56+
echo "Detected Scoop installation. Upgrading..."
57+
scoop update gh
58+
59+
elif command_exists winget; then
60+
echo "Detected winget. Attempting upgrade..."
61+
winget upgrade --id GitHub.cli
62+
63+
else
64+
echo "Error: Could not determine how gh was installed."
65+
echo "Please upgrade gh manually using the method you used to install it."
66+
echo ""
67+
echo "Common methods:"
68+
echo " - Homebrew: brew upgrade gh"
69+
echo " - apt: sudo apt update && sudo apt install gh"
70+
echo " - dnf: sudo dnf upgrade gh"
71+
echo " - Try: gh upgrade (if supported)"
72+
exit 1
73+
fi
74+
75+
echo ""
76+
echo "Upgrade complete!"
77+
new_version=$(gh --version | head -n 1)
78+
echo "New version: $new_version"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Terraform
2+
.terraform
3+
*.tfstate
4+
*.tfstate.backup
5+
6+
# Gruntwork recommends that you track the `.terraform.lock.hcl` file in version control, both to ensure that updates
7+
# are reproducible, and to ensure that providers can be reliably cached. Take note that the lock file is platform specific.
8+
# To mitigate issues that you might encounter due to the fact that the lock file is platform specific,
9+
# you can explicitly generate a lock file that is compatible with all desired platforms for your team using the providers lock command:
10+
#
11+
# terragrunt run-all providers lock -platform=darwin_amd64 -platform=linux_amd64
12+
#
13+
# Refer to https://www.terraform.io/docs/cli/commands/providers/lock.html for more info.
14+
15+
# OS X
16+
.history
17+
.DS_Store
18+
19+
# IntelliJ
20+
.idea_modules
21+
*.iml
22+
*.iws
23+
*.ipr
24+
.idea/
25+
build/
26+
*/build/
27+
out/
28+
29+
# Terragrunt
30+
.terragrunt-cache
31+
.terragrunt-stack

0 commit comments

Comments
 (0)