Skip to content

Commit b01913f

Browse files
committed
Add s3 permissions to ci user. Also reference cert validations when creating the cloudfront dist so it becomes a true dependency to prevent a race condition.
1 parent c615a2d commit b01913f

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

terraform/modules/environment/iam.tf

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,40 @@ data "aws_iam_policy_document" "eks_list_and_describe" {
5454
}
5555

5656
resource "aws_iam_policy" "eks_list_and_describe_policy" {
57-
name = "eks_list_and_describe"
57+
name = "${var.project}_eks_list_and_describe"
5858
policy = data.aws_iam_policy_document.eks_list_and_describe.json
5959
}
6060

61-
resource "aws_iam_user_policy_attachment" "ci_user_list_and_describe_access" {
61+
resource "aws_iam_user_policy_attachment" "ci_user_list_and_describe_policy" {
6262
user = data.aws_iam_user.ci_user.user_name
6363
policy_arn = aws_iam_policy.eks_list_and_describe_policy.arn
6464
}
6565

66+
# Allow the CI user read/write access to the frontend assets bucket
67+
data "aws_iam_policy_document" "read_write_s3_policy" {
68+
statement {
69+
actions = [
70+
"s3:ListBucket",
71+
]
72+
73+
resources = formatlist("arn:aws:s3:::%s", var.s3_hosting_buckets)
74+
}
75+
76+
statement {
77+
actions = [
78+
"s3:*Object",
79+
]
80+
81+
resources = formatlist("arn:aws:s3:::%s/*", var.s3_hosting_buckets)
82+
}
83+
}
84+
85+
resource "aws_iam_policy" "read_write_s3_policy" {
86+
name = "${var.project}_ci_s3_policy"
87+
policy = data.aws_iam_policy_document.read_write_s3_policy.json
88+
}
89+
90+
resource "aws_iam_user_policy_attachment" "ci_s3_policy" {
91+
user = data.aws_iam_user.ci_user.user_name
92+
policy_arn = aws_iam_policy.read_write_s3_policy.arn
93+
}

terraform/modules/s3_hosting/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ resource "aws_cloudfront_distribution" "client_assets_distribution" {
126126
ssl_support_method = "sni-only"
127127
}
128128

129+
# Reference the cert validations only so it becomes a dependency
130+
tags = {
131+
"certs-validated" = join(",", var.certificate_validations)
132+
}
129133
}
130134

131135
# Subdomain to point at CF

0 commit comments

Comments
 (0)