|
| 1 | + |
| 2 | +# AWS Github OIDC Provider Terraform Module |
| 3 | + |
| 4 | +## Purpose |
| 5 | +This module allows you to create a GitHub OIDC provider and the associated IAM roles, that will help Github Actions to securely authenticate against the AWS API using an IAM role |
| 6 | + |
| 7 | +## Features |
| 8 | +* Create an AWS OIDC provider for GitHub Actions |
| 9 | +* Create one or more IAM role that can be assumed by GitHub Actions |
| 10 | +* IAM roles can be scoped to : |
| 11 | + * One or more GitHub organisations |
| 12 | + * One or more GitHub repository |
| 13 | + * One or more branches in a repository |
| 14 | + |
| 15 | +| Feature | Status | |
| 16 | +|--------------------------------------------------------------------------------------------------------|--------| |
| 17 | +| Create a role for all repositories in a specific Github organisation | ✅ | |
| 18 | +| Create a role specific to a repository for a specific organisation | ✅ | |
| 19 | +| Create a role specific to a branch in a repository | ✅ | |
| 20 | +| Create a role for multiple organisations/repositories/branches | ✅ | |
| 21 | +| Create a role for organisations/repositories/branches selected by wildcard (e.g. `feature/*` branches) | ✅ | |
| 22 | +| Create multiple roles for a repository, each one with his own set of branches | ❌ | |
| 23 | +| Create the OIDC provider and multiple roles configurations in separate terraform root modules | ✅ | |
| 24 | + |
| 25 | +## Usage |
| 26 | +TL;DR : |
| 27 | +```hcl |
| 28 | +module "aws_github_actions_oidc" { |
| 29 | + source = "registry.terraform.io/SamuelBagattin/github-oidc-provider/aws" |
| 30 | + permissions = { |
| 31 | + "my-org" : { # Specify the GitHub organisation name |
| 32 | + role_name = "default-org-role" # Default role name for subsequent repositories |
| 33 | + allowed_branches = ["main"] # Default branches for subsequent repositories |
| 34 | + repositories = { |
| 35 | + "my-repository" = { # GitHub repository name |
| 36 | + role_name : "my-role" # IAM role specific to a repository |
| 37 | + allowed_branches : ["my-branch","my-other-branch", "feature/*"] # List of branches allowed to assume the specific role |
| 38 | + } |
| 39 | + "another-repository" = {} # Will inherit role_name and allowed_branches from the organisation |
| 40 | + } |
| 41 | + } |
| 42 | + # The wildcard "*" can be used to allow any org, repository or branch |
| 43 | + "*": { # Allow any organisation |
| 44 | + repositories = { |
| 45 | + "*": { # Allow any repository |
| 46 | + role_name : "my-role" |
| 47 | + allowed_branches : ["*"] # Allow any branch |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +For more simple or detailed use cases, please refer to the following examples : |
| 56 | +- [Simple example](./examples/simple) |
| 57 | +- [Complete example](./examples/complete) |
| 58 | +- [Separated OIDC provider and IAM roles](./examples/separate_configuration) |
| 59 | + |
| 60 | + |
1 | 61 | <!-- BEGIN_TF_DOCS --> |
2 | 62 | # AWS Github OIDC Provider Terraform Module |
3 | 63 |
|
@@ -28,14 +88,26 @@ This module allows you to create a Github OIDC provider for your AWS account, th |
28 | 88 | | Name | Description | Type | Default | Required | |
29 | 89 | |------|-------------|------|---------|:--------:| |
30 | 90 | | <a name="input_create_iam_roles"></a> [create\_iam\_roles](#input\_create\_iam\_roles) | Whether or not to create IAM roles. | `bool` | `true` | no | |
31 | | -| <a name="input_create_oidc_provider"></a> [create\_oidc\_provider](#input\_create\_oidc\_provider) | Whether or not to create the associated oidc provider. If true, variable 'oidc\_provider\_arn is required' | `bool` | `true` | no | |
| 91 | +| <a name="input_create_oidc_provider"></a> [create\_oidc\_provider](#input\_create\_oidc\_provider) | Whether or not to create the associated oidc provider. If true, variable 'oidc\_provider\_arn' is required | `bool` | `true` | no | |
32 | 92 | | <a name="input_oidc_provider_arn"></a> [oidc\_provider\_arn](#input\_oidc\_provider\_arn) | Used if create\_oidc\_provider is true | `string` | `""` | no | |
33 | | -| <a name="input_permissions"></a> [permissions](#input\_permissions) | Github Repositories than can assumerole | `map(any)` | n/a | yes | |
| 93 | +| <a name="input_permissions"></a> [permissions](#input\_permissions) | Permissions configuration. See 'Permissions specifications' below | `map(any)` | n/a | yes | |
34 | 94 |
|
35 | 95 | ## Outputs |
36 | 96 |
|
37 | 97 | | Name | Description | |
38 | 98 | |------|-------------| |
39 | 99 | | <a name="output_oidc_provider_arn"></a> [oidc\_provider\_arn](#output\_oidc\_provider\_arn) | OIDC provider ARN | |
40 | 100 | | <a name="output_roles_arns"></a> [roles\_arns](#output\_roles\_arns) | Roles to be assumed by github actions | |
41 | | -<!-- END_TF_DOCS --> |
| 101 | +<!-- END_TF_DOCS --> |
| 102 | + |
| 103 | +## Permissions specifications |
| 104 | +```hcl |
| 105 | +permissions = map(object({ |
| 106 | + "role_name": string, # optional, default: "githubActions-iamRole" |
| 107 | + "allowed_branches": list(string), # optional, default: ["master"] |
| 108 | + "repositories": map(object({ # optional, default: ["*":{}] |
| 109 | + "role_name": string, # optional, defaults to the organisation role_name |
| 110 | + "allowed_branches": list(string), # optional, defaults to the organisation allowed_branches |
| 111 | + })) |
| 112 | +})) |
| 113 | +``` |
0 commit comments