Search in sources :

Example 1 with StackResource

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");
    }
}
Also used : HashMap(java.util.HashMap) ListableStackResourceFactory(io.awspring.cloud.core.env.stack.ListableStackResourceFactory) StackResource(io.awspring.cloud.core.env.stack.StackResource) Test(org.junit.jupiter.api.Test)

Example 2 with StackResource

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();
}
Also used : HashMap(java.util.HashMap) ListableStackResourceFactory(io.awspring.cloud.core.env.stack.ListableStackResourceFactory) StackResource(io.awspring.cloud.core.env.stack.StackResource) Test(org.junit.jupiter.api.Test)

Example 3 with StackResource

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");
}
Also used : StackResource(io.awspring.cloud.core.env.stack.StackResource) Test(org.junit.jupiter.api.Test)

Example 4 with StackResource

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;
}
Also used : HashMap(java.util.HashMap) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) StackResource(io.awspring.cloud.core.env.stack.StackResource)

Example 5 with StackResource

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;
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) StackResource(io.awspring.cloud.core.env.stack.StackResource)

Aggregations

StackResource (io.awspring.cloud.core.env.stack.StackResource)5 HashMap (java.util.HashMap)4 Test (org.junit.jupiter.api.Test)3 StackResourceSummary (com.amazonaws.services.cloudformation.model.StackResourceSummary)2 ListableStackResourceFactory (io.awspring.cloud.core.env.stack.ListableStackResourceFactory)2 Map (java.util.Map)1