Skip to content

Commit 6bcb8de

Browse files
feat: init (#1)
Moved adding any stacks to a subsequent PR. This initial PR includes adding the workflows only but no actual Terramate stacks.
2 parents 03091c7 + 661c284 commit 6bcb8de

File tree

5 files changed

+174
-2
lines changed

5 files changed

+174
-2
lines changed

.github/workflows/apply.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Run Terraform Apply
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
preview:
10+
name: Apply
11+
runs-on: ubuntu-latest
12+
13+
permissions:
14+
id-token: write
15+
contents: write
16+
pull-requests: write
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
with:
22+
ref: ${{ github.head_ref }}
23+
fetch-depth: 0
24+
25+
- name: Install tools using asdf
26+
uses: asdf-vm/actions/[email protected]
27+
28+
- name: List changed stacks
29+
id: list
30+
run: |
31+
echo "stdout<<STDOUT" >>$GITHUB_OUTPUT
32+
terramate list --changed >>$GITHUB_OUTPUT
33+
EXIT_CODE=$?
34+
echo "STDOUT" >>$GITHUB_OUTPUT
35+
exit ${EXIT_CODE}
36+
37+
- name: Configure AWS Credentials
38+
if: steps.list.outputs.stdout
39+
uses: aws-actions/configure-aws-credentials@v2
40+
with:
41+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
42+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
43+
aws-region: eu-central-1
44+
45+
- name: Run Terraform init on changed stacks
46+
if: steps.list.outputs.stdout
47+
id: init
48+
run: |
49+
terramate run --changed -- terraform init
50+
51+
- name: Create Terraform apply on changed stacks
52+
if: steps.list.outputs.stdout
53+
id: apply
54+
run: |
55+
terramate run --changed -- terraform apply -input=false -auto-approve

.github/workflows/plan.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Preview Terraform Plan
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
preview:
8+
name: Plan
9+
runs-on: ubuntu-latest
10+
11+
permissions:
12+
id-token: write
13+
contents: write
14+
pull-requests: write
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v3
19+
with:
20+
ref: ${{ github.head_ref }}
21+
fetch-depth: 0
22+
23+
- name: Install tools using asdf
24+
uses: asdf-vm/actions/[email protected]
25+
26+
- name: List changed stacks
27+
id: list
28+
run: |
29+
echo "stdout<<STDOUT" >>$GITHUB_OUTPUT
30+
terramate list --changed >>$GITHUB_OUTPUT
31+
EXIT_CODE=$?
32+
echo "STDOUT" >>$GITHUB_OUTPUT
33+
exit ${EXIT_CODE}
34+
35+
- name: Configure AWS Credentials
36+
if: steps.list.outputs.stdout
37+
uses: aws-actions/configure-aws-credentials@v2
38+
with:
39+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
40+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
41+
aws-region: eu-central-1
42+
43+
- name: Create Terraform plan on changed stacks
44+
if: steps.list.outputs.stdout
45+
run: |
46+
terramate run --changed -- terraform init
47+
terramate run --changed -- terraform validate
48+
terramate run --changed -- terraform plan -out out.tfplan
49+
50+
- name: Generate Preview Comment
51+
if: steps.list.outputs.stdout
52+
id: comment
53+
run: |
54+
echo >>pr-comment.txt "### List of Changed Stacks"
55+
echo >>pr-comment.txt
56+
echo >>pr-comment.txt '```bash'
57+
echo >>pr-comment.txt "${{ steps.list.outputs.stdout }}"
58+
echo >>pr-comment.txt '```'
59+
echo >>pr-comment.txt
60+
echo >>pr-comment.txt "#### Terraform Plan"
61+
echo >>pr-comment.txt
62+
echo >>pr-comment.txt '```terraform'
63+
terramate run --changed -- terraform show -no-color out.tfplan 2>&1 | dd bs=1024 count=248 >>pr-comment.txt
64+
echo >>pr-comment.txt '```'
65+
cat pr-comment.txt >>$GITHUB_STEP_SUMMARY
66+
67+
- name: Inform about no Changed Stacks
68+
if: (!steps.list.outputs.stdout)
69+
run: |
70+
echo >>pr-comment.txt '### No changed stacks.'
71+
cat pr-comment.txt >>$GITHUB_STEP_SUMMARY
72+
73+
- name: Publish Plans for Changed Stacks
74+
uses: marocchino/sticky-pull-request-comment@v2
75+
with:
76+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
header: terraform-plan
78+
path: pr-comment.txt

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Intellij
2+
.idea
3+
4+
# MacOS
5+
.DS_STORE
6+
7+
# VSCode configuration
8+
.vscode
9+
10+
# Ignore Terraform init files
11+
terraform.tfstate*
12+
.terraform
13+
.terraform.lock.hcl
14+
15+
# Ignore all files generated during CI/CD workflows
16+
*.tfplan
17+
pr-comment.txt

.tool-versions

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
terraform 1.5.3
2+
terramate 0.4.0

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,22 @@
1-
# terramate-github-actions-example
2-
terramate-github-actions-example
1+
<p align="center">
2+
<picture width="160px" align="center">
3+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/terramate-io/brand/5a799813d429116741243b9b06a9f034a3991bf3/darkmode/stamp.svg">
4+
<img alt="Terramate" src="https://raw.githubusercontent.com/terramate-io/brand/5a799813d429116741243b9b06a9f034a3991bf3/whitemode/stamp.svg" width="160px" align="center">
5+
</picture>
6+
<h1 align="center">Terramate</h1>
7+
<p align="center">
8+
✨ <a href="https://terramate.io/docs/cli">https://terramate.io</a> ✨
9+
<br/>
10+
Terramate helps implement and maintain <strong>highly scalable</strong> Terraform projects by adding powerful capabilities
11+
such as code generation, stacks, orchestration, change detection, data sharing and more.
12+
</p>
13+
</p>
14+
<br/>
15+
16+
<p align="center">
17+
<a href="https://terramate.io/docs/cli">📖 Terramate Documentation</a> | <a href="https://play.terramate.io">💻 Playground</a> | <a href="https://terramate.io/discord" title="Join our Discord Community">💬 Discord Community</a> | <a href="https://jobs.ashbyhq.com/terramate" title="Terrmate Job Board">🚀 We are hiring!</a>
18+
</p>
19+
20+
## Examples
21+
22+
This repository demonstrates a simple example of how Terramate helps run simple and efficient workflows using GitHub Actions.

0 commit comments

Comments
 (0)