Skip to content

Commit d6be689

Browse files
committed
Allow ci user to invalidate cloudfront
1 parent 0806f59 commit d6be689

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

terraform/modules/environment/iam.tf

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ resource "aws_iam_user_policy_attachment" "ci_user_list_and_describe_policy" {
5959
policy_arn = aws_iam_policy.eks_list_and_describe_policy.arn
6060
}
6161

62-
# Allow the CI user read/write access to the frontend assets bucket
63-
data "aws_iam_policy_document" "read_write_s3_policy" {
62+
# Allow the CI user read/write access to the frontend assets bucket and CF invalidations
63+
data "aws_iam_policy_document" "deploy_assets_policy" {
6464
statement {
6565
actions = [
6666
"s3:ListBucket",
@@ -77,14 +77,29 @@ data "aws_iam_policy_document" "read_write_s3_policy" {
7777

7878
resources = formatlist("arn:aws:s3:::%s/*", var.s3_hosting_buckets)
7979
}
80+
81+
statement {
82+
actions = [
83+
"cloudfront:ListDistributions",
84+
]
85+
86+
resources = ["*"]
87+
}
88+
89+
statement {
90+
actions = [
91+
"cloudfront:CreateInvalidation",
92+
]
93+
resources = formatlist("arn:aws:cloudfront::%s:distribution/%s", data.aws_caller_identity.current.account_id, module.s3_hosting.cloudfront_distribution_ids)
94+
}
8095
}
8196

82-
resource "aws_iam_policy" "read_write_s3_policy" {
83-
name = "${var.project}_ci_s3_policy"
84-
policy = data.aws_iam_policy_document.read_write_s3_policy.json
97+
resource "aws_iam_policy" "deploy_assets_policy" {
98+
name = "${var.project}_ci_deploy_assets_policy"
99+
policy = data.aws_iam_policy_document.deploy_assets_policy.json
85100
}
86101

87102
resource "aws_iam_user_policy_attachment" "ci_s3_policy" {
88103
user = data.aws_iam_user.ci_user.user_name
89-
policy_arn = aws_iam_policy.read_write_s3_policy.arn
104+
policy_arn = aws_iam_policy.deploy_assets_policy.arn
90105
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "cloudfront_distribution_ids" {
2+
description = "Identifiers of the created cloudfront distributions"
3+
value = values(aws_cloudfront_distribution.client_assets_distribution)[*].id
4+
}

0 commit comments

Comments
 (0)