-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add module for GitHub Actions OIDC IAM role (#24)
- Loading branch information
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
data "aws_iam_policy_document" "assume_role" { | ||
statement { | ||
actions = ["sts:AssumeRoleWithWebIdentity"] | ||
|
||
principals { | ||
type = "Federated" | ||
identifiers = [var.idp_arn] | ||
} | ||
|
||
condition { | ||
test = "StringEquals" | ||
variable = "token.actions.githubusercontent.com:aud" | ||
values = ["sts.amazonaws.com"] | ||
} | ||
|
||
condition { | ||
test = "StringLike" | ||
variable = "token.actions.githubusercontent.com:sub" | ||
values = ["repo:${var.github_repos}:${var.github_branches}"] | ||
} | ||
} | ||
} | ||
|
||
|
||
resource "aws_iam_role" "main" { | ||
name = var.name | ||
assume_role_policy = data.aws_iam_policy_document.assume_role.json | ||
tags = var.tags | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "main" { | ||
count = length(var.policies) | ||
|
||
role = aws_iam_role.main.name | ||
policy_arn = var.policies[count.index] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "role_arn" { | ||
value = aws_iam_role.main.arn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
variable "name" { | ||
type = string | ||
description = "The name of the IAM Role to create" | ||
nullable = false | ||
} | ||
|
||
variable "idp_arn" { | ||
type = string | ||
description = "The ARN of the GitHub Actions IAM Identity Provider" | ||
nullable = false | ||
} | ||
|
||
variable "github_repos" { | ||
type = string | ||
description = "The GitHub repos (e.g. org/repo-name or org/*) to grant access to" | ||
nullable = false | ||
} | ||
|
||
variable "github_branches" { | ||
type = string | ||
description = "The branches in the GitHub repos to grant access to" | ||
default = "*" | ||
} | ||
|
||
variable "policies" { | ||
type = list(string) | ||
description = "The ARNs of the IAM Policies to attach to the IAM role" | ||
default = [] | ||
} | ||
|
||
|
||
variable "tags" { | ||
type = map(string) | ||
description = "Tags of the IAM Role to create" | ||
default = {} | ||
} |