This tutorial will walk you through how to use the “Using stack and launch outputs” feature.
We will assume you have:
We will assume you are comfortable:
Here are the steps you need to follow to “Using stack and launch outputs”
In order to use a stack output you must first provision a stack that provides the output. Here is an example of such a template:
Parameters:
CidrBlock:
Type: String
Name:
Type: String
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref CidrBlock
EnableDnsHostnames: True
EnableDnsSupport: True
Tags:
- Key: Name
Value: !Ref Name
Outputs:
VpcId:
Value: !Ref VPC
Description: Output VPC ID for utilisation by dependent product
VpcCidrBlock:
Value: !GetAtt VPC.CidrBlock
Here we are provisioning a stack that outputs VpcId as an output.
Once you have provisioned the stack that provides the output you will need to define a stack that uses the output:
Parameters:
CidrBlock:
Type: String
VpcId:
Type: String
Resources:
Subnet:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: !Select [ 0, !Cidr [ !Ref CidrBlock, 6, 5 ]]
AvailabilityZone: !Select
- 0
- Fn::GetAZs: !Ref "AWS::Region"
Tags:
- Key: Name
Value: "Example-Subnet-AZ1"
VpcId: !Ref VpcId
Here we are defining a stack that uses VpcId as a parameter.
Now we are ready to provision the stack using the manifest file.
To use the output from one stack as a parameter for another you can use the following syntax:
stacks:
example-subnet:
name: example-subnet
version: v1
depends_on:
- example-vpc
parameters:
CidrBlock:
cloudformation_stack_output:
account_id: ${AWS::AccountId}
region: ${AWS::Region}
stack_name: example-vpc
output_key: VpcCidrBlock
VpcId:
cloudformation_stack_output:
account_id: ${AWS::AccountId}
region: ${AWS::Region}
stack_name: example-vpc
output_key: VpcId
deploy_to:
tags:
- tag: type:prod
regions: regions_enabled
In this example we are reading VpcCidrBlock and VpcId from the stack named example-vpc when provisioning the stack named example-subnet.
If you would like to obtain the output of a provisioned product deployment, it is possible to call
the servicecatalog_provisioned_product_output
method to obtain stack outputs. In the example below we are calling from
the output of a launch called ‘example-vpc’
stacks:
example-subnet:
name: example-subnet
version: v1
depends_on:
- example-vpc
parameters:
CidrBlock:
servicecatalog_provisioned_product_output:
account_id: ${AWS::AccountId}
region: ${AWS::Region}
provisioned_product_name: example-vpc
output_key: VpcCidrBlock
VpcId:
servicecatalog_provisioned_product_output:
account_id: ${AWS::AccountId}
region: ${AWS::Region}
provisioned_product_name: example-vpc
output_key: VpcId
deploy_to:
tags:
- tag: type:prod
regions: regions_enabled