Skip to content

Commit 794a904

Browse files
authored
feat: create envs for managed repos using terraform (#44)
1 parent ee690f7 commit 794a904

File tree

4 files changed

+118
-9
lines changed

4 files changed

+118
-9
lines changed

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,10 @@ Django Commons packages.
101101
with repo owner to transfer repo
102102
7. Wait for repository transferred in
103103
8. [Make Terraform changes to add new project](#terraform-changes-to-add-a-new-project)
104-
9. [Configure environments](https://docs.github.com/en/actions/administering-github-actions/managing-environments-for-deployment#creating-an-environment)
105-
pypi and testpypi in the repository to
106-
enable [publishing packages via GitHub Actions](https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/#)
107-
10. For pypi environment, add Deployment protection rule with reviewers as [repo]-admins and enable "Allow
108-
administrators to bypass configured protection rules"
109-
11. Under Actions > General > "Fork pull request workflows from outside collaborators", set "Require approval for
104+
9. Under Actions > General > "Fork pull request workflows from outside collaborators", set "Require approval for
110105
first-time contributors"
111-
12. Set a calendar event or reminder for 30 days in the future to remove previous repository owner from team
106+
10. Have the maintainer push a new tag and walk them through the release process
107+
11. Set a calendar event or reminder for 30 days in the future to remove previous repository owner from team
112108

113109
### Terraform changes to add a new project
114110

@@ -190,4 +186,4 @@ The expected changes:
190186
The expected changes:
191187

192188
- The repository will be removed from the organization.
193-
- The repository's teams will be removed from the organization.
189+
- The repository's teams will be removed from the organization.

terraform/production/repositories.tfvars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ repositories = {
5656
description = "Schedule async tasks using redis pub/sub."
5757
homepage_url = "https://django-tasks-scheduler.readthedocs.io/"
5858
allow_merge_commit = true
59+
5960
admins = [
6061
"cunla",
6162
]

terraform/resources-environments.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
resource "github_repository_environment" "pypi" {
2+
for_each = { for k, v in var.repositories : k => v if v.is_django_commons_repo == false }
3+
4+
environment = "pypi"
5+
repository = each.key
6+
prevent_self_review = false
7+
reviewers {
8+
teams = [github_team.repo_admin_team[each.key].id]
9+
}
10+
}
11+
12+
resource "github_repository_environment" "testpypi" {
13+
for_each = { for k, v in var.repositories : k => v if v.is_django_commons_repo == false }
14+
15+
environment = "testpypi"
16+
repository = each.key
17+
prevent_self_review = false
18+
}

terraform/tfstate.json

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"version": 4,
33
"terraform_version": "1.9.5",
4-
"serial": 188,
4+
"serial": 192,
55
"lineage": "425397de-8394-a003-8a6c-bce854d9cc53",
66
"outputs": {},
77
"resources": [
@@ -688,6 +688,100 @@
688688
}
689689
]
690690
},
691+
{
692+
"mode": "managed",
693+
"type": "github_repository_environment",
694+
"name": "pypi",
695+
"provider": "provider[\"registry.terraform.io/integrations/github\"]",
696+
"instances": [
697+
{
698+
"index_key": "django-commons-playground",
699+
"schema_version": 0,
700+
"attributes": {
701+
"can_admins_bypass": true,
702+
"deployment_branch_policy": [],
703+
"environment": "pypi",
704+
"id": "django-commons-playground:pypi",
705+
"prevent_self_review": false,
706+
"repository": "django-commons-playground",
707+
"reviewers": [
708+
{
709+
"teams": [
710+
9757650
711+
],
712+
"users": []
713+
}
714+
],
715+
"wait_timer": 0
716+
},
717+
"sensitive_attributes": [],
718+
"private": "eyJzY2hlbWFfdmVyc2lvbiI6IjAifQ=="
719+
},
720+
{
721+
"index_key": "django-fsm-2",
722+
"schema_version": 0,
723+
"attributes": {
724+
"can_admins_bypass": true,
725+
"deployment_branch_policy": [],
726+
"environment": "pypi",
727+
"id": "django-fsm-2:pypi",
728+
"prevent_self_review": false,
729+
"repository": "django-fsm-2",
730+
"reviewers": [
731+
{
732+
"teams": [
733+
10870432
734+
],
735+
"users": []
736+
}
737+
],
738+
"wait_timer": 0
739+
},
740+
"sensitive_attributes": [],
741+
"private": "eyJzY2hlbWFfdmVyc2lvbiI6IjAifQ=="
742+
}
743+
]
744+
},
745+
{
746+
"mode": "managed",
747+
"type": "github_repository_environment",
748+
"name": "testpypi",
749+
"provider": "provider[\"registry.terraform.io/integrations/github\"]",
750+
"instances": [
751+
{
752+
"index_key": "django-commons-playground",
753+
"schema_version": 0,
754+
"attributes": {
755+
"can_admins_bypass": true,
756+
"deployment_branch_policy": [],
757+
"environment": "testpypi",
758+
"id": "django-commons-playground:testpypi",
759+
"prevent_self_review": null,
760+
"repository": "django-commons-playground",
761+
"reviewers": [],
762+
"wait_timer": 0
763+
},
764+
"sensitive_attributes": [],
765+
"private": "eyJzY2hlbWFfdmVyc2lvbiI6IjAifQ=="
766+
},
767+
{
768+
"index_key": "django-fsm-2",
769+
"schema_version": 0,
770+
"attributes": {
771+
"can_admins_bypass": true,
772+
"deployment_branch_policy": [],
773+
"environment": "testpypi",
774+
"id": "django-fsm-2:testpypi",
775+
"prevent_self_review": null,
776+
"repository": "django-fsm-2",
777+
"reviewers": [],
778+
"wait_timer": 0
779+
},
780+
"sensitive_attributes": [],
781+
"private": "eyJzY2hlbWFfdmVyc2lvbiI6IjAifQ=="
782+
}
783+
]
784+
},
691785
{
692786
"mode": "managed",
693787
"type": "github_team",

0 commit comments

Comments
 (0)