I've noticed that on a brand-new stack deployment with DnsConfigEnabled, DNS fails to update, with the launch event lost or unprocessed.
Prior to this PR, LaunchEvent is depending on AutoScalingGroup, via the AutoScalingGroupName: !Ref AutoScalingGroup reference. This forces CF to create the ASG first, and it starts launching an instance, before the LaunchEvent starts being created, and it can often happen that the instance launches successfully and fires the event before the LaunchEvent creation completes, and the event is lost and DNS is not updated.
This change reverses the dependency, by changing the LaunchEvent's reference from an instance to a string with the same construction as in the ASG, and adds Metadata to the ASG, which decouples and reverses the ASG-first dependency.
To reverse the dependency, a Metadata is added to the ASG, referencing the LaunchEvent, when DnsConfigEnabled. Note that a simple DependsOn is not possible, as this can't be done based on a condition, and DNS is optional, so LaunchEvent won't always exist and can't be depended-on directly.
I've noticed that on a brand-new stack deployment with
DnsConfigEnabled
, DNS fails to update, with the launch event lost or unprocessed.Prior to this PR,
LaunchEvent
is depending onAutoScalingGroup
, via theAutoScalingGroupName: !Ref AutoScalingGroup
reference. This forces CF to create the ASG first, and it starts launching an instance, before theLaunchEvent
starts being created, and it can often happen that the instance launches successfully and fires the event before theLaunchEvent
creation completes, and the event is lost and DNS is not updated.This change reverses the dependency, by changing the
LaunchEvent
's reference from an instance to a string with the same construction as in the ASG, and addsMetadata
to the ASG, which decouples and reverses the ASG-first dependency.To reverse the dependency, a
Metadata
is added to the ASG, referencing theLaunchEvent
, whenDnsConfigEnabled
. Note that a simpleDependsOn
is not possible, as this can't be done based on a condition, and DNS is optional, soLaunchEvent
won't always exist and can't be depended-on directly.