Search in sources :

Example 1 with CreateStackRequest

use of com.amazonaws.services.cloudformation.model.CreateStackRequest in project pipeline-aws-plugin by jenkinsci.

the class CloudFormationStack method create.

public void create(String templateBody, String templateUrl, Collection<Parameter> params, Collection<Tag> tags, Integer timeoutInMinutes, long pollIntervallMillis, String roleArn, String onFailure) throws ExecutionException {
    if ((templateBody == null || templateBody.isEmpty()) && (templateUrl == null || templateUrl.isEmpty())) {
        throw new IllegalArgumentException("Either a file or url for the template must be specified");
    }
    CreateStackRequest req = new CreateStackRequest();
    req.withStackName(this.stack).withCapabilities(Capability.CAPABILITY_IAM, Capability.CAPABILITY_NAMED_IAM);
    req.withTemplateBody(templateBody).withTemplateURL(templateUrl).withParameters(params).withTags(tags).withTimeoutInMinutes(timeoutInMinutes).withRoleARN(roleArn).withOnFailure(OnFailure.valueOf(onFailure));
    this.client.createStack(req);
    new EventPrinter(this.client, this.listener).waitAndPrintStackEvents(this.stack, this.client.waiters().stackCreateComplete(), pollIntervallMillis);
}
Also used : CreateStackRequest(com.amazonaws.services.cloudformation.model.CreateStackRequest)

Example 2 with CreateStackRequest

use of com.amazonaws.services.cloudformation.model.CreateStackRequest in project cloudbreak by hortonworks.

the class AwsCreateVpcNetworkTest method createNetwork.

@Test
@Parameters({ "networkName", "description", "publicInAccount", "regionName", "vpcStackName", "vpcName", "existingSubnet" })
public void createNetwork(String networkName, @Optional("") String description, @Optional("false") boolean publicInAccount, String regionName, @Optional("it-vpc-stack") String vpcStackName, @Optional("it-vpc") String vpcName, boolean existingSubnet) {
    AmazonCloudFormationClient client = new AmazonCloudFormationClient();
    client.setRegion(RegionUtils.getRegion(regionName));
    Map<String, Object> networkMap = new HashMap<>();
    String vpcCreationJson = existingSubnet ? "public_vpc_with_subnet.json" : "public_vpc_wihout_subnet.json";
    try (InputStream vpcJsonInputStream = getClass().getResourceAsStream("/cloudformation/" + vpcCreationJson)) {
        String vpcCFTemplateString = IOUtils.toString(vpcJsonInputStream);
        CreateStackRequest stackRequest = createStackRequest(vpcStackName, vpcName, vpcCFTemplateString);
        client.createStack(stackRequest);
        List<Output> outputForRequest = getOutputForRequest(vpcStackName, client);
        if (existingSubnet) {
            networkMap.put("vpcId", outputForRequest.get(0).getOutputValue());
            networkMap.put("subnetId", outputForRequest.get(1).getOutputValue());
        } else {
            networkMap.put("vpcId", outputForRequest.get(1).getOutputValue());
            networkMap.put("internetGatewayId", outputForRequest.get(0).getOutputValue());
        }
    } catch (IOException e) {
        LOGGER.error("can't read vpc cloudformation template file");
        throw new RuntimeException(e);
    }
    NetworkRequest networkRequest = new NetworkRequest();
    networkRequest.setName(networkName);
    networkRequest.setDescription(description);
    networkRequest.setParameters(networkMap);
    if (!existingSubnet) {
        networkRequest.setSubnetCIDR("10.0.0.0/24");
    }
    networkRequest.setCloudPlatform("AWS");
    String id = getCloudbreakClient().networkEndpoint().postPrivate(networkRequest).getId().toString();
    getItContext().putContextParam(CloudbreakITContextConstants.NETWORK_ID, id, true);
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) Output(com.amazonaws.services.cloudformation.model.Output) NetworkRequest(com.sequenceiq.cloudbreak.api.model.NetworkRequest) IOException(java.io.IOException) AmazonCloudFormationClient(com.amazonaws.services.cloudformation.AmazonCloudFormationClient) CreateStackRequest(com.amazonaws.services.cloudformation.model.CreateStackRequest) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 3 with CreateStackRequest

use of com.amazonaws.services.cloudformation.model.CreateStackRequest in project cloudbreak by hortonworks.

the class AwsCreateVpcNetworkTest method createStackRequest.

private CreateStackRequest createStackRequest(String vpcStackName, String vpcName, String vpcCFTemplateString) {
    CreateStackRequest createStackRequest = new CreateStackRequest();
    Parameter vpcNameParameter = new Parameter();
    vpcNameParameter.setParameterKey("VpcName");
    vpcNameParameter.setParameterValue(vpcName);
    createStackRequest.withParameters(vpcNameParameter);
    createStackRequest.withStackName(vpcStackName);
    createStackRequest.withTemplateBody(vpcCFTemplateString);
    return createStackRequest;
}
Also used : Parameter(com.amazonaws.services.cloudformation.model.Parameter) CreateStackRequest(com.amazonaws.services.cloudformation.model.CreateStackRequest)

Aggregations

CreateStackRequest (com.amazonaws.services.cloudformation.model.CreateStackRequest)3 AmazonCloudFormationClient (com.amazonaws.services.cloudformation.AmazonCloudFormationClient)1 Output (com.amazonaws.services.cloudformation.model.Output)1 Parameter (com.amazonaws.services.cloudformation.model.Parameter)1 NetworkRequest (com.sequenceiq.cloudbreak.api.model.NetworkRequest)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Parameters (org.testng.annotations.Parameters)1 Test (org.testng.annotations.Test)1