-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AUTH-2655 -initial cloud front resource creation (#1577)
* initial cloud front resource creation on staging Co-authored-by: Ethan Mills <[email protected]>
- Loading branch information
1 parent
2d79d43
commit c223bc8
Showing
11 changed files
with
835 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
resource "aws_cloudformation_stack" "cloudfront" { | ||
count = var.cloudfront_auth_frontend_enabled ? 1 : 0 | ||
name = "${var.environment}-auth-fe-cloudfront" | ||
#using fixed version of template for now | ||
template_url = "https://template-storage-templatebucket-1upzyw6v9cs42.s3.amazonaws.com/cloudfront-distribution/template.yaml?versionId=EKk9m9vMv10qF5vHzWZogFLnQQw6_Yjc" | ||
|
||
capabilities = ["CAPABILITY_NAMED_IAM"] | ||
|
||
parameters = { | ||
AddWWWPrefix = var.Add_WWWPrefix | ||
ApplyCloakingHeaderWAFToOrigin = var.Apply_CloakingHeader_WAFToOrigin | ||
CloudFrontCertArn = aws_acm_certificate.cloudfront_frontend_certificate[0].arn | ||
CloudfrontWafAcl = aws_wafv2_web_acl.frontend_cloudfront_waf_web_acl[0].arn | ||
DistributionAlias = local.frontend_fqdn | ||
FraudHeaderEnabled = var.Fraud_Header_Enabled | ||
OriginCloakingHeader = var.auth_origin_cloakingheader | ||
OriginResourceArn = aws_lb.frontend_alb.id | ||
OriginWafAcl = "none" | ||
PreviousOriginCloakingHeader = var.previous_auth_origin_cloakingheader | ||
StandardLoggingEnabled = true | ||
} | ||
tags = local.default_tags | ||
} | ||
|
||
resource "aws_cloudformation_stack" "cloudfront-monitoring" { | ||
count = var.cloudfront_auth_frontend_enabled ? 1 : 0 | ||
provider = aws.cloudfront | ||
name = "${var.environment}-auth-fe-cloudfront-monitoring" | ||
template_url = "https://template-storage-templatebucket-1upzyw6v9cs42.s3.amazonaws.com/cloudfront-monitoring-alarm/template.yaml?z=${timestamp()}" | ||
|
||
capabilities = ["CAPABILITY_NAMED_IAM"] | ||
|
||
parameters = { | ||
CacheHitAlarmSNSTopicARN = aws_sns_topic.slack_events[0].arn | ||
CloudFrontAdditionaldMetricsEnabled = true | ||
CloudfrontDistribution = aws_cloudformation_stack.cloudfront[0].outputs["DistributionId"] | ||
} | ||
depends_on = [aws_cloudformation_stack.cloudfront] | ||
tags = local.default_tags | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#This is SNS topic created in us-east-1 region for cloudwatch Alarm for Cloudfront | ||
|
||
resource "aws_sns_topic" "slack_events" { | ||
provider = aws.cloudfront | ||
count = var.cloudfront_auth_frontend_enabled ? 1 : 0 | ||
name = "${var.environment}-cloudfront-alerts" | ||
lambda_failure_feedback_role_arn = aws_iam_role.sns_logging_iam_role[0].arn | ||
|
||
tags = local.default_tags | ||
} | ||
|
||
data "aws_iam_policy_document" "sns_topic_policy" { | ||
version = "2012-10-17" | ||
provider = aws.cloudfront | ||
count = var.cloudfront_auth_frontend_enabled ? 1 : 0 | ||
|
||
statement { | ||
actions = [ | ||
"SNS:Subscribe", | ||
"SNS:SetTopicAttributes", | ||
"SNS:RemovePermission", | ||
"SNS:Receive", | ||
"SNS:Publish", | ||
"SNS:ListSubscriptionsByTopic", | ||
"SNS:GetTopicAttributes", | ||
"SNS:DeleteTopic", | ||
"SNS:AddPermission", | ||
] | ||
|
||
effect = "Allow" | ||
|
||
principals { | ||
type = "Service" | ||
identifiers = ["cloudwatch.amazonaws.com"] | ||
} | ||
|
||
condition { | ||
test = "StringEquals" | ||
values = [data.aws_caller_identity.current.account_id] | ||
variable = "aws:SourceAccount" | ||
} | ||
|
||
resources = [ | ||
aws_sns_topic.slack_events[0].arn, | ||
] | ||
} | ||
} | ||
|
||
resource "aws_sns_topic_policy" "sns_alert_policy" { | ||
provider = aws.cloudfront | ||
count = var.cloudfront_auth_frontend_enabled ? 1 : 0 | ||
arn = aws_sns_topic.slack_events[0].arn | ||
|
||
policy = data.aws_iam_policy_document.sns_topic_policy[0].json | ||
} | ||
|
||
resource "aws_iam_role" "sns_logging_iam_role" { | ||
provider = aws.cloudfront | ||
count = var.cloudfront_auth_frontend_enabled ? 1 : 0 | ||
name_prefix = "sns-failed-slack-alerts-role" | ||
path = "/${var.environment}/" | ||
assume_role_policy = data.aws_iam_policy_document.sns_can_assume_policy[0].json | ||
|
||
tags = local.default_tags | ||
} | ||
|
||
data "aws_iam_policy_document" "sns_can_assume_policy" { | ||
version = "2012-10-17" | ||
provider = aws.cloudfront | ||
count = var.cloudfront_auth_frontend_enabled ? 1 : 0 | ||
|
||
statement { | ||
effect = "Allow" | ||
principals { | ||
identifiers = [ | ||
"sns.amazonaws.com" | ||
] | ||
type = "Service" | ||
} | ||
|
||
actions = [ | ||
"sts:AssumeRole" | ||
] | ||
} | ||
} | ||
|
||
data "aws_iam_policy_document" "sns_logging_policy" { | ||
version = "2012-10-17" | ||
provider = aws.cloudfront | ||
count = var.cloudfront_auth_frontend_enabled ? 1 : 0 | ||
|
||
statement { | ||
effect = "Allow" | ||
actions = [ | ||
"logs:CreateLogGroup", | ||
"logs:CreateLogStream", | ||
"logs:DescribeLogGroups", | ||
"logs:DescribeLogStreams", | ||
"logs:PutLogEvents", | ||
"logs:GetLogEvents", | ||
"logs:FilterLogEvents", | ||
] | ||
|
||
resources = [ | ||
"arn:aws:logs:*:*:*", | ||
] | ||
} | ||
} | ||
|
||
resource "aws_iam_policy" "api_gateway_logging_policy" { | ||
count = var.cloudfront_auth_frontend_enabled ? 1 : 0 | ||
provider = aws.cloudfront | ||
name_prefix = "sns-failed-alert-logging" | ||
path = "/${var.environment}/" | ||
description = "IAM policy for logging failed SNS alerts" | ||
|
||
policy = data.aws_iam_policy_document.sns_logging_policy[0].json | ||
|
||
lifecycle { | ||
create_before_destroy = true | ||
} | ||
|
||
tags = local.default_tags | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "api_gateway_logging_logs" { | ||
provider = aws.cloudfront | ||
count = var.cloudfront_auth_frontend_enabled ? 1 : 0 | ||
role = aws_iam_role.sns_logging_iam_role[0].name | ||
policy_arn = aws_iam_policy.api_gateway_logging_policy[0].arn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.