1- # aws_iam_role.github_role_pre-prod [0]:
2- resource "aws_iam_role" "github_role_pre_prod " {
1+ # aws_iam_role.pre_prod_github_actions [0]:
2+ resource "aws_iam_role" "pre_prod_github_actions " {
33 count = local. is_pre_production ? 1 : 0
4- description = " This role is to provide access for GitHub actions to the pre-prod environment. "
4+ name = " ${ terraform . workspace } -github-actions-role"
5+ description = " This role is to provide access for GitHub Actions to the ${ terraform . workspace } environment."
56 force_detach_policies = false
67 max_session_duration = 3600
7- name = " Github-Actions-pre-prod-role"
88 name_prefix = null
99 path = " /"
1010 permissions_boundary = null
@@ -30,13 +30,6 @@ resource "aws_iam_role" "github_role_pre_prod" {
3030 Federated = " arn:aws:iam::${ data . aws_caller_identity . current . account_id } :oidc-provider/token.actions.githubusercontent.com"
3131 }
3232 },
33- {
34- Action = " sts:AssumeRole"
35- Effect = " Allow"
36- Principal = {
37- AWS = " arn:aws:sts::${ data . aws_caller_identity . current . account_id } :assumed-role/AWSReservedSSO_DomainCGpit-Administrators_3f00be4c22ce78e5/ABKH2@hscic.gov.uk"
38- }
39- },
4033 ]
4134 Version = " 2012-10-17"
4235 }
@@ -48,7 +41,7 @@ resource "aws_iam_role" "github_role_pre_prod" {
4841
4942resource "aws_iam_role_policy" "cloudfront_policy_pre_prod" {
5043 count = local. is_pre_production ? 1 : 0
51- role = aws_iam_role. github_role_pre_prod [0 ]. id
44+ role = aws_iam_role. pre_prod_github_actions [0 ]. name
5245 name = " cloudfront_policy"
5346 policy = jsonencode (
5447 {
@@ -68,7 +61,7 @@ resource "aws_iam_role_policy" "cloudfront_policy_pre_prod" {
6861 " cloudfront:CreateInvalidation" ,
6962 " cloudfront:UpdateOriginAccessControl" ,
7063 " cloudfront:CreateOriginRequestPolicy" ,
71- " cloudfront:UpdateOriginRequestPolicy"
64+ " cloudfront:UpdateOriginRequestPolicy" ,
7265 ]
7366 Effect = " Allow"
7467 Resource = " *"
@@ -82,7 +75,7 @@ resource "aws_iam_role_policy" "cloudfront_policy_pre_prod" {
8275
8376resource "aws_iam_role_policy" "cloudwatch_logs_policy_pre_prod" {
8477 count = local. is_pre_production ? 1 : 0
85- role = aws_iam_role. github_role_pre_prod [0 ]. id
78+ role = aws_iam_role. pre_prod_github_actions [0 ]. name
8679 name = " cloudwatch_logs_policy"
8780 policy = jsonencode (
8881 {
@@ -112,7 +105,7 @@ resource "aws_iam_role_policy" "cloudwatch_logs_policy_pre_prod" {
112105
113106resource "aws_iam_role_policy" "ecr_policy_pre_prod" {
114107 count = local. is_pre_production ? 1 : 0
115- role = aws_iam_role. github_role_pre_prod [0 ]. id
108+ role = aws_iam_role. pre_prod_github_actions [0 ]. name
116109 name = " ecr_policy"
117110 policy = jsonencode (
118111 {
@@ -141,7 +134,7 @@ resource "aws_iam_role_policy" "ecr_policy_pre_prod" {
141134
142135resource "aws_iam_role_policy" "ecs_policy_pre_prod" {
143136 count = local. is_pre_production ? 1 : 0
144- role = aws_iam_role. github_role_pre_prod [0 ]. id
137+ role = aws_iam_role. pre_prod_github_actions [0 ]. name
145138 name = " ecs_policy"
146139 policy = jsonencode (
147140 {
@@ -163,7 +156,7 @@ resource "aws_iam_role_policy" "ecs_policy_pre_prod" {
163156
164157resource "aws_iam_role_policy" "github_extended_policy_virus_scanner_pre_prod" {
165158 count = local. is_pre_production ? 1 : 0
166- role = aws_iam_role. github_role_pre_prod [0 ]. id
159+ role = aws_iam_role. pre_prod_github_actions [0 ]. name
167160 name = " github-extended-policy-virus-scanner"
168161 policy = jsonencode (
169162 {
@@ -198,7 +191,7 @@ resource "aws_iam_role_policy" "github_extended_policy_virus_scanner_pre_prod" {
198191
199192resource "aws_iam_role_policy" "lambda_pre_prod" {
200193 count = local. is_pre_production ? 1 : 0
201- role = aws_iam_role. github_role_pre_prod [0 ]. id
194+ role = aws_iam_role. pre_prod_github_actions [0 ]. name
202195 name = " lambda"
203196 policy = jsonencode (
204197 {
@@ -234,7 +227,7 @@ resource "aws_iam_role_policy" "lambda_pre_prod" {
234227
235228resource "aws_iam_role_policy" "mtls_gateway_pre_prod" {
236229 count = local. is_pre_production ? 1 : 0
237- role = aws_iam_role. github_role_pre_prod [0 ]. id
230+ role = aws_iam_role. pre_prod_github_actions [0 ]. name
238231 name = " mtls-gateway"
239232 policy = jsonencode (
240233 {
@@ -302,7 +295,7 @@ resource "aws_iam_role_policy" "mtls_gateway_pre_prod" {
302295
303296resource "aws_iam_role_policy" "resource_tagging_pre_prod" {
304297 count = local. is_pre_production ? 1 : 0
305- role = aws_iam_role. github_role_pre_prod [0 ]. id
298+ role = aws_iam_role. pre_prod_github_actions [0 ]. name
306299 name = " resource_tagging"
307300 policy = jsonencode (
308301 {
@@ -437,23 +430,129 @@ resource "aws_iam_role_policy" "resource_tagging_pre_prod" {
437430 )
438431}
439432
433+ resource "aws_iam_role_policy" "rum_policy_pre_prod" {
434+ count = local. is_pre_production ? 1 : 0
435+ role = aws_iam_role. pre_prod_github_actions [0 ]. name
436+ name = " rum_policy"
437+ policy = jsonencode (
438+ {
439+ Statement = [
440+ {
441+ Action = [
442+ " cognito-identity:SetIdentityPoolRoles" ,
443+ " cognito-identity:CreateIdentityPool" ,
444+ " cognito-identity:DeleteIdentityPool" ,
445+ " cognito-identity:UpdateIdentityPool" ,
446+ ]
447+ Effect = " Allow"
448+ Resource = " arn:aws:cognito-identity:eu-west-2:${ data . aws_caller_identity . current . account_id } :identitypool/*"
449+ Sid = " AllowIdentityPool"
450+ },
451+ {
452+ Action = [
453+ " rum:TagResource" ,
454+ " rum:UntagResource" ,
455+ " rum:ListTagsForResource" ,
456+ " iam:PassRole" ,
457+ " rum:UpdateAppMonitor" ,
458+ " rum:GetAppMonitor" ,
459+ " rum:CreateAppMonitor" ,
460+ " rum:DeleteAppMonitor" ,
461+ ]
462+ Effect = " Allow"
463+ Resource = " arn:aws:rum:eu-west-2:${ data . aws_caller_identity . current . account_id } :appmonitor/*"
464+ Sid = " AllowAppMonitor"
465+ },
466+ {
467+ Action = [
468+ " logs:DeleteLogGroup" ,
469+ " logs:DeleteResourcePolicy" ,
470+ " logs:DescribeLogGroups" ,
471+ ]
472+ Effect = " Allow"
473+ Resource = " arn:aws:logs:eu-west-2:${ data . aws_caller_identity . current . account_id } :log-group:*RUMService*"
474+ Sid = " AllowRumServiceLogs"
475+ },
476+ {
477+ Action = [
478+ " logs:CreateLogDelivery" ,
479+ " logs:GetLogDelivery" ,
480+ " logs:UpdateLogDelivery" ,
481+ " logs:DeleteLogDelivery" ,
482+ " logs:ListLogDeliveries" ,
483+ " logs:DescribeResourcePolicies" ,
484+ ]
485+ Effect = " Allow"
486+ Resource = " *"
487+ Sid = " AllowRumServiceAllLogs"
488+ },
489+ ]
490+ Version = " 2012-10-17"
491+ }
492+ )
493+ }
494+
495+ resource "aws_iam_role_policy" "scheduler_policy_pre_prod" {
496+ count = local. is_pre_production ? 1 : 0
497+ role = aws_iam_role. pre_prod_github_actions [0 ]. name
498+ name = " scheduler_policy"
499+ policy = jsonencode (
500+ {
501+ Statement = [
502+ {
503+ Action = " scheduler:DeleteSchedule"
504+ Effect = " Allow"
505+ Resource = " *"
506+ Sid = " VisualEditor0"
507+ },
508+ ]
509+ Version = " 2012-10-17"
510+ }
511+ )
512+ }
513+
514+ resource "aws_iam_role_policy" "step_functions_pre_prod" {
515+ count = local. is_pre_production ? 1 : 0
516+ role = aws_iam_role. pre_prod_github_actions [0 ]. name
517+ name = " step_functions"
518+ policy = jsonencode (
519+ {
520+ Statement = [
521+ {
522+ Action = [
523+ " states:DescribeStateMachine" ,
524+ " states:UpdateStateMachine" ,
525+ " states:DeleteStateMachine" ,
526+ " states:CreateStateMachine" ,
527+ " states:TagResource" ,
528+ " states:UntagResource" ,
529+ ]
530+ Effect = " Allow"
531+ Resource = " arn:aws:states:eu-west-2:${ data . aws_caller_identity . current . account_id } :stateMachine:*"
532+ Sid = " VisualEditor0"
533+ },
534+ ]
535+ Version = " 2012-10-17"
536+ }
537+ )
538+ }
539+
440540
441- # #############################################################################################################
442541# ATTACHED POLICIES
443542
444543resource "aws_iam_role_policy_attachment" "ReadOnlyAccess_pre_prod" {
445544 count = local. is_pre_production ? 1 : 0
446- role = aws_iam_role. github_role_pre_prod [0 ]. name
545+ role = aws_iam_role. pre_prod_github_actions [0 ]. name
447546 policy_arn = " arn:aws:iam::aws:policy/ReadOnlyAccess"
448547}
449548
450549resource "aws_iam_role_policy_attachment" "github_actions_policy_pre_prod" {
451550 count = local. is_pre_production ? 1 : 0
452- role = aws_iam_role. github_role_pre_prod [0 ]. name
551+ role = aws_iam_role. pre_prod_github_actions [0 ]. name
453552 policy_arn = aws_iam_policy. github_actions_policy_pre_prod [0 ]. arn
454553}
455554
456- # aws_iam_policy.github_actions_policy_pre-prod [0]:
555+ # aws_iam_policy.github_actions_policy_pre_prod [0]:
457556resource "aws_iam_policy" "github_actions_policy_pre_prod" {
458557 count = local. is_pre_production ? 1 : 0
459558 description = null
@@ -696,7 +795,7 @@ resource "aws_iam_policy" "github_actions_policy_pre_prod" {
696795 " ec2:AllocateAddress" ,
697796 " ec2:CreateNatGateway" ,
698797 " scheduler:CreateSchedule" ,
699- " scheduler:UpdateSchedule"
798+ " scheduler:UpdateSchedule" ,
700799 ]
701800 Effect = " Allow"
702801 Resource = " *"
@@ -711,11 +810,11 @@ resource "aws_iam_policy" "github_actions_policy_pre_prod" {
711810
712811resource "aws_iam_role_policy_attachment" "github_extended_policy_1_pre_prod" {
713812 count = local. is_pre_production ? 1 : 0
714- role = aws_iam_role. github_role_pre_prod [0 ]. name
813+ role = aws_iam_role. pre_prod_github_actions [0 ]. name
715814 policy_arn = aws_iam_policy. github_extended_policy_1_pre_prod [0 ]. arn
716815}
717816
718- # aws_iam_policy.github_extended_policy_1_pre-prod [0]:
817+ # aws_iam_policy.github_extended_policy_1_pre_prod [0]:
719818resource "aws_iam_policy" "github_extended_policy_1_pre_prod" {
720819 count = local. is_pre_production ? 1 : 0
721820 description = " more required items for GitHub access"
@@ -845,12 +944,21 @@ resource "aws_iam_policy" "github_extended_policy_1_pre_prod" {
845944 " s3:PutBucketNotification" ,
846945 " iam:UpdateAssumeRolePolicy" ,
847946 " sqs:sendmessage" ,
848- " kms:GenerateDataKey"
947+ " kms:GenerateDataKey" ,
849948 ]
850949 Effect = " Allow"
851950 Resource = " *"
852951 Sid = " VisualEditor0"
853952 },
953+ {
954+ Action = [
955+ " acm:AddTagsToCertificate" ,
956+ " acm:DeleteCertificate" ,
957+ ]
958+ Effect = " Allow"
959+ Resource = " arn:aws:acm:us-east-1:${ data . aws_caller_identity . current . account_id } :certificate/*"
960+ Sid = " VisualEditor1"
961+ },
854962 ]
855963 Version = " 2012-10-17"
856964 }
0 commit comments