Skip to content

Commit a46194e

Browse files
authored
Merge pull request #2 from dsodk/fix-org-projects-and-org-webhooks
fix-org-projects-and-org-webhooks
2 parents ad1f7ee + 4ac4567 commit a46194e

File tree

9 files changed

+77
-104
lines changed

9 files changed

+77
-104
lines changed

README.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,16 @@ No modules.
4848
| <a name="input_blog_url"></a> [blog\_url](#input\_blog\_url) | The blog URL (https://example.com) for the GitHub Organization. (Optional) | `string` | `""` | no |
4949
| <a name="input_company"></a> [company](#input\_company) | The company name for the GitHub Organization. (Optional) | `string` | `""` | no |
5050
| <a name="input_create_github_organization"></a> [create\_github\_organization](#input\_create\_github\_organization) | Whether to create the GitHub Organization. | `bool` | `true` | no |
51-
| <a name="input_create_github_organization_project"></a> [create\_github\_organization\_project](#input\_create\_github\_organization\_project) | Whether to create projects in the GitHub Organization. | `bool` | `false` | no |
52-
| <a name="input_create_github_organization_webhook"></a> [create\_github\_organization\_webhook](#input\_create\_github\_organization\_webhook) | Whether to create webhooks in the GitHub Organization. | `bool` | `false` | no |
51+
| <a name="input_create_github_organization_project"></a> [create\_github\_organization\_project](#input\_create\_github\_organization\_project) | Whether to create Projects in the GitHub Organization. | `bool` | `false` | no |
52+
| <a name="input_create_github_organization_webhook"></a> [create\_github\_organization\_webhook](#input\_create\_github\_organization\_webhook) | Whether to create Webhooks in the GitHub Organization. | `bool` | `false` | no |
5353
| <a name="input_default_repository_permission"></a> [default\_repository\_permission](#input\_default\_repository\_permission) | The default permission [read\|write\|admin\|none] for GitHub Organization members to create new repositories . (Optional) | `string` | `"read"` | no |
5454
| <a name="input_dependabot_alerts_enabled_for_new_repositories"></a> [dependabot\_alerts\_enabled\_for\_new\_repositories](#input\_dependabot\_alerts\_enabled\_for\_new\_repositories) | Whether or not dependabot alerts are enabled for new repositories. (Optional) | `bool` | `false` | no |
5555
| <a name="input_dependabot_security_updates_enabled_for_new_repositories"></a> [dependabot\_security\_updates\_enabled\_for\_new\_repositories](#input\_dependabot\_security\_updates\_enabled\_for\_new\_repositories) | Whether or not dependabot security updates are enabled for new repositories. (Optional) | `bool` | `false` | no |
5656
| <a name="input_dependency_graph_enabled_for_new_repositories"></a> [dependency\_graph\_enabled\_for\_new\_repositories](#input\_dependency\_graph\_enabled\_for\_new\_repositories) | Whether or not dependency graph is enabled for new repositories. (Optional) | `bool` | `false` | no |
5757
| <a name="input_description"></a> [description](#input\_description) | The description for the GitHub Organization. (Optional) | `string` | `""` | no |
5858
| <a name="input_email"></a> [email](#input\_email) | The email address ([email protected]) for the GitHub Organization. (Optional) | `string` | `""` | no |
59-
| <a name="input_github_organization_project_body"></a> [github\_organization\_project\_body](#input\_github\_organization\_project\_body) | The body of the project. (Optional) | `string` | `""` | no |
60-
| <a name="input_github_organization_project_name"></a> [github\_organization\_project\_name](#input\_github\_organization\_project\_name) | The name of the project. (Required) | `string` | `""` | no |
61-
| <a name="input_github_organization_webhook_active"></a> [github\_organization\_webhook\_active](#input\_github\_organization\_webhook\_active) | Indicate of the webhook should receive events. (Optional) | `bool` | `true` | no |
62-
| <a name="input_github_organization_webhook_config_content_type"></a> [github\_organization\_webhook\_config\_content\_type](#input\_github\_organization\_webhook\_config\_content\_type) | The content type of the webhook. [form\|json] | `string` | `"form"` | no |
63-
| <a name="input_github_organization_webhook_config_insecure_ssl"></a> [github\_organization\_webhook\_config\_insecure\_ssl](#input\_github\_organization\_webhook\_config\_insecure\_ssl) | Whether to allow insecure\_ssl. | `bool` | `false` | no |
64-
| <a name="input_github_organization_webhook_config_secret"></a> [github\_organization\_webhook\_config\_secret](#input\_github\_organization\_webhook\_config\_secret) | Secret for the Webhook | `string` | `""` | no |
65-
| <a name="input_github_organization_webhook_config_url"></a> [github\_organization\_webhook\_config\_url](#input\_github\_organization\_webhook\_config\_url) | The URL of the webhook | `string` | `""` | no |
66-
| <a name="input_github_organization_webhook_events"></a> [github\_organization\_webhook\_events](#input\_github\_organization\_webhook\_events) | A list of events which should trigger the webhook. (Optional)<br>For list of valid events, visit https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#issues | `list(any)` | `[]` | no |
59+
| <a name="input_github_organization_projects"></a> [github\_organization\_projects](#input\_github\_organization\_projects) | Map of GitHub Organization Projects to create. (Optional) | `map(any)` | `{}` | no |
60+
| <a name="input_github_organization_webhooks"></a> [github\_organization\_webhooks](#input\_github\_organization\_webhooks) | Map of GitHub Organization Webhooks to create. (Optional)<br>For list of valid events, visit https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#issues | `map(any)` | `{}` | no |
6761
| <a name="input_has_organization_projects"></a> [has\_organization\_projects](#input\_has\_organization\_projects) | Whether or not organization projects are enabled for the GitHub Organization. (Optional) | `bool` | `true` | no |
6862
| <a name="input_has_repository_projects"></a> [has\_repository\_projects](#input\_has\_repository\_projects) | Whether or not repository projects are enabled for the GitHub Organization. (Optional) | `bool` | `true` | no |
6963
| <a name="input_location"></a> [location](#input\_location) | The location for the GitHub Organization. (Optional) | `string` | `""` | no |
@@ -85,9 +79,9 @@ No modules.
8579

8680
| Name | Description |
8781
|------|-------------|
88-
| <a name="output_github_organization_project_url"></a> [github\_organization\_project\_url](#output\_github\_organization\_project\_url) | The URL of the project |
89-
| <a name="output_github_organization_settings_id"></a> [github\_organization\_settings\_id](#output\_github\_organization\_settings\_id) | The ID of the organization settings |
90-
| <a name="output_github_organization_webhook_url"></a> [github\_organization\_webhook\_url](#output\_github\_organization\_webhook\_url) | The URL of the webhook |
82+
| <a name="output_organization_project_url"></a> [organization\_project\_url](#output\_organization\_project\_url) | The URL of the project |
83+
| <a name="output_organization_settings_id"></a> [organization\_settings\_id](#output\_organization\_settings\_id) | The ID of the organization settings |
84+
| <a name="output_organization_webhook_url"></a> [organization\_webhook\_url](#output\_organization\_webhook\_url) | The URL of the webhook |
9185
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
9286

9387
## Authors
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ No providers.
3434

3535
| Name | Source | Version |
3636
|------|--------|---------|
37-
| <a name="module_github_organization_settings"></a> [github\_organization\_settings](#module\_github\_organization\_settings) | ../ | n/a |
37+
| <a name="module_github_organizations"></a> [github\_organizations](#module\_github\_organizations) | ../.. | n/a |
3838

3939
## Resources
4040

@@ -45,8 +45,8 @@ No resources.
4545
| Name | Description | Type | Default | Required |
4646
|------|-------------|------|---------|:--------:|
4747
| <a name="input_billing_email"></a> [billing\_email](#input\_billing\_email) | The billing email address for the GitHub Organization. (Required) | `string` | n/a | yes |
48-
| <a name="input_owner"></a> [owner](#input\_owner) | Target GitHub organization or individual user account to manage. (Required) | `string` | n/a | yes |
49-
| <a name="input_token"></a> [token](#input\_token) | GitHub API Auth using OAuth or Personal Access Token. (Required) | `string` | n/a | yes |
48+
| <a name="input_github_owner"></a> [github\_owner](#input\_github\_owner) | Target GitHub organization or individual user account to manage. (Required) | `string` | n/a | yes |
49+
| <a name="input_github_token"></a> [github\_token](#input\_github\_token) | GitHub API Auth using OAuth or Personal Access Token. (Required) | `string` | n/a | yes |
5050

5151
## Outputs
5252

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
provider "github" {
22

3-
owner = var.owner
4-
token = var.token
5-
6-
#token = var.github_token # GITHUB_TOKEN - GitHub API Auth using OAuth or Personal Access Token
3+
token = var.github_token # GITHUB_TOKEN - GitHub API Auth using OAuth or Personal Access Token
74
#base_url = var.github_base_url # GITHUB_BASE_URL - Target GitHub base API endpoint. Required for GitHub Enterprise
8-
#owner = var.github_owner # GITHUB_OWNER - Target GitHub organization or individual user account to manage
5+
owner = var.github_owner # GITHUB_OWNER - Target GitHub organization or individual user account to manage
96

107
#write_delay_ms = try(var.github_write_delay_ms, 1000) # Milliseconds to sleep between write ops for GitHub API Rate Limit
118
#read_delay_ms = try(var.github_read_delay_ms, 0) # Milliseconds to sleep between read ops for GitHub API Rate Limit
129
}
1310

11+
locals {
12+
billing_email = var.billing_email
13+
}
1414
##################################################
1515
# GitHub Organization
1616
##################################################
1717

18-
module "github_organization_settings" {
19-
source = "../"
18+
module "github_organizations" {
19+
source = "../.."
2020

21-
billing_email = var.billing_email
21+
billing_email = local.billing_email
2222
company = "dsodk"
2323
24-
location = "Global"
2524
name = "dsodk-test-github-org-module"
25+
location = "Global"
2626
description = "Test organization used by example in dsodk-code-module-terraform-github-organization"
2727

2828
default_repository_permission = "read"

examples/variables.tf renamed to examples/github_organizations/variables.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
# GitHub Provider Config
33
##################################################
44

5-
variable "owner" {
6-
description = "Target GitHub organization or individual user account to manage. (Required)"
5+
variable "github_token" {
6+
description = "GitHub API Auth using OAuth or Personal Access Token. (Required)"
77
type = string
8+
sensitive = true
89
}
910

10-
variable "token" {
11-
description = "GitHub API Auth using OAuth or Personal Access Token. (Required)"
11+
variable "github_owner" {
12+
description = "Target GitHub organization or individual user account to manage. (Required)"
1213
type = string
13-
sensitive = true
1414
}
1515

1616
##################################################

main.tf

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,29 @@ resource "github_organization_settings" "this" {
4040
##################################################
4141

4242
resource "github_organization_project" "this" {
43-
count = var.create_github_organization && var.create_github_organization_project ? 1 : 0
43+
#count = var.create_github_organization && var.create_github_organization_project ? 1 : 0
44+
for_each = var.create_github_organization_project ? var.github_organization_projects : {}
4445

45-
name = var.github_organization_project_name
46-
body = var.github_organization_project_body
46+
name = each.key
47+
body = try(each.value.body, null)
4748
}
4849

4950
##################################################
5051
# GitHub Organization Webhook
5152
##################################################
5253

5354
resource "github_organization_webhook" "this" {
54-
count = var.create_github_organization && var.create_github_organization_webhook ? 1 : 0
55+
#count = var.create_github_organization && var.create_github_organization_webhook ? 1 : 0
56+
for_each = var.create_github_organization_webhook ? var.github_organization_webhooks : {}
5557

56-
events = var.github_organization_webhook_events
58+
events = each.value.events
5759

5860
configuration {
59-
url = var.github_organization_webhook_config_url
60-
content_type = var.github_organization_webhook_config_content_type
61-
insecure_ssl = var.github_organization_webhook_config_insecure_ssl
62-
secret = var.github_organization_webhook_config_secret
61+
url = each.value.configuration.url
62+
content_type = each.value.configuration.content_type
63+
insecure_ssl = try(each.value.configuration.insecure_ssl, false)
64+
secret = try(each.value.configuration.secret, null)
6365
}
6466

65-
active = var.github_organization_webhook_active
67+
active = try(each.value.active, true)
6668
}

outputs.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# GitHub Organization
33
##################################################
44

5-
output "github_organization_settings_id" {
5+
output "organization_settings_id" {
66
description = "The ID of the organization settings"
77
value = try(github_organization_settings.this[0].id, "")
88
}
@@ -11,16 +11,16 @@ output "github_organization_settings_id" {
1111
# GitHub Organization Project
1212
##################################################
1313

14-
output "github_organization_project_url" {
14+
output "organization_project_url" {
1515
description = "The URL of the project"
16-
value = try(github_organization_project.this[0].url, "")
16+
value = try(github_organization_project.this, "")
1717
}
1818

1919
##################################################
2020
# GitHub Organization Webhook
2121
##################################################
2222

23-
output "github_organization_webhook_url" {
23+
output "organization_webhook_url" {
2424
description = "The URL of the webhook"
25-
value = try(github_organization_webhook.this[0].url, "")
25+
value = try(github_organization_webhook.this, "")
2626
}

variables.tf

Lines changed: 36 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -168,81 +168,58 @@ variable "secret_scanning_push_protection_enabled_for_new_repositories" {
168168
##################################################
169169

170170
variable "create_github_organization_project" {
171-
description = "Whether to create projects in the GitHub Organization."
171+
description = "Whether to create Projects in the GitHub Organization."
172172
type = bool
173173
default = false
174174
}
175175

176-
variable "github_organization_project_name" {
177-
description = "The name of the project. (Required)"
178-
type = string
179-
default = ""
180-
}
176+
variable "github_organization_projects" {
177+
description = "Map of GitHub Organization Projects to create. (Optional)"
178+
type = map(any)
179+
default = {}
181180

182-
variable "github_organization_project_body" {
183-
description = "The body of the project. (Optional)"
184-
type = string
185-
default = ""
181+
# type = object({
182+
# name = object({
183+
# body = optional(string)
184+
# })
185+
# })
186+
187+
# github_organization_projects = {
188+
# my_org_project_name = {
189+
# body = "My Project Body"
190+
# },
191+
# my_org_project_name_2 = {
192+
# body = "My Project Body 2"
193+
# },
194+
# }
186195
}
187196

188197
##################################################
189198
# GitHub Organization Webhook
190199
##################################################
191200

192201
variable "create_github_organization_webhook" {
193-
description = "Whether to create webhooks in the GitHub Organization."
202+
description = "Whether to create Webhooks in the GitHub Organization."
194203
type = bool
195204
default = false
196205
}
197206

198-
#variable "github_organization_webhook_config" {
199-
# description = "Map containing the config for this webhook. (Required)"
200-
# type = map(string)
201-
# default = {}
202-
# #type = object({
203-
# # url = (string),
204-
# # content_type = (string, form), # [form|json]
205-
# # insecure_ssl = (bool, false)
206-
# # secret = optional(string)
207-
# #})
208-
#}
209-
210-
variable "github_organization_webhook_config_url" {
211-
description = "The URL of the webhook"
212-
type = string
213-
default = ""
214-
}
215-
216-
variable "github_organization_webhook_config_content_type" {
217-
description = "The content type of the webhook. [form|json]"
218-
type = string
219-
default = "form"
220-
}
221-
222-
variable "github_organization_webhook_config_insecure_ssl" {
223-
description = "Whether to allow insecure_ssl."
224-
type = bool
225-
default = false
226-
}
227-
228-
variable "github_organization_webhook_config_secret" {
229-
description = "Secret for the Webhook"
230-
type = string
231-
default = ""
232-
sensitive = true
233-
}
234-
235-
variable "github_organization_webhook_active" {
236-
description = "Indicate of the webhook should receive events. (Optional)"
237-
type = bool
238-
default = true
239-
}
240-
241-
variable "github_organization_webhook_events" {
207+
variable "github_organization_webhooks" {
242208
description = <<-EOT
243-
A list of events which should trigger the webhook. (Optional)
244-
For list of valid events, visit https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#issues
209+
Map of GitHub Organization Webhooks to create. (Optional)
210+
For list of valid events, visit https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#issues
245211
EOT
246-
type = list(any)
247-
default = []
212+
type = map(any)
213+
default = {}
214+
215+
# type = object({
216+
# events = (list[any])
217+
# configuration = object({
218+
# url = (string)
219+
# content_type = (string, form) # The content type of the webhook. [form|json]
220+
# insecure_ssl = optional(bool, false)
221+
# secret = optional(string)
222+
# })
223+
# active = optional(bool, true)
224+
# })
248225
}

0 commit comments

Comments
 (0)