Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use terraform to maintain the organizational structure #14

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c5285e1
terraform org mgmt
cunla Jul 12, 2024
f175617
terraform org mgmt
cunla Jul 12, 2024
e59e51d
terraform org mgmt
cunla Jul 12, 2024
19ce7dc
terraform org mgmt
cunla Jul 13, 2024
de7a932
terraform org mgmt
cunla Jul 13, 2024
5d0ede6
terraform org mgmt
cunla Jul 13, 2024
56d0267
terraform org mgmt
cunla Jul 13, 2024
6edf954
terraform org mgmt
cunla Jul 15, 2024
1165e81
terraform org mgmt
cunla Jul 16, 2024
6b638e7
remove webhooks
cunla Jul 20, 2024
2023d5f
added permissions to readme
cunla Jul 20, 2024
6616b25
readme changes
cunla Jul 20, 2024
46ff1b4
readme changes
cunla Jul 20, 2024
9ffc5e6
readme changes
cunla Jul 20, 2024
b423afc
gha
cunla Jul 20, 2024
0c37c09
gha
cunla Jul 20, 2024
0bb5e56
gha
cunla Jul 20, 2024
bad31e0
gha
cunla Jul 20, 2024
61dc4a4
gha
cunla Jul 20, 2024
9ac827d
gha
cunla Jul 20, 2024
9cff7bb
gha
cunla Jul 20, 2024
298065b
gha
cunla Jul 20, 2024
0874fda
gha
cunla Jul 20, 2024
96000ca
gha
cunla Jul 20, 2024
6bb454d
gha
cunla Jul 20, 2024
a9e312b
gha
cunla Jul 20, 2024
6661316
Use member as dynamic variable to avoid confusion with the members list.
tim-schilling Jul 24, 2024
e042e5b
Adjust repository defaults.
tim-schilling Jul 24, 2024
3332bf9
Comment the main terraform file with descriptions of what each sectio…
tim-schilling Jul 24, 2024
8b997ce
Pin the terraform github action third-party actions to SHA hashes.
tim-schilling Jul 24, 2024
1d0af1e
Use domain specific naming for variables.
tim-schilling Jul 24, 2024
bd3f0ad
Re-add review request delegation.
tim-schilling Jul 24, 2024
94358af
Attempt to split the org teams from the repo teams.
tim-schilling Jul 24, 2024
16354a6
Revise the playbooks for the new names for the variables.
tim-schilling Jul 24, 2024
7e5837f
Fix missed team_parents reference.
tim-schilling Jul 24, 2024
99c0cfc
Update terraform specific docs with new variable names.
tim-schilling Jul 24, 2024
274b098
The teams are maps, not lists.
tim-schilling Jul 24, 2024
b057101
Revert change, use dynamic members.
tim-schilling Jul 24, 2024
e46b855
Remove maintainers collections where they are unnecessary.
tim-schilling Jul 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/apply.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: "Apply org changes"

on:
push:
branches:
- main
paths:
- 'terraform/production/*.tfvars'

jobs:
apply-changes:
name: "Org changes plan"
runs-on: ubuntu-latest

permissions:
contents: write

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: terraform apply
# v1.43.0
# Use the commit hash for security hardening
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-third-party-actions
uses: dflook/terraform-apply@dcda97d729f1843ede471d2fac989cb946f5622a
env:
TERRAFORM_ACTIONS_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
path: "terraform"
variables: |
github_token = "${{ secrets.TERRAFORM_MANAGEMENT_GITHUB_TOKEN }}"
var_file: |
terraform/production/org.tfvars
terraform/production/repositories.tfvars
terraform/production/teams.tfvars

- name: Commit changes
uses: devops-infra/action-commit-push@v0.9.2
with:
github_token: "${{ secrets.GITHUB_TOKEN }}"
commit_prefix: "[AUTO]"
commit_message: "State changes after apply"
force: false
38 changes: 0 additions & 38 deletions .github/workflows/new_team.yml

This file was deleted.

37 changes: 37 additions & 0 deletions .github/workflows/plan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: "Plan org changes and list them in a PR"
on:
pull_request:
branches:
- main
paths:
- 'terraform/production/*.tfvars'

jobs:
plan-changes:
name: "Org changes plan"
runs-on: ubuntu-latest

permissions:
pull-requests: write
contents: read

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: terraform plan
# v1.43.0
# Use the commit hash for security hardening
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-third-party-actions
uses: dflook/terraform-plan@d9df4f6c2484e709ba7ffaa16c98a6906f4760cd
env:
TERRAFORM_ACTIONS_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
add_github_comment: true
path: "terraform"
variables: |
github_token = "${{ secrets.TERRAFORM_MANAGEMENT_GITHUB_TOKEN }}"
var_file: |
terraform/production/org.tfvars
terraform/production/repositories.tfvars
terraform/production/teams.tfvars
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.backup
notes.txt
182 changes: 158 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,184 @@ Django Commons packages.
- [New project](#new-project-playbook)
- [Remove project](#remove-project-playbook)


## New Member Playbook

1. Review new issues/application at https://github.com/django-commons/membership/issues/
2. If they are a real human and are reasonably trustworthy, comment "Approved" and nothing else
3. The [new_member](https://github.com/django-commons/membership/blob/main/.github/workflows/new_member.yml) action will send the invite and close the issue
4. Add the member to any relevant teams if requested

If they aren't a real human or reasonably trustworthy, close the issue.
2. If they are not a real human or not reasonably trustworthy, close the issue, asking for more information they are a human and not a spam bot. You can explain that by being a member, they can impact repositories immediately.
3. Add the user to the `members` collection in the [`terraform/production/org.tfvars`](https://github.com/django-commons/controls/blob/main/terraform/production/org.tfvars) file.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
3. Add the user to the `members` collection in the [`terraform/production/org.tfvars`](https://github.com/django-commons/controls/blob/main/terraform/production/org.tfvars) file.
3. Add the user's GitHub username to the `members` collection in the [`terraform/production/org.tfvars`](https://github.com/django-commons/controls/blob/main/terraform/production/org.tfvars) file.

```terraform
members = [
# ...
"new_user"
]
```
5. If they requested to be on specific repository team(s), in the [`terraform/production/teams.tfvars`](https://github.com/django-commons/controls/blob/main/terraform/production/teams.tfvars) file, for the repository's key under `teams_repositories`, add them to the `members` collection.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
5. If they requested to be on specific repository team(s), in the [`terraform/production/teams.tfvars`](https://github.com/django-commons/controls/blob/main/terraform/production/teams.tfvars) file, for the repository's key under `teams_repositories`, add them to the `members` collection.
5. If they requested to be on specific repository team(s), find that team's repository in the [`terraform/production/teams.tfvars`](https://github.com/django-commons/controls/blob/main/terraform/production/teams.tfvars) file under `teams_repositories`. Add the new user to the `members` collection.

```terraform
teams_repositories = {
"[REPOSITORY]" = {
# ...
members = [
# ...
"new_user"
]
}
}
```
6. Create a pull-request to `main` branch, it will trigger terraform to plan the changes in the organization to be
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
6. Create a pull-request to `main` branch, it will trigger terraform to plan the changes in the organization to be
6. Create a pull request to the `main` branch. This will trigger terraform to plan the changes in the organization to be

executed. Review the changes and make sure they align with the request.
7. Merge the pull-request, it will trigger terraform to apply the changes in the organization.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
7. Merge the pull-request, it will trigger terraform to apply the changes in the organization.
7. Merge the pull request. This will trigger terraform to apply the changes to the organization.


## Team Change Playbook

1. If they are a real human and are reasonably trustworthy, comment "Approved" and close the issue manually
2. Add the member to requested team(s)
1. If they are not a real human or not reasonably trustworthy, close the issue, asking for more information they are a human and not a spam bot. You can explain that by being a member, they can impact repositories immediately.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically duplicated from the section "New Member Playbook." Should the New Member Playbook maybe refer to this section, instead of reproducing it? Something like, "If they requested to be on specific repository team(s), follow the instructions below in Team Change Playbook."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking here is that after X successful PRs, the existing admins/committers invite a person to have commit or admin rights on a repo. That's what flow this is attempting to cover which is separate from a new member.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tim-schilling Sounds good, thank you for clarifying!

2. For the requested repository's team(s), in the [`terraform/production/teams.tfvars`](https://github.com/django-commons/controls/blob/main/terraform/production/teams.tfvars) file, for the repository's key under `teams_repositories`, add them to the `members` collection.
```terraform
teams_repositories = {
"[REPOSITORY]" = {
# ...
members = [
# ...
"new_user"
]
}
}
```
3. Create a pull-request to `main` branch, it will trigger terraform to plan the changes in the organization to be
executed. Review the changes and make sure they align with the request.
4. Merge the pull-request, it will trigger terraform to apply the changes in the organization.

## New Repository Admin Playbook
## New Repository Admin or Committer Playbook

1. Confirm with all existing admins that they are okay with the prospective admin
1. Confirm with all existing admins that they are okay with the change
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. Confirm with all existing admins that they are okay with the change
1. Confirm with all existing admins that they approve changes to the repository admins or committers.

2. If there's disagreement, close the issue and ask for the admins to come to a consensus
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
2. If there's disagreement, close the issue and ask for the admins to come to a consensus
2. If there's disagreement, close the issue and ask for the admins to come to a consensus.

3. If there's agreement, add the prospective admin to the [repo]-admins team
3. For the requested repository's team(s), in the [`terraform/production/teams.tfvars`](https://github.com/django-commons/controls/blob/main/terraform/production/teams.tfvars)
file, for the repository's key under `teams_repositories_privileged`, add them to the `members` collection for the correct team. There will be two privileged teams for each repository, `*-admins` and `*-committers`, the user should be added to the requested team.
```terraform
teams_repositories_privileged = {
"[REPOSITORY]-[admins | committers]" = {
# ...
members = [
# ...
"new_user"
]
}
}
```
4. Create a pull-request to `main` branch, it will trigger terraform to plan the changes in the organization to be
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
4. Create a pull-request to `main` branch, it will trigger terraform to plan the changes in the organization to be
4. Create a pull request to `main` branch. This will trigger terraform to plan the changes in the organization to be

executed. Review the changes and make sure they align with the request.
5. Merge the pull-request, it will trigger terraform to apply the changes in the organization.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
5. Merge the pull-request, it will trigger terraform to apply the changes in the organization.
5. Merge the pull request. This will trigger terraform to apply the changes in the organization.


## New Project Playbook

1. Check if repository meets [inbound requirements](https://github.com/django-commons/membership/blob/main/incoming_repo_requirements.md)
1. Check if repository
meets [inbound requirements](https://github.com/django-commons/membership/blob/main/incoming_repo_requirements.md)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
meets [inbound requirements](https://github.com/django-commons/membership/blob/main/incoming_repo_requirements.md)
meets [inbound requirements](https://github.com/django-commons/membership/blob/main/incoming_repo_requirements.md).

2. Confirm who will be the admins and maintainers for the repository
3. PyPI project owner must add you (Django Commons admin) as owner in PyPI
4. (TODO: Determine how this works with transfering out of an org and into the Django Commons org)
5. [Add repository owner to Django Commons as member](https://github.com/orgs/django-commons/people) (they'll be added to a team later)
6. Share link ([https://docs.github.com/en/repositories/creating-and-managing-repositories/transferring-a-repository](https://docs.github.com/en/repositories/creating-and-managing-repositories/transferring-a-repository)) with repo owner to transfer repo
4. (TODO: Determine how this works with transferring out of an org and into the Django Commons org)
5. [Add repository owner to Django Commons as member](#new-member-playbook) (they'll be added
to a team later)
6. Share
link ([https://docs.github.com/en/repositories/creating-and-managing-repositories/transferring-a-repository](https://docs.github.com/en/repositories/creating-and-managing-repositories/transferring-a-repository))
with repo owner to transfer repo
7. Wait for repository transferred in
8. [Run new team action](https://github.com/django-commons/controls/actions/workflows/new_team.yml)
9. Invite repository admins to [repo]-admins team, repository maintainers to [repo]-committers team
10. Configure environments pypi and testpypi
11. For pypi environment, add Deployment protection rule with reviewers as [repo]-admins and enable "Allow administrators to bypass configured protection rules"
12. Under Actions > General > "Fork pull request workflows from outside collaborators", set "Require approval for first-time contributors"
13. Add previous repository owner to [repo]-admins team
14. Set a calender event or reminder for 30 days in the future to remove previous repository owner from team
9. [Make Terraform changes to add new project](#terraform-changes-to-add-a-new-project)
10. [Configure environments](https://docs.github.com/en/actions/administering-github-actions/managing-environments-for-deployment#creating-an-environment) pypi and testpypi in the repository to enable [publishing packages via GitHub Actions](https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/#)
11. For pypi environment, add Deployment protection rule with reviewers as [repo]-admins and enable "Allow
administrators to bypass configured protection rules"
12. Under Actions > General > "Fork pull request workflows from outside collaborators", set "Require approval for
first-time contributors"
13. Set a calendar event or reminder for 30 days in the future to remove previous repository owner from team

### Terraform changes to add a new project

Assuming repository name is `repo-name`:

1. In [`terraform/production/respositories.tfvars`](https://github.com/django-commons/controls/blob/main/terraform/production/respositories.tfvars), Add the new repository to the `repositories` section:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. In [`terraform/production/respositories.tfvars`](https://github.com/django-commons/controls/blob/main/terraform/production/respositories.tfvars), Add the new repository to the `repositories` section:
1. In [`terraform/production/respositories.tfvars`](https://github.com/django-commons/controls/blob/main/terraform/production/respositories.tfvars), add the new repository to the `repositories` section:

```terraform
repositories = {
# ...
"repo-name" = {
description = "repo description"
allow_auto_merge = false # optional, default is false
allow_merge_commit = false # optional, default is false
allow_rebase_merge = false # optional, default is false
allow_squash_merge = false # optional, default is false
allow_update_branch = false # optional, default is false
enable_branch_protection = true # optional, default is true
has_discussions = true # optional, default is true
has_downloads = true # optional, default is true
has_wiki = false # optional, default is false
is_template = false # optional, default is false
push_allowances = []
required_status_checks_contexts = [] # optional, default is []
template = "" # optional, default is ""
topics = []
visibility = "public" # optional, default is "public"
}
}
```
2. In [`terraform/production/teams.tfvars`](https://github.com/django-commons/controls/blob/main/terraform/production/teams.tfvars), add the new team `repo-name` for the repository in the `teams_repositories` section with the
relevant members:
```terraform
teams_repositories = {
# ...
"repo-name" = {
description = "repo-name team"
members = [
# Put the user from Step 5 here
"username",
]
permission = "triage"
repositories = [
"repo-name",
]
}
}
```
3. Add two new child teams `repo-name-admins` and `repo-name-committers` for the repository in the `teams_repositories_privileged`
section with the relevant members:
```terraform
teams_repositories_privileged = {
# ...
"repo-name-admins" = {
description = "repo-name admins team"
parent_team_key = "repo-name"
members = [
# Put the user from Step 5 here
"username",
]
permission = "admin"
}
"repo-name-committers" = {
description = "repo-name committers team"
parent_team_key = "repo-name"
members = [
# Leave empty unless there are committers ready to be designated
]
permission = "push"
}
}
```
4. Create a pull-request to `main` branch, it will trigger terraform to plan the changes in the organization to be
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
4. Create a pull-request to `main` branch, it will trigger terraform to plan the changes in the organization to be
4. Create a pull request to the `main` branch. This will trigger terraform to plan the changes in the organization to be

executed. Review the changes and make sure they align with the request.
5. Merge the pull-request, it will trigger terraform to apply the changes in the organization.

## Remove Project Playbook

1. Confirm there's agreement amongst current project maintainers to move project out of Django Commons
2. Add new Owner(s) to project in PyPI
3. [Transfer GitHub repo to new owner or Org](https://github.com/orgs/django-commons/people)
4. Wait for repository to be transferred out.
5. [Delete top-level team for repository](https://github.com/orgs/django-commons/teams) (the delete will cascade to the sub-teams)
6. Remove all Django Commons members from PyPI project (except any that are staying on from step 2)
7. (TODO: Determine how to handle transferring a PyPI project out of an organization)
5. Remove all Django Commons members from PyPI project (except any that are staying on from step 2)
6. (TODO: Determine how to handle transferring a PyPI project out of an organization)

### Terraform changes to remove a project

1. Remove the repository from the `repositories` section in [`terraform/production/respositories.tfvars`](https://github.com/django-commons/controls/blob/main/terraform/production/respositories.tfvars)
2. Remove the parent team and child teams for the repository from the `teams_repositories` and `teams_repositories_privileged` sections in
[`terraform/production/teams.tfvars`](https://github.com/django-commons/controls/blob/main/terraform/production/teams.tfvars)
3. Create a pull-request to `main` branch, it will trigger terraform to plan the changes in the organization to be
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
3. Create a pull-request to `main` branch, it will trigger terraform to plan the changes in the organization to be
3. Create a pull request to the `main` branch. This will trigger terraform to plan the changes in the organization to be

executed.
Review the changes and make sure they align with the request.
4. Merge the pull-request, it will trigger terraform to apply the changes in the organization.
Loading