@@ -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
87102resource "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}
0 commit comments