@@ -88,18 +88,90 @@ resource "aws_iam_role" "pool" {
8888}
8989
9090resource "aws_iam_role_policy" "pool" {
91- name = " pool-policy"
92- role = aws_iam_role. pool . name
93- policy = templatefile (" ${ path . module } /policies/lambda-pool.json" , {
94- arn_ssm_parameters_path_config = var.config.arn_ssm_parameters_path_config
95- arn_runner_instance_role = var.config.runner.role.arn
96- github_app_id_arn = nonsensitive (var. config . github_app_parameters . id . arn )
97- github_app_key_base64_arn = nonsensitive (var. config . github_app_parameters . key_base64 . arn )
98- kms_key_arn = var.config.kms_key_arn
99- ami_kms_key_arn = var.config.ami_kms_key_arn
100- ssm_ami_id_parameter_arn = var.config.ami_id_ssm_parameter_arn
101- enterprise_pat_arn = nonsensitive (try (var. config . enterprise_pat_parameter . arn , " " ))
102- })
91+ name = " pool-policy"
92+ role = aws_iam_role. pool . name
93+ policy = data. aws_iam_policy_document . pool . json
94+ }
95+
96+ data "aws_iam_policy_document" "pool" {
97+ statement {
98+ effect = " Allow"
99+ actions = [
100+ " ec2:DescribeInstances" ,
101+ " ec2:DescribeTags" ,
102+ " ec2:RunInstances" ,
103+ " ec2:CreateFleet" ,
104+ " ec2:CreateTags" ,
105+ ]
106+ resources = [" *" ]
107+ }
108+
109+ statement {
110+ effect = " Allow"
111+ actions = [" iam:PassRole" ]
112+ resources = [var . config . runner . role . arn ]
113+ }
114+
115+ statement {
116+ effect = " Allow"
117+ actions = [" ssm:AddTagsToResource" , " ssm:PutParameter" ]
118+ resources = [" *" ]
119+ }
120+
121+ statement {
122+ effect = " Allow"
123+ actions = [" ssm:GetParameter" , " ssm:GetParameters" , " ssm:GetParametersByPath" ]
124+ resources = [var . config . arn_ssm_parameters_path_config , " ${ var . config . arn_ssm_parameters_path_config } /*" ]
125+ }
126+
127+ statement {
128+ effect = " Allow"
129+ actions = [" ssm:GetParameters" ]
130+ resources = [var . config . ami_id_ssm_parameter_arn ]
131+ }
132+
133+ statement {
134+ effect = " Allow"
135+ actions = [" ssm:GetParameter" , " ssm:GetParameters" ]
136+ resources = compact ([
137+ " ${ var . config . arn_ssm_parameters_path_config } /*" ,
138+ var . config . github_app_parameters . key_base64 . arn ,
139+ var . config . github_app_parameters . id . arn ,
140+ try (var. config . enterprise_pat_parameter . arn , " " ),
141+ ])
142+ }
143+
144+ dynamic "statement" {
145+ for_each = var. config . kms_key_arn != " " ? [var . config . kms_key_arn ] : []
146+ content {
147+ effect = " Allow"
148+ actions = [" kms:Decrypt" ]
149+ resources = [statement . value ]
150+ }
151+ }
152+
153+ dynamic "statement" {
154+ for_each = var. config . ami_kms_key_arn != " " ? [var . config . ami_kms_key_arn ] : []
155+ content {
156+ effect = " Allow"
157+ actions = [" kms:DescribeKey" , " kms:ReEncrypt*" , " kms:Decrypt" ]
158+ resources = [statement . value ]
159+ }
160+ }
161+
162+ dynamic "statement" {
163+ for_each = var. config . ami_kms_key_arn != " " ? [var . config . ami_kms_key_arn ] : []
164+ content {
165+ effect = " Allow"
166+ actions = [" kms:CreateGrant" ]
167+ resources = [statement . value ]
168+ condition {
169+ test = " Bool"
170+ variable = " aws:ViaAWSService"
171+ values = [" true" ]
172+ }
173+ }
174+ }
103175}
104176
105177resource "aws_iam_role_policy" "pool_logging" {
0 commit comments