use of io.awspring.cloud.core.env.stack.StackResource in project spring-cloud-aws by awspring.
the class StackResourceRegistryFactoryBeanTest method createInstance_stackWithTwoResources_listsBothResources.
@Test
void createInstance_stackWithTwoResources_listsBothResources() throws Exception {
// Arrange
Map<String, String> resourceIdMappings = new HashMap<>();
resourceIdMappings.put("logicalResourceIdOne", "physicalResourceIdOne");
resourceIdMappings.put("logicalResourceIdTwo", "physicalResourceIdTwo");
StackResourceRegistryFactoryBean stackResourceRegistryFactoryBean = makeStackResourceRegistryFactoryBean(STACK_NAME, resourceIdMappings);
// Act
ListableStackResourceFactory stackResourceRegistry = stackResourceRegistryFactoryBean.createInstance();
// Assert
assertThat(stackResourceRegistry.getAllResources().size()).isEqualTo(2);
for (StackResource stackResource : stackResourceRegistry.getAllResources()) {
assertThat(stackResource.getLogicalId()).isIn("logicalResourceIdOne", "logicalResourceIdTwo");
assertThat(stackResource.getPhysicalId()).isIn("physicalResourceIdOne", "physicalResourceIdTwo");
assertThat(stackResource.getType()).isEqualTo("Amazon::SES::Test");
}
}
use of io.awspring.cloud.core.env.stack.StackResource in project spring-cloud-aws by awspring.
the class StackResourceRegistryFactoryBeanTest method createInstance_stackWithNestedStack.
@Test
void createInstance_stackWithNestedStack() throws Exception {
// Arrange
Map<String, String> resourceIdMappings = new HashMap<>();
resourceIdMappings.put("logicalResourceIdOne", "physicalResourceIdOne");
resourceIdMappings.put("logicalNestedStack", "physicalStackId");
resourceIdMappings.put("logicalNestedStack.logicalResourceIdTwo", "physicalResourceIdTwo");
StackResourceRegistryFactoryBean stackResourceRegistryFactoryBean = makeStackResourceRegistryFactoryBean(STACK_NAME, resourceIdMappings);
// Act
ListableStackResourceFactory stackResourceRegistry = stackResourceRegistryFactoryBean.createInstance();
// Assert
assertThat(stackResourceRegistry.getAllResources().size()).isEqualTo(3);
for (StackResource stackResource : stackResourceRegistry.getAllResources()) {
assertThat(stackResource.getLogicalId()).isIn("logicalResourceIdOne", "logicalNestedStack", "logicalNestedStack.logicalResourceIdTwo");
assertThat(stackResource.getPhysicalId()).isIn("physicalResourceIdOne", "physicalStackId", "physicalResourceIdTwo");
assertThat(stackResource.getType()).isIn("AWS::CloudFormation::Stack", "Amazon::SES::Test");
}
assertThat(stackResourceRegistry.lookupPhysicalResourceId("logicalNestedStack.logicalResourceIdTwo")).isNotNull();
assertThat(stackResourceRegistry.lookupPhysicalResourceId("logicalResourceIdTwo")).isNotNull();
}
use of io.awspring.cloud.core.env.stack.StackResource in project spring-cloud-aws by awspring.
the class StackConfigurationAwsTest method resourcesByType_withResourceType_containsMinimumResources.
@Test
void resourcesByType_withResourceType_containsMinimumResources() throws Exception {
// Arrange
// Act
Collection<StackResource> resourcesByType = this.stackResourceFactory.resourcesByType("AWS::EC2::Instance");
// Assert
assertThat(resourcesByType.size()).isEqualTo(1);
StackResource stackResource = resourcesByType.iterator().next();
assertThat(stackResource.getLogicalId()).isEqualTo("UserTagAndUserDataInstance");
assertThat(stackResource.getType()).isEqualTo("AWS::EC2::Instance");
}
use of io.awspring.cloud.core.env.stack.StackResource in project spring-cloud-aws by awspring.
the class StackResourceRegistryFactoryBean method convertToStackResourceMappings.
private Map<String, StackResource> convertToStackResourceMappings(String prefix, List<StackResourceSummary> stackResourceSummaries) {
Map<String, StackResource> stackResourceMappings = new HashMap<>();
for (StackResourceSummary stackResourceSummary : stackResourceSummaries) {
String logicalResourceId = toNestedResourceId(prefix, stackResourceSummary.getLogicalResourceId());
stackResourceMappings.put(logicalResourceId, new StackResource(logicalResourceId, stackResourceSummary.getPhysicalResourceId(), stackResourceSummary.getResourceType()));
}
return stackResourceMappings;
}
use of io.awspring.cloud.core.env.stack.StackResource in project spring-cloud-aws by awspring.
the class StackResourceRegistryFactoryBean method getResourceMappings.
private Map<String, StackResource> getResourceMappings(String prefix, String stackName) {
List<StackResourceSummary> stackResourceSummaries = getStackResourceSummaries(stackName);
Map<String, StackResource> current = convertToStackResourceMappings(prefix, stackResourceSummaries);
Map<String, StackResource> stackResourceMappings = new HashMap<>(current);
for (Map.Entry<String, StackResource> e : current.entrySet()) {
StackResource resource = e.getValue();
if ("AWS::CloudFormation::Stack".equals(resource.getType())) {
stackResourceMappings.putAll(getResourceMappings(e.getKey(), resource.getPhysicalId()));
}
}
return stackResourceMappings;
}
Aggregations