From cae1609f12b138c16495fc47c333fcff6dd8da06 Mon Sep 17 00:00:00 2001 From: John Trimble Date: Mon, 18 Nov 2013 17:23:16 -0700 Subject: [PATCH] Fixes issue #12 - Added support for AWS's new Capabilities parameter. Added FAQ to document some unexpected consequences of this AWS API change. --- README.md | 11 ++++++++++ .../maven/plugins/CreateStackMojo.groovy | 22 +++++++++++++++++-- pom.xml | 2 +- 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..4ec498c --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +## FAQ +### Why do I get an "Requires capabilities : [CAPABILITY_IAM]" error when creating a stack? +On 11/8/2013, Amazon updated the CreateStack operation to take an optional `Capabilities` parameter which should be set to `CAPABILITY_IAM` if the given template creates any IAM resources. However, it appears that even when a template does not contain any IAM resources that it is sometimes necessary to set the `Capabilities` parameter to `CAPABILITY_IAM` anyways. To do so, add the following configuration for the plugin to the POM.xml: + +``` + + CAPABILITY_IAM + +``` + +This should work even if the AWS account used by the plugin does not have any IAM permissions, so long as the template does not actually specify any IAM resources. \ No newline at end of file diff --git a/molior-maven-plugin/src/main/groovy/com/github/johntrimble/molior/maven/plugins/CreateStackMojo.groovy b/molior-maven-plugin/src/main/groovy/com/github/johntrimble/molior/maven/plugins/CreateStackMojo.groovy index dfb42ef..e90ec71 100644 --- a/molior-maven-plugin/src/main/groovy/com/github/johntrimble/molior/maven/plugins/CreateStackMojo.groovy +++ b/molior-maven-plugin/src/main/groovy/com/github/johntrimble/molior/maven/plugins/CreateStackMojo.groovy @@ -80,6 +80,13 @@ class CreateStackMojo extends AbstractMojo { @MojoParameter(defaultValue='30') public int cloudFormationTimeout + /** + * The list of capabilities for the stack. You should include CAPABILITY_IAM if + * you're creating any IAM resources in this stack. + */ + @MojoParameter + public List capabilities + void execute() throws MojoExecutionException, MojoFailureException { if( !stackName ) stackName = "${stackNamePrefix}${new Date().format('yyyyMMddHHmmss')}" @@ -92,9 +99,20 @@ class CreateStackMojo extends AbstractMojo { // Create stack parameters List cfParameters = [] this.parameters.collect cfParameters, { key, value -> new Parameter(parameterKey:key, parameterValue: value) } - + + // Get capabilities + List capabilities = this.capabilities ?: [] + + // Build stack request + def stackRequest = new CreateStackRequest( + stackName:stackName, + templateBody:template.text, + timeoutInMinutes: cloudFormationTimeout, + parameters: cfParameters, + capabilities: capabilities) + // Create stack - String stackId = cloudFormation.createStack(new CreateStackRequest(stackName:stackName, templateBody:template.text, timeoutInMinutes: cloudFormationTimeout, parameters: cfParameters)).stackId + String stackId = cloudFormation.createStack(stackRequest).stackId log.info "Creating stack: ${stackId}" // Poll stack until created diff --git a/pom.xml b/pom.xml index e97fd56..dfceb74 100644 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,7 @@ com.amazonaws aws-java-sdk - 1.3.27 + 1.6.6