@@ -10,72 +10,6 @@ resource "aws_iam_openid_connect_provider" "github_actions" {
1010 thumbprint_list = [data . tls_certificate . github_actions . certificates . 0 . sha1_fingerprint ]
1111}
1212
13- resource "aws_iam_role" "github_actions_readonly" {
14- count = var. deployment_name == " prod" ? 1 : 0
15-
16- name = " GitHubActionsReadonlyRole"
17- description = " Managed by Terraform. IAM Role that a GitHub Actions runner can assume to authenticate with AWS."
18-
19- assume_role_policy = jsonencode ({
20- " Version" : " 2012-10-17" ,
21- " Statement" : [
22- {
23- " Effect" : " Allow" ,
24- " Principal" : {
25- " Federated" : aws_iam_openid_connect_provider.github_actions[0 ].arn
26- },
27- " Action" : " sts:AssumeRoleWithWebIdentity" ,
28- " Condition" : {
29- " StringLike" : {
30- " token.actions.githubusercontent.com:sub" : " repo:spack/spack-infrastructure:ref:refs/heads/main" ,
31- " token.actions.githubusercontent.com:aud" : " sts.amazonaws.com"
32- }
33- }
34- },
35- {
36- " Action" : " sts:AssumeRole" ,
37- " Principal" : {
38- # Unfortunately, we need to do this until https://github.com/hashicorp/terraform-provider-aws/issues/27034 is resolved.
39- # This trust statement allows the role to assume itself, which is necessary for the GitHub Actions session user to run terraform plan.
40- " AWS" : " arn:aws:sts::${ data . aws_caller_identity . current . account_id } :assumed-role/GitHubActionsReadonlyRole/GitHubActions"
41- },
42- " Effect" : " Allow" ,
43- },
44- ]
45- })
46- }
47-
48- # The `ReadOnlyAccess` managed policy doesn't include secretsmanager, so we explicitly grant it here.
49- resource "aws_iam_role_policy" "github_actions_readonly" {
50- count = var. deployment_name == " prod" ? 1 : 0
51-
52- name = " read-secrets"
53- role = aws_iam_role. github_actions_readonly [0 ]. id
54-
55- policy = jsonencode ({
56- " Version" : " 2012-10-17" ,
57- " Statement" : [
58- {
59- " Effect" : " Allow" ,
60- " Action" : [
61- " secretsmanager:GetSecretValue"
62- ],
63- " Resource" : " *"
64- }
65- ]
66- })
67- }
68-
69- # This policy grants the GitHub Actions role read-only access to most resources in the AWS account.
70- # There are some exceptions, such as secretsmanager (see inline_policy above)
71- resource "aws_iam_role_policy_attachment" "github_actions_readonly" {
72- count = var. deployment_name == " prod" ? 1 : 0
73-
74- role = aws_iam_role. github_actions_readonly [0 ]. name
75- policy_arn = " arn:aws:iam::aws:policy/ReadOnlyAccess"
76- }
77-
78-
7913# Allow github actions run from the develop branch of spack/spack to put objects into the source mirror
8014resource "aws_iam_role" "github_actions_put_to_source_mirror" {
8115 count = var. deployment_name == " prod" ? 1 : 0
0 commit comments