-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub.tf
74 lines (65 loc) · 1.69 KB
/
github.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# See: https://github.blog/changelog/2022-01-13-github-actions-update-on-oidc-based-deployments-to-aws/
locals {
github_thumbprint = ["6938fd4d98bab03faadb97b34396831e3780aea1"]
github_repo = "terraform-demo"
}
resource "aws_iam_openid_connect_provider" "github" {
client_id_list = ["sts.amazonaws.com"]
thumbprint_list = local.github_thumbprint
url = "https://token.actions.githubusercontent.com"
}
module "github-demo" {
source = "./modules/github"
repo_name = local.github_repo
repo_policy = data.aws_iam_policy_document.s3_rw.json
}
data "aws_iam_policy_document" "s3_rw" {
statement {
actions = [
"s3:ListBucket",
"s3:GetBucketLocation",
"s3:ListAllMyBuckets"
]
resources = [aws_s3_bucket.s3_bucket.arn]
}
statement {
actions = [
"s3:PutObject",
"s3:PutObjectAcl",
"s3:GetObject",
"s3:GetObjectAcl",
"s3:ListMultipartUploadParts",
"s3:AbortMultipartUpload",
"s3:DeleteObject"
]
resources = ["${aws_s3_bucket.s3_bucket.arn}/*"]
}
}
data "aws_ssm_parameter" "github_token" {
name = "GITHUB_TOKEN"
with_decryption = true
}
provider "github" {
owner = "alexsergeyev"
token = data.aws_ssm_parameter.github_token.value
}
terraform {
required_providers {
github = {
source = "integrations/github"
}
}
}
locals {
github_secrets = {
"AWS_ROLE_ARN" = module.github-demo.role_arn
"AWS_REGION" = "eu-north-1"
"AWS_BUCKET" = aws_s3_bucket.s3_bucket.id
}
}
resource "github_actions_secret" "aws" {
for_each = local.github_secrets
repository = local.github_repo
secret_name = each.key
plaintext_value = each.value
}