-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
51 lines (46 loc) · 1.3 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
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
}
}
data "aws_caller_identity" "current" {}
resource "aws_iam_openid_connect_provider" "github_oidc_provider" {
count = var.create_oidc_provider ? 1 : 0
url = "https://token.actions.githubusercontent.com"
client_id_list = [
"sts.amazonaws.com",
]
thumbprint_list = [
"6938fd4d98bab03faadb97b34396831e3780aea1",
"1c58a3a8518e8759bf075b76b750d4f2df264fcd"
]
}
resource "aws_iam_role" "terrateam_role" {
name = var.aws_iam_role_name
assume_role_policy = jsonencode({
Version : "2012-10-17",
Statement : [
{
Effect : "Allow",
Principal : {
Federated : "arn:aws:iam::${data.aws_caller_identity.current.account_id}:oidc-provider/token.actions.githubusercontent.com"
},
Action : "sts:AssumeRoleWithWebIdentity",
Condition : {
StringEquals : {
"token.actions.githubusercontent.com:aud" : "sts.amazonaws.com"
},
StringLike : {
"token.actions.githubusercontent.com:sub" : "repo:${var.github_org}/*"
}
}
}
]
})
}
resource "aws_iam_role_policy_attachment" "terrateam_iam_role_policy_attachment" {
role = aws_iam_role.terrateam_role.name
policy_arn = var.aws_policy_arn
}