generated from terraform-module/terraform-module-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
57 lines (48 loc) · 1.68 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* # AWS CircelCI OIDC Provider Terraform Module
*
* ## Purpose
* This module allows you to create a CircleCI OIDC provider for your AWS account, that will help CircleCI to securely authenticate against the AWS API using an IAM role
*
*/
resource "aws_iam_openid_connect_provider" "circleci" {
client_id_list = [
var.circleci_org_uuid,
]
thumbprint_list = [var.circleci_thumbprint]
url = "https://oidc.circleci.com/org/${var.circleci_org_uuid}"
}
resource "aws_iam_role" "circleci" {
name = var.circleci_role_name
description = var.circleci_role_description
max_session_duration = var.circleci_max_session_duration
assume_role_policy = join("", data.aws_iam_policy_document.circleci[*].json)
tags = var.tags
# path = var.iam_role_path
# permissions_boundary = var.iam_role_permissions_boundary
depends_on = [aws_iam_openid_connect_provider.circleci]
}
resource "aws_iam_role_policy_attachment" "attach" {
for_each = toset(var.circleci_oidc_role_attach_policies)
policy_arn = each.key
role = join("", aws_iam_role.circleci[*].name)
depends_on = [aws_iam_role.circleci]
}
data "aws_iam_policy_document" "circleci" {
statement {
actions = ["sts:AssumeRoleWithWebIdentity"]
effect = "Allow"
condition {
test = "StringLike"
values = [
for project in var.circleci_project_uuids :
"org/${var.circleci_org_uuid}/project/${project}/user/*"
]
variable = "oidc.circleci.com/org/${var.circleci_org_uuid}:sub"
}
principals {
identifiers = [aws_iam_openid_connect_provider.circleci.arn]
type = "Federated"
}
}
}