mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudformation): replace changed launch configurations safely (#8599)
* fix(cloudformation): replace changed launch configurations safely * fix(autoscaling): guard launch configuration replacement races * fix(cloudformation): reuse replacement decisions and valid fixtures
This commit is contained in:
1 parent
43363c0f8d
commit
8ad3e2b419
9 files changed
+794
-136
No files matched your search
@@ -370,9 +370,19 @@ public class AutoScalingService implements PassedRoleLookup {
|
||||
}
|
||||
|
||||
public void deleteLaunchConfiguration(String region, String name) {
|
||||
if (launchConfigs.remove(lcKey(region, name)) == null) {
|
||||
throw new AwsException("ValidationError",
|
||||
"Launch configuration '" + name + "' not found.", 400);
|
||||
synchronized (lockFor(region)) {
|
||||
String key = lcKey(region, name);
|
||||
if (!launchConfigs.containsKey(key)) {
|
||||
throw new AwsException("ValidationError",
|
||||
"Launch configuration '" + name + "' not found.", 400);
|
||||
}
|
||||
boolean inUse = groups.values().stream().anyMatch(group -> region.equals(group.getRegion())
|
||||
&& name.equals(group.getLaunchConfigurationName()));
|
||||
if (inUse) {
|
||||
throw new AwsException("ResourceInUse",
|
||||
"Launch configuration '" + name + "' is in use by an Auto Scaling group.", 400);
|
||||
}
|
||||
launchConfigs.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,43 +402,45 @@ public class AutoScalingService implements PassedRoleLookup {
|
||||
Map<String, String> tags,
|
||||
Map<String, Boolean> tagPropagateAtLaunch,
|
||||
AsgOptionalFields optionalFields) {
|
||||
String key = asgKey(region, name);
|
||||
if (groups.containsKey(key)) {
|
||||
throw new AwsException("AlreadyExists",
|
||||
"Auto Scaling group '" + name + "' already exists.", 400);
|
||||
}
|
||||
validateLaunchSource(launchConfigName, launchTemplateId, launchTemplateName, mixedInstancesPolicy);
|
||||
if (launchConfigName == null && launchTemplateId == null && launchTemplateName == null
|
||||
&& mixedInstancesPolicy == null) {
|
||||
throw new AwsException("ValidationError",
|
||||
"Valid requests must contain either LaunchTemplate, LaunchConfigurationName, "
|
||||
+ "InstanceId or MixedInstancesPolicy parameter.", 400);
|
||||
}
|
||||
validateEffectiveLaunchImage(region, launchConfigName, launchTemplateId, launchTemplateName,
|
||||
launchTemplateVersion, mixedInstancesPolicy);
|
||||
validateOptionalFields(optionalFields);
|
||||
validateDesiredCapacityType(
|
||||
optionalFields != null ? optionalFields.desiredCapacityType() : null,
|
||||
mixedInstancesPolicy);
|
||||
synchronized (lockFor(region)) {
|
||||
String key = asgKey(region, name);
|
||||
if (groups.containsKey(key)) {
|
||||
throw new AwsException("AlreadyExists",
|
||||
"Auto Scaling group '" + name + "' already exists.", 400);
|
||||
}
|
||||
validateLaunchSource(launchConfigName, launchTemplateId, launchTemplateName, mixedInstancesPolicy);
|
||||
if (launchConfigName == null && launchTemplateId == null && launchTemplateName == null
|
||||
&& mixedInstancesPolicy == null) {
|
||||
throw new AwsException("ValidationError",
|
||||
"Valid requests must contain either LaunchTemplate, LaunchConfigurationName, "
|
||||
+ "InstanceId or MixedInstancesPolicy parameter.", 400);
|
||||
}
|
||||
validateEffectiveLaunchImage(region, launchConfigName, launchTemplateId, launchTemplateName,
|
||||
launchTemplateVersion, mixedInstancesPolicy);
|
||||
validateOptionalFields(optionalFields);
|
||||
validateDesiredCapacityType(
|
||||
optionalFields != null ? optionalFields.desiredCapacityType() : null,
|
||||
mixedInstancesPolicy);
|
||||
|
||||
AutoScalingGroup asg = newGroup(region, name, minSize, maxSize, desiredCapacity,
|
||||
resolveAvailabilityZones(region, availabilityZones, subnetIds), subnetIds, terminationPolicies,
|
||||
tags, tagPropagateAtLaunch);
|
||||
asg.setLaunchConfigurationName(launchConfigName);
|
||||
asg.setLaunchTemplateId(launchTemplateId);
|
||||
asg.setLaunchTemplateName(launchTemplateName);
|
||||
asg.setLaunchTemplateVersion(launchTemplateVersion);
|
||||
asg.setMixedInstancesPolicy(mixedInstancesPolicy);
|
||||
asg.setDefaultCooldown(defaultCooldown > 0 ? defaultCooldown : 300);
|
||||
asg.setTargetGroupARNs(targetGroupArns != null ? new ArrayList<>(targetGroupArns) : new ArrayList<>());
|
||||
asg.setLoadBalancerNames(lbNames != null ? new ArrayList<>(lbNames) : new ArrayList<>());
|
||||
asg.setHealthCheckType(healthCheckType != null ? healthCheckType : "EC2");
|
||||
asg.setHealthCheckGracePeriod(healthCheckGracePeriod);
|
||||
if (optionalFields != null) {
|
||||
optionalFields.applyToNewGroup(asg);
|
||||
AutoScalingGroup asg = newGroup(region, name, minSize, maxSize, desiredCapacity,
|
||||
resolveAvailabilityZones(region, availabilityZones, subnetIds), subnetIds, terminationPolicies,
|
||||
tags, tagPropagateAtLaunch);
|
||||
asg.setLaunchConfigurationName(launchConfigName);
|
||||
asg.setLaunchTemplateId(launchTemplateId);
|
||||
asg.setLaunchTemplateName(launchTemplateName);
|
||||
asg.setLaunchTemplateVersion(launchTemplateVersion);
|
||||
asg.setMixedInstancesPolicy(mixedInstancesPolicy);
|
||||
asg.setDefaultCooldown(defaultCooldown > 0 ? defaultCooldown : 300);
|
||||
asg.setTargetGroupARNs(targetGroupArns != null ? new ArrayList<>(targetGroupArns) : new ArrayList<>());
|
||||
asg.setLoadBalancerNames(lbNames != null ? new ArrayList<>(lbNames) : new ArrayList<>());
|
||||
asg.setHealthCheckType(healthCheckType != null ? healthCheckType : "EC2");
|
||||
asg.setHealthCheckGracePeriod(healthCheckGracePeriod);
|
||||
if (optionalFields != null) {
|
||||
optionalFields.applyToNewGroup(asg);
|
||||
}
|
||||
groups.put(key, asg);
|
||||
return asg;
|
||||
}
|
||||
groups.put(key, asg);
|
||||
return asg;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -471,68 +483,70 @@ public class AutoScalingService implements PassedRoleLookup {
|
||||
String healthCheckType, Integer healthCheckGracePeriod,
|
||||
List<String> terminationPolicies,
|
||||
AsgOptionalFields optionalFields) {
|
||||
// Under the group's lock, which EnterStandby, ExitStandby and the reconciler hold while they read and
|
||||
// change the group's capacity.
|
||||
String key = asgKey(region, name);
|
||||
synchronized (lockFor(key)) {
|
||||
AutoScalingGroup asg = requireGroup(region, name);
|
||||
validateLaunchSource(launchConfigName, launchTemplateId, launchTemplateName, mixedInstancesPolicy);
|
||||
if (launchTemplateVersion != null && launchTemplateId == null && launchTemplateName == null) {
|
||||
throw new AwsException("ValidationError",
|
||||
"LaunchTemplateVersion requires a LaunchTemplateId or LaunchTemplateName.", 400);
|
||||
synchronized (lockFor(region)) {
|
||||
// Under the group's lock, which EnterStandby, ExitStandby and the reconciler hold while they read and
|
||||
// change the group's capacity.
|
||||
String key = asgKey(region, name);
|
||||
synchronized (lockFor(key)) {
|
||||
AutoScalingGroup asg = requireGroup(region, name);
|
||||
validateLaunchSource(launchConfigName, launchTemplateId, launchTemplateName, mixedInstancesPolicy);
|
||||
if (launchTemplateVersion != null && launchTemplateId == null && launchTemplateName == null) {
|
||||
throw new AwsException("ValidationError",
|
||||
"LaunchTemplateVersion requires a LaunchTemplateId or LaunchTemplateName.", 400);
|
||||
}
|
||||
validateOptionalFields(optionalFields);
|
||||
rejectDesiredConfigurationUpdateDuringActiveRefresh(region, name,
|
||||
launchConfigName, launchTemplateId, launchTemplateName, launchTemplateVersion, mixedInstancesPolicy);
|
||||
LaunchIdentity effectiveIdentity = effectiveLaunchIdentity(asg, launchConfigName,
|
||||
launchTemplateId, launchTemplateName, launchTemplateVersion, mixedInstancesPolicy);
|
||||
validateEffectiveLaunchImage(region,
|
||||
effectiveIdentity.launchConfigurationName(),
|
||||
effectiveIdentity.launchTemplateId(),
|
||||
effectiveIdentity.launchTemplateName(),
|
||||
effectiveIdentity.launchTemplateVersion(),
|
||||
effectiveIdentity.mixedInstancesPolicy());
|
||||
validateDesiredCapacityType(
|
||||
effectiveDesiredCapacityType(asg, optionalFields),
|
||||
effectiveIdentity.mixedInstancesPolicy());
|
||||
List<String> updatedZones = availabilityZones;
|
||||
if (subnetIds != null && !subnetIds.isEmpty()) {
|
||||
updatedZones = resolveAvailabilityZones(region, availabilityZones, subnetIds);
|
||||
}
|
||||
if (launchConfigName != null) {
|
||||
asg.setLaunchConfigurationName(launchConfigName);
|
||||
asg.setLaunchTemplateId(null);
|
||||
asg.setLaunchTemplateName(null);
|
||||
asg.setLaunchTemplateVersion(null);
|
||||
asg.setMixedInstancesPolicy(null);
|
||||
}
|
||||
if (launchTemplateId != null || launchTemplateName != null) {
|
||||
asg.setLaunchConfigurationName(null);
|
||||
asg.setLaunchTemplateId(launchTemplateId);
|
||||
asg.setLaunchTemplateName(launchTemplateName);
|
||||
asg.setLaunchTemplateVersion(launchTemplateVersion);
|
||||
asg.setMixedInstancesPolicy(null);
|
||||
}
|
||||
if (mixedInstancesPolicy != null) {
|
||||
asg.setLaunchConfigurationName(null);
|
||||
asg.setLaunchTemplateId(null);
|
||||
asg.setLaunchTemplateName(null);
|
||||
asg.setLaunchTemplateVersion(null);
|
||||
asg.setMixedInstancesPolicy(mixedInstancesPolicy);
|
||||
}
|
||||
if (minSize != null) { asg.setMinSize(minSize); }
|
||||
if (maxSize != null) { asg.setMaxSize(maxSize); }
|
||||
if (desiredCapacity != null) { asg.setDesiredCapacity(desiredCapacity); }
|
||||
if (defaultCooldown != null) { asg.setDefaultCooldown(defaultCooldown); }
|
||||
if (updatedZones != null) { asg.setAvailabilityZones(new ArrayList<>(updatedZones)); }
|
||||
if (subnetIds != null) { asg.setSubnetIds(new ArrayList<>(subnetIds)); }
|
||||
if (healthCheckType != null) { asg.setHealthCheckType(healthCheckType); }
|
||||
if (healthCheckGracePeriod != null) { asg.setHealthCheckGracePeriod(healthCheckGracePeriod); }
|
||||
if (terminationPolicies != null) { asg.setTerminationPolicies(new ArrayList<>(terminationPolicies)); }
|
||||
if (optionalFields != null) {
|
||||
optionalFields.applyToExistingGroup(asg);
|
||||
}
|
||||
groups.put(key, asg);
|
||||
}
|
||||
validateOptionalFields(optionalFields);
|
||||
rejectDesiredConfigurationUpdateDuringActiveRefresh(region, name,
|
||||
launchConfigName, launchTemplateId, launchTemplateName, launchTemplateVersion, mixedInstancesPolicy);
|
||||
LaunchIdentity effectiveIdentity = effectiveLaunchIdentity(asg, launchConfigName,
|
||||
launchTemplateId, launchTemplateName, launchTemplateVersion, mixedInstancesPolicy);
|
||||
validateEffectiveLaunchImage(region,
|
||||
effectiveIdentity.launchConfigurationName(),
|
||||
effectiveIdentity.launchTemplateId(),
|
||||
effectiveIdentity.launchTemplateName(),
|
||||
effectiveIdentity.launchTemplateVersion(),
|
||||
effectiveIdentity.mixedInstancesPolicy());
|
||||
validateDesiredCapacityType(
|
||||
effectiveDesiredCapacityType(asg, optionalFields),
|
||||
effectiveIdentity.mixedInstancesPolicy());
|
||||
List<String> updatedZones = availabilityZones;
|
||||
if (subnetIds != null && !subnetIds.isEmpty()) {
|
||||
updatedZones = resolveAvailabilityZones(region, availabilityZones, subnetIds);
|
||||
}
|
||||
if (launchConfigName != null) {
|
||||
asg.setLaunchConfigurationName(launchConfigName);
|
||||
asg.setLaunchTemplateId(null);
|
||||
asg.setLaunchTemplateName(null);
|
||||
asg.setLaunchTemplateVersion(null);
|
||||
asg.setMixedInstancesPolicy(null);
|
||||
}
|
||||
if (launchTemplateId != null || launchTemplateName != null) {
|
||||
asg.setLaunchConfigurationName(null);
|
||||
asg.setLaunchTemplateId(launchTemplateId);
|
||||
asg.setLaunchTemplateName(launchTemplateName);
|
||||
asg.setLaunchTemplateVersion(launchTemplateVersion);
|
||||
asg.setMixedInstancesPolicy(null);
|
||||
}
|
||||
if (mixedInstancesPolicy != null) {
|
||||
asg.setLaunchConfigurationName(null);
|
||||
asg.setLaunchTemplateId(null);
|
||||
asg.setLaunchTemplateName(null);
|
||||
asg.setLaunchTemplateVersion(null);
|
||||
asg.setMixedInstancesPolicy(mixedInstancesPolicy);
|
||||
}
|
||||
if (minSize != null) { asg.setMinSize(minSize); }
|
||||
if (maxSize != null) { asg.setMaxSize(maxSize); }
|
||||
if (desiredCapacity != null) { asg.setDesiredCapacity(desiredCapacity); }
|
||||
if (defaultCooldown != null) { asg.setDefaultCooldown(defaultCooldown); }
|
||||
if (updatedZones != null) { asg.setAvailabilityZones(new ArrayList<>(updatedZones)); }
|
||||
if (subnetIds != null) { asg.setSubnetIds(new ArrayList<>(subnetIds)); }
|
||||
if (healthCheckType != null) { asg.setHealthCheckType(healthCheckType); }
|
||||
if (healthCheckGracePeriod != null) { asg.setHealthCheckGracePeriod(healthCheckGracePeriod); }
|
||||
if (terminationPolicies != null) { asg.setTerminationPolicies(new ArrayList<>(terminationPolicies)); }
|
||||
if (optionalFields != null) {
|
||||
optionalFields.applyToExistingGroup(asg);
|
||||
}
|
||||
groups.put(key, asg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2448,6 +2462,10 @@ public class AutoScalingService implements PassedRoleLookup {
|
||||
String launchTemplateVersion,
|
||||
MixedInstancesPolicy mixedInstancesPolicy) {
|
||||
if (launchConfigName != null) {
|
||||
if (!launchConfigs.containsKey(lcKey(region, launchConfigName))) {
|
||||
throw new AwsException("ValidationError",
|
||||
"Launch configuration '" + launchConfigName + "' not found.", 400);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (launchTemplateId != null || launchTemplateName != null) {
|
||||
|
||||
+121
-27
@@ -11,6 +11,7 @@ import io.floci.aws.services.autoscaling.model.AvailabilityZoneDistribution;
|
||||
import io.floci.aws.services.autoscaling.model.CapacityReservationSpecification;
|
||||
import io.floci.aws.services.autoscaling.model.InstanceMaintenancePolicy;
|
||||
import io.floci.aws.services.autoscaling.model.LaunchConfiguration;
|
||||
import io.floci.aws.services.autoscaling.model.LaunchConfigurationBlockDeviceMapping;
|
||||
import io.floci.aws.services.autoscaling.model.MixedInstancesPolicy;
|
||||
import io.floci.aws.services.cloudformation.CloudFormationTemplateEngine;
|
||||
import io.floci.aws.services.cloudformation.model.StackResource;
|
||||
@@ -77,14 +78,29 @@ public class AutoScalingGroupCfnProvisioner implements CfnResourceProvisioner {
|
||||
@Override
|
||||
public void delete(String resourceType, String physicalId, String region) {
|
||||
switch (resourceType) {
|
||||
case LAUNCH_CONFIGURATION -> autoScalingService.deleteLaunchConfiguration(region, physicalId);
|
||||
case LAUNCH_CONFIGURATION -> deleteLaunchConfiguration(region, physicalId);
|
||||
case GROUP -> autoScalingService.deleteAutoScalingGroup(region, physicalId, true);
|
||||
default -> throw unsupported(resourceType);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteLaunchConfiguration(String region, String physicalId) {
|
||||
try {
|
||||
autoScalingService.deleteLaunchConfiguration(region, physicalId);
|
||||
} catch (AwsException failure) {
|
||||
if (!"ValidationError".equals(failure.getErrorCode())
|
||||
|| !autoScalingService.describeLaunchConfigurations(region, List.of(physicalId)).isEmpty()) {
|
||||
throw failure;
|
||||
}
|
||||
LOG.debugv("Launch configuration {0} is already absent", physicalId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rollbackUpdate(StackResource resource) {
|
||||
if (LAUNCH_CONFIGURATION.equals(resource.getResourceType())) {
|
||||
return ReplacementCleanup.rollback(resource, this::delete);
|
||||
}
|
||||
if (GROUP.equals(resource.getResourceType())) {
|
||||
String rawSnapshot = resource.getAttributes().remove(CfnRollback.ASG_UPDATE_SNAPSHOT_ATTR);
|
||||
if (rawSnapshot != null) {
|
||||
@@ -147,6 +163,9 @@ public class AutoScalingGroupCfnProvisioner implements CfnResourceProvisioner {
|
||||
@Override
|
||||
public void clearUpdate(StackResource resource) {
|
||||
resource.getAttributes().remove(CfnRollback.ASG_UPDATE_SNAPSHOT_ATTR);
|
||||
if (LAUNCH_CONFIGURATION.equals(resource.getResourceType())) {
|
||||
ReplacementCleanup.clear(resource);
|
||||
}
|
||||
}
|
||||
|
||||
public record AsgSnapshot(
|
||||
@@ -184,35 +203,67 @@ public class AutoScalingGroupCfnProvisioner implements CfnResourceProvisioner {
|
||||
|
||||
private void provisionLaunchConfiguration(StackResource r, JsonNode props, ProvisionContext ctx) {
|
||||
String region = ctx.region();
|
||||
String name = ctx.stablePhysicalName(ctx.resolveOptional(props, "LaunchConfigurationName"),
|
||||
r.getLogicalId(), 255, false);
|
||||
|
||||
// Launch configurations have no update API on real AWS at all (any property change replaces
|
||||
// the resource), so provision() being re-invoked on every UpdateStack means a same-named one
|
||||
// already on file must be left alone rather than re-created (createLaunchConfiguration throws
|
||||
// AlreadyExists).
|
||||
LaunchConfiguration lc = existingEntity(ctx, name, n -> requireLaunchConfiguration(region, n));
|
||||
if (lc == null) {
|
||||
String associatePublicIp = ctx.resolveOptional(props, "AssociatePublicIpAddress");
|
||||
lc = autoScalingService.createLaunchConfiguration(region, name,
|
||||
ctx.resolveOptional(props, "InstanceId"),
|
||||
ctx.resolveOptional(props, "ImageId"),
|
||||
ctx.resolveOptional(props, "InstanceType"),
|
||||
ctx.resolveOptional(props, "KeyName"),
|
||||
ctx.resolveStringList(props, "SecurityGroups"),
|
||||
ctx.resolveOptional(props, "UserData"),
|
||||
ctx.resolveOptional(props, "IamInstanceProfile"),
|
||||
// Absent in the template means the subnet default applies, so
|
||||
// it stays null rather than collapsing to false.
|
||||
associatePublicIp == null || associatePublicIp.isBlank()
|
||||
? null
|
||||
: Boolean.parseBoolean(associatePublicIp), null, List.of(), metadataOptions(props, ctx));
|
||||
deleteRenamedResource(ctx, name, n -> autoScalingService.deleteLaunchConfiguration(region, n),
|
||||
"launch configuration");
|
||||
String explicitName = ctx.resolveOptional(props, "LaunchConfigurationName");
|
||||
String name = ctx.stablePhysicalName(explicitName, r.getLogicalId(), 255, false);
|
||||
List<LaunchConfigurationBlockDeviceMapping> mappings = blockDeviceMappings(props, ctx);
|
||||
LaunchTemplateData.MetadataOptions metadata = metadataOptions(props, ctx);
|
||||
LaunchConfiguration prior = existingEntity(ctx, ctx.priorPhysicalId(),
|
||||
n -> requireLaunchConfiguration(region, n));
|
||||
if (ctx.isUpdate()) {
|
||||
ReplacementCleanup.endRollbackRetry(r);
|
||||
if (!launchConfigurationRequiresReplacement(props, ctx)
|
||||
&& ctx.reusesPriorEntity(name) && prior != null) {
|
||||
return;
|
||||
}
|
||||
if (explicitName != null && !explicitName.isBlank() && ctx.reusesPriorEntity(name)) {
|
||||
throw CfnExceptions.customNamedReplacement(name);
|
||||
}
|
||||
if (explicitName == null || explicitName.isBlank()) {
|
||||
name = ctx.generatePhysicalName(r.getLogicalId(), 255, false);
|
||||
}
|
||||
}
|
||||
// Ref returns the launch configuration name.
|
||||
Map<String, String> before = Map.copyOf(r.getAttributes());
|
||||
String associatePublicIp = ctx.resolveOptional(props, "AssociatePublicIpAddress");
|
||||
LaunchConfiguration lc = autoScalingService.createLaunchConfiguration(region, name,
|
||||
ctx.resolveOptional(props, "InstanceId"), ctx.resolveOptional(props, "ImageId"),
|
||||
ctx.resolveOptional(props, "InstanceType"), ctx.resolveOptional(props, "KeyName"),
|
||||
ctx.resolveStringList(props, "SecurityGroups"), ctx.resolveOptional(props, "UserData"),
|
||||
ctx.resolveOptional(props, "IamInstanceProfile"),
|
||||
associatePublicIp == null || associatePublicIp.isBlank() ? null
|
||||
: Boolean.parseBoolean(associatePublicIp), null, mappings, metadata);
|
||||
r.setPhysicalId(name);
|
||||
r.getAttributes().put("Arn", lc.getLaunchConfigurationArn());
|
||||
ReplacementCleanup.record(r, ctx, before);
|
||||
}
|
||||
|
||||
private static boolean launchConfigurationRequiresReplacement(JsonNode props, ProvisionContext ctx) {
|
||||
PropertyChanges changes = ctx.changes(LAUNCH_CONFIGURATION, props);
|
||||
if (changes.requiresReplacement()) {
|
||||
return true;
|
||||
}
|
||||
if (ctx.priorProperties() == null) {
|
||||
return false;
|
||||
}
|
||||
// The shared replacement flag currently omits newly added create-only properties.
|
||||
return changes.byName().values().stream()
|
||||
.anyMatch(change -> change.createOnly() && change.kind() == PropertyChanges.Kind.ADDED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasReplacementUpdate(StackResource resource) {
|
||||
return LAUNCH_CONFIGURATION.equals(resource.getResourceType()) && ReplacementCleanup.hasReplacement(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String updateCleanupPhysicalId(StackResource resource) {
|
||||
return LAUNCH_CONFIGURATION.equals(resource.getResourceType())
|
||||
? ReplacementCleanup.cleanupPhysicalId(resource) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpdateCleanupResult completeUpdate(StackResource resource) {
|
||||
return LAUNCH_CONFIGURATION.equals(resource.getResourceType())
|
||||
? ReplacementCleanup.complete(resource, this::delete) : UpdateCleanupResult.notApplicable();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -241,6 +292,49 @@ public class AutoScalingGroupCfnProvisioner implements CfnResourceProvisioner {
|
||||
return options;
|
||||
}
|
||||
|
||||
private List<LaunchConfigurationBlockDeviceMapping> blockDeviceMappings(JsonNode props, ProvisionContext ctx) {
|
||||
CfnPropertyTypes.Reader types = new CfnPropertyTypes.Reader(ctx.engine());
|
||||
JsonNode mappings = types.read("BlockDeviceMappings", props.get("BlockDeviceMappings"),
|
||||
CfnPropertyTypes.propertyShape(LAUNCH_CONFIGURATION, "BlockDeviceMappings"));
|
||||
types.finish();
|
||||
List<LaunchConfigurationBlockDeviceMapping> result = new ArrayList<>();
|
||||
if (mappings == null) {
|
||||
return result;
|
||||
}
|
||||
for (JsonNode mapping : mappings) {
|
||||
LaunchConfigurationBlockDeviceMapping value = new LaunchConfigurationBlockDeviceMapping();
|
||||
value.setDeviceName(mapping.path("DeviceName").asText(null));
|
||||
value.setVirtualName(mapping.path("VirtualName").asText(null));
|
||||
if (mapping.hasNonNull("NoDevice")) {
|
||||
value.setNoDevice(mapping.get("NoDevice").booleanValue());
|
||||
}
|
||||
JsonNode ebs = mapping.get("Ebs");
|
||||
if (ebs != null && !ebs.isNull()) {
|
||||
LaunchConfigurationBlockDeviceMapping.Ebs disk = new LaunchConfigurationBlockDeviceMapping.Ebs();
|
||||
disk.setSnapshotId(ebs.path("SnapshotId").asText(null));
|
||||
disk.setVolumeType(ebs.path("VolumeType").asText(null));
|
||||
if (ebs.hasNonNull("VolumeSize")) {
|
||||
disk.setVolumeSize(ebs.get("VolumeSize").intValue());
|
||||
}
|
||||
if (ebs.hasNonNull("Iops")) {
|
||||
disk.setIops(ebs.get("Iops").intValue());
|
||||
}
|
||||
if (ebs.hasNonNull("Throughput")) {
|
||||
disk.setThroughput(ebs.get("Throughput").intValue());
|
||||
}
|
||||
if (ebs.hasNonNull("Encrypted")) {
|
||||
disk.setEncrypted(ebs.get("Encrypted").booleanValue());
|
||||
}
|
||||
if (ebs.hasNonNull("DeleteOnTermination")) {
|
||||
disk.setDeleteOnTermination(ebs.get("DeleteOnTermination").booleanValue());
|
||||
}
|
||||
value.setEbs(disk);
|
||||
}
|
||||
result.add(value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private LaunchConfiguration requireLaunchConfiguration(String region, String name) {
|
||||
List<LaunchConfiguration> found = autoScalingService.describeLaunchConfigurations(region, List.of(name));
|
||||
if (found.isEmpty()) {
|
||||
|
||||
Reference in new issue
Block a user