diff --git a/README.md b/README.md index 200a1df..d3f9538 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,8 @@ module "github_runner" { | [s3\_logs\_bucket\_prefix](#input\_s3\_logs\_bucket\_prefix) | Prefix to use for the logs in the S3 bucket | `string` | `""` | no | | [security\_group\_ids](#input\_security\_group\_ids) | The list of Security Group IDs for AWS CodeBuild to launch ephemeral EC2 instances in. | `list(string)` | `[]` | no | | [security\_group\_name](#input\_security\_group\_name) | Name to use on created Security Group. Defaults to `name` | `string` | `null` | no | -| [source\_location](#input\_source\_location) | Your source code repo location, for example https://github.com/my/repo.git | `string` | n/a | yes | +| [source\_location](#input\_source\_location) | Your source code repo location, for example https://github.com/my/repo.git, or `CODEBUILD_DEFAULT_WEBHOOK_SOURCE_LOCATION` for org-level webhooks | `string` | n/a | yes | +| [source\_organization](#input\_source\_organization) | Your Github organization name for organization-level webhook creation | `string` | `null` | no | | [subnet\_ids](#input\_subnet\_ids) | The list of Subnet IDs for AWS CodeBuild to launch ephemeral EC2 instances in. | `list(string)` | `[]` | no | | [vpc\_id](#input\_vpc\_id) | The VPC ID for AWS CodeBuild to launch ephemeral instances in. | `string` | `null` | no | diff --git a/docs/org_level_runners.md b/docs/org_level_runners.md new file mode 100644 index 0000000..8c98824 --- /dev/null +++ b/docs/org_level_runners.md @@ -0,0 +1,12 @@ +# Organization Level Runners + +To set up the codebuild runners at the GitHub organization level, use the `source_location` and `source_organization` module inputs like the following: + +```hcl +module "github_runner" { + ... + source_location = "CODEBUILD_DEFAULT_WEBHOOK_SOURCE_LOCATION" + source_organization = "your-org-name" + ... +} +``` diff --git a/examples/basic-org/README.md b/examples/basic-org/README.md new file mode 100644 index 0000000..f322618 --- /dev/null +++ b/examples/basic-org/README.md @@ -0,0 +1,69 @@ + +---- +## main.tf +```hcl +module "github_runner" { + source = "../../" + + # Required parameters + ############################ + # Naming for all created resources + name = "github-runner-codebuild-test" + source_location = "CODEBUILD_DEFAULT_WEBHOOK_SOURCE_LOCATION" + source_organization = "cloudandthings" + + # Environment image is not specified so it will default to: + # "aws/codebuild/amazonlinux2-x86_64-standard:5.0" + + # Optional parameters + ############################ + description = "Created by my-org/my-runner-repo.git" + + github_personal_access_token = "example" + + vpc_id = "vpc-0ffaabbcc1122" + subnet_ids = ["subnet-0123", "subnet-0456"] +} +``` +---- + +## Documentation + +---- +### Inputs + +No inputs. + +---- +### Modules + +| Name | Source | Version | +|------|--------|---------| +| [github\_runner](#module\_github\_runner) | ../../ | n/a | + +---- +### Outputs + +No outputs. + +---- +### Providers + +No providers. + +---- +### Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 0.14.0 | +| [aws](#requirement\_aws) | >= 4.9 | +| [http](#requirement\_http) | 3.0.1 | + +---- +### Resources + +No resources. + +---- + diff --git a/examples/basic-org/main.tf b/examples/basic-org/main.tf new file mode 100644 index 0000000..863d918 --- /dev/null +++ b/examples/basic-org/main.tf @@ -0,0 +1,22 @@ +module "github_runner" { + source = "../../" + + # Required parameters + ############################ + # Naming for all created resources + name = "github-runner-codebuild-test" + source_location = "CODEBUILD_DEFAULT_WEBHOOK_SOURCE_LOCATION" + source_organization = "cloudandthings" + + # Environment image is not specified so it will default to: + # "aws/codebuild/amazonlinux2-x86_64-standard:5.0" + + # Optional parameters + ############################ + description = "Created by my-org/my-runner-repo.git" + + github_personal_access_token = "example" + + vpc_id = "vpc-0ffaabbcc1122" + subnet_ids = ["subnet-0123", "subnet-0456"] +} diff --git a/examples/basic-org/outputs.tf b/examples/basic-org/outputs.tf new file mode 100644 index 0000000..e69de29 diff --git a/examples/basic-org/providers.tf b/examples/basic-org/providers.tf new file mode 100644 index 0000000..e62fc36 --- /dev/null +++ b/examples/basic-org/providers.tf @@ -0,0 +1,3 @@ +provider "aws" { + region = "eu-west-1" +} diff --git a/examples/basic-org/terraform.tf b/examples/basic-org/terraform.tf new file mode 100644 index 0000000..f975384 --- /dev/null +++ b/examples/basic-org/terraform.tf @@ -0,0 +1,13 @@ +terraform { + required_version = ">= 0.14.0" + required_providers { + http = { + source = "hashicorp/http" + version = "3.0.1" + } + aws = { + source = "hashicorp/aws" + version = ">= 4.9" + } + } +} diff --git a/examples/basic-org/variables.tf b/examples/basic-org/variables.tf new file mode 100644 index 0000000..e69de29 diff --git a/main.tf b/main.tf index 427b04d..882267c 100644 --- a/main.tf +++ b/main.tf @@ -108,6 +108,13 @@ resource "aws_codebuild_webhook" "this" { pattern = "WORKFLOW_JOB_QUEUED" } } + dynamic "scope_configuration" { + for_each = var.source_location == "CODEBUILD_DEFAULT_WEBHOOK_SOURCE_LOCATION" ? toset([1]) : toset([]) + content { + name = var.source_organization + scope = "GITHUB_ORGANIZATION" + } + } } ################################################################################ diff --git a/variables.tf b/variables.tf index 1fbf0c6..5415d65 100644 --- a/variables.tf +++ b/variables.tf @@ -13,7 +13,7 @@ variable "name" { variable "source_location" { type = string - description = "Your source code repo location, for example https://github.com/my/repo.git" + description = "Your source code repo location, for example https://github.com/my/repo.git, or `CODEBUILD_DEFAULT_WEBHOOK_SOURCE_LOCATION` for org-level webhooks" } # ----------------------------------------------------- @@ -21,6 +21,12 @@ variable "source_location" { # ----------------------------------------------------- # General +variable "source_organization" { + type = string + default = null + description = "Your Github organization name for organization-level webhook creation" +} + variable "build_timeout" { type = number default = 5