How do I add a reference to the latest version number of the launch template in the auto-scaling group? The launch template and auto scaling group are in separate files as the launch template is used by other autoscaling groups as well. Can Fn::GetAtt and Ref be used here to refer to another resource located in a separate file? If so, how can I use it? The end goal is when I make an update to the launch template, the autoscaling group should automatically refer to the latest launch template.
Note - I am creating the launch template completely separate before creating the auto-scaling group. It works this way, but I would like the auto-scaling group to refer to the latest launch template. It currently defaults to version 1.
launch_template.yaml
---
AWSTemplateFormatVersion: '2010-09-09'
Resources:
LaunchTemplate:
Type: 'AWS::EC2::LaunchTemplate'
Properties:
LaunchTemplateName: testtemplate
LaunchTemplateData:
IamInstanceProfile:
Arn: >-
arn:aws:iam::blah
ImageId: ami-12345
InstanceRequirements:
InstanceGenerations:
- current
MemoryMiB:
Min: 8192
VCpuCount:
Min: 2
Max: 4
BlockDeviceMappings:
- Ebs:
VolumeSize: 16
VolumeType: gp2
DeleteOnTermination: true
Encrypted: true
DeviceName: /dev/xvda
Monitoring:
Enabled: true
KeyName: testkey
SecurityGroupIds:
- sg-1234
PrivateDnsNameOptions:
HostnameType: ip-name
InstanceInitiatedShutdownBehavior: terminate
autoscaling_group.yaml
---
Resources:
testautoscalinggroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
AutoScalingGroupName: test-autoscaling-group
MaxSize: '2'
MinSize: '1'
DesiredCapacity: '1'
VPCZoneIdentifier:
- subnet-1234
TargetGroupARNs:
- Ref: targetgroup
MixedInstancesPolicy:
InstancesDistribution:
OnDemandAllocationStrategy: lowest-price
LaunchTemplate:
LaunchTemplateSpecification:
LaunchTemplateName: testtemplate
Tags:
- Key: Cluster
Value: test
PropagateAtLaunch: true
dynamicscalingpolicy:
Type: AWS::AutoScaling::ScalingPolicy
Properties:
AutoScalingGroupName:
Ref: testautoscalinggroup
PolicyType: TargetTrackingScaling
TargetTrackingConfiguration:
DisableScaleIn: false
PredefinedMetricSpecification:
PredefinedMetricType: ASGAverageCPUUtilization
TargetValue: 30
targetgroup:
Type: 'AWS::ElasticLoadBalancingV2::TargetGroup'
Properties:
HealthCheckEnabled: true
HealthCheckIntervalSeconds: 30
HealthCheckProtocol: TCP
HealthCheckTimeoutSeconds: 10
HealthyThresholdCount: 3
Name: testtargetgroup
Protocol: TCP_UDP
Port: 53
UnhealthyThresholdCount: 3
VpcId: vpc-1234