Is there a way to iterate over all CfnResources in a CfnInclude?

Viewed 282

I'm trying to get a list of all resources of type AWS::SSM::Parameter defined in a Cloudformation template, using the Java AWSCDK. The template file is being loaded and parsed as a CfInclude object. Am I overlooking something, or is there really no way to iterate over all resources in CfInclude? All I see in the documentation for software.amazon.awscdk.cloudformation.include.CfnInclude is getResource, which requires the logical ID to be known.

1 Answers

You can reference all resources with getNode().findAll().

For example to list all IAM Roles defined in the included file:

List<IConstruct> roles = include.getNode()
        .findAll()
        .stream().filter(n -> n instanceof CfnRole)
        .collect(Collectors.toList())
Related