Skip to content

Commit

Permalink
Use inline policy
Browse files Browse the repository at this point in the history
  • Loading branch information
jemnery committed Nov 17, 2023
1 parent 3650254 commit 325be8b
Showing 1 changed file with 43 additions and 24 deletions.
67 changes: 43 additions & 24 deletions terraform/environments/performance-hub/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,62 @@
# S3 bucket access policy for AP landing bucket (data pushed from
# Performance Hub to a bucket in the AP account - hence hard-coded bucket name)
# Legacy account was arn:aws:iam::677012035582:policy/read-ap-ppas
resource "aws_iam_policy" "s3_ap_landing_policy" {
name = "${local.application_name}-s3-ap-landing-policy"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
# resource "aws_iam_policy" "s3_ap_landing_policy" {
# name = "${local.application_name}-s3-ap-landing-policy"
# policy = <<EOF
# {
# "Version": "2012-10-17",
# "Statement": [
# {
# "Sid": "MOJAnalyticalPlatformListBucket",
# "Effect": "Allow",
# "Action": [
# "s3:ListBucket",
# "s3:GetBucketLocation"
# ],
# "Resource": "arn:aws:s3:::hmpps-performance-hub-landing"
# },
# {
# "Sid": "MOJAnalyticalPlatformWriteBucket",
# "Effect": "Allow",
# "Action": [
# "s3:PutObject",
# "s3:PutObjectAcl",
# "s3:GetObject"
# ],
# "Resource": "arn:aws:s3:::hmpps-performance-hub-landing/*"
# }
# ]
# }
# EOF
# }

resource "aws_iam_role" "s3_ap_landing_role" {
name = "${local.application_name}-s3-ap-landing-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
"Sid": "MOJAnalyticalPlatformListBucket",
"Effect": "Allow",
"Action": [
Sid: "MOJAnalyticalPlatformListBucket",
Effect: "Allow",
Action: [
"s3:ListBucket",
"s3:GetBucketLocation"
],
"Resource": "arn:aws:s3:::hmpps-performance-hub-landing"
},
{
"Sid": "MOJAnalyticalPlatformWriteBucket",
"Effect": "Allow",
"Action": [
Sid: "MOJAnalyticalPlatformWriteBucket",
Effect: "Allow",
Action: [
"s3:PutObject",
"s3:PutObjectAcl",
"s3:GetObject"
],
"Resource": "arn:aws:s3:::hmpps-performance-hub-landing/*"
Resource: "arn:aws:s3:::hmpps-performance-hub-landing/*"
}
]
}
EOF
}

resource "aws_iam_role" "s3_ap_landing_role" {
name = "${local.application_name}-s3-ap-landing-role"
assume_role_policy = data.aws_iam_policy.s3_ap_landing_policy
})
tags = merge(
local.tags,
{
Expand All @@ -48,10 +71,6 @@ resource "aws_iam_role" "s3_ap_landing_role" {
)
}

resource "aws_iam_role_policy_attachment" "s3_ap_landing_attachment" {
role = aws_iam_role.s3_ap_landing_role.name
policy_arn = aws_iam_policy.s3_ap_landing_policy.arn
}

# S3 bucket access policy for Performance Hub landing bucket (data pushed from
# AP to a bucket in this account)
Expand Down

0 comments on commit 325be8b

Please sign in to comment.