AWSTemplateFormatVersion: "2010-09-09"

Parameters:
  EnvironmentLabel:
    Type: String

  EnvironmentType:
    Type: String

Resources:
  Accelerator:
    Type: "AWS::GlobalAccelerator::Accelerator"
    DeletionPolicy: "Retain"
    Properties:
      Enabled: true
      IpAddressType: "IPV4"
      Name: !Sub "${EnvironmentLabel}-${EnvironmentType}-accelerator"
      Tags:
        - Key: "EnvironmentLabel"
          Value: !Ref EnvironmentLabel
        - Key: "EnvironmentType"
          Value: !Ref EnvironmentType

  ListenerHttpHttps:
    Type: "AWS::GlobalAccelerator::Listener"
    DeletionPolicy: "Retain"
    Properties:
      AcceleratorArn: !GetAtt Accelerator.AcceleratorArn
      ClientAffinity: "NONE"
      PortRanges:
        - FromPort: 80
          ToPort: 80
        - FromPort: 443
          ToPort: 443
      Protocol: "TCP"

  EndpointGroup:
    Type: "AWS::GlobalAccelerator::EndpointGroup"
    DeletionPolicy: "Retain"
    Properties:
      EndpointConfigurations:
        - ClientIPPreservationEnabled: true
          # REPLACE THE ENDPOINT ID WITH ALB/NLB ARN
          EndpointId: ""
          Weight: 255
      EndpointGroupRegion: "us-west-1"
      HealthCheckIntervalSeconds: 30
      HealthCheckPort: 80
      HealthCheckProtocol: "HTTP"
      ListenerArn: !GetAtt ListenerHttpHttps.ListenerArn
      ThresholdCount: 3
      TrafficDialPercentage: 100.0