aws-cloudformation / cfn-lint

CloudFormation Linter
MIT No Attribution
2.41k stars 580 forks source link

Feature request: Dns alias sanity check #642

Open viraptor opened 5 years ago

viraptor commented 5 years ago

cfn-lint version: 0.13.1

Description of issue.

I tried to create an elb with a silly error:

 DNSRecord:
   Type: "AWS::Route53::RecordSet"
   Properties:
    AliasTarget:
      DNSName: !GetAtt Elb.DNSName
      HostedZoneId: !Ref HostedZone  <- copy pasta - should be elb's attribute
    HostedZoneId: !Ref HostedZone
    Name: !Ref DomainName
    Type: 'A'

I'm not sure this deserves a rule in cfn-lint, since it's not necessarily an error. But this is a common enough pattern in a recordset:

   AliasTarget:
     DNSName: !GetAtt Elb.DNSName
     HostedZoneId: !GetAtt Elb.CanonicalHostedZoneID

that maybe there should be an info level / clippy style - "It looks like you're trying to create an alias for ELB. Are you sure you didn't mean to use ELB's CanonicalHostedZoneId?"

cmmeyer commented 5 years ago

Thanks for the feedback. Could be something we could do with a value check here. We're slowly trying to enrich the spec with value data, but we're doing it service by service.

kddejong commented 5 years ago

I can't image many resources provide back a HostedZoneId valid attribute. Let me see if I can throw together a quick list cause this just becomes a definition in the enriched spec if we can knock out that list.

kddejong commented 5 years ago

Here are the ones I could find. Anyone think of anything else I should look at?

AWS::ElasticLoadBalancing::LoadBalancer.CanonicalHostedZoneNameID AWS::ElasticLoadBalancingV2::LoadBalancer.CanonicalHostedZoneID AWS::ApiGateway::DomainName.DistributionHostedZoneId AWS::ApiGateway::DomainName.RegionalHostedZoneId

kddejong commented 1 month ago

Much easier for us to do this in v1 but a similar exercise to above exists. We need to know what resources provide a hosted zone ID.

It would be similar to our approach here. https://github.com/aws-cloudformation/cfn-lint/blob/main/docs/format_keyword.md