CloudFormation - DHCPOptions - Array of DomainNameServers doesn't maintain order

579 views Asked by At

I have a DHCPOptions defined in my CloudFormation template as so:

DhcpOptionSet:
  Type: AWS::EC2::DHCPOptions
  DependsOn:
    - DnsInstance
    - DnsSecondaryInstance
  Properties:
    DomainName: test.local
    DomainNameServers:
      - !GetAtt DnsInstance.PrivateIp
      - !GetAtt DnsSecondaryInstance.PrivateIp
      - AmazonProvidedDNS       
    Tags:
      - Key: Name
        Value: test-option-set

However, when CF creates the DHCP OptionSet, the order of the Name Servers doesn't match what I've defined in the template. It seems that no matter what order I put them in for my template, they end up as:

DnsSecondaryInstance.PrivateIp,AmazonProvidedDNS,DnsInstance.PrivateIp

This causes the resolv.conf on servers to be in the wrong order. Is there anyway to ensure the ordering of the OptionSet?

1

There are 1 answers

0
user7751 On

What worked for me was to specify the list of DNS address as a comma separated list. The technique is described in the description of the DomainNameServers parameter under https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-dhcp-options.html which states:

If specifying more than one domain name server, specify the IP addresses in a single parameter, separated by commas.

To be more specific, assuming the DNS IP addresses are 10.10.0.1, 10.10.0.2, 10.10.0.3.

  Properties:
    DomainNameServers:
      - 10.10.0.1, 10.10.0.2, 10.10.0.3