|
| 1 | +locals { |
| 2 | + role_name = "twitch-live-1710204-my-web-site" |
| 3 | +} |
| 4 | + |
| 5 | +import { |
| 6 | + to = aws_iam_openid_connect_provider.github |
| 7 | + id = "arn:aws:iam::448878779811:oidc-provider/token.actions.githubusercontent.com" |
| 8 | +} |
| 9 | + |
| 10 | +resource "aws_iam_openid_connect_provider" "github" { |
| 11 | + url = "https://token.actions.githubusercontent.com" |
| 12 | + |
| 13 | + client_id_list = [ |
| 14 | + "sts.amazonaws.com", |
| 15 | + ] |
| 16 | + |
| 17 | + thumbprint_list = ["d89e3bd43d5d909b47a18977aa9d5ce36cee184c"] |
| 18 | +} |
| 19 | + |
| 20 | +import { |
| 21 | + to = aws_iam_role.twitch_live |
| 22 | + id = local.role_name |
| 23 | +} |
| 24 | + |
| 25 | +resource "aws_iam_role" "twitch_live" { |
| 26 | + name = local.role_name |
| 27 | + description = "Role dedicated to deploy infrastructure during the Twitch Live on October 17th 2024 with Arnaud and Timothee" |
| 28 | + assume_role_policy = data.aws_iam_policy_document.twitch_live_assume_role.json |
| 29 | +} |
| 30 | + |
| 31 | +data "aws_iam_policy_document" "twitch_live_assume_role" { |
| 32 | + statement { |
| 33 | + effect = "Allow" |
| 34 | + principals { |
| 35 | + type = "Federated" |
| 36 | + identifiers = [ |
| 37 | + aws_iam_openid_connect_provider.github.arn |
| 38 | + ] |
| 39 | + } |
| 40 | + actions = [ |
| 41 | + "sts:AssumeRoleWithWebIdentity" |
| 42 | + ] |
| 43 | + condition { |
| 44 | + test = "StringEquals" |
| 45 | + variable = "token.actions.githubusercontent.com:aud" |
| 46 | + values = [ |
| 47 | + "sts.amazonaws.com" |
| 48 | + ] |
| 49 | + } |
| 50 | + condition { |
| 51 | + test = "StringLike" |
| 52 | + variable = "token.actions.githubusercontent.com:sub" |
| 53 | + values = [ |
| 54 | + "repo:ippontech/my-web-site:*" |
| 55 | + ] |
| 56 | + } |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +resource "aws_iam_role_policy_attachment" "cloudfront" { |
| 61 | + role = aws_iam_role.twitch_live.name |
| 62 | + policy_arn = "arn:aws:iam::aws:policy/CloudFrontFullAccess" |
| 63 | +} |
| 64 | + |
| 65 | +resource "aws_iam_role_policy" "twitch_live_runner" { |
| 66 | + name = "${local.role_name}-runner" |
| 67 | + role = aws_iam_role.twitch_live.id |
| 68 | + policy = data.aws_iam_policy_document.twitch_live_runner.json |
| 69 | +} |
| 70 | + |
| 71 | +data "aws_iam_policy_document" "twitch_live_runner" { |
| 72 | + statement { |
| 73 | + effect = "Allow" |
| 74 | + actions = [ |
| 75 | + "s3:*" |
| 76 | + ] |
| 77 | + resources = [ |
| 78 | + "arn:aws:s3:::twitch-live-17102024-*" |
| 79 | + ] |
| 80 | + } |
| 81 | + statement { |
| 82 | + effect = "Allow" |
| 83 | + actions = [ |
| 84 | + "dynamodb:*" |
| 85 | + ] |
| 86 | + resources = [ |
| 87 | + "arn:aws:dynamodb:${var.region}:${data.aws_caller_identity.current.account_id}:table/twitch-live-17102024-tf-states-lock" |
| 88 | + ] |
| 89 | + } |
| 90 | + statement { |
| 91 | + effect = "Allow" |
| 92 | + actions = [ |
| 93 | + "iam:*OpenID*" |
| 94 | + ] |
| 95 | + resources = [ |
| 96 | + "arn:aws:iam::${data.aws_caller_identity.current.account_id}:oidc-provider/token.actions.githubusercontent.com" |
| 97 | + ] |
| 98 | + } |
| 99 | + statement { |
| 100 | + effect = "Allow" |
| 101 | + actions = [ |
| 102 | + "iam:*" |
| 103 | + ] |
| 104 | + resources = [ |
| 105 | + "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/twitch-live-1710204-my-web-site" |
| 106 | + ] |
| 107 | + } |
| 108 | +} |
0 commit comments