public void setupProvisioning(Stack stack) {
MDCBuilder.buildMdcContext(stack);
AwsTemplate awsTemplate = (AwsTemplate) stack.getTemplate();
AwsCredential awsCredential = (AwsCredential) stack.getCredential();
SnsTopic snsTopic = snsTopicRepository.findOneForCredentialInRegion(awsCredential.getId(), awsTemplate.getRegion());
if (snsTopic == null) {
LOGGER.info("There is no SNS topic created for credential '{}' in region {}. Creating topic now.", awsCredential.getId(),
awsTemplate.getRegion().name());
snsTopicManager.createTopicAndSubscribe(awsCredential, awsTemplate.getRegion());
} else if (!snsTopic.isConfirmed()) {
LOGGER.info(
"SNS topic found for credential '{}' in region {}, but the subscription is not confirmed. Trying to subscribe again [arn: {}, id: {}]",
awsCredential.getId(), awsTemplate.getRegion().name(), snsTopic.getTopicArn(), snsTopic.getId());
snsTopicManager.subscribeToTopic(awsCredential, awsTemplate.getRegion(), snsTopic.getTopicArn());
} else {
LOGGER.info("SNS topic found for credential '{}' in region {}. [arn: {}, id: {}]", awsCredential.getId(), awsTemplate.getRegion().name(),
snsTopic.getTopicArn(), snsTopic.getId());
LOGGER.info("Publishing {} event [StackId: '{}']", ReactorConfig.PROVISION_SETUP_COMPLETE_EVENT, stack.getId());
reactor.notify(ReactorConfig.PROVISION_SETUP_COMPLETE_EVENT, Event.wrap(new ProvisionSetupComplete(getCloudPlatform(), stack.getId())
.withSetupProperties(getSetupProperties(stack))
.withUserDataParams(getUserDataProperties(stack))
)