File tree 6 files changed +51
-15
lines changed
6 files changed +51
-15
lines changed Original file line number Diff line number Diff line change @@ -2,12 +2,6 @@ data "tls_certificate" "oidc_thumbprint" {
2
2
url = " https://token.actions.githubusercontent.com"
3
3
}
4
4
5
- resource "aws_iam_openid_connect_provider" "github_actions" {
6
- url = " https://token.actions.githubusercontent.com"
7
- client_id_list = [" sts.amazonaws.com" ]
8
- thumbprint_list = [data . tls_certificate . oidc_thumbprint . certificates [0 ]. sha1_fingerprint ]
9
- }
10
-
11
5
data "aws_iam_policy_document" "assume_role" {
12
6
statement {
13
7
actions = [
@@ -23,7 +17,13 @@ data "aws_iam_policy_document" "assume_role" {
23
17
condition {
24
18
test = " StringEquals"
25
19
variable = " token.actions.githubusercontent.com:sub"
26
- values = [" repo:developer-friendly/aws-lambda-opentofu-github-actions:ref:refs/heads/main" ]
20
+ values = [" repo:developer-friendly/aws-lambda-opentofu-github-actions:environment:${ var . environment_name } " ]
21
+ }
22
+
23
+ condition {
24
+ test = " StringEquals"
25
+ variable = " token.actions.githubusercontent.com:aud"
26
+ values = [" sts.amazonaws.com" ]
27
27
}
28
28
}
29
29
}
@@ -40,6 +40,14 @@ data "aws_iam_policy_document" "lambda_policy" {
40
40
}
41
41
}
42
42
43
+ resource "aws_iam_openid_connect_provider" "github_actions" {
44
+ url = " https://token.actions.githubusercontent.com"
45
+ client_id_list = [" sts.amazonaws.com" ]
46
+ thumbprint_list = [
47
+ data . tls_certificate . oidc_thumbprint . certificates [0 ]. sha1_fingerprint ,
48
+ ]
49
+ }
50
+
43
51
resource "aws_iam_role" "this" {
44
52
name = " github-actions"
45
53
assume_role_policy = data. aws_iam_policy_document . assume_role . json
Original file line number Diff line number Diff line change 1
1
output "role_arn" {
2
2
value = aws_iam_role. this . arn
3
3
}
4
+
5
+ output "environment_name" {
6
+ value = var. environment_name
7
+ }
Original file line number Diff line number Diff line change
1
+ variable "environment_name" {
2
+ type = string
3
+ default = " prod"
4
+ }
Original file line number Diff line number Diff line change 1
- data "github_user" "current" {
2
- username = " "
1
+ data "aws_region" "current" {}
2
+
3
+ resource "github_branch_protection" "this" {
4
+ repository_id = " aws-lambda-opentofu-github-actions"
5
+
6
+ pattern = " main"
7
+ enforce_admins = true
8
+ allows_deletions = false
9
+
10
+ force_push_bypassers = [
11
+ " /meysam81" ,
12
+ ]
3
13
}
4
14
5
15
resource "github_repository_environment" "this" {
6
- environment = " prod "
16
+ environment = var . environment_name
7
17
repository = " aws-lambda-opentofu-github-actions"
8
18
9
- reviewers {
10
- users = [data . github_user . current . id ]
11
- }
12
-
13
19
prevent_self_review = false
14
20
15
21
deployment_branch_policy {
@@ -25,3 +31,11 @@ resource "github_actions_environment_secret" "this" {
25
31
secret_name = " AWS_IAM_ROLE"
26
32
plaintext_value = var. aws_iam_role
27
33
}
34
+
35
+ resource "github_actions_environment_variable" "this" {
36
+ repository = " aws-lambda-opentofu-github-actions"
37
+ environment = var. environment_name
38
+
39
+ variable_name = " AWS_REGION"
40
+ value = data. aws_region . current . name
41
+ }
Original file line number Diff line number Diff line change @@ -3,7 +3,8 @@ include "root" {
3
3
}
4
4
5
5
inputs = {
6
- aws_iam_role = dependency.github_oidc.outputs.role_arn
6
+ aws_iam_role = dependency.github_oidc.outputs.role_arn
7
+ environment_name = dependency.github_oidc.outputs.environment_name
7
8
}
8
9
9
10
dependency "github_oidc" {
Original file line number Diff line number Diff line change @@ -2,3 +2,8 @@ variable "aws_iam_role" {
2
2
type = string
3
3
description = " The ARN of the IAM role to assume"
4
4
}
5
+
6
+ variable "environment_name" {
7
+ type = string
8
+ nullable = false
9
+ }
You can’t perform that action at this time.
0 commit comments