-
Notifications
You must be signed in to change notification settings - Fork 0
/
transformer-poc-iam.tf
73 lines (60 loc) · 2.15 KB
/
transformer-poc-iam.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
72
# This file is almost exactly the same as retriever-poc-iam.tf.
# Even though permissions and roles are near identical,
# the seperation of concerns is worth the slight code duplication.
# Cloud items required for the transformer proof of concept.
# The transformer is part of the Cloud Image Directory codebase.
# https://github.com/redhatcloudx/transformer
# IAM policy document for managing JSON content in the bucket.
data "aws_iam_policy_document" "transform_image_data" {
statement {
sid = "TransformImageData"
effect = "Allow"
actions = [
"s3:DeleteObjectTagging",
"s3:PutObject",
"s3:GetObject",
"s3:GetObjectAttributes",
"s3:GetObjectTagging",
"s3:ListBucket",
"s3:PutObjectTagging",
"s3:PutObjectAcl"
]
resources = [
"arn:aws:s3:::${aws_s3_bucket.cloudx_json_bucket.bucket}",
"arn:aws:s3:::${aws_s3_bucket.cloudx_json_bucket.bucket}/*"
]
}
}
# Load the IAM policy document into a policy that we can use with a role.
resource "aws_iam_policy" "transform_image_data" {
name = "transform_data"
policy = data.aws_iam_policy_document.transform_image_data.json
}
# IAM policy document that allows actions in the cloud-image-transformer repo to
# assume the role.
data "aws_iam_policy_document" "github_cloud_image_transformer" {
statement {
sid = "GitHubActionsWebIdentityPolicy"
effect = "Allow"
actions = ["sts:AssumeRoleWithWebIdentity"]
principals {
type = "Federated"
identifiers = [aws_iam_openid_connect_provider.github_actions.arn]
}
condition {
test = "ForAnyValue:StringEquals"
variable = "token.actions.githubusercontent.com:aud"
values = ["sts.amazonaws.com"]
}
condition {
test = "ForAnyValue:StringLike"
variable = "token.actions.githubusercontent.com:sub"
values = ["repo:redhatcloudx/transformer:*"]
}
}
}
resource "aws_iam_role" "github_actions_image_transformer" {
name = "github_actions_image_transformer"
managed_policy_arns = [aws_iam_policy.publish_image_data.arn]
assume_role_policy = data.aws_iam_policy_document.github_cloud_image_transformer.json
}