-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
71 lines (61 loc) · 1.71 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.63"
}
}
required_version = ">= 1.0.10"
}
provider "aws" {
profile = "terraform"
region = "ap-northeast-1"
}
locals {
github = {
org = "daku10"
repo = "github-oidc-terraform-sample"
}
}
resource "aws_iam_openid_connect_provider" "github_oidc" {
url = "https://token.actions.githubusercontent.com"
thumbprint_list = ["6938fd4d98bab03faadb97b34396831e3780aea1"]
client_id_list = ["https://github.com/${local.github.org}", "sts.amazonaws.com"]
}
data "aws_iam_policy_document" "github_actions_policy_document" {
statement {
actions = ["sts:AssumeRoleWithWebIdentity"]
effect = "Allow"
condition {
test = "StringLike"
variable = "token.actions.githubusercontent.com:sub"
values = ["repo:${local.github.org}/${local.github.repo}:*"]
}
principals {
identifiers = [aws_iam_openid_connect_provider.github_oidc.arn]
type = "Federated"
}
}
}
resource "aws_iam_role" "github_actions_role" {
assume_role_policy = data.aws_iam_policy_document.github_actions_policy_document.json
name = "github_actions_role"
}
data "aws_iam_policy_document" "sample_policy_document" {
statement {
actions = [
"ec2:Describe*",
"ec2:Get*"
]
effect = "Allow"
resources = ["*"]
}
}
resource "aws_iam_policy" "sample_policy" {
name = "sample_policy"
policy = data.aws_iam_policy_document.sample_policy_document.json
}
resource "aws_iam_role_policy_attachment" "my_test_role_pol_attachment" {
role = aws_iam_role.github_actions_role.name
policy_arn = aws_iam_policy.sample_policy.arn
}