AWSTemplateFormatVersion: "2010-09-09"
Description: "Route53 resources"
Parameters:
  DomainName:
    Type: String
    Default: "www.example.com"
  AliasTarget:
    Type: String
    Default: "a1bcde2f3ghij4.cloudfront.net"
  CloudFrontStaticZoneId:
    Type: String
    Default: "Z2FDTNDATAQYW2" # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-aliastarget-1.html#cfn-route53-aliastarget-hostedzoneid
Conditions:
  isPrimaryRegion: !Equals [!Ref 'AWS::Region', 'us-east-1']
Resources:
  MyHostedZone:
    Type: "AWS::Route53::HostedZone"
    Properties:
      Name: !Ref "DomainName"
      VPCs:
        - VPCId: !ImportValue "infrastructure-vpc"
          VPCRegion: AWS::Region
  MyTXTRecordSet:
    Type: "AWS::Route53::RecordSet"
    Properties:
      Comment: "Invalid TXT Record"
      HostedZoneId: !Ref "MyHostedZone"
      Name: "x.example.com"
      Type: "TXT"
      TTL: "300"
      ResourceRecords:
        - '"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"'  # 256 "a" characters - too long
        - '"a""bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"'  # 256 "b" characters in a second record - too long
        - "\"MS=ms123123\""
        - "test2" # No quotation
  MyARecordSet:
    Type: "AWS::Route53::RecordSet"
    Properties:
      Comment: "Invalid A Record"
      HostedZoneId: !Ref "MyHostedZone"
      Name: "www.example.com"
      Type: "A"
      TTL: "300"
      ResourceRecords:
        - "127.0.0.1"
  MyAAAARecordSet:
    Type: "AWS::Route53::RecordSet"
    Properties:
      Comment: "Invalid AAAA Record"
      HostedZoneId: !Ref "MyHostedZone"
      Name: "www.example.com"
      Type: "AAAA"
      TTL: "300"
      ResourceRecords:
        - "127.0.0.1" # IPv4 address
        - "XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:1.2.3.4" # Invalid data
        - "2001:0db8: 85a3:0:0:8a2e:0370:7334" # Spaces
        - "1111:2222:3333:4444:5555:6666:7777" # Missing components
        - "1111:2222:3333:4444:5555:6666:7777:8888::" # Too much components
  MyCAARecordSet:
    Type: "AWS::Route53::RecordSet"
    Properties:
      Comment: "Invalid CAA Record"
      HostedZoneId: !Ref "MyHostedZone"
      Name: "www.example.com"
      Type: "CAA"
      TTL: "300"
      ResourceRecords:
        - "127.0.0.1" # No 3 items
        - "0 issue amazon.com; henk" # Missing quotes around the value
  MyCNAMERecordSet:
    Type: "AWS::Route53::RecordSet"
    Properties:
      Comment: "Invalid CNAME Record"
      HostedZoneId: !Ref "MyHostedZone"
      Name: "cname.example.com"
      Type: "CNAME"
      TTL: "300"
      ResourceRecords: # Multiple records
        - "cname1.example.com"
        - "cname2.example.com"
  MyCNAMERecordSetConditions:
    Type: "AWS::Route53::RecordSet"
    Properties:
      Comment: "Invalid CNAME Record"
      HostedZoneId: !Ref "MyHostedZone"
      Name: "cname.example.com"
      Type: "CNAME"
      TTL: "300"
      ResourceRecords: # Multiple records
        Fn::If:
        - isPrimaryRegion
        - - "cname1.example.com"
          - "cname2.example.com"
        - - "cname1.example.com"
  MyMXRecordSet:
    Type: "AWS::Route53::RecordSet"
    Properties:
      HostedZoneId: !Ref "MyHostedZone"
      Name: "example.com."
      Type: "MX"
      TTL: "300"
      ResourceRecords:
        - "127.0.0.1"
        - "10 my domain"
  MyAliasRecordSet:
    Type: "AWS::Route53::RecordSet"
    Properties:
      Comment: "Invalid Alias A Record"
      HostedZoneId: !Ref "MyHostedZone"
      Name: "alias.example.com"
      Type: "A"
      TTL: "300" # TTL not allowed on Alias
      AliasTarget:
        DNSName: !Ref "AliasTarget"
        EvaluateTargetHealth: false
        HostedZoneId: !Ref "CloudFrontStaticZoneId"
  MyRecordSetGroup:
    Type: "AWS::Route53::RecordSetGroup"
    Properties:
      HostedZoneId: !Ref "MyHostedZone"
      RecordSets:
        - Name: "y.example.com"
          Type: "TXT"
          TTL: "300"
          ResourceRecords:
            - "test4" # No quotation
        - Name: "www1.example.com"
          Type: "A"
          TTL: "300"
          ResourceRecords:
            - "a.example.com" # No IPv4 address
        - Name: "www1.example.com"
          Type: "AAAA"
          TTL: "300"
          ResourceRecords:
            - "1111:2222:3333:4444:55556666:7777:8888" # Mssing :
            - "1111:2222:3333:4444:5555:6666:7777:8888:" # Missing : intended for ::
            - "1111:2222:3333:::5555:6666:7777:8888" # :::
            - "1111::3333:4444:5555::7777:8888" # Double ::
            - "::1.2.3." # Missing parts
            - ":1111:2222:3333:4444:5555::7777:8888" # Extra : in front
        - Name: "www2.example.com"
          Type: "A"
          TTL: "300"
          ResourceRecords:
            - "127.0.0.1 " # Spaces
        - Name: "www3.example.com"
          Type: "A"
          TTL: "300"
          ResourceRecords:
            - "256.10.1.256" # Invalid values
        - Name: "www.example.com"
          Type: "CAA"
          TTL: "300"
          ResourceRecords:
            - "1 issue \"amazon.com; example.com\"" # Invalid flag
            - "A issue \"amazon.com; example.com\"" # Invalid flag
            - "0 special-value \"amazon.com\"" # Invalid tag (not numeric)
        - Name: "cname.example.com"
          Type: "CNAME"
          TTL: "300"
          ResourceRecords:
            - "No valid domain name" # No valid domain name
        - Name: "example.com."
          Type: "MX"
          TTL: "300"
          ResourceRecords:
            - "mx1.example.com"
            - "65536 mx2.example.com"
  PoorlyConfiguredRoute53:
    Type: "AWS::Route53::RecordSetGroup"
    Properties:
      HostedZoneId: !Ref "MyHostedZone"
      RecordSets:
        - Name: "z.example.com"
          Type: "TXT"
          TTL: "300"
          # Missing AliasTarget and ResourceRecords.  Don't fail
