Skip to content

Commit 32c0fa8

Browse files
authored
Break terraform to modules (#365)
* separate modules * move readme * updated org state * Break to tf modules * Change GH action version * update state file * add auto_approve * update state
1 parent a3f576f commit 32c0fa8

31 files changed

+332
-8170
lines changed

.github/workflows/add_member.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
python-version: '3.12'
3030

3131
- name: Checkout code
32-
uses: actions/checkout@v6.0.1
32+
uses: actions/checkout@v6 # zizmor: ignore[unpinned-uses]
3333
with:
3434
# This is the default, but it's required since we are performing
3535
# Git operations later on.
@@ -94,7 +94,7 @@ jobs:
9494
9595
- name: Commit changes
9696
run: |
97-
git add terraform/production/org.tfvars
97+
git add terraform/org.tfvars
9898
git commit -m "Add ${USERNAME} to django-commons"
9999
git push origin ${BRANCH_NAME}
100100

.github/workflows/member-verification.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
steps:
1515
- name: Checkout code
16-
uses: actions/checkout@v6.0.1
16+
uses: actions/checkout@v6 # zizmor: ignore[unpinned-uses]
1717
with:
1818
persist-credentials: false
1919

Original file line numberDiff line numberDiff line change
@@ -1,54 +1,51 @@
1-
name: "Apply org changes"
1+
name: "Apply org membership changes"
22

33
on:
44
push:
55
branches:
66
- main
77
paths:
8-
- 'terraform/production/*.tfvars'
9-
- 'terraform/*.tf'
10-
- '.github/workflows/apply.yml'
11-
- '.github/workflows/plan.yml'
8+
- 'terraform/org.tfvars'
9+
- 'terraform/members/*.tf'
10+
- '.github/workflows/members-apply.yml'
11+
- '.github/workflows/members-plan.yml'
1212

1313
concurrency:
14-
group: terraform-actions
14+
group: terraform-actions-members
1515

1616
jobs:
17-
apply-changes:
18-
name: "Org changes apply"
17+
org-apply-changes:
18+
name: "Apply org membership changes"
1919
runs-on: ubuntu-latest
2020

2121
permissions:
2222
contents: read
2323
pull-requests: write
24-
2524
timeout-minutes: 10
26-
2725
steps:
2826
- name: Checkout code
29-
uses: actions/checkout@v6.0.1
27+
uses: actions/checkout@v6 # zizmor: ignore[unpinned-uses]
3028
with:
3129
persist-credentials: false
3230
- name: terraform apply
33-
# v1.44.0
34-
uses: dflook/terraform-apply@5489b988934a50bf1489d5b7c5253b46520a7dca
31+
uses: dflook/terraform-apply@8f47d0ad9f3cb9e50fd6b3595c0cb98f00c518df # v2.2.2
3532
env:
3633
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3734
TERRAFORM_ACTIONS_GITHUB_TOKEN: ${{ secrets.TERRAFORM_MANAGEMENT_GITHUB_TOKEN }}
3835
with:
39-
path: "terraform"
36+
auto_approve: true
37+
path: "terraform/members"
38+
label: 'members'
4039
variables: |
4140
github_token = "${{ secrets.TERRAFORM_MANAGEMENT_GITHUB_TOKEN }}"
4241
var_file: |
43-
terraform/production/org.tfvars
44-
terraform/production/repositories.tfvars
42+
terraform/org.tfvars
4543
4644
- name: Commit changes
4745
if: ${{ always() }}
48-
# v0.10.0
49-
uses: devops-infra/action-commit-push@8a2d9d73c3f506468129be2e4409e60dbed70357
46+
uses: devops-infra/action-commit-push@8a2d9d73c3f506468129be2e4409e60dbed70357 # v1.0.3
5047
with:
5148
github_token: ${{ secrets.TERRAFORM_MANAGEMENT_GITHUB_TOKEN }}
5249
commit_prefix: "[AUTO]"
53-
commit_message: "State changes after apply"
50+
commit_message: "Members state changes after apply"
5451
force: false
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
name: "Plan org changes and list them in a PR"
1+
name: "Plan org membership changes and list them in a PR"
22
on:
33
pull_request:
44
branches:
55
- main
66
paths:
7-
- 'terraform/production/*.tfvars'
8-
- 'terraform/*.tf'
9-
- '.github/workflows/apply.yml'
7+
- 'terraform/org.tfvars'
8+
- 'terraform/members/*.tf'
9+
- '.github/workflows/members-apply.yml'
1010
# Do not trigger the plan action when it's been changed since this action has write permissions
1111

1212
concurrency:
13-
group: terraform-actions
13+
group: terraform-actions-members
1414

1515
jobs:
1616
format-terraform-code:
@@ -19,43 +19,42 @@ jobs:
1919
permissions:
2020
contents: read
2121
pull-requests: write
22-
timeout-minutes: 10
22+
timeout-minutes: 4
2323
steps:
2424
- name: Checkout code
25-
uses: actions/checkout@v6.0.1
25+
uses: actions/checkout@v6 # zizmor: ignore[unpinned-uses]
2626
with:
2727
persist-credentials: false
2828

2929
- name: terraform fmt check
30-
# v2.2.2
31-
uses: dflook/terraform-fmt-check@59168426e242f665bf7b70644d706224e665056a
30+
uses: dflook/terraform-fmt-check@10eaa13fa61437aa51be2d12fafe95f152e3512d # v2.2.2
3231
with:
33-
path: "terraform"
32+
path: "terraform/members"
3433

35-
plan-changes:
36-
name: "Org changes plan"
34+
org-plan-changes:
35+
name: "Plan org membership changes and list them in a PR"
3736
runs-on: ubuntu-latest
38-
needs: [ "format-terraform-code" ]
37+
needs: ["format-terraform-code"]
3938
permissions:
4039
pull-requests: write
4140
contents: read
41+
timeout-minutes: 10
4242
steps:
4343
- name: Checkout code
44-
uses: actions/checkout@v6.0.1
44+
uses: actions/checkout@v6 # zizmor: ignore[unpinned-uses]
4545
with:
4646
persist-credentials: false
4747

4848
- name: terraform plan
49-
# v1.44.0
50-
uses: dflook/terraform-plan@7878bff63e2099cdc9be9a6f33cbbbf687f8f0fe
49+
uses: dflook/terraform-plan@dc251c444763eed5defd065b866874b6343017ca # v2.2.2
5150
env:
5251
TERRAFORM_ACTIONS_GITHUB_TOKEN: ${{ secrets.TERRAFORM_MANAGEMENT_GITHUB_TOKEN }}
5352
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5453
with:
5554
add_github_comment: true
56-
path: "terraform"
55+
path: "terraform/members"
56+
label: 'members'
5757
variables: |
5858
github_token = "${{ secrets.TERRAFORM_MANAGEMENT_GITHUB_TOKEN }}"
5959
var_file: |
60-
terraform/production/org.tfvars
61-
terraform/production/repositories.tfvars
60+
terraform/org.tfvars

.github/workflows/repos-apply.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: "Apply org repositories changes"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'terraform/repositories.tfvars'
9+
- 'terraform/repositories/*.tf'
10+
- '.github/workflows/repos-apply.yml'
11+
- '.github/workflows/repos-plan.yml'
12+
13+
concurrency:
14+
group: terraform-actions-repos
15+
16+
jobs:
17+
repos-apply-changes:
18+
name: "Apply org-repositories changes"
19+
runs-on: ubuntu-latest
20+
21+
permissions:
22+
contents: read
23+
pull-requests: write
24+
timeout-minutes: 10
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v6 # zizmor: ignore[unpinned-uses]
28+
with:
29+
persist-credentials: false
30+
- name: terraform apply
31+
uses: dflook/terraform-apply@8f47d0ad9f3cb9e50fd6b3595c0cb98f00c518df # v2.2.2
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
TERRAFORM_ACTIONS_GITHUB_TOKEN: ${{ secrets.TERRAFORM_MANAGEMENT_GITHUB_TOKEN }}
35+
with:
36+
auto_approve: true
37+
path: "terraform/repositories"
38+
label: 'repositories'
39+
variables: |
40+
github_token = "${{ secrets.TERRAFORM_MANAGEMENT_GITHUB_TOKEN }}"
41+
var_file: |
42+
terraform/repositories.tfvars
43+
44+
- name: Commit changes
45+
if: ${{ always() }}
46+
uses: devops-infra/action-commit-push@8a2d9d73c3f506468129be2e4409e60dbed70357 # v1.0.3
47+
with:
48+
github_token: ${{ secrets.TERRAFORM_MANAGEMENT_GITHUB_TOKEN }}
49+
commit_prefix: "[AUTO]"
50+
commit_message: "Repositories state changes after apply"
51+
force: false

.github/workflows/repos-plan.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: "Plan org repositories changes and list them in a PR"
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
paths:
7+
- 'terraform/repositories.tfvars'
8+
- 'terraform/repositories/*.tf'
9+
- '.github/workflows/repos-apply.yml'
10+
# Do not trigger the plan action when it's been changed since this action has write permissions
11+
12+
concurrency:
13+
group: terraform-actions-repos
14+
15+
jobs:
16+
format-terraform-code:
17+
name: "Check Terraform code formatting"
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
pull-requests: write
22+
timeout-minutes: 4
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v6 # zizmor: ignore[unpinned-uses]
26+
with:
27+
persist-credentials: false
28+
29+
- name: terraform fmt check
30+
uses: dflook/terraform-fmt-check@10eaa13fa61437aa51be2d12fafe95f152e3512d # v2.2.2
31+
with:
32+
path: "terraform/repositories"
33+
34+
repos-plan-changes:
35+
name: "Plan org-repositories changes and list them in a PR"
36+
runs-on: ubuntu-latest
37+
needs: ["format-terraform-code"]
38+
permissions:
39+
pull-requests: write
40+
contents: read
41+
timeout-minutes: 10
42+
steps:
43+
- name: Checkout code
44+
uses: actions/checkout@v6 # zizmor: ignore[unpinned-uses]
45+
with:
46+
persist-credentials: false
47+
48+
- name: terraform plan
49+
uses: dflook/terraform-plan@dc251c444763eed5defd065b866874b6343017ca # v2.2.2
50+
env:
51+
TERRAFORM_ACTIONS_GITHUB_TOKEN: ${{ secrets.TERRAFORM_MANAGEMENT_GITHUB_TOKEN }}
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
with:
54+
add_github_comment: true
55+
path: "terraform/repositories"
56+
label: 'repos'
57+
variables: |
58+
github_token = "${{ secrets.TERRAFORM_MANAGEMENT_GITHUB_TOKEN }}"
59+
var_file: |
60+
terraform/repositories.tfvars

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
*.backup
22
notes.txt
33
.terraform
4-
.terraform.lock.hcl
54
.idea
65
.dflook-terraform-github-actions
76
tags

docs/projects.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
These are the projects that have joined Django commons and the dates they joined.
44
The true list of projects can be found in the
5-
[repositories.tfvars](https://github.com/django-commons/membership/blob/main/terraform/production/repositories.tfvars) file.
5+
[repositories.tfvars](https://github.com/django-commons/membership/blob/main/terraform/repositories.tfvars) file.
66

77
- django-valkey: 2025-06-17
88
- django-prometheus: 2025-06-17

scripts/add_member.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22
import sys
33

4-
TERRAFORM_ORG_FILE = "./terraform/production/org.tfvars"
4+
TERRAFORM_ORG_FILE = "./terraform/org.tfvars"
55

66

77
def add_member(content, new_member_name, team_name):

0 commit comments

Comments
 (0)