-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
condi/terraform-plans: Add mastodon upload assets role
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
modules/roles/terraform-plans/policy-mastodon-upload-assets.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
35
modules/roles/terraform-plans/role-mastodon-upload-assets.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |