-
Notifications
You must be signed in to change notification settings - Fork 39
Open
Description
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
PeeringConnectioninto a nested stack. I can use an import to populate theVpcModuleparameter 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
Labels
No labels