Skip to content

Commit 9213b1a

Browse files
committed
Fix for AlreadyExists
1 parent b9cfe28 commit 9213b1a

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@
295295
<java>
296296
<!-- this automatically inserts line breaks, so apply it before eclipse formatter! -->
297297
<importOrder>
298-
<order>com,edu,java,lombok,javax,org,software</order>
298+
<order>com,edu,java,javax,lombok,org,software</order>
299299
</importOrder>
300300
<removeUnusedImports/>
301301
<eclipse>

src/main/java/software/amazon/cloudformation/AbstractWrapper.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ public void processRequest(final InputStream inputStream, final OutputStream out
326326
if (request.getRequestData().getCallerCredentials() != null) {
327327
awsClientProxy = new AmazonWebServicesClientProxy(this.loggerProxy, request.getRequestData().getCallerCredentials(),
328328
DelayFactory.CONSTANT_DEFAULT_DELAY_FACTORY,
329-
WaitStrategy.scheduleForCallbackStrategy());
329+
WaitStrategy.scheduleForCallbackStrategy(),
330+
request.getStackId() != null);
330331
}
331332

332333
ProgressEvent<ResourceT, CallbackT> handlerResponse = wrapInvocationAndHandleErrors(awsClientProxy,

src/main/java/software/amazon/cloudformation/HookAbstractWrapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ private ProgressEvent<TargetT, CallbackT> processInvocation(final JSONObject raw
249249
if (processedCallerCredentials != null) {
250250
awsClientProxy = new AmazonWebServicesClientProxy(this.loggerProxy, processedCallerCredentials,
251251
DelayFactory.CONSTANT_DEFAULT_DELAY_FACTORY,
252-
WaitStrategy.scheduleForCallbackStrategy());
252+
WaitStrategy.scheduleForCallbackStrategy(), true);
253253

254254
}
255255

src/main/java/software/amazon/cloudformation/proxy/AmazonWebServicesClientProxy.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import java.util.function.Function;
3232
import java.util.function.Supplier;
3333
import javax.annotation.Nonnull;
34+
import lombok.Getter;
35+
import lombok.Setter;
3436
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
3537
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
3638
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
@@ -66,6 +68,9 @@ public class AmazonWebServicesClientProxy implements CallChain {
6668
private final LoggerProxy loggerProxy;
6769
private final DelayFactory override;
6870
private final WaitStrategy waitStrategy;
71+
@Getter
72+
@Setter
73+
private Boolean invokedByCfn;
6974

7075
public AmazonWebServicesClientProxy(final LoggerProxy loggerProxy,
7176
final Credentials credentials,
@@ -77,13 +82,14 @@ public AmazonWebServicesClientProxy(final LoggerProxy loggerProxy,
7782
final Credentials credentials,
7883
final Supplier<Long> remainingTimeToExecute,
7984
final DelayFactory override) {
80-
this(loggerProxy, credentials, override, WaitStrategy.newLocalLoopAwaitStrategy(remainingTimeToExecute));
85+
this(loggerProxy, credentials, override, WaitStrategy.newLocalLoopAwaitStrategy(remainingTimeToExecute), null);
8186
}
8287

8388
public AmazonWebServicesClientProxy(final LoggerProxy loggerProxy,
8489
final Credentials credentials,
8590
final DelayFactory override,
86-
final WaitStrategy waitStrategy) {
91+
final WaitStrategy waitStrategy,
92+
final Boolean invokedByCfn) {
8793
this.loggerProxy = loggerProxy;
8894
BasicSessionCredentials basicSessionCredentials = new BasicSessionCredentials(credentials.getAccessKeyId(),
8995
credentials.getSecretAccessKey(),
@@ -95,6 +101,7 @@ public AmazonWebServicesClientProxy(final LoggerProxy loggerProxy,
95101
this.v2CredentialsProvider = StaticCredentialsProvider.create(awsSessionCredentials);
96102
this.override = Objects.requireNonNull(override);
97103
this.waitStrategy = Objects.requireNonNull(waitStrategy);
104+
this.invokedByCfn = invokedByCfn;
98105
}
99106

100107
public <ClientT> ProxyClient<ClientT> newProxy(@Nonnull Supplier<ClientT> client) {
@@ -331,6 +338,15 @@ public Completed<RequestT, ResponseT, ClientT, ModelT, CallbackT> handleError(Ex
331338
do {
332339
try {
333340
event = inner.invoke(request, ex, client_, model_, context_);
341+
342+
//
343+
// Ensure that we null out model for AlreadyExists to meet CFN IaC expectations
344+
//
345+
if (event.getErrorCode() == HandlerErrorCode.AlreadyExists
346+
&& AmazonWebServicesClientProxy.this.invokedByCfn) {
347+
event.setResourceModel(null);
348+
}
349+
334350
} catch (RetryableException e) {
335351
break;
336352
} catch (Exception e) {

src/main/java/software/amazon/cloudformation/proxy/hook/targetmodel/HookTargetModel.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
import java.util.HashMap;
2626
import java.util.Map;
2727
import java.util.Map.Entry;
28+
import javax.annotation.CheckForNull;
2829
import lombok.AccessLevel;
2930
import lombok.Data;
3031
import lombok.NonNull;
3132
import lombok.Setter;
32-
import javax.annotation.CheckForNull;
3333
import org.json.JSONObject;
3434
import software.amazon.cloudformation.resource.Serializer;
3535

0 commit comments

Comments
 (0)