-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance GitHub repository management by adding environment support, r…
…efining secret handling, and improving collaborator permissions mapping
- Loading branch information
Dave Arnold
committed
Feb 19, 2025
1 parent
30851e4
commit 88899ff
Showing
11 changed files
with
717 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,27 @@ | ||
| locals { | ||
| # Permission mapping for collaborator roles | ||
| permission_map = { | ||
| "pull" = "read" | ||
| "triage" = "triage" | ||
| "push" = "write" | ||
| "maintain" = "maintain" | ||
| "admin" = "admin" | ||
| } | ||
| } | ||
|
|
||
| data "github_user" "collaborators" { | ||
| for_each = var.collaborators | ||
| username = each.key | ||
| } | ||
|
|
||
| # Add a collaborator to a repository | ||
| resource "github_repository_collaborator" "collaborators" { | ||
| for_each = tomap(var.collaborators) | ||
| repository = local.github_repo.name | ||
| username = each.key | ||
| permission = each.value | ||
| permission = local.permission_map[each.value] | ||
|
|
||
| depends_on = [ | ||
| data.github_user.collaborators | ||
| ] | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| resource "github_repository_environment" "environments" { | ||
| for_each = { for env in var.environments : env.name => env } | ||
|
|
||
| environment = each.value.name | ||
| repository = github_repository.repo[0].name | ||
| reviewers { | ||
| teams = try(each.value.reviewers.teams, []) | ||
| users = try(each.value.reviewers.users, []) | ||
| } | ||
| deployment_branch_policy { | ||
| protected_branches = try(each.value.deployment_branch_policy.protected_branches, true) | ||
| custom_branch_policies = try(each.value.deployment_branch_policy.custom_branch_policies, false) | ||
| } | ||
| } | ||
|
|
||
| resource "github_actions_environment_secret" "environment_secrets" { | ||
| for_each = { | ||
| for pair in flatten([ | ||
| for env in var.environments : [ | ||
| for secret in coalesce(env.secrets, []) : { | ||
| env_name = env.name | ||
| name = secret.name | ||
| value = secret.value | ||
| } | ||
| ] | ||
| ]) : "${pair.env_name}.${pair.name}" => pair | ||
| } | ||
|
|
||
| repository = github_repository.repo[0].name | ||
| environment = each.value.env_name | ||
| secret_name = each.value.name | ||
| plaintext_value = each.value.value | ||
|
|
||
| depends_on = [github_repository_environment.environments] | ||
| } | ||
|
|
||
| resource "github_actions_environment_variable" "environment_variables" { | ||
| for_each = { | ||
| for pair in flatten([ | ||
| for env in var.environments : [ | ||
| for _var in coalesce(env.vars, []) : { | ||
| env_name = env.name | ||
| name = _var.name | ||
| value = _var.value | ||
| } | ||
| ] | ||
| ]) : "${pair.env_name}.${pair.name}" => pair | ||
| } | ||
|
|
||
| repository = github_repository.repo[0].name | ||
| environment = each.value.env_name | ||
| variable_name = each.value.name | ||
| value = each.value.value | ||
|
|
||
| depends_on = [github_repository_environment.environments] | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.