Skip to content

Commit

Permalink
Add enterprise-organization module
Browse files Browse the repository at this point in the history
  • Loading branch information
posquit0 committed Jun 3, 2024
1 parent 5821745 commit 4785fbd
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .github/labeler.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Modules
":floppy_disk: enterprise-organization":
- changed-files:
- any-glob-to-any-file:
- modules/enterprise-organization/**/*

":floppy_disk: org-organization":
- changed-files:
- any-glob-to-any-file:
Expand Down
3 changes: 3 additions & 0 deletions .github/labels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
name: "size/XL"

# Modules
- color: "fbca04"
description: "This issue or pull request is related to enterprise-organization module."
name: ":floppy_disk: enterprise-organization"
- color: "fbca04"
description: "This issue or pull request is related to org-organization module."
name: ":floppy_disk: org-organization"
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

Terraform package which manage all of things on GitHub.

- [enterprise-organization](./modules/enterprise-organization)
- [org-organization](./modules/org-organization)
- [org-team](./modules/org-team)
- [project](./modules/project)
- [repository](./modules/repository)
- [webhook](./modules/webhook)


## Self Promotion

Expand All @@ -16,4 +23,4 @@ Like this project? Follow the repository on [GitHub](https://github.com/tedilabs

Provided under the terms of the [Apache License](LICENSE).

Copyright © 2022-2023, [Byungjin Park](https://www.posquit0.com).
Copyright © 2022-2024, [Byungjin Park](https://www.posquit0.com).
56 changes: 56 additions & 0 deletions modules/enterprise-organization/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# enterprise-organization

This module creates following resources.

- `github_membership` (optional)
- `github_organization_block` (optional)

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.6 |
| <a name="requirement_github"></a> [github](#requirement\_github) | >= 6.2 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_github"></a> [github](#provider\_github) | 6.2.1 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [github_enterprise_organization.this](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/enterprise_organization) | resource |
| [github_enterprise.this](https://registry.terraform.io/providers/integrations/github/latest/docs/data-sources/enterprise) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_billing_email"></a> [billing\_email](#input\_billing\_email) | (Required) The billing email address. | `string` | n/a | yes |
| <a name="input_enterprise"></a> [enterprise](#input\_enterprise) | (Required) The name (slug) of the enterprise. | `string` | n/a | yes |
| <a name="input_name"></a> [name](#input\_name) | (Required) The name of the organization. | `string` | n/a | yes |
| <a name="input_description"></a> [description](#input\_description) | (Optional) The description of the organization. | `string` | `"Managed by Terraform."` | no |
| <a name="input_display_name"></a> [display\_name](#input\_display\_name) | (Optional) The display name of the organization. If not set, the `name` will be used as the `display_name`. | `string` | `""` | no |
| <a name="input_owners"></a> [owners](#input\_owners) | (Optional) A list of usernames to add users as `owner` role. | `set(string)` | `[]` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_billing_email"></a> [billing\_email](#output\_billing\_email) | The billing email address. |
| <a name="output_database_id"></a> [database\_id](#output\_database\_id) | The database ID of the organization. |
| <a name="output_description"></a> [description](#output\_description) | The description of the organization. |
| <a name="output_display_name"></a> [display\_name](#output\_display\_name) | The display name of the organization. |
| <a name="output_enterprise"></a> [enterprise](#output\_enterprise) | The information of the enterprise which the organization belongs to. |
| <a name="output_id"></a> [id](#output\_id) | The ID of the organization. |
| <a name="output_name"></a> [name](#output\_name) | The name of the organization. |
| <a name="output_owners"></a> [owners](#output\_owners) | A list of organization owner usernames. |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
19 changes: 19 additions & 0 deletions modules/enterprise-organization/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
data "github_enterprise" "this" {
slug = var.enterprise
}


###################################################
# Organization of GitHub Enterprise
###################################################

resource "github_enterprise_organization" "this" {
enterprise_id = data.github_enterprise.this.id

name = var.name
display_name = coalesce(var.display_name, var.name)
description = var.description

admin_logins = var.owners
billing_email = var.billing_email
}
50 changes: 50 additions & 0 deletions modules/enterprise-organization/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
output "enterprise" {
description = "The information of the enterprise which the organization belongs to."
value = {
id = github_enterprise_organization.this.enterprise_id
name = var.enterprise
}
}

output "id" {
description = "The ID of the organization."
value = github_enterprise_organization.this.id
}

output "database_id" {
description = "The database ID of the organization."
value = github_enterprise_organization.this.database_id
}

output "name" {
description = "The name of the organization."
value = github_enterprise_organization.this.name
}

output "display_name" {
description = "The display name of the organization."
value = github_enterprise_organization.this.display_name
}

output "description" {
description = "The description of the organization."
value = github_enterprise_organization.this.description
}

output "owners" {
description = "A list of organization owner usernames."
value = github_enterprise_organization.this.admin_logins
}

output "billing_email" {
description = "The billing email address."
value = github_enterprise_organization.this.billing_email
}

# output "debug" {
# value = {
# for k, v in github_enterprise_organization.this :
# k => v
# if !contains(["id", "name", "display_name", "description", "admin_logins", "billing_email", "database_id", "enterprise_id"], k)
# }
# }
38 changes: 38 additions & 0 deletions modules/enterprise-organization/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
variable "enterprise" {
description = "(Required) The name (slug) of the enterprise."
type = string
nullable = false
}

variable "name" {
description = "(Required) The name of the organization."
type = string
nullable = false
}

variable "display_name" {
description = "(Optional) The display name of the organization. If not set, the `name` will be used as the `display_name`."
type = string
default = ""
nullable = false
}

variable "description" {
description = "(Optional) The description of the organization."
type = string
default = "Managed by Terraform."
nullable = false
}

variable "owners" {
description = "(Optional) A list of usernames to add users as `owner` role."
type = set(string)
default = []
nullable = false
}

variable "billing_email" {
description = "(Required) The billing email address."
type = string
nullable = false
}
10 changes: 10 additions & 0 deletions modules/enterprise-organization/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.6"

required_providers {
github = {
source = "integrations/github"
version = ">= 6.2"
}
}
}

0 comments on commit 4785fbd

Please sign in to comment.