Skip to content

Commit fef0d7a

Browse files
github oidc setup
1 parent 3a79355 commit fef0d7a

File tree

5 files changed

+62
-14
lines changed

5 files changed

+62
-14
lines changed

README.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ See `examples` directory for working examples to reference
7373
## Available features
7474

7575
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
76+
# AWS Github OIDC Provider Terraform Module
77+
78+
## Purpose
79+
This module allows you to create a Github OIDC provider for your AWS account, that will help Github Actions to securely authenticate against the AWS API using an IAM role
80+
7681
## Requirements
7782

7883
| Name | Version |
@@ -81,27 +86,43 @@ See `examples` directory for working examples to reference
8186

8287
## Providers
8388

84-
No providers.
89+
| Name | Version |
90+
|------|---------|
91+
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |
8592

8693
## Modules
8794

8895
No modules.
8996

9097
## Resources
9198

92-
No resources.
99+
| Name | Type |
100+
|------|------|
101+
| [aws_iam_openid_connect_provider.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_openid_connect_provider) | resource |
102+
| [aws_iam_role.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
103+
| [aws_iam_role_policy_attachment.attach](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
104+
| [aws_iam_policy_document.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
93105

94106
## Inputs
95107

96108
| Name | Description | Type | Default | Required |
97109
|------|-------------|------|---------|:--------:|
98-
| <a name="input_variable"></a> [variable](#input\_variable) | defaul,description,type | `string` | `"variable"` | no |
110+
| <a name="input_create_oidc_provider"></a> [create\_oidc\_provider](#input\_create\_oidc\_provider) | Whether or not to create the associated oidc provider. If false, variable 'oidc\_provider\_arn' is required | `bool` | `true` | no |
111+
| <a name="input_create_oidc_role"></a> [create\_oidc\_role](#input\_create\_oidc\_role) | Whether or not to create the OIDC attached role | `bool` | `true` | no |
112+
| <a name="input_github_repositories"></a> [github\_repositories](#input\_github\_repositories) | List of GitHub organization/repository names authorized to assume the role. | `list(string)` | `[]` | no |
113+
| <a name="input_github_thumbprint"></a> [github\_thumbprint](#input\_github\_thumbprint) | GitHub OpenID TLS certificate thumbprint. | `string` | `"6938fd4d98bab03faadb97b34396831e3780aea1"` | no |
114+
| <a name="input_max_session_duration"></a> [max\_session\_duration](#input\_max\_session\_duration) | Maximum session duration in seconds. | `number` | `3600` | no |
115+
| <a name="input_oidc_role_attach_policies"></a> [oidc\_role\_attach\_policies](#input\_oidc\_role\_attach\_policies) | Attach policies to OIDC role. | `list(string)` | `[]` | no |
116+
| <a name="input_role_description"></a> [role\_description](#input\_role\_description) | (Optional) Description of the role. | `string` | `"Role assumed by the GitHub OIDC provider."` | no |
117+
| <a name="input_role_name"></a> [role\_name](#input\_role\_name) | (Optional, Forces new resource) Friendly name of the role. | `string` | `"oidc-provider-aws-github-action"` | no |
118+
| <a name="input_tags"></a> [tags](#input\_tags) | A mapping of tags to assign to all resources | `map(string)` | `{}` | no |
99119

100120
## Outputs
101121

102122
| Name | Description |
103123
|------|-------------|
104-
| <a name="output_used"></a> [used](#output\_used) | used value |
124+
| <a name="output_oidc_provider_arn"></a> [oidc\_provider\_arn](#output\_oidc\_provider\_arn) | OIDC provider ARN |
125+
| <a name="output_oidc_role"></a> [oidc\_role](#output\_oidc\_role) | CICD GitHub role. |
105126
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
106127

107128

examples/basic/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,32 @@ $ terraform apply
1515
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
1616

1717
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
18+
## Requirements
1819

20+
No requirements.
21+
22+
## Providers
23+
24+
No providers.
25+
26+
## Modules
27+
28+
| Name | Source | Version |
29+
|------|--------|---------|
30+
| <a name="module_github-oidc"></a> [github-oidc](#module\_github-oidc) | ../.. | n/a |
31+
32+
## Resources
33+
34+
No resources.
35+
36+
## Inputs
37+
38+
No inputs.
39+
40+
## Outputs
41+
42+
| Name | Description |
43+
|------|-------------|
44+
| <a name="output_github_oidc_role"></a> [github\_oidc\_role](#output\_github\_oidc\_role) | CICD GitHub role. |
45+
| <a name="output_oidc_provider_arn"></a> [oidc\_provider\_arn](#output\_oidc\_provider\_arn) | OIDC provider ARN |
1946
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/basic/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Resources
33
################################################################################
44
module "github-oidc" {
5-
source = "../.."
5+
source = "../.."
66

77
create_oidc_provider = true
88
create_oidc_role = true

main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ resource "aws_iam_role" "this" {
2323
tags = var.tags
2424
# path = var.iam_role_path
2525
# permissions_boundary = var.iam_role_permissions_boundary
26-
depends_on = [ aws_iam_openid_connect_provider.this ]
26+
depends_on = [aws_iam_openid_connect_provider.this]
2727
}
2828

2929
resource "aws_iam_role_policy_attachment" "attach" {
@@ -32,7 +32,7 @@ resource "aws_iam_role_policy_attachment" "attach" {
3232
policy_arn = var.oidc_role_attach_policies[count.index]
3333
role = aws_iam_role.this[0].id
3434

35-
depends_on = [ aws_iam_role.this ]
35+
depends_on = [aws_iam_role.this]
3636
}
3737

3838
data "aws_iam_policy_document" "this" {
@@ -54,7 +54,7 @@ data "aws_iam_policy_document" "this" {
5454
}
5555

5656
principals {
57-
identifiers = [ statement.value.arn ]
57+
identifiers = [statement.value.arn]
5858
type = "Federated"
5959
}
6060
}

variables.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ variable "create_oidc_role" {
1010
default = true
1111
}
1212

13-
// Refer to the README for information on obtaining the thumbprint.
14-
// This is specified as a variable to allow it to be updated quickly if it is
15-
// unexpectedly changed by GitHub.
16-
// See: https://github.blog/changelog/2022-01-13-github-actions-update-on-oidc-based-deployments-to-aws/
13+
# Refer to the README for information on obtaining the thumbprint.
14+
# This is specified as a variable to allow it to be updated quickly if it is
15+
# unexpectedly changed by GitHub.
16+
# See: https://github.blog/changelog/2022-01-13-github-actions-update-on-oidc-based-deployments-to-aws/
1717
variable "github_thumbprint" {
1818
description = "GitHub OpenID TLS certificate thumbprint."
1919
type = string
@@ -26,8 +26,8 @@ variable "github_repositories" {
2626
default = []
2727

2828
validation {
29-
// Ensures each element of github_repositories list matches the
30-
// organization/repository format used by GitHub.
29+
# Ensures each element of github_repositories list matches the
30+
# organization/repository format used by GitHub.
3131
condition = length([
3232
for repo in var.github_repositories : 1
3333
if length(regexall("^[A-Za-z0-9_.-]+?/([A-Za-z0-9_.:/-]+|\\*)$", repo)) > 0

0 commit comments

Comments
 (0)