Example usage for com.amazonaws.services.cloudformation.model ValidateTemplateResult getParameters

List of usage examples for com.amazonaws.services.cloudformation.model ValidateTemplateResult getParameters

Introduction

In this page you can find the example usage for com.amazonaws.services.cloudformation.model ValidateTemplateResult getParameters.

Prototype


public java.util.List<TemplateParameter> getParameters() 

Source Link

Document

A list of TemplateParameter structures.

Usage

From source file:br.com.ingenieux.mojo.cloudformation.PushStackMojo.java

License:Apache License

@Override
protected Object executeInternal() throws Exception {
    shouldFailIfMissingStack(failIfMissing);

    if (!templateLocation.exists() && !templateLocation.isFile()) {
        getLog().warn("File not found (or not a file): " + templateLocation.getPath() + ". Skipping.");

        return null;
    }//from  w ww. j  av a 2 s.c  o  m

    if (isNotBlank(s3Url)) {
        getLog().info("Uploading file " + this.templateLocation + " to location " + this.s3Url);

        s3Client = new BeanstalkerS3Client(getAWSCredentials(), getClientConfiguration(), getRegion());

        s3Client.setMultipartUpload(false);

        this.destinationS3Uri = new AmazonS3URI(s3Url);

        uploadContents(templateLocation, destinationS3Uri);
    } else {
        templateBody = IOUtils.toString(new FileInputStream(this.templateLocation));
    }

    {
        ValidateTemplateResult validateTemplateResult = validateTemplate();

        if (!validateTemplateResult.getParameters().isEmpty()) {
            Set<String> existingParameterNames = this.parameters.stream().map(x -> x.getParameterKey())
                    .collect(Collectors.toSet());

            Set<String> requiredParameterNames = validateTemplateResult.getParameters().stream()
                    .map(x -> x.getParameterKey()).collect(Collectors.toSet());

            for (String requiredParameter : requiredParameterNames) {
                if (!existingParameterNames.contains(requiredParameter)) {
                    getLog().warn("Missing required parameter name: " + requiredParameter);
                    getLog().warn("If its an update, will reuse previous value");
                }

                this.parameters.add(new com.amazonaws.services.cloudformation.model.Parameter()
                        .withParameterKey(requiredParameter).withUsePreviousValue(true));
            }
        }
    }

    WaitForStackCommand.WaitForStackContext ctx = null;

    Object result = null;

    if (null == stackSummary) {
        getLog().info("Must Create Stack");

        CreateStackResult createStackResult;
        result = createStackResult = createStack();

        ctx = new WaitForStackCommand.WaitForStackContext(createStackResult.getStackId(), getService(),
                this::info, 30, asList(StackStatus.CREATE_COMPLETE));

    } else {
        getLog().info("Must Update Stack");

        UpdateStackResult updateStackResult;

        result = updateStackResult = updateStack();

        if (null != result) {

            ctx = new WaitForStackCommand.WaitForStackContext(updateStackResult.getStackId(), getService(),
                    this::info, 30, asList(StackStatus.UPDATE_COMPLETE));
        }
    }

    if (null != ctx)
        new WaitForStackCommand(ctx).execute();

    return result;
}

From source file:com.deploymentio.cfnstacker.CloudFormationClient.java

License:Apache License

/**
 * Validates the stack template with CloudFormation and ensure that values
 * were provided for all required parameters
 * /*  w  w w  .  j a  v  a2  s.c  o m*/
 * @param templateBody ClouadFormation JSON template
 * @param options options needed to validate the stack template
 * @return <code>true</code> if the stack is valid, <code>false</code>
 *         otherwise
 */
public boolean validateTemplate(JsonNode templateBody) throws Exception {

    boolean allOK = true;
    Map<String, JsonNode> stackProperties = config.getParameters();
    ValidateTemplateResult validationResult = client.validateTemplate(new ValidateTemplateRequest()
            .withTemplateURL(uploadCfnTemplateToS3(config.getName(), "validate", templateBody)));

    // check if the template has any parameters without defaults for which no stack properties were provided
    for (TemplateParameter param : validationResult.getParameters()) {
        String key = param.getParameterKey();
        if (StringUtils.isEmpty(param.getDefaultValue())) {
            JsonNode value = stackProperties.get(key);
            if (value == null) {
                logger.error("Missing template parameter value: Key=" + key);
                allOK = false;
            } else if (value.isContainerNode()) {
                logger.error("Template parameter can only be a scaler value: Key=" + key);
                allOK = false;
            }
        }
    }

    return allOK;
}

From source file:org.xmlsh.aws.cfnValidateTemplate.java

License:BSD License

private void writeResult(ValidateTemplateResult result) throws XMLStreamException {
    startElement("template");

    attribute("capabilities-reason", result.getCapabilitiesReason());
    attribute("description", result.getDescription());

    writeTemplateParameters(result.getParameters());

    writeCapibilities(result.getCapabilities());
    endElement();//from www.ja v  a2s . c  o  m

}