Skip to content

Conversation

@evilneuro
Copy link

Add CanonicalHostedZoneID NLB attribute as stack output

  • This allows a parent stack to create a Route 53 alias record to point at the NLB
  • Just outputting the DNS name is insufficient, as an ALIAS requires the hosted zone ID of the target when the target resource is not in the same hosted zone

Example:

Resources:
  StackVSensor:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: !Ref VSensorDeploymentStackTemplateS3Uri
      Parameters:
        DarktraceInstanceHostname: !Ref SSMParamHostname
        DarktraceInstancePushtoken: !Ref SSMParamPpushtoken
        DarktraceInstanceProxy: !Ref SSMParamProxy
        InstanceType: !Ref VSensorInstanceType
        KeyPairName: !Ref EC2KPVSensorAppliance
        InstanceSecurityGroups: ''
        VsensorUpdatekey: !Ref SSMParamUpdatekey
        DesiredCapacityASG: !Ref VSensorDesiredCapacityASG
        MinSizeASG: !Ref VSensorMinSizeASG
        MaxSizeASG: !Ref VSensorMaxSizeASG
        osSensorHMAC: !Ref SSMParamHmac
        DeploymentVPC: !Ref VPCCore
        VpcCIDRBlock: !GetAtt VPCCore.CidrBlock
        SshCIDRBlock: !Ref SshCidrBlock
        Subnets: !Ref VSensorSubnets
        TrafficMirrorRuleNumber: 100
        TrafficMirrorSourceCIDR: 0.0.0.0/0
        TrafficMirrorDestCIDR: 0.0.0.0/0
        LogGroupRetention: 30
        LifecycleS3BucketDays: 7
        ShortID: ''
    DeletionPolicy: !Ref UpdateReplaceDeletePolicy
    UpdateReplacePolicy: !Ref UpdateReplaceDeletePolicy
  Route53RecordSetNLBVSensor:
    Type: AWS::Route53::RecordSet
    Properties:
      Name: !Sub ${AWS::Region}.example.net.
      Type: A
      AliasTarget:
        DNSName: !GetAtt StackVSensor.Outputs.LoadBalancerDNS
        EvaluateTargetHealth: false
        HostedZoneId: !GetAtt StackVSensor.Outputs.LoadBalancerDNSZoneID
    DeletionPolicy: !Ref UpdateReplaceDeletePolicy
    UpdateReplacePolicy: !Ref UpdateReplaceDeletePolicy

@evilneuro evilneuro marked this pull request as ready for review June 10, 2025 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant