diff --git a/docs/services/cloudformation.md b/docs/services/cloudformation.md
index 237c070c95..dbc23ecbba 100644
--- a/docs/services/cloudformation.md
+++ b/docs/services/cloudformation.md
@@ -736,9 +736,11 @@ goes back to its create default, or is kept, on the AppSync resources and the EC
an API key's `Expires`, a GraphQL API's `ApiType` and `Visibility`, a UNIT resolver's `DataSourceName`,
a `NatGateway`'s `PrivateIpAddress` and a `PrefixList`'s `MaxEntries`. An update that drops a
`PrefixList`'s `AddressFamily` or `PrefixListName` fails. Create-only members are not cleared either.
-A property the stack never declared keeps the value set outside it, with two exceptions that an update
-clears even then: a GraphQL API's `Tags` and `EnvironmentVariables`, which every update drives to the
-template, and the `NatGateway` secondary address properties. The table says so on each of those rows.
+A property the stack never declared keeps the value set outside it, with one exception: a GraphQL API's
+`Tags` and `EnvironmentVariables`, which every update drives to the template. The table says so on
+those rows. The three `NatGateway` `Secondary*` properties count as one
+address set: when the new or the previous template declares any of them, an update brings all three
+to the template.
`src/test/resources/cloudformation/drop-policy.tsv` lists what a drop does to each property, and
`CfnSchemaCoverageTest` keeps the list complete. Other services follow
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkCfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkCfnProvisioner.java
index c9d6443207..cdf6ab0304 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkCfnProvisioner.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkCfnProvisioner.java
@@ -671,7 +671,7 @@ public class Ec2NetworkCfnProvisioner implements CfnResourceProvisioner {
// SubnetId, AllocationId, ConnectivityType and PrivateIpAddress are createOnly: the same
// values keep the gateway, a change replaces it. With no PrivateIpAddress the gateway keeps
// the address it was given. The Secondary* properties are not createOnly: the gateway is
- // kept and its secondary addresses are changed in place.
+ // kept and its secondary addresses are changed in place, when the stack manages them.
NatGateway existing = ctx.isUpdate() ? findNatGateway(ctx.priorPhysicalId(), ctx.region()) : null;
boolean reuse = existing != null && Objects.equals(subnetId, existing.getSubnetId())
&& Objects.equals(allocationId, existing.getAllocationId())
@@ -687,9 +687,14 @@ public class Ec2NetworkCfnProvisioner implements CfnResourceProvisioner {
}
NatGateway[] current = {nat};
int secondaryCountValue = Ec2Service.secondaryPrivateIpCount(secondaryCount, "private".equals(connectivityType));
+ // The three properties are one address set: declaring any of them, now or before,
+ // puts all three under the stack.
+ boolean managesSecondaries = Stream.of("SecondaryAllocationIds", "SecondaryPrivateIpAddresses",
+ "SecondaryPrivateIpAddressCount")
+ .anyMatch(name -> (props != null && props.hasNonNull(name)) || ctx.previouslyDeclared(name));
if (reuse) {
CfnRollback.guarded(r, ctx, false, () -> { }, () -> undoInPlace(r), () -> {
- if (!holdsSecondaries(existing, secondaryAllocationIds, secondaryPrivateIps, secondaryCountValue)) {
+ if (managesSecondaries && !holdsSecondaries(existing, secondaryAllocationIds, secondaryPrivateIps, secondaryCountValue)) {
ObjectNode prior = inPlacePrior(r, existing.getNatGatewayId(), ctx);
if (!prior.has("natSecondaries")) {
prior.set("natSecondaries", natSecondaries(existing));
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEc2NetworkingIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEc2NetworkingIntegrationTest.java
index 0ad63700e5..5a8c4670b1 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEc2NetworkingIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationEc2NetworkingIntegrationTest.java
@@ -1,10 +1,12 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
+import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.specification.RequestSpecification;
+import jakarta.inject.Inject;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -42,6 +44,9 @@ class CloudFormationEc2NetworkingIntegrationTest {
"AWS4-HMAC-SHA256 Credential=test/20260907/us-east-1/ec2/aws4_request";
private static final String STACK = "ec2-networking-it";
+ @Inject
+ Ec2Service ec2Service;
+
private static String template(String vpcId, String publicSubnetCidr) {
return template(vpcId, publicSubnetCidr, "{\"Key\": \"tier\", \"Value\": \"web\"}");
}
@@ -245,6 +250,94 @@ class CloudFormationEc2NetworkingIntegrationTest {
ec2("DeleteVpc", Map.of("VpcId", vpcId));
}
+ private static final String TAGGED_PUBLIC_NAT = PUBLIC_NAT + ", \"Tags\": [{\"Key\": \"%s\", \"Value\": \"v\"}]";
+
+ /**
+ * A property the stack never declared keeps the value set outside it. The three secondary-address
+ * properties form one set, so a gateway whose templates declared none of them keeps a secondary
+ * Elastic IP added through the service, which is what AssociateNatGatewayAddress does (the
+ * query action is not exposed, so the test calls the service it maps to).
+ */
+ @Test
+ void aNatGatewaySecondaryElasticIpAddedOutsideTheStackSurvivesAnUnrelatedUpdate() {
+ String stack = "ec2-nat-secondary-outside-it";
+ String vpcId = between(ec2("CreateVpc", Map.of("CidrBlock", "10.97.0.0/16")), "", "");
+ cloudFormation(stack, "CreateStack", secondaryNatTemplate(vpcId, "10.97.0.0/24",
+ TAGGED_PUBLIC_NAT.formatted("before"), false));
+ String natId = XmlParser.extractPairs(describeStacks(stack, "CREATE_COMPLETE"),
+ "Outputs", "OutputKey", "OutputValue").get("NatId");
+ String outside = between(ec2("AllocateAddress", Map.of("Domain", "vpc")), "", "");
+ ec2Service.updateNatGatewaySecondaryAddresses("us-east-1", natId, List.of(outside), List.of(), null);
+ assertTrue(natXml(natId).contains("" + outside + ""), natXml(natId));
+
+ cloudFormation(stack, "UpdateStack", secondaryNatTemplate(vpcId, "10.97.0.0/24",
+ TAGGED_PUBLIC_NAT.formatted("after"), false));
+
+ assertEquals(natId, XmlParser.extractPairs(describeStacks(stack, "UPDATE_COMPLETE"),
+ "Outputs", "OutputKey", "OutputValue").get("NatId"), "the gateway is kept");
+ String nat = natXml(natId);
+ assertTrue(nat.contains("" + outside + ""),
+ "the secondary added outside the stack must survive: " + nat);
+ assertTrue(ec2("DescribeAddresses", Map.of("AllocationId.1", outside)).contains(""),
+ "the Elastic IP added outside the stack is still held");
+
+ cloudFormation(stack, "DeleteStack", null);
+ CfnStackWaits.awaitStackDeleted(stack);
+ ec2("ReleaseAddress", Map.of("AllocationId", outside));
+ ec2("DeleteVpc", Map.of("VpcId", vpcId));
+ }
+
+ /** {@code AWS::NoValue} is removed before the provisioner runs, so such a property was never declared. */
+ @Test
+ void aSecondaryPropertyThatIsNoValueCountsAsNeverDeclared() {
+ String stack = "ec2-nat-secondary-novalue-it";
+ String vpcId = between(ec2("CreateVpc", Map.of("CidrBlock", "10.98.0.0/16")), "", "");
+ String noValue = PUBLIC_NAT + ", \"SecondaryAllocationIds\": {\"Ref\": \"AWS::NoValue\"}";
+ cloudFormation(stack, "CreateStack", secondaryNatTemplate(vpcId, "10.98.0.0/24", noValue, false));
+ String natId = XmlParser.extractPairs(describeStacks(stack, "CREATE_COMPLETE"),
+ "Outputs", "OutputKey", "OutputValue").get("NatId");
+ String outside = between(ec2("AllocateAddress", Map.of("Domain", "vpc")), "", "");
+ ec2Service.updateNatGatewaySecondaryAddresses("us-east-1", natId, List.of(outside), List.of(), null);
+
+ cloudFormation(stack, "UpdateStack", secondaryNatTemplate(vpcId, "10.98.0.0/24",
+ noValue + ", \"Tags\": [{\"Key\": \"k\", \"Value\": \"v\"}]", false));
+
+ describeStacks(stack, "UPDATE_COMPLETE");
+ String nat = natXml(natId);
+ assertTrue(nat.contains("" + outside + ""),
+ "a NoValue property never declared the set, so the secondary added outside must survive: " + nat);
+
+ cloudFormation(stack, "DeleteStack", null);
+ CfnStackWaits.awaitStackDeleted(stack);
+ ec2("ReleaseAddress", Map.of("AllocationId", outside));
+ ec2("DeleteVpc", Map.of("VpcId", vpcId));
+ }
+
+ /** The contrast: a secondary Elastic IP the stack declared is released when a template drops the property. */
+ @Test
+ void aSecondaryElasticIpTheStackDeclaredIsClearedWhenATemplateDropsIt() {
+ String stack = "ec2-nat-secondary-dropped-it";
+ String vpcId = between(ec2("CreateVpc", Map.of("CidrBlock", "10.99.0.0/16")), "", "");
+ cloudFormation(stack, "CreateStack", secondaryNatTemplate(vpcId, "10.99.0.0/24",
+ PUBLIC_NAT + ", \"SecondaryAllocationIds\": [{\"Fn::GetAtt\": [\"Eip2\", \"AllocationId\"]}]", false));
+ Map out = XmlParser.extractPairs(describeStacks(stack, "CREATE_COMPLETE"),
+ "Outputs", "OutputKey", "OutputValue");
+ String natId = out.get("NatId");
+ String eip2 = out.get("Eip2Id");
+ assertTrue(natXml(natId).contains("" + eip2 + ""), natXml(natId));
+
+ cloudFormation(stack, "UpdateStack", secondaryNatTemplate(vpcId, "10.99.0.0/24", PUBLIC_NAT, false));
+
+ describeStacks(stack, "UPDATE_COMPLETE");
+ String nat = natXml(natId);
+ assertFalse(nat.contains(eip2) || !secondaryIps(nat).isEmpty(), "the declared secondary is cleared: " + nat);
+ assertFalse(ec2("DescribeAddresses", Map.of("AllocationId.1", eip2)).contains(""));
+
+ cloudFormation(stack, "DeleteStack", null);
+ CfnStackWaits.awaitStackDeleted(stack);
+ ec2("DeleteVpc", Map.of("VpcId", vpcId));
+ }
+
@Test
void aPrivateNatGatewaysSecondaryAddressesChangeInPlace() {
String stack = "ec2-nat-secondary-private-it";
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkCfnProvisionerTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkCfnProvisionerTest.java
index 84ff85453a..a13ba2b43b 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkCfnProvisionerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2NetworkCfnProvisionerTest.java
@@ -698,13 +698,193 @@ class Ec2NetworkCfnProvisionerTest {
.thenReturn(natGateway(NAT_ID, "eni-0123456789abcdef0", "10.0.1.50"));
StackResource changed = prior("AWS::EC2::NatGateway", "Nat", NAT_ID, Map.of("NatGatewayId", NAT_ID));
provisioner.provision(changed, mapper.createObjectNode().put("SubnetId", SUBNET_ID).put("AllocationId", ALLOC_ID),
- ctx(NAT_ID));
+ ctx(NAT_ID, props));
verify(ec2).updateNatGatewaySecondaryAddresses(REGION, NAT_ID, List.of(), List.of(), null);
verify(ec2).createNatGateway(any(), any(), any(), any(), any(), any(), any(), any(), any());
assertEquals(NAT_ID, changed.getPhysicalId(), "changed secondaries keep the gateway");
assertFalse(changed.getAttributes().containsKey(CfnRollback.USES_ATTR_PREFIX + "SecondaryPublicIp.0"));
}
+ private static final String OUTSIDE_ALLOC = "eipalloc-0aaaaaaaaaaaaaaaa";
+ private static final String OUTSIDE_PUBLIC_IP = "203.0.113.80";
+
+ /** A gateway holding a secondary address that no template of the stack declared. */
+ private static NatGateway natGatewayHoldingAnOutsideSecondary(String connectivityType) {
+ NatGateway nat = natGateway(NAT_ID, "eni-0123456789abcdef0", "10.0.1.50");
+ nat.setSubnetId(SUBNET_ID);
+ nat.setConnectivityType(connectivityType);
+ NatGatewayAddress secondary = new NatGatewayAddress();
+ secondary.setPrimary(false);
+ secondary.setNetworkInterfaceId("eni-0123456789abcdef0");
+ secondary.setPrivateIp("10.0.1.80");
+ if ("public".equals(connectivityType)) {
+ nat.setAllocationId(ALLOC_ID);
+ nat.getNatGatewayAddresses().get(0).setAllocationId(ALLOC_ID);
+ secondary.setAllocationId(OUTSIDE_ALLOC);
+ secondary.setPublicIp(OUTSIDE_PUBLIC_IP);
+ }
+ nat.getNatGatewayAddresses().add(secondary);
+ return nat;
+ }
+
+ private ObjectNode publicNatProps() {
+ return mapper.createObjectNode().put("SubnetId", SUBNET_ID).put("AllocationId", ALLOC_ID);
+ }
+
+ /**
+ * A property the stack never declared keeps the value set outside it: with none of the three
+ * secondary-address properties in either template, the update leaves the gateway's secondaries
+ * alone, and the attributes list what it holds.
+ */
+ @Test
+ void aNatGatewayWhoseTemplatesNeverDeclaredSecondariesKeepsTheOnesAddedOutsideTheStack() {
+ when(ec2.describeNatGateways(REGION, List.of(NAT_ID), Map.of()))
+ .thenReturn(List.of(natGatewayHoldingAnOutsideSecondary("public")));
+ // Only reached by an implementation that clears the set: it reports a gateway with none left.
+ when(ec2.updateNatGatewaySecondaryAddresses(any(), any(), any(), any(), any()))
+ .thenReturn(natGateway(NAT_ID, "eni-0123456789abcdef0", "10.0.1.50"));
+
+ for (ProvisionContext context : List.of(ctx(NAT_ID, publicNatProps()), ctx(NAT_ID))) {
+ StackResource r = prior("AWS::EC2::NatGateway", "Nat", NAT_ID, Map.of("NatGatewayId", NAT_ID));
+ provisioner.provision(r, publicNatProps(), context);
+
+ assertEquals(NAT_ID, r.getPhysicalId());
+ assertEquals(OUTSIDE_PUBLIC_IP, r.getAttributes().get(CfnRollback.USES_ATTR_PREFIX + "SecondaryPublicIp.0"));
+ }
+ verify(ec2, never()).updateNatGatewaySecondaryAddresses(any(), any(), any(), any(), any());
+ verify(ec2, never()).createNatGateway(any(), any(), any(), any(), any(), any(), any(), any(), any());
+ }
+
+ /** A JSON null counts as not declared, as {@code AWS::NoValue} does, so the set is not the stack's. */
+ @Test
+ void aNullSecondaryPropertyCountsAsNotDeclaredAndKeepsTheSecondariesAddedOutsideTheStack() {
+ ObjectNode props = publicNatProps();
+ props.putNull("SecondaryAllocationIds");
+ when(ec2.describeNatGateways(REGION, List.of(NAT_ID), Map.of()))
+ .thenReturn(List.of(natGatewayHoldingAnOutsideSecondary("public")));
+ // Only reached by an implementation that clears the set: it reports a gateway with none left.
+ when(ec2.updateNatGatewaySecondaryAddresses(any(), any(), any(), any(), any()))
+ .thenReturn(natGateway(NAT_ID, "eni-0123456789abcdef0", "10.0.1.50"));
+ StackResource r = prior("AWS::EC2::NatGateway", "Nat", NAT_ID, Map.of("NatGatewayId", NAT_ID));
+
+ provisioner.provision(r, props, ctx(NAT_ID, publicNatProps()));
+
+ assertEquals(NAT_ID, r.getPhysicalId());
+ assertEquals(OUTSIDE_PUBLIC_IP, r.getAttributes().get(CfnRollback.USES_ATTR_PREFIX + "SecondaryPublicIp.0"));
+ verify(ec2, never()).updateNatGatewaySecondaryAddresses(any(), any(), any(), any(), any());
+ }
+
+ /** Each of the three properties makes the set the stack's once the previous template declared it. */
+ @Test
+ void droppingAnyOneOfTheSecondaryPropertiesThePreviousTemplateDeclaredClearsTheSet() {
+ ObjectNode previousAlloc = publicNatProps();
+ previousAlloc.putArray("SecondaryAllocationIds").add(OUTSIDE_ALLOC);
+ ObjectNode previousIp = publicNatProps();
+ previousIp.putArray("SecondaryPrivateIpAddresses").add("10.0.1.80");
+ when(ec2.describeNatGateways(REGION, List.of(NAT_ID), Map.of()))
+ .thenReturn(List.of(natGatewayHoldingAnOutsideSecondary("public")));
+ when(ec2.updateNatGatewaySecondaryAddresses(REGION, NAT_ID, List.of(), List.of(), null))
+ .thenReturn(natGateway(NAT_ID, "eni-0123456789abcdef0", "10.0.1.50"));
+
+ for (ObjectNode previous : List.of(previousAlloc, previousIp)) {
+ StackResource r = prior("AWS::EC2::NatGateway", "Nat", NAT_ID, Map.of("NatGatewayId", NAT_ID));
+ provisioner.provision(r, publicNatProps(), ctx(NAT_ID, previous));
+
+ assertEquals(NAT_ID, r.getPhysicalId(), "the gateway is kept");
+ assertFalse(r.getAttributes().containsKey(CfnRollback.USES_ATTR_PREFIX + "SecondaryPublicIp.0"));
+ }
+ verify(ec2, times(2)).updateNatGatewaySecondaryAddresses(REGION, NAT_ID, List.of(), List.of(), null);
+ }
+
+ @Test
+ void droppingTheSecondaryAddressCountThePreviousTemplateDeclaredClearsTheSet() {
+ ObjectNode privateNat = mapper.createObjectNode().put("SubnetId", SUBNET_ID).put("ConnectivityType", "private");
+ ObjectNode previous = privateNat.deepCopy().put("SecondaryPrivateIpAddressCount", 1);
+ when(ec2.describeNatGateways(REGION, List.of(NAT_ID), Map.of()))
+ .thenReturn(List.of(natGatewayHoldingAnOutsideSecondary("private")));
+ when(ec2.updateNatGatewaySecondaryAddresses(REGION, NAT_ID, List.of(), List.of(), null))
+ .thenReturn(natGateway(NAT_ID, "eni-0123456789abcdef0", "10.0.1.50"));
+ StackResource r = prior("AWS::EC2::NatGateway", "Nat", NAT_ID, Map.of("NatGatewayId", NAT_ID));
+
+ provisioner.provision(r, privateNat, ctx(NAT_ID, previous));
+
+ verify(ec2).updateNatGatewaySecondaryAddresses(REGION, NAT_ID, List.of(), List.of(), null);
+ assertEquals(NAT_ID, r.getPhysicalId());
+ }
+
+ /** An explicit empty list is a declaration: it asks for no secondary, and a template that never declared one still gets it. */
+ @Test
+ void anExplicitlyEmptySecondaryListClearsTheSecondariesAddedOutsideTheStack() {
+ ObjectNode props = publicNatProps();
+ props.putArray("SecondaryAllocationIds");
+ when(ec2.describeNatGateways(REGION, List.of(NAT_ID), Map.of()))
+ .thenReturn(List.of(natGatewayHoldingAnOutsideSecondary("public")));
+ when(ec2.updateNatGatewaySecondaryAddresses(REGION, NAT_ID, List.of(), List.of(), null))
+ .thenReturn(natGateway(NAT_ID, "eni-0123456789abcdef0", "10.0.1.50"));
+ StackResource r = prior("AWS::EC2::NatGateway", "Nat", NAT_ID, Map.of("NatGatewayId", NAT_ID));
+
+ provisioner.provision(r, props, ctx(NAT_ID, publicNatProps()));
+
+ verify(ec2).updateNatGatewaySecondaryAddresses(REGION, NAT_ID, List.of(), List.of(), null);
+ assertEquals(NAT_ID, r.getPhysicalId());
+ assertFalse(r.getAttributes().containsKey(CfnRollback.USES_ATTR_PREFIX + "SecondaryPublicIp.0"));
+ }
+
+ /**
+ * The three properties are one address set: a template that declares only the Elastic IP list
+ * manages the private-address and count properties too, so a secondary added outside the stack
+ * goes when the update brings the set to what the template says.
+ */
+ @Test
+ void aDeclaredSecondaryPropertyManagesTheWholeSetAndRemovesAnOutsideSecondary() {
+ String declaredAlloc = "eipalloc-0bbbbbbbbbbbbbbbb";
+ ObjectNode props = publicNatProps();
+ props.putArray("SecondaryAllocationIds").add(declaredAlloc);
+ NatGateway held = natGatewayHoldingAnOutsideSecondary("public");
+ NatGatewayAddress declared = new NatGatewayAddress();
+ declared.setPrimary(false);
+ declared.setNetworkInterfaceId("eni-0123456789abcdef0");
+ declared.setPrivateIp("10.0.1.81");
+ declared.setAllocationId(declaredAlloc);
+ declared.setPublicIp("203.0.113.81");
+ held.getNatGatewayAddresses().add(declared);
+ when(ec2.describeNatGateways(REGION, List.of(NAT_ID), Map.of())).thenReturn(List.of(held));
+ NatGateway reconciled = natGateway(NAT_ID, "eni-0123456789abcdef0", "10.0.1.50");
+ reconciled.getNatGatewayAddresses().add(declared);
+ when(ec2.updateNatGatewaySecondaryAddresses(REGION, NAT_ID, List.of(declaredAlloc), List.of(), null))
+ .thenReturn(reconciled);
+ StackResource r = prior("AWS::EC2::NatGateway", "Nat", NAT_ID, Map.of("NatGatewayId", NAT_ID));
+
+ provisioner.provision(r, props, ctx(NAT_ID, props));
+
+ verify(ec2).updateNatGatewaySecondaryAddresses(REGION, NAT_ID, List.of(declaredAlloc), List.of(), null);
+ assertEquals(NAT_ID, r.getPhysicalId());
+ assertEquals("203.0.113.81", r.getAttributes().get(CfnRollback.USES_ATTR_PREFIX + "SecondaryPublicIp.0"));
+ assertFalse(r.getAttributes().containsKey(CfnRollback.USES_ATTR_PREFIX + "SecondaryPublicIp.1"),
+ "the secondary added outside the stack is gone");
+ }
+
+ /** Declaring a secondary for the first time on a kept gateway brings the set to the template's. */
+ @Test
+ void aSecondaryDeclaredForTheFirstTimeOnAKeptGatewayIsAppliedInPlace() {
+ ObjectNode props = publicNatProps();
+ props.putArray("SecondaryAllocationIds").add(OUTSIDE_ALLOC);
+ NatGateway bare = natGateway(NAT_ID, "eni-0123456789abcdef0", "10.0.1.50");
+ bare.setSubnetId(SUBNET_ID);
+ bare.setAllocationId(ALLOC_ID);
+ bare.getNatGatewayAddresses().get(0).setAllocationId(ALLOC_ID);
+ when(ec2.describeNatGateways(REGION, List.of(NAT_ID), Map.of())).thenReturn(List.of(bare));
+ when(ec2.updateNatGatewaySecondaryAddresses(REGION, NAT_ID, List.of(OUTSIDE_ALLOC), List.of(), null))
+ .thenReturn(natGatewayHoldingAnOutsideSecondary("public"));
+ StackResource r = prior("AWS::EC2::NatGateway", "Nat", NAT_ID, Map.of("NatGatewayId", NAT_ID));
+
+ provisioner.provision(r, props, ctx(NAT_ID, publicNatProps()));
+
+ verify(ec2).updateNatGatewaySecondaryAddresses(REGION, NAT_ID, List.of(OUTSIDE_ALLOC), List.of(), null);
+ assertEquals(NAT_ID, r.getPhysicalId());
+ assertEquals(OUTSIDE_PUBLIC_IP, r.getAttributes().get(CfnRollback.USES_ATTR_PREFIX + "SecondaryPublicIp.0"));
+ }
+
@Test
void aPrivateNatGatewayPassesItsSecondaryAddressCount() {
when(ec2.createNatGateway(REGION, SUBNET_ID, null, "private", null, List.of(), List.of(), "2", List.of()))
diff --git a/src/test/resources/cloudformation/drop-policy.tsv b/src/test/resources/cloudformation/drop-policy.tsv
index bdf57e2cf3..703fa2adef 100644
--- a/src/test/resources/cloudformation/drop-policy.tsv
+++ b/src/test/resources/cloudformation/drop-policy.tsv
@@ -68,9 +68,9 @@ AWS::EC2::NatGateway AllocationId create-only a drop is refused for a public gat
AWS::EC2::NatGateway AvailabilityMode create-only a drop is accepted and skipped
AWS::EC2::NatGateway ConnectivityType create-only a drop reads as public, so a private gateway is replaced
AWS::EC2::NatGateway PrivateIpAddress keep:a drop keeps the address the gateway holds
-AWS::EC2::NatGateway SecondaryAllocationIds clear an update also clears it when the stack never declared it, so a value set outside the stack is lost
-AWS::EC2::NatGateway SecondaryPrivateIpAddressCount clear an update also clears it when the stack never declared it, so a value set outside the stack is lost
-AWS::EC2::NatGateway SecondaryPrivateIpAddresses clear an update also clears it when the stack never declared it, so a value set outside the stack is lost
+AWS::EC2::NatGateway SecondaryAllocationIds clear one address set with the other two Secondary* properties
+AWS::EC2::NatGateway SecondaryPrivateIpAddressCount clear one address set with the other two Secondary* properties
+AWS::EC2::NatGateway SecondaryPrivateIpAddresses clear one address set with the other two Secondary* properties
AWS::EC2::NatGateway SubnetId create-only a drop is refused
AWS::EC2::NatGateway Tags clear
AWS::EC2::PrefixList AddressFamily keep:required, a drop is refused