classmethod/gradle-aws-plugin

Throw in `AmazonCloudFormationPluginExtension` if stacks cannot be described

tellary opened this issue · 3 comments

We need to distinguish the following 3 outcomes of the getStack call:

  1. Stack found by name.
  2. Stack with this name doesn't exist.
  3. Unable to get stack.

The 3rd outcome should be represented by an exception.

The getStack method currently logs an exception at debug (!) level and returns an empty Optional. This leads us to inability to distinguish whatever the stack doesn't exist or we aren't able to get it. In the later case we just want to terminate Gradle execution.

For example, we want to see simply the following in the gradle --stacktrace output if a user cannot authenticate to describe a stack:

com.amazonaws.AmazonClientException: Unable to load AWS credentials from any provider in the chain
    at com.amazonaws.auth.AWSCredentialsProviderChain.getCredentials(AWSCredentialsProviderChain.java:131)
    ...
    at com.amazonaws.services.cloudformation.AmazonCloudFormationClient.describeStacks(AmazonCloudFormationClient.java:943)
    at jp.classmethod.aws.gradle.cloudformation.AmazonCloudFormationPluginExtension.getStack(AmazonCloudFormationPluginExtension.java:112)
    at jp.classmethod.aws.gradle.cloudformation.AmazonCloudFormationPluginExtension$getStack.call(Unknown Source)
    at build_b3pyhnx70z64rtnyfr59mg5hm$_run_closure4.doCall(/ssd/git/gw/loginservice/BuildInfo/build.gradle:50)
    ...

I'm about to submit a pull request that removes all occurences of try/catch and return empty behavior.

Also, could you please clarify the purpose of returning empty Optional if Gradle is offline? What is the following if statement for in AmazonCloudFormationPluginExtension?

public Optional<Stack> getStack(String stackName) {
    if (getProject().getGradle().getStartParameter().isOffline() == false) {

I didn't carefully learn how describeStacks works: it throws AmazonCloudFormationException with errorCode equal to "ValidationError" if a stack doesn't exist. A quote from Javadoc:

If the stack does not exist, an AmazonCloudFormationException is returned.

This leads to an error when getStack throws if no stack exists, but I want it to return an empty Optionals if there is no stack.

I'm about to fix this such that an empty Optional is returned by the getStack method. I'm investigating if this also affects getStackResources method.

The getStackResources methods behaves the same if stack doesn't exist:

    ...
Caused by: com.amazonaws.services.cloudformation.model.AmazonCloudFormationException: Stack with id unexistent does not exist (Service: AmazonCloudFormation; Status Code: 400; Error Code: ValidationError; Request ID: ab9a4990-d6ec-11e6-ac3c-efb5617f0d47)
    ...
    at com.amazonaws.services.cloudformation.AmazonCloudFormationClient.describeStackResources(AmazonCloudFormationClient.java:778)
    at jp.classmethod.aws.gradle.cloudformation.AmazonCloudFormationPluginExtension.getStackResources(AmazonCloudFormationPluginExtension.java:172)
    ...

The problem is fixed in 4ce1078, I wait for the pull request #89 to be merged, then I will issue a pull request for this commit as it's based on the #89.