Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow choice of rollback/delete/donothing on stack creation failure #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.amazonaws.services.cloudformation.model.DescribeStackEventsResult;
import com.amazonaws.services.cloudformation.model.DescribeStacksRequest;
import com.amazonaws.services.cloudformation.model.DescribeStacksResult;
import com.amazonaws.services.cloudformation.model.OnFailure;
import com.amazonaws.services.cloudformation.model.Parameter;
import com.amazonaws.services.cloudformation.model.Stack;
import com.amazonaws.services.cloudformation.model.StackEvent;
Expand Down Expand Up @@ -72,6 +73,7 @@ public CarrotCloudForm(final Logger logger, final String stackName,
this.endpoint = endpoint;

this.waitBetweenAttempts = 10; // query every 10s


this.amazonClient = newClient(); // keep last

Expand Down Expand Up @@ -219,13 +221,14 @@ private void sleep() throws Exception {

/**
*/
public Stack stackCreate() throws Exception {
public Stack stackCreate(final OnFailure onFailure) throws Exception {

final CreateStackRequest request = new CreateStackRequest();

request.withStackName(name);
request.withParameters(paramList);
request.withTemplateBody(template);
request.setOnFailure(onFailure);

amazonClient.createStack(request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import org.apache.maven.plugin.MojoFailureException;

import com.amazonaws.services.cloudformation.model.OnFailure;
import com.amazonaws.services.cloudformation.model.Output;
import com.amazonaws.services.cloudformation.model.Stack;
import com.amazonaws.services.cloudformation.model.StackStatus;
Expand Down Expand Up @@ -136,6 +137,11 @@ public class CloudFormCreateStack extends CloudForm {
* @parameter default-value="true"
*/
protected boolean stackIsPersistOutputProperties;

/**
* @parameter default-value="ROLLBACK"
*/
protected OnFailure onFailure;

/**
* {@inheritDoc}
Expand All @@ -161,7 +167,7 @@ public void execute() throws MojoFailureException {

formation.logParamList();

final Stack stack = formation.stackCreate();
final Stack stack = formation.stackCreate(onFailure);

final StackStatus status = StackStatus.fromValue(stack
.getStackStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.cloudformation.model.OnFailure;

public class TestCarrotCloudForm {

Expand Down Expand Up @@ -49,7 +50,7 @@ public void testStack() throws Exception {
final CarrotCloudForm formation = new CarrotCloudForm(logger, stackName,
stackTemplate, stackParams, timeout, credentials, null);

formation.stackCreate();
formation.stackCreate(OnFailure.ROLLBACK);

assertTrue(true);

Expand Down