com.carrotgarden.maven.aws.cfn.CloudFormCreateStack Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of carrot-maven-aws-plugin Show documentation
Show all versions of carrot-maven-aws-plugin Show documentation
${project.organization.name} AWS Maven Plugin
/**
* Copyright (C) 2010-2012 Andrei Pozolotin
*
* All rights reserved. Licensed under the OSI BSD License.
*
* http://www.opensource.org/licenses/bsd-license.php
*/
package com.carrotgarden.maven.aws.cfn;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.maven.plugin.MojoFailureException;
import com.amazonaws.services.cloudformation.model.Output;
import com.amazonaws.services.cloudformation.model.Stack;
import com.amazonaws.services.cloudformation.model.StackStatus;
import com.carrotgarden.maven.aws.util.Util;
/**
* cloud formation:
*
* create stack
*
* based on:
*
* stack name,
*
* stack
* template
*
* ({@link #stackTemplateFile}),
*
* stack parameters
*
* ({@link #stackPropertiesInputFile} + {@link #stackInputParams}),
*
* and produce a
*
* stack output
*
* ({@link #stackPropertiesOutputFile})
*
* as well as inject output into into project.properties
*
* ; wait for completion or fail ({@link #stackTimeout});
*
* @goal cloud-formation-create
*
* @phase prepare-package
*
* @inheritByDefault true
*
* @requiresDependencyResolution test
*
*/
public class CloudFormCreateStack extends CloudForm {
/**
* AWS CloudFormation
*
* template
*
* file
*
* @required
* @parameter default-value="./target/formation/formation.template"
*/
protected File stackTemplateFile;
/**
* AWS CloudFormation
*
* Parameters Declaration
*
* stack template input parameters; optional; overrides settings from
* #stackPropertiesInputFile
*
* @parameter
*/
protected Map stackInputParams = new HashMap();
/**
* AWS CloudFormation stack create execution
*
* Parameters Declaration
*
* input properties file;
*
* will be overridden by #stackInputParams if any
*
* @parameter default-value="./target/formation/formation-input.properties"
*/
protected File stackPropertiesInputFile;
/**
* AWS CloudFormation stack create execution result
*
* Outputs Section
*
* output properties file
*
* @parameter default-value="./target/formation/formation-output.properties"
*/
protected File stackPropertiesOutputFile;
/**
* should inject stack operation output into the project.properties?
*
* @parameter default-value="true"
*/
protected boolean stackIsInjectOutputProperties;
/**
* should persist stack operation output into
* {@link #stackPropertiesOutputFile}
*
* @parameter default-value="true"
*/
protected boolean stackIsPersistOutputProperties;
/**
* {@inheritDoc}
*/
@Override
public void execute() throws MojoFailureException {
try {
getLog().info("stack create init [" + stackName() + "]");
final Properties stackInputProps = Util.propsLoad(getLog(),
stackPropertiesInputFile);
final Map pluginProps = mergePluginProps(
stackInputProps, stackInputParams);
final Map stackTemplateParams = loadTemplateParameters(
stackTemplateFile, pluginProps);
final CarrotCloudForm formation = newCloudFormation(
stackTemplateFile, stackTemplateParams);
formation.logParamList();
final Stack stack = formation.stackCreate();
final StackStatus status = StackStatus.fromValue(stack
.getStackStatus());
switch (status) {
case CREATE_COMPLETE:
break;
default:
throw new IllegalStateException("stack create failed");
}
//
getLog().info("stack create stack=\n" + stack);
getLog().info("stack create output:");
final List