}
@Override
public void buildStack(Stack stack, String userData, Map<String, Object> setupProperties) {
MDCBuilder.buildMdcContext(stack);
AwsTemplate awsTemplate = (AwsTemplate) stack.getTemplate();
AwsCredential awsCredential = (AwsCredential) stack.getCredential();
AmazonCloudFormationClient client = awsStackUtil.createCloudFormationClient(awsTemplate.getRegion(), awsCredential);
String stackName = String.format("%s-%s", stack.getName(), stack.getId());
boolean spotPriced = awsTemplate.getSpotPrice() == null ? false : true;
List<Parameter> parameters = new ArrayList<>(Arrays.asList(
new Parameter().withParameterKey("SSHLocation").withParameterValue(awsTemplate.getSshLocation()),
new Parameter().withParameterKey("CBUserData").withParameterValue(userData),
new Parameter().withParameterKey("StackName").withParameterValue(stackName),
new Parameter().withParameterKey("StackOwner").withParameterValue(awsCredential.getRoleArn()),
new Parameter().withParameterKey("InstanceCount").withParameterValue(stack.getNodeCount().toString()),
new Parameter().withParameterKey("InstanceType").withParameterValue(awsTemplate.getInstanceType().toString()),
new Parameter().withParameterKey("KeyName").withParameterValue(awsCredential.getKeyPairName()),
new Parameter().withParameterKey("AMI").withParameterValue(awsTemplate.getAmiId()),
new Parameter().withParameterKey("VolumeSize").withParameterValue(awsTemplate.getVolumeSize().toString()),
new Parameter().withParameterKey("VolumeType").withParameterValue(awsTemplate.getVolumeType().toString())));
if (spotPriced) {
parameters.add(new Parameter().withParameterKey("SpotPrice").withParameterValue(awsTemplate.getSpotPrice().toString()));
}
CreateStackRequest createStackRequest = createStackRequest()
.withStackName(stackName)
.withTemplateBody(cfTemplateBuilder.build("templates/aws-cf-stack.ftl", awsTemplate.getVolumeCount(), spotPriced))
.withNotificationARNs((String) setupProperties.get(SnsTopicManager.NOTIFICATION_TOPIC_ARN_KEY))
.withParameters(parameters);
client.createStack(createStackRequest);
Set<Resource> resources = new HashSet<>();
resources.add(new Resource(ResourceType.CLOUDFORMATION_STACK, stackName, stack));