Skip to content

Commit

Permalink
condi/terraform-plans: Add mastodon upload assets role
Browse files Browse the repository at this point in the history
  • Loading branch information
bencord0 committed Oct 7, 2023
1 parent 6672d7a commit 6b0ed20
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
17 changes: 17 additions & 0 deletions modules/roles/terraform-plans/policy-mastodon-upload-assets.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resource "aws_iam_policy" "mastodon-upload-assets" {
name = "mastodon-upload-assets"
policy = data.aws_iam_policy_document.mastodon-upload-assets.json
}

data "aws_iam_policy_document" "mastodon-upload-assets" {
statement {
actions = [
"s3:PutObject",
]

resources = [
# github.com/condime/terraform-plans:eu-west-1/s3.tf
"arn:aws:s3:::nfra-club/*",
]
}
}
35 changes: 35 additions & 0 deletions modules/roles/terraform-plans/role-mastodon-upload-assets.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
resource "aws_iam_role" "mastodon-upload-assets" {
name = "mastodon-upload-assets"
assume_role_policy = data.aws_iam_policy_document.assume-mastodon-upload-assets.json
}

# Only permit github actions workflows for the matched repository to assume this by webidentity
data "aws_iam_policy_document" "assume-mastodon-upload-assets" {
statement {
actions = [
"sts:AssumeRoleWithWebIdentity",
]

principals {
type = "Federated"
identifiers = [
var.github_oidc_provider_arn,
]
}

# Match the specific repository and branch
condition {
test = "ForAnyValue:StringLike"
variable = "token.actions.githubusercontent.com:sub"

values = [
"repo:${var.github_repository}:ref:*",
]
}
}
}

resource "aws_iam_role_policy_attachment" "mastodon-upload-assets" {
role = aws_iam_role.mastodon-upload-assets.name
policy_arn = aws_iam_policy.mastodon-upload-assets.arn
}

0 comments on commit 6b0ed20

Please sign in to comment.