Skip to content

Commit bec1c65

Browse files
authored
Merge pull request #104 from davidtabat/main
Migrate from Terraform to OpenTofu
2 parents aea7ed6 + d054146 commit bec1c65

8 files changed

+131
-130
lines changed

.github/workflows/terraform-checks.yml

-49
This file was deleted.

.github/workflows/terraform-apply.yml .github/workflows/tofu-apply.yml

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
name: "Terraform apply"
1+
name: "OpenTofu apply"
22

3-
concurrency: terraform-ci
3+
concurrency: tofu-ci
44

55
on:
66
push:
@@ -14,8 +14,8 @@ on:
1414
- main
1515

1616
jobs:
17-
terraform-apply:
18-
name: "Terraform apply"
17+
tofu-apply:
18+
name: "OpenTofu apply"
1919
runs-on: ubuntu-latest
2020
env:
2121
TF_LOG: DEBUG
@@ -34,16 +34,16 @@ jobs:
3434
- name: Checkout
3535
uses: actions/checkout@v4
3636

37-
- name: Setup Terraform
38-
uses: hashicorp/setup-terraform@v3
37+
- name: Set up OpenTofu
38+
uses: opentofu/setup-opentofu@v1
3939

40-
- name: Terraform init
40+
- name: OpenTofu init
4141
id: init
42-
run: terraform init
42+
run: tofu init
4343

44-
- name: Terraform validate
44+
- name: OpenTofu validate
4545
id: validate
46-
run: terraform validate -no-color
46+
run: tofu validate -no-color
4747

48-
- name: Terraform apply
49-
run: terraform apply -auto-approve
48+
- name: OpenTofu apply
49+
run: tofu apply -auto-approve

.github/workflows/tofu-checks.yml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: "OpenTofu checks"
2+
3+
on:
4+
pull_request:
5+
paths-ignore:
6+
- .gitignore
7+
- "*.md"
8+
- CODEOWNERS
9+
branches:
10+
- main
11+
12+
jobs:
13+
tofu-checks:
14+
name: "OpenTofu checks"
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Get pull request ref
18+
id: sha
19+
uses: actions/github-script@v7
20+
with:
21+
result-encoding: string
22+
script: |
23+
const { owner, repo, number } = context.issue;
24+
const pr = await github.rest.pulls.get({
25+
owner,
26+
repo,
27+
pull_number: number,
28+
});
29+
return pr.data.head.sha
30+
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
with:
34+
ref: ${{ steps.sha.outputs.result }}
35+
36+
- name: Setup OpenTofu
37+
uses: opentofu/setup-opentofu@v1
38+
39+
- name: OpenTofu Format
40+
id: fmt
41+
run: tofu fmt -check -diff
42+
43+
- name: OpenTofu Init
44+
id: init
45+
run: tofu init -backend=false
46+
47+
- name: OpenTofu Validate
48+
id: validate
49+
run: tofu validate -no-color

.github/workflows/terraform-plan.yml .github/workflows/tofu-plan.yml

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
name: "Terraform plan"
1+
name: "OpenTofu plan"
22

3-
concurrency: terraform-ci
3+
concurrency: tofu-ci
44

55
on:
66
issue_comment:
77
types: [created]
88

99
jobs:
10-
terraform-plan:
11-
name: "Terraform plan"
10+
opentofu-plan:
11+
name: "OpenTofu plan"
1212
# This conditional acts as an access control list to prevent exposing
1313
# secrets to untrusted pull requests.
1414
if: |
@@ -49,33 +49,33 @@ jobs:
4949
issue_number: context.issue.number,
5050
owner: context.repo.owner,
5151
repo: context.repo.repo,
52-
body: "@${{ github.actor }} Starting Terraform plan ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
52+
body: "@${{ github.actor }} Starting OpenTofu plan ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
5353
})
5454
5555
- name: Checkout
5656
uses: actions/checkout@v4
5757
with:
5858
ref: ${{ steps.ref.outputs.result }}
5959

60-
- name: Setup Terraform
61-
uses: hashicorp/setup-terraform@v3
60+
- name: Setup OpenTofu
61+
uses: opentofu/setup-opentofu@v1
6262

63-
- name: Terraform init
63+
- name: OpenTofu init
6464
id: init
65-
run: terraform init
65+
run: tofu init
6666

67-
- name: Terraform plan
67+
- name: OpenTofu plan
6868
id: plan
69-
run: terraform plan -no-color
69+
run: tofu plan -no-color
7070
continue-on-error: true
7171

7272
- uses: actions/github-script@v7
7373
env:
74-
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
74+
PLAN: "tofu\n${{ steps.plan.outputs.stdout }}"
7575
with:
7676
github-token: ${{ secrets.GITHUB_TOKEN }}
7777
script: |
78-
const output = `#### Terraform Plan \`${{ steps.plan.outcome }}\`
78+
const output = `#### OpenTofu Plan \`${{ steps.plan.outcome }}\`
7979
8080
<details><summary>Show Plan</summary>
8181
@@ -94,6 +94,6 @@ jobs:
9494
body: output
9595
})
9696
97-
- name: Terraform plan status
97+
- name: OpenTofu plan status
9898
if: steps.plan.outcome == 'failure'
9999
run: exit 1

.terraform.lock.hcl

+19-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

INSTALL.md

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
# Managing GitHub organization with Terraform
1+
# Managing GitHub organization with OpenTofu
22

33
This setup is based on
44
[hashicorp/learn-terraform-github-actions](https://github.com/hashicorp/learn-terraform-github-actions),
55
but relies exclusively on GitHub Actions without communicating with Terraform
66
Cloud.
77

8-
# 1. Cloning Terraform repository
8+
# 1. Cloning OpenTofu repository
99

1010
Clone this repository to your GitHub organization and adjust variables to your
1111
liking.
1212

1313
# 2. GitHub App configuration
1414

15-
Github App will be used by Terraform to provision organization.
15+
GitHub App will be used by OpenTofu to provision organization.
1616

1717
## Creating new GitHub App
1818

19-
It can created by following [this guide](https://docs.github.com/en/developers/apps/building-github-apps/creating-a-github-app).
19+
It can be created by following [this guide](https://docs.github.com/en/developers/apps/building-github-apps/creating-a-github-app).
2020
Application should be limited to only one account. Permissions depend on what
21-
resources you plan to manage with Terraform, but sensible base is:
21+
resources you plan to manage with OpenTofu, but a sensible base is:
2222

2323
- Repository/Administration - Read and write
2424
- Repository/Contents - Read and write
@@ -30,11 +30,11 @@ resources you plan to manage with Terraform, but sensible base is:
3030
- Organization/Members - Read and write
3131
- Organization/Projects - Admin
3232

33-
After creating App you may need to [install it in
33+
After creating the App, you may need to [install it in
3434
organization](https://docs.github.com/en/developers/apps/managing-github-apps/installing-github-apps).
3535

36-
Github App will use [private key](https://docs.github.com/en/developers/apps/building-github-apps/authenticating-with-github-apps)
37-
for authentication. In order to properly authenticate with Terraform GitHub
36+
GitHub App will use [private key](https://docs.github.com/en/developers/apps/building-github-apps/authenticating-with-github-apps)
37+
for authentication. In order to properly authenticate with OpenTofu GitHub
3838
provider you will need:
3939

4040
- GitHub App ID (GitHub Action secret `GH_APP_ID`)
@@ -43,22 +43,22 @@ provider you will need:
4343

4444
## Getting GitHub App node ID
4545

46-
Node ID is used in GraphQL API. Some Terraform resources like
47-
[github_branch_protection](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/branch_protection)
48-
may require node IDs for access control lists. Knowing you App node ID will be
49-
handy, when you want to allow some actions only to it. While there maybe some
50-
better way of getting node ID, you can use your newly created App to query
51-
itself for node ID. First generate [JWT token](https://docs.github.com/en/developers/apps/building-github-apps/authenticating-with-github-apps#authenticating-as-a-github-app)
46+
Node ID is used in GraphQL API. Some OpenTofu resources like
47+
[github_branch_protection](https://search.opentofu.org/provider/hashicorp/github/latest/docs/resources/branch_protection)
48+
may require node IDs for access control lists. Knowing your App node ID will be
49+
handy, when you want to allow some actions only to it. While there may be some
50+
better way of getting the node ID, you can use your newly created App to query
51+
itself for node ID. First, generate [JWT token](https://docs.github.com/en/developers/apps/building-github-apps/authenticating-with-github-apps#authenticating-as-a-github-app)
5252
and then [query /app endpoint](https://docs.github.com/en/rest/reference/apps).
5353

5454
# 3. Configuring state backend
5555

56-
Terraform requires backend to store configuration state. This example repository
57-
uses OpenStack Swift. Consult [Terraform documentation](https://www.terraform.io/language/settings/backends)
56+
OpenTofu requires a backend to store configuration state. This example repository
57+
uses OpenStack Swift. Consult [OpenTofu documentation](https://opentofu.org/docs/language/settings/backends/configuration/)
5858
and choose your preferred backend. Keep in mind that you will also have to pass
5959
access credentials as GitHub secrets in order to use it.
6060

61-
# 4. Configuring Terraform repository secrets
61+
# 4. Configuring OpenTofu repository secrets
6262

6363
Visit `Repository` -> `Settings` -> `Secrets` -> `Actions` and ensure that at
6464
least the following variables are configured:
@@ -76,12 +76,12 @@ least the following variables are configured:
7676

7777
Workflows are divided into 3 files:
7878

79-
- `.github/workflows/terraform-checks.yml` - Validates pull request without
79+
- `.github/workflows/tofu-checks.yml` - Validates pull request without
8080
accessing repository secrets.
81-
- `.github/workflows/terraform-plan.yml` - Generates Terraform plan. This
82-
workflow is launched only after user whitelisted in file comments pull request
83-
with _/plan_ message. It ensures that untrusted code from pull request won't
81+
- `.github/workflows/tofu-plan.yml` - Generates OpenTofu plan. This
82+
workflow is launched only after a user whitelists in file comments pull request
83+
with the _/plan_ message. It ensures that untrusted code from pull requests won't
8484
be run automatically with repository secrets. See [this article](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/)
8585
for more details.
86-
- `.github/workflows/terraform-apply.yml` - Enforces state after pushing code to
87-
main branch.
86+
- `.github/workflows/tofu-apply.yml` - Enforces state after pushing code to
87+
the main branch.

0 commit comments

Comments
 (0)