Skip to content

Commit d36367c

Browse files
committed
More multi-env fixes
1 parent 638cf29 commit d36367c

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

modules/loom/main.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module "cloudfront" {
2828

2929
create_origin_access_control = true
3030
origin_access_control = {
31-
s3_oac = {
31+
(var.example_env) = {
3232
description = "CloudFront access to S3"
3333
origin_type = "s3"
3434
signing_behavior = "always"
@@ -76,7 +76,7 @@ module "cloudfront" {
7676

7777
s3_oac = { # with origin access control settings (recommended)
7878
domain_name = module.s3_one.s3_bucket_bucket_regional_domain_name
79-
origin_access_control = "s3_oac" # key in `origin_access_control`
79+
origin_access_control = var.example_env # key in `origin_access_control`
8080
# origin_access_control_id = "E345SXM82MIOSU" # external OAС resource
8181
}
8282
}
@@ -349,7 +349,7 @@ resource "aws_cloudfront_distribution" "s3_distribution" {
349349
}
350350

351351
resource "aws_cloudfront_response_headers_policy" "headers-policy" {
352-
name = "baseline"
352+
name = "baseline-${var.example_env}"
353353
comment = "This controls which headers are cached for baseline applications. This includes headers that are safe to cache"
354354

355355
cors_config {

terraform.tf

+20-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ resource "aws_iam_role" "deploy_role" {
6363
managed_policy_arns = [aws_iam_policy.state_access.arn, "arn:aws:iam::aws:policy/AdministratorAccess"]
6464
assume_role_policy = jsonencode({
6565
Version = "2012-10-17"
66-
Statement = [
66+
# Ensure that there is a valid federated principal, even on the non-default environments
67+
Statement = var.example_env == "terraform-example" ? [
6768
{
6869
Sid = "AllowGithubOIDC",
6970
Effect = "Allow",
@@ -84,8 +85,7 @@ resource "aws_iam_role" "deploy_role" {
8485
Sid = "AllowTerraformOIDC",
8586
Effect = "Allow",
8687
Principal = {
87-
# Ensure that there is a valid federated principal, even on the non default environments
88-
Federated = var.example_env == "terraform-example" ? aws_iam_openid_connect_provider.tfc_provider[0].arn : "arn:aws:iam::${local.account_id}:oidc-provider/token.actions.githubusercontent.com"
88+
Federated = aws_iam_openid_connect_provider.tfc_provider[0].arn
8989
},
9090
Action = "sts:AssumeRoleWithWebIdentity"
9191
Condition = {
@@ -97,6 +97,23 @@ resource "aws_iam_role" "deploy_role" {
9797
}
9898
}
9999
}
100+
] : [
101+
{
102+
Sid = "AllowGithubOIDC",
103+
Effect = "Allow",
104+
Principal = {
105+
Federated = "arn:aws:iam::${local.account_id}:oidc-provider/token.actions.githubusercontent.com"
106+
},
107+
Action = "sts:AssumeRoleWithWebIdentity"
108+
Condition = {
109+
StringLike = {
110+
"token.actions.githubusercontent.com:sub" = "repo:overmindtech/terraform-example:*"
111+
},
112+
StringEquals = {
113+
"token.actions.githubusercontent.com:aud" = "sts.amazonaws.com"
114+
}
115+
}
116+
}
100117
]
101118
})
102119
}

0 commit comments

Comments
 (0)