Skip to content

Commit 5e3e09f

Browse files
Added detailed documentation and examples
1 parent 656ea3f commit 5e3e09f

File tree

22 files changed

+439
-4
lines changed

22 files changed

+439
-4
lines changed

.terraform-docs.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
formatter: "markdown table"
22

3-
header-from: main.tf
4-
53
output:
64
file: "./README.md"
7-
mode: replace
5+
mode: inject
6+
template: |-
7+
<!-- BEGIN_TF_DOCS -->
8+
{{ .Content }}
9+
<!-- END_TF_DOCS -->
810
911
recursive:
1012
enabled: true

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,63 @@
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+
161
<!-- BEGIN_TF_DOCS -->
262
# AWS Github OIDC Provider Terraform Module
363

examples/complete/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Complete example
2+
This example will create the following IAM resources/configurations for the `my-org` GitHub organisation :
3+
- `githubActions-default-role` IAM role scoped to :
4+
- `another-repository` from the `main` branches
5+
- `third-repository` from the `my-branch`and `my-other-branch` branches
6+
- `my-role` IAM role scoped to :
7+
- `my-repository` from the `main` branch
8+
- `global-role` IAM role scoped to :
9+
- ANY repository from any branch that begins with `feature/*`

examples/complete/main.tf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
provider "aws" {
2+
region = "us-east-1"
3+
}
4+
5+
terraform {
6+
required_version = ">= 0.13.0"
7+
required_providers {
8+
aws = "~> 3.0"
9+
}
10+
}
11+
12+
module "aws_github_actions_oidc" {
13+
source = "registry.terraform.io/SamuelBagattin/github-oidc-provider/aws"
14+
version = "0.3.0"
15+
permissions = {
16+
"my-org" : { # Specify the GitHub organisation name
17+
role_name : "githubActions-default-role"
18+
allowed_branches : ["main"]
19+
repositories = {
20+
"my-repository" = { # GitHub repository name
21+
role_name : "my-role" # IAM role name
22+
}
23+
"another-repository" = {}
24+
"third-repository" = {
25+
allowed_branches : ["my-branch", "my-other-branch"]
26+
}
27+
"*" = {
28+
role_name : "global-role"
29+
allowed_branches : ["feature/*"]
30+
}
31+
}
32+
}
33+
}
34+
}

examples/complete/outputs.tf

Whitespace-only changes.

examples/complete/tflint.hcl

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
config {
2+
module = false
3+
force = false
4+
disabled_by_default = false
5+
}
6+
7+
plugin "aws" {
8+
enabled = true
9+
version = "0.11.0"
10+
source = "github.com/terraform-linters/tflint-ruleset-aws"
11+
}
12+
13+
rule "terraform_comment_syntax" {
14+
enabled = true
15+
}
16+
17+
rule "terraform_deprecated_index" {
18+
enabled = true
19+
}
20+
21+
rule "terraform_deprecated_interpolation" {
22+
enabled = true
23+
}
24+
25+
rule "terraform_documented_outputs" {
26+
enabled = true
27+
}
28+
29+
rule "terraform_documented_variables" {
30+
enabled = true
31+
}
32+
33+
rule "terraform_module_pinned_source" {
34+
enabled = true
35+
}
36+
37+
rule "terraform_naming_convention" {
38+
enabled = true
39+
}
40+
41+
rule "terraform_required_providers" {
42+
enabled = true
43+
}
44+
45+
rule "terraform_standard_module_structure" {
46+
enabled = true
47+
}
48+
49+
rule "terraform_typed_variables" {
50+
enabled = true
51+
}
52+
53+
rule "terraform_unused_declarations" {
54+
enabled = true
55+
}
56+
57+
rule "terraform_unused_required_providers" {
58+
enabled = true
59+
}

examples/complete/variables.tf

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Separated configuration
2+
This example show how the OIDC provider and the IAM roles can be created separately :
3+
1. Creates the OIDC provider
4+
2. Stores the ARN of the OIDC provider in an SSM parameter
5+
3. Retrieves the ARN of the OIDC provider from the SSM parameter in another root module
6+
4. Creates the IAM role and attaches it to the OIDC provider
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
provider "aws" {
2+
region = "us-east-1"
3+
}
4+
5+
terraform {
6+
required_version = ">= 0.13.0"
7+
required_providers {
8+
aws = "~> 3.0"
9+
}
10+
}
11+
12+
module "aws_github_actions_oidc" {
13+
source = "registry.terraform.io/SamuelBagattin/github-oidc-provider/aws"
14+
version = "0.3.0"
15+
create_oidc_provider = true
16+
create_iam_roles = false
17+
permissions = {}
18+
}
19+
20+
resource "aws_ssm_parameter" "github_actions_oidc_provider_arn" {
21+
name = "githubActions-oidcProviderArn-ssmParam"
22+
type = "String"
23+
value = module.aws_github_actions_oidc.oidc_provider_arn
24+
}

examples/separate_configuration/oidc_provider/outputs.tf

Whitespace-only changes.

0 commit comments

Comments
 (0)