Skip to content

Dedicated/Standardized Exports Unwrapper #38

@ambsw-technology

Description

@ambsw-technology

Assume I want to create a module like this:

Parameters:
  Environment:
    Description: 'Name of client Environment.'
    Type: String
Resources
  PeeringConnection:
    Type: 'AWS::EC2::VPCPeeringConnection'
    Properties:
      VpcId: {'Fn::ImportValue': !Sub '${VpcModule}-Id'}
      ...

BUT the VpcModule has been exported at ${Environment}-VpcModule. How do I get to VpcModule from Environment?

  • My first solution was to move the PeeringConnection into a nested stack. I can use an import to populate the VpcModule parameter and, within the stack, do the secondary import.
  • I've since realized that you can get these exports to the outer layer using a dedicated nested stack. For example...
# cfn-modules/vpc/outputs.yaml

Parameters:
  VpcModule:
    Type: String
Conditions:
  Never: !Equals ['true', 'false']
Resources:
  NullResource:
    Condition: Never
    Type: 'Custom::Null'
Outputs:
  Id:
    Value: {'Fn::ImportValue': !Sub '${VpcModule}-Id'}
    Export:
      Name: !Sub '${AWS::StackName}-Id'

This lets me do everything on the outer level:

Parameters:
  Environment:
    Description: 'Name of client Environment.'
    Type: String
Resources
  VpcModuleOutputs:
    Type: 'AWS::CloudFormation::Stack'
    Properties:
      Parameters:
        VpcModule:  {'Fn::ImportValue': !Sub '${Environment}-VpcModule'}
      TemplateURL: './cfn-modules/vpc/outputs.yml'
  PeeringConnection:
    Type: 'AWS::EC2::VPCPeeringConnection'
    Properties:
      VpcId: !GetAtt 'VpcModuleOutputs.Outputs.Id'
      ...

I'd like to suggest including a standardized outputs (or exports) YAML file in each package that wraps a module's stackname and provides all of its exports.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions