Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More multi-env fixes #153

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions modules/loom/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module "cloudfront" {

create_origin_access_control = true
origin_access_control = {
s3_oac = {
(var.example_env) = {
description = "CloudFront access to S3"
origin_type = "s3"
signing_behavior = "always"
Expand Down Expand Up @@ -76,7 +76,7 @@ module "cloudfront" {

s3_oac = { # with origin access control settings (recommended)
domain_name = module.s3_one.s3_bucket_bucket_regional_domain_name
origin_access_control = "s3_oac" # key in `origin_access_control`
origin_access_control = var.example_env # key in `origin_access_control`
# origin_access_control_id = "E345SXM82MIOSU" # external OAС resource
}
}
Expand Down Expand Up @@ -349,7 +349,7 @@ resource "aws_cloudfront_distribution" "s3_distribution" {
}

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

cors_config {
Expand Down
23 changes: 20 additions & 3 deletions terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ resource "aws_iam_role" "deploy_role" {
managed_policy_arns = [aws_iam_policy.state_access.arn, "arn:aws:iam::aws:policy/AdministratorAccess"]
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
# Ensure that there is a valid federated principal, even on the non-default environments
Statement = var.example_env == "terraform-example" ? [
{
Sid = "AllowGithubOIDC",
Effect = "Allow",
Expand All @@ -84,8 +85,7 @@ resource "aws_iam_role" "deploy_role" {
Sid = "AllowTerraformOIDC",
Effect = "Allow",
Principal = {
# Ensure that there is a valid federated principal, even on the non default environments
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"
Federated = aws_iam_openid_connect_provider.tfc_provider[0].arn
},
Action = "sts:AssumeRoleWithWebIdentity"
Condition = {
Expand All @@ -97,6 +97,23 @@ resource "aws_iam_role" "deploy_role" {
}
}
}
] : [
{
Sid = "AllowGithubOIDC",
Effect = "Allow",
Principal = {
Federated = "arn:aws:iam::${local.account_id}:oidc-provider/token.actions.githubusercontent.com"
},
Action = "sts:AssumeRoleWithWebIdentity"
Condition = {
StringLike = {
"token.actions.githubusercontent.com:sub" = "repo:overmindtech/terraform-example:*"
},
StringEquals = {
"token.actions.githubusercontent.com:aud" = "sts.amazonaws.com"
}
}
}
]
})
}
Expand Down
Loading