Java源码示例:com.amazonaws.services.cloudformation.model.Parameter

示例1
private static void saveStackInputProperties(String stackName) throws Exception {
    LOGGER.info("Save some stack inputs to file test.props for stack: " + stackName);
    try (BufferedWriter writer = new BufferedWriter(new FileWriter(new File("mdlt/conf/test.props"), true))) {

        CloudFormationClient cfClient = new CloudFormationClient(stackName);
        List<Parameter> stackInputParameters = cfClient.getStackByName(stackName).getParameters();
        Parameter env = stackInputParameters.stream()
            .filter(parameter -> parameter.getParameterKey().equals(StackInputParameterKeyEnum.ENVIRONMENT.getKey()))
            .findFirst().get();

        writer.write(env.getParameterKey() + "=" + env.getParameterValue());
        writer.newLine();

        Parameter instanceName = stackInputParameters.stream()
            .filter(parameter -> parameter.getParameterKey().equals(StackInputParameterKeyEnum.MDL_INSTANCE_NAME.getKey()))
            .findFirst().get();
        writer.write(StackInputParameterKeyEnum.MDL_INSTANCE_NAME.getKey() + "=" + instanceName.getParameterValue());
        writer.newLine();
    }
}
 
示例2
@Override
public Collection<Parameter> parseParams(InputStream fileContent) throws IOException {
	ObjectMapper mapper = new ObjectMapper();
	JsonNode tree = mapper.readTree(fileContent);
	Collection<Parameter> parameters = new ArrayList<>();
	if (tree instanceof ArrayNode) {
		ArrayNode jsonNodes = (ArrayNode) tree;
		for (JsonNode node : jsonNodes) {
			Parameter param = new Parameter();
			param.withParameterKey(node.get("ParameterKey").asText());
			if (node.has("ParameterValue")) {
				param.withParameterValue(node.get("ParameterValue").asText());
			}
			if (node.has("UsePreviousValue")) {
				param.withUsePreviousValue(node.get("UsePreviousValue").booleanValue());
			}
			parameters.add(param);
		}
	}
	return parameters;
}
 
示例3
private static Collection<Parameter> parseParamsFile(FilePath workspace, String paramsFileName) {
	try {
		if (paramsFileName == null) {
			return Collections.emptyList();
		}
		final ParameterFileParser parser;
		FilePath paramsFile = workspace.child(paramsFileName);
		if (paramsFile.getName().endsWith(".json")) {
			parser = new JSONParameterFileParser();
		} else if (paramsFile.getName().endsWith(".yaml")) {
			parser = new YAMLParameterFileParser();
		} else {
			throw new IllegalArgumentException("Invalid file extension for parameter file (supports json/yaml)");
		}
		return parser.parseParams(paramsFile.read());
	} catch (Exception e) {
		throw new IllegalArgumentException(e);
	}
}
 
示例4
@Override
public Collection<Parameter> parseParams(InputStream fileContent) throws IOException {
	Yaml yaml = new Yaml(new SafeConstructor());
	@SuppressWarnings("unchecked")
	Map<String, Object> parse = yaml.load(new InputStreamReader(fileContent, Charsets.UTF_8));

	Collection<Parameter> parameters = new ArrayList<>();
	for (Map.Entry<String, Object> entry : parse.entrySet()) {
		Object value = entry.getValue();
		if (value instanceof Collection) {
			String val = Joiner.on(",").join((Collection) value);
			parameters.add(new Parameter().withParameterKey(entry.getKey()).withParameterValue(val));
		} else {
			parameters.add(new Parameter().withParameterKey(entry.getKey()).withParameterValue(value.toString()));
		}
	}
	return parameters;
}
 
示例5
public Map<String, String> create(String templateBody, String templateUrl, Collection<Parameter> params, Collection<Tag> tags, Collection<String> notificationARNs, PollConfiguration pollConfiguration, String roleArn, String onFailure, Boolean enableTerminationProtection) 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, Capability.CAPABILITY_AUTO_EXPAND).withEnableTerminationProtection(enableTerminationProtection);
	req.withTemplateBody(templateBody).withTemplateURL(templateUrl).withParameters(params).withTags(tags).withNotificationARNs(notificationARNs)
			.withTimeoutInMinutes(pollConfiguration.getTimeout() == null ? null : (int) pollConfiguration.getTimeout().toMinutes())
			.withRoleARN(roleArn)
			.withOnFailure(OnFailure.valueOf(onFailure));
	this.client.createStack(req);

	new EventPrinter(this.client, this.listener).waitAndPrintStackEvents(this.stack, this.client.waiters().stackCreateComplete(), pollConfiguration);

	Map<String, String> outputs = this.describeOutputs();
	outputs.put(UPDATE_STATUS_OUTPUT, "true");
	return outputs;
}
 
示例6
public CreateStackSetResult create(String templateBody, String templateUrl, Collection<Parameter> params, Collection<Tag> tags, String administratorRoleArn, String executionRoleName) {
	if ((templateBody == null || templateBody.isEmpty()) && (templateUrl == null || templateUrl.isEmpty())) {
		throw new IllegalArgumentException("Either a file or url for the template must be specified");
	}

	this.listener.getLogger().println("Creating stack set " + this.stackSet);
	CreateStackSetRequest req = new CreateStackSetRequest()
		.withStackSetName(this.stackSet)
		.withCapabilities(Capability.CAPABILITY_IAM, Capability.CAPABILITY_NAMED_IAM, Capability.CAPABILITY_AUTO_EXPAND)
		.withTemplateBody(templateBody)
		.withTemplateURL(templateUrl)
		.withParameters(params)
		.withAdministrationRoleARN(administratorRoleArn)
		.withExecutionRoleName(executionRoleName)
		.withTags(tags);
	CreateStackSetResult result = this.client.createStackSet(req);
	this.listener.getLogger().println("Created Stack set stackSetId=" + result.getStackSetId());
	return result;
}
 
示例7
@Test
public void test() {
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String stackName = "fargate-cluster-" + this.random8String();
    final String classB = "10";
    try {
        this.createStack(vpcStackName,
                "vpc/vpc-2azs.yaml",
                new Parameter().withParameterKey("ClassB").withParameterValue(classB)
        );
        try {
            this.createStack(stackName,
                    "fargate/cluster.yaml",
                    new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName)
            );
        } finally {
            this.deleteStack(stackName);
        }
    } finally {
        this.deleteStack(vpcStackName);
    }
}
 
示例8
@Test
public void test() {
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String endpointStackName = "vpc-endpoint-dynamodb-" + this.random8String();
    final String classB = "10";
    try {
        this.createStack(vpcStackName,
                "vpc/vpc-2azs.yaml",
                new Parameter().withParameterKey("ClassB").withParameterValue(classB)
        );
        try {
            this.createStack(endpointStackName,
                    "vpc/vpc-endpoint-dynamodb.yaml",
                    new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName)
            );
            // TODO how can we check if this stack works?
        } finally {
            this.deleteStack(endpointStackName);
        }
    } finally {
        this.deleteStack(vpcStackName);
    }
}
 
示例9
@Test
public void createNonExistantStackWithCustomAdminArn() throws Exception {
	WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "testStepWithGlobalCredentials");
	Mockito.when(stackSet.exists()).thenReturn(false);
	job.setDefinition(new CpsFlowDefinition(""
			+ "node {\n"
			+ "  cfnUpdateStackSet(stackSet: 'foo', administratorRoleArn: 'bar', executionRoleName: 'baz')"
			+ "}\n", true)
	);
	jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));

	PowerMockito.verifyNew(CloudFormationStackSet.class, Mockito.atLeastOnce())
			.withArguments(
					Mockito.any(AmazonCloudFormation.class),
					Mockito.eq("foo"),
					Mockito.any(TaskListener.class),
					Mockito.eq(SleepStrategy.EXPONENTIAL_BACKOFF_STRATEGY)
			);
	Mockito.verify(stackSet).create(Mockito.anyString(), Mockito.anyString(), Mockito.anyCollectionOf(Parameter.class), Mockito.anyCollectionOf(Tag.class), Mockito.eq("bar"), Mockito.eq("baz"));
}
 
示例10
@Test
public void test() {
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String natStackName = "vpc-nat-gateway-" + this.random8String();
    final String classB = "10";
    try {
        this.createStack(vpcStackName,
                "vpc/vpc-2azs.yaml",
                new Parameter().withParameterKey("ClassB").withParameterValue(classB)
        );
        try {
            this.createStack(natStackName,
                    "vpc/vpc-nat-gateway.yaml",
                    new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName)
            );
            this.testVPCSubnetInternetAccess(vpcStackName, "SubnetAPrivate");
        } finally {
            this.deleteStack(natStackName);
        }
    } finally {
        this.deleteStack(vpcStackName);
    }
}
 
示例11
@Test
public void doNotCreateNonExistantStack() throws Exception {
	WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
	Mockito.when(stackSet.exists()).thenReturn(false);
	job.setDefinition(new CpsFlowDefinition(""
			+ "node {\n"
			+ "  cfnUpdateStackSet(stackSet: 'foo', create: false)"
			+ "}\n", true)
	);
	jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));

	PowerMockito.verifyNew(CloudFormationStackSet.class, Mockito.atLeastOnce())
			.withArguments(
					Mockito.any(AmazonCloudFormation.class),
					Mockito.eq("foo"),
					Mockito.any(TaskListener.class),
					Mockito.eq(SleepStrategy.EXPONENTIAL_BACKOFF_STRATEGY)
			);
	Mockito.verify(stackSet, Mockito.never()).create(Mockito.anyString(), Mockito.anyString(), Mockito.anyCollectionOf(Parameter.class), Mockito.anyCollectionOf(Tag.class), Mockito.isNull(String.class), Mockito.isNull(String.class));
}
 
示例12
@Test
public void createChangeSetStackParametersFromMap() throws Exception {
	WorkflowJob job = this.jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
	Mockito.when(this.stack.exists()).thenReturn(true);
	Mockito.when(this.stack.describeChangeSet("bar")).thenReturn(new DescribeChangeSetResult()
			.withChanges(new Change())
			.withStatus(ChangeSetStatus.CREATE_COMPLETE)
	);
	job.setDefinition(new CpsFlowDefinition(""
			+ "node {\n"
			+ "  def changes = cfnCreateChangeSet(stack: 'foo', changeSet: 'bar', params: ['foo': 'bar', 'baz': 'true'])\n"
			+ "  echo \"changesCount=${changes.size()}\"\n"
			+ "}\n", true)
	);
	Run run = this.jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
	this.jenkinsRule.assertLogContains("changesCount=1", run);

	PowerMockito.verifyNew(CloudFormationStack.class, Mockito.atLeastOnce()).withArguments(Mockito.any(AmazonCloudFormation.class), Mockito.eq("foo"), Mockito.any(TaskListener.class));
	Mockito.verify(this.stack).createChangeSet(Mockito.eq("bar"), Mockito.anyString(), Mockito.anyString(), Mockito.eq(Arrays.asList(
			new Parameter().withParameterKey("foo").withParameterValue("bar"),
			new Parameter().withParameterKey("baz").withParameterValue("true")
	)), Mockito.anyCollectionOf(Tag.class), Mockito.anyCollectionOf(String.class), Mockito.any(PollConfiguration.class), Mockito.eq(ChangeSetType.UPDATE), Mockito.anyString(),
											   Mockito.any());
}
 
示例13
@Test
public void createChangeSetWithRawTemplate() throws Exception {
	WorkflowJob job = this.jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
	Mockito.when(this.stack.exists()).thenReturn(true);
	Mockito.when(this.stack.describeChangeSet("bar")).thenReturn(new DescribeChangeSetResult()
			.withChanges(new Change())
			.withStatus(ChangeSetStatus.CREATE_COMPLETE)
	);
	job.setDefinition(new CpsFlowDefinition(""
			+ "node {\n"
			+ "  def changes = cfnCreateChangeSet(stack: 'foo', changeSet: 'bar', template: 'foobaz')\n"
			+ "  echo \"changesCount=${changes.size()}\"\n"
			+ "}\n", true)
	);
	Run run = this.jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
	this.jenkinsRule.assertLogContains("changesCount=1", run);

	PowerMockito.verifyNew(CloudFormationStack.class, Mockito.atLeastOnce()).withArguments(Mockito.any(AmazonCloudFormation.class), Mockito.eq("foo"), Mockito.any(TaskListener.class));
	Mockito.verify(this.stack).createChangeSet(Mockito.eq("bar"), Mockito.eq("foobaz"), Mockito.anyString(), Mockito.anyCollectionOf(Parameter.class), Mockito.anyCollectionOf(Tag.class),
											   Mockito.anyCollectionOf(String.class), Mockito.any(PollConfiguration.class), Mockito.eq(ChangeSetType.UPDATE), Mockito.anyString(), Mockito.any());
}
 
示例14
@Test
public void updateChangeSetWithRawTemplate() throws Exception {
	WorkflowJob job = this.jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
	Mockito.when(this.stack.exists()).thenReturn(false);
	Mockito.when(this.stack.describeChangeSet("bar")).thenReturn(new DescribeChangeSetResult()
			.withChanges(new Change())
			.withStatus(ChangeSetStatus.CREATE_COMPLETE)
	);
	job.setDefinition(new CpsFlowDefinition(""
			+ "node {\n"
			+ "  def changes = cfnCreateChangeSet(stack: 'foo', changeSet: 'bar', template: 'foobaz')\n"
			+ "  echo \"changesCount=${changes.size()}\"\n"
			+ "}\n", true)
	);
	Run run = this.jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
	this.jenkinsRule.assertLogContains("changesCount=1", run);

	PowerMockito.verifyNew(CloudFormationStack.class, Mockito.atLeastOnce()).withArguments(Mockito.any(AmazonCloudFormation.class), Mockito.eq("foo"), Mockito.any(TaskListener.class));
	Mockito.verify(this.stack).createChangeSet(Mockito.eq("bar"), Mockito.eq("foobaz"), Mockito.anyString(), Mockito.anyCollectionOf(Parameter.class), Mockito.anyCollectionOf(Tag.class),
											   Mockito.anyCollectionOf(String.class), Mockito.any(PollConfiguration.class), Mockito.eq(ChangeSetType.CREATE), Mockito.anyString(), Mockito.any());
}
 
示例15
@Test
public void createChangeSetStackDoesNotExist() throws Exception {
	WorkflowJob job = this.jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
	Mockito.when(this.stack.exists()).thenReturn(false);
	Mockito.when(this.stack.describeChangeSet("bar")).thenReturn(new DescribeChangeSetResult()
			.withChanges(new Change())
			.withStatus(ChangeSetStatus.CREATE_COMPLETE)
	);
	job.setDefinition(new CpsFlowDefinition(""
			+ "node {\n"
			+ "  def changes = cfnCreateChangeSet(stack: 'foo', changeSet: 'bar')\n"
			+ "  echo \"changesCount=${changes.size()}\"\n"
			+ "}\n", true)
	);
	Run run = this.jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
	this.jenkinsRule.assertLogContains("changesCount=1", run);

	PowerMockito.verifyNew(CloudFormationStack.class, Mockito.atLeastOnce()).withArguments(Mockito.any(AmazonCloudFormation.class), Mockito.eq("foo"), Mockito.any(TaskListener.class));
	Mockito.verify(this.stack).createChangeSet(Mockito.eq("bar"), Mockito.anyString(), Mockito.anyString(), Mockito.anyCollectionOf(Parameter.class), Mockito.anyCollectionOf(Tag.class),
											   Mockito.anyCollectionOf(String.class), Mockito.any(PollConfiguration.class), Mockito.eq(ChangeSetType.CREATE), Mockito.anyString(), Mockito.any());
}
 
示例16
@Test
public void testCentOS() throws Exception {
    final String stackName = "showcase-" + this.random8String();
    final String userName = "user-" + this.random8String();
    try {
        final User user = this.createUser(userName);
        try {
            this.createStack(stackName,
                    "showcase.yaml",
                    new Parameter().withParameterKey("VPC").withParameterValue(this.getDefaultVPC().getVpcId()),
                    new Parameter().withParameterKey("Subnet").withParameterValue(this.getDefaultSubnets().get(0).getSubnetId()),
                    new Parameter().withParameterKey("OS").withParameterValue("CentOS")
            );
            final String host = this.getStackOutputValue(stackName, "PublicName");
            this.probeSSH(host, user);
        } finally {
            this.deleteStack(stackName);
        }
    } finally {
        this.deleteUser(userName);
    }
}
 
示例17
@Test
public void testRHEL() throws Exception {
    final String stackName = "showcase-" + this.random8String();
    final String userName = "user-" + this.random8String();
    try {
        final User user = this.createUser(userName);
        try {
            this.createStack(stackName,
                    "showcase.yaml",
                    new Parameter().withParameterKey("VPC").withParameterValue(this.getDefaultVPC().getVpcId()),
                    new Parameter().withParameterKey("Subnet").withParameterValue(this.getDefaultSubnets().get(0).getSubnetId()),
                    new Parameter().withParameterKey("OS").withParameterValue("RHEL")
            );
            final String host = this.getStackOutputValue(stackName, "PublicName");
            this.probeSSH(host, user);
        } finally {
            this.deleteStack(stackName);
        }
    } finally {
        this.deleteUser(userName);
    }
}
 
示例18
@Test
public void testUbuntu() throws Exception {
    final String stackName = "showcase-" + this.random8String();
    final String userName = "user-" + this.random8String();
    try {
        final User user = this.createUser(userName);
        try {
            this.createStack(stackName,
                    "showcase.yaml",
                    new Parameter().withParameterKey("VPC").withParameterValue(this.getDefaultVPC().getVpcId()),
                    new Parameter().withParameterKey("Subnet").withParameterValue(this.getDefaultSubnets().get(0).getSubnetId()),
                    new Parameter().withParameterKey("OS").withParameterValue("Ubuntu")
            );
            final String host = this.getStackOutputValue(stackName, "PublicName");
            this.probeSSH(host, user);
        } finally {
            this.deleteStack(stackName);
        }
    } finally {
        this.deleteUser(userName);
    }
}
 
示例19
@Test
public void testAmazonLinux2() throws Exception {
    final String stackName = "showcase-" + this.random8String();
    final String userName = "user-" + this.random8String();
    try {
        final User user = this.createUser(userName);
        try {
            this.createStack(stackName,
                    "showcase.yaml",
                    new Parameter().withParameterKey("VPC").withParameterValue(this.getDefaultVPC().getVpcId()),
                    new Parameter().withParameterKey("Subnet").withParameterValue(this.getDefaultSubnets().get(0).getSubnetId()),
                    new Parameter().withParameterKey("OS").withParameterValue("AmazonLinux2")
            );
            final String host = this.getStackOutputValue(stackName, "PublicName");
            this.probeSSH(host, user);
        } finally {
            this.deleteStack(stackName);
        }
    } finally {
        this.deleteUser(userName);
    }
}
 
示例20
@Test
public void test() {
    final String kmsStackName = "kms-" + this.random8String();
    final String terraformStateStackName = "tf-state-" + this.random8String();
    try {
        this.createStack(kmsStackName,
                "security/kms-key.yaml",
                new Parameter().withParameterKey("Service").withParameterValue("s3")
        );
        try {
            this.createStack(terraformStateStackName,
                    "operations/terraform-state.yaml",
                    new Parameter().withParameterKey("ParentKmsKeyStack").withParameterValue(kmsStackName),
                    new Parameter().withParameterKey("TerraformStateIdentifier").withParameterValue(terraformStateStackName),
                    new Parameter().withParameterKey("TerraformStateAdminARNs").withParameterValue("arn:aws:iam::" + this.getAccount() + ":root," + System.getenv("IAM_ROLE_ARN") + "," + this.getCallerIdentityArn())
            );
        } finally {
            this.deleteStack(terraformStateStackName);
        }
    } finally {
        this.deleteStack(kmsStackName);
    }
}
 
示例21
@Test
public void testEncryption() {
    final String kmsKeyStackName = "key-" + this.random8String();
    final String stackName = "dynamodb-" + this.random8String();
    try {
        this.createStack(kmsKeyStackName,"security/kms-key.yaml");
        try {
            this.createStack(stackName,
                    "state/dynamodb.yaml",
                    new Parameter().withParameterKey("ParentKmsKeyStack").withParameterValue(kmsKeyStackName),
                    new Parameter().withParameterKey("PartitionKeyName").withParameterValue("id")
            );
            // TODO how can we check if this stack works?
        } finally {
            this.deleteStack(stackName);
        }
    } finally {
        this.deleteStack(kmsKeyStackName);
    }
}
 
示例22
@Test
public void testGSI() {
    final String stackName = "dynamodb-" + this.random8String();
    try {
        this.createStack(stackName,
                "state/dynamodb.yaml",
                new Parameter().withParameterKey("PartitionKeyName").withParameterValue("id"),
                new Parameter().withParameterKey("SortKeyName").withParameterValue("timestamp"),
                new Parameter().withParameterKey("Attribute1Name").withParameterValue("organisation"),
                new Parameter().withParameterKey("Attribute2Name").withParameterValue("category"),
                new Parameter().withParameterKey("Index1PartitionKeyName").withParameterValue("timestamp"),
                new Parameter().withParameterKey("Index2PartitionKeyName").withParameterValue("organisation"),
                new Parameter().withParameterKey("Index2SortKeyName").withParameterValue("category")
        );
        // TODO how can we check if this stack works?
    } finally {
        this.deleteStack(stackName);
    }
}
 
示例23
public Collection<Parameter> getCloudFormationParameters() {
    Collection<Parameter> parameters = new ArrayList<>();
    for (Map.Entry<Object, Object> e : properties.entrySet()) {
        parameters.add(new Parameter().withParameterKey((String) e.getKey()).withParameterValue((String) e.getValue()));
    }
    return parameters;
}
 
示例24
@Test
public void test() {
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String bastionStackName = "vpc-vpn-bastion-" + this.random8String();
    final String classB = "10";
    final String keyName = "key-" + this.random8String();
    final String vpnPSK = this.random8String();
    final String vpnUserPassword = this.random8String();
    final String vpnAdminPassword = this.random8String();
    try {
        final KeyPair key = this.createKey(keyName);
        try {
            this.createStack(vpcStackName,
                    "vpc/vpc-2azs.yaml",
                    new Parameter().withParameterKey("ClassB").withParameterValue(classB)
            );
            try {
                this.createStack(bastionStackName,
                        "vpc/vpc-vpn-bastion.yaml",
                        new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName),
                        new Parameter().withParameterKey("KeyName").withParameterValue(keyName),
                        new Parameter().withParameterKey("VPNPSK").withParameterValue(vpnPSK),
                        new Parameter().withParameterKey("VPNUserName").withParameterValue("test"),
                        new Parameter().withParameterKey("VPNUserPassword").withParameterValue(vpnUserPassword),
                        new Parameter().withParameterKey("VPNAdminPassword").withParameterValue(vpnAdminPassword)
                );
                // TODO how can we check if this stack works?
            } finally {
                this.deleteStack(bastionStackName);
            }
        } finally {
            this.deleteStack(vpcStackName);
        }
    } finally {
        this.deleteKey(keyName);
    }
}
 
示例25
@Test
public void test() {
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String clientStackName = "client-" + this.random8String();
    final String stackName = "documentdb-" + this.random8String();
    try {
        this.createStack(vpcStackName, "vpc/vpc-2azs.yaml");
        try {
            this.createStack(clientStackName,
                    "state/client-sg.yaml",
                    new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName)
            );
            try {
                this.createStack(stackName,
                        "state/documentdb.yaml",
                        new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName),
                        new Parameter().withParameterKey("ParentClientStack").withParameterValue(clientStackName),
                        new Parameter().withParameterKey("MasterUserPassword").withParameterValue("Test!1234")
                );
                // TODO how can we check if this stack works? start a bastion host and try to connect?
            } finally {
                this.deleteStack(stackName);
            }
        } finally {
            this.deleteStack(clientStackName);
        }
    } finally {
        this.deleteStack(vpcStackName);
    }
}
 
示例26
private static Collection<Parameter> parseParams(Object o) {
	if (o == null) {
		return Collections.emptyList();
	} else if (o instanceof String[]) {
		return parseParams(Arrays.asList((String[]) o));
	} else if (o instanceof List) {
		return parseParams((List<String>) o);
	} else if (o instanceof Map) {
		return parseParams((Map<Object, Object>) o);
	} else {
		throw new IllegalStateException("Invalid params type: " + o.getClass());
	}
}
 
示例27
private static Collection<Parameter> parseParams(Map<Object, Object> map) {
	Collection<Parameter> parameters = new ArrayList<>();
	for (Map.Entry<Object, Object> entry : map.entrySet()) {
		if (entry.getValue() == null) {
			throw new IllegalStateException(entry.getKey() + " has a null value");
		}
		parameters.add(new Parameter()
				.withParameterKey((String) entry.getKey())
				.withParameterValue(entry.getValue().toString())
		);
	}
	return parameters;
}
 
示例28
private static Collection<Parameter> parseParams(List<String> params) {
	Collection<Parameter> parameters = new ArrayList<>();
	for (String param : params) {
		int i = param.indexOf('=');
		if (i < 0) {
			throw new IllegalArgumentException("Missing = in param " + param);
		}
		String key = param.substring(0, i);
		String value = param.substring(i + 1);
		parameters.add(new Parameter().withParameterKey(key).withParameterValue(value));
	}
	return parameters;
}
 
示例29
@Test
public void test() {
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String stackName = "vpc-2azs-legacy-" + this.random8String();
    try {
        this.createStack(vpcStackName,
                "vpc/vpc-2azs.yaml",
                new Parameter().withParameterKey("ClassB").withParameterValue("10")
        );
        final Map<String, String> vpcOutputs = this.getStackOutputs(vpcStackName);
        try {
            this.createStack(stackName,
                    "vpc/vpc-2azs-legacy.yaml",
                    new Parameter().withParameterKey("AZA").withParameterValue(vpcOutputs.get("AZA")),
                    new Parameter().withParameterKey("AZB").withParameterValue(vpcOutputs.get("AZB")),
                    new Parameter().withParameterKey("CidrBlock").withParameterValue(vpcOutputs.get("CidrBlock")),
                    new Parameter().withParameterKey("CidrBlockIPv6").withParameterValue(vpcOutputs.get("CidrBlockIPv6")),
                    new Parameter().withParameterKey("VPC").withParameterValue(vpcOutputs.get("VPC")),
                    new Parameter().withParameterKey("InternetGateway").withParameterValue(vpcOutputs.get("InternetGateway")),
                    new Parameter().withParameterKey("SubnetAPublic").withParameterValue(vpcOutputs.get("SubnetAPublic")),
                    new Parameter().withParameterKey("RouteTableAPublic").withParameterValue(vpcOutputs.get("RouteTableAPublic")),
                    new Parameter().withParameterKey("SubnetBPublic").withParameterValue(vpcOutputs.get("SubnetBPublic")),
                    new Parameter().withParameterKey("RouteTableBPublic").withParameterValue(vpcOutputs.get("RouteTableBPublic")),
                    new Parameter().withParameterKey("SubnetAPrivate").withParameterValue(vpcOutputs.get("SubnetAPrivate")),
                    new Parameter().withParameterKey("RouteTableAPrivate").withParameterValue(vpcOutputs.get("RouteTableAPrivate")),
                    new Parameter().withParameterKey("SubnetBPrivate").withParameterValue(vpcOutputs.get("SubnetBPrivate")),
                    new Parameter().withParameterKey("RouteTableBPrivate").withParameterValue(vpcOutputs.get("RouteTableBPrivate"))
            );
            this.testVPCSubnetInternetAccess(stackName, "SubnetAPublic");
            this.testVPCSubnetInternetAccess(stackName, "SubnetBPublic");
        } finally {
            this.deleteStack(stackName);
        }
    } finally {
        this.deleteStack(vpcStackName);
    }
}
 
示例30
@Test
public void test() {
    final String stackName = "vpc-2azs-" + this.random8String();
    try {
        this.createStack(stackName,
                "vpc/vpc-2azs.yaml",
                new Parameter().withParameterKey("ClassB").withParameterValue("10")
        );
        this.testVPCSubnetInternetAccess(stackName, "SubnetAPublic");
        this.testVPCSubnetInternetAccess(stackName, "SubnetBPublic");
    } finally {
        this.deleteStack(stackName);
    }
}