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);
}
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);
}
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;
}
Aggregations