From 39dbe5f0f96ba0482ef553c36d7543dadaa8516e Mon Sep 17 00:00:00 2001 From: Chris Kalafarski Date: Mon, 16 Oct 2023 14:07:29 -0400 Subject: [PATCH] Adds redirect to Metrics host-header rule --- spire/templates/apps-300A.yml | 2 ++ spire/templates/apps/metrics.yml | 22 ++++++++++++++++++++++ spire/templates/root.yml | 1 + 3 files changed, 25 insertions(+) diff --git a/spire/templates/apps-300A.yml b/spire/templates/apps-300A.yml index c3609ac64..0fce792f1 100644 --- a/spire/templates/apps-300A.yml +++ b/spire/templates/apps-300A.yml @@ -46,6 +46,7 @@ Parameters: AdFilesHostname: { Type: String } AuguryHostname: { Type: String } FeederHostname: { Type: String } + MetricsHostname: { Type: String } DovetailCdnHostname: { Type: String } CmsHostname: { Type: String } TheCountHostname: { Type: String } @@ -207,6 +208,7 @@ Resources: CloudWatchAlarmTaggerServiceToken: !Ref CloudWatchAlarmTaggerServiceToken CastleHostname: !Ref CastleHostname IdHostname: !Ref IdHostname + MetricsHostname: !Ref MetricsHostname Tags: - { Key: prx:meta:tagging-version, Value: "2021-04-07" } - { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName } diff --git a/spire/templates/apps/metrics.yml b/spire/templates/apps/metrics.yml index 3cc1c2014..a7facdccb 100644 --- a/spire/templates/apps/metrics.yml +++ b/spire/templates/apps/metrics.yml @@ -27,9 +27,11 @@ Parameters: AlbListenerRulePriorityPrefix: { Type: String } CastleHostname: { Type: String } IdHostname: { Type: String } + MetricsHostname: { Type: String } Conditions: IsProduction: !Equals [!Ref EnvironmentType, Production] + IsStaging: !Equals [!Ref EnvironmentType, Staging] Resources: HostHeaderListenerRule: @@ -46,6 +48,7 @@ Resources: Priority: !Join ["", [!Ref AlbListenerRulePriorityPrefix, "00"]] AltHostHeaderListenerRule: Type: AWS::ElasticLoadBalancingV2::ListenerRule + Condition: IsProduction Properties: Actions: - TargetGroupArn: !Ref TargetGroup @@ -56,6 +59,25 @@ Resources: - metrics.* ListenerArn: !Ref AlbHttpsListenerArn Priority: !Join ["", [!Ref AlbListenerRulePriorityPrefix, "01"]] + RedirectHostHeaderListenerRule: + Type: AWS::ElasticLoadBalancingV2::ListenerRule + Condition: IsStaging + Properties: + Actions: + - RedirectConfig: + Host: !Ref MetricsHostname + Path: "/#{path}" + Port: "#{port}" + Protocol: "#{protocol}" + Query: "#{query}" + StatusCode: "HTTP_301" + Type: redirect + Conditions: + - Field: host-header + Values: + - metrics.* + ListenerArn: !Ref AlbHttpsListenerArn + Priority: !Join ["", [!Ref AlbListenerRulePriorityPrefix, "02"]] TargetGroup: Type: AWS::ElasticLoadBalancingV2::TargetGroup diff --git a/spire/templates/root.yml b/spire/templates/root.yml index 87c1f9796..b190f667f 100644 --- a/spire/templates/root.yml +++ b/spire/templates/root.yml @@ -768,6 +768,7 @@ Resources: AdFilesHostname: !GetAtt Constants2.Outputs.AdFilesHostname AuguryHostname: !GetAtt Constants2.Outputs.AuguryHostname FeederHostname: !GetAtt Constants2.Outputs.FeederHostname + MetricsHostname: !GetAtt Constants2.Outputs.MetricsHostname CmsHostname: !GetAtt Constants2.Outputs.CmsHostname DovetailCdnHostname: !GetAtt Constants2.Outputs.DovetailCdnHostname DovetailRouterHostname: !GetAtt Constants2.Outputs.DovetailRouterHostname