cloudtools / troposphere

troposphere - Python library to create AWS CloudFormation descriptions
BSD 2-Clause "Simplified" License
4.93k stars 1.44k forks source link

Support Nested Stack #526

Closed pilgrim2go closed 7 years ago

pilgrim2go commented 8 years ago

Hi,

I have question. Does Troposphere support CF nested stack? Some thing like this post http://cloudacademy.com/blog/understanding-nested-cloudformation-stacks/?

{
   "AWSTemplateFormatVersion": "2010-09-09",
   "Resources": {
       "ChildStack01": {
           "Type": "AWS::CloudFormation::Stack",
           "Properties": {
               "TemplateURL": "https://s3.amazonaws.com/cloudformation-templates-us-east-1/VPC.template",
               "TimeoutInMinutes": "60"
           }
       },
       "ChildStack02": {
           "Type": "AWS::CloudFormation::Stack",
           "Properties": {
               "TemplateURL": "https://s3.amazonaws.com/cloudformation-templates-us-east-1/Subnet.template",
               "Parameters": {
                  "VpcId" : { "Fn::GetAtt" : [ "ChildStack01", "Outputs.VpcID" ] },
               },
               "TimeoutInMinutes": "60"
           }
       }
   },
   "Outputs": {
       "StackRef": {
           "Value": { "Ref": "ChildStack02" }
       },
       "OutputFromNestedStack": {
           "Value": { "Fn::GetAtt": [ "ChildStack02", "Outputs.SubnetID" ]}
       }
   }
}

If yes, it's great.

benbridts commented 8 years ago

Yes,

you can use something like "template.add_resource(cloudformation.Stack("ChildStack01", TemplateURL='...', TimeoutInMinutes=60))"

Ben Bridts ben@bridts.be

On Mon, Jul 11, 2016 at 11:10 AM, iapilgrim notifications@github.com wrote:

Hi,

I have question. Does Troposphere support CF nested stack? Some thing like this post http://cloudacademy.com/blog/understanding-nested-cloudformation-stacks/?

{ "AWSTemplateFormatVersion": "2010-09-09", "Resources": { "ChildStack01": { "Type": "AWS::CloudFormation::Stack", "Properties": { "TemplateURL": "https://s3.amazonaws.com/cloudformation-templates-us-east-1/VPC.template", "TimeoutInMinutes": "60" } }, "ChildStack02": { "Type": "AWS::CloudFormation::Stack", "Properties": { "TemplateURL": "https://s3.amazonaws.com/cloudformation-templates-us-east-1/Subnet.template", "Parameters": { "VpcId" : { "Fn::GetAtt" : [ "ChildStack01", "Outputs.VpcID" ] }, }, "TimeoutInMinutes": "60" } } }, "Outputs": { "StackRef": { "Value": { "Ref": "ChildStack02" } }, "OutputFromNestedStack": { "Value": { "Fn::GetAtt": [ "ChildStack02", "Outputs.SubnetID" ]} } } }

If yes, it's great.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cloudtools/troposphere/issues/526, or mute the thread https://github.com/notifications/unsubscribe/ABPa5ZZd4aglOTfgRSFfKOwywEf7B0BTks5qUgh8gaJpZM4JJKuN .

pilgrim2go commented 8 years ago

Thanks. I will try it

tdi commented 7 years ago

@pilgrim2go what is the status on this bug ?

phobologic commented 7 years ago

I'm going to go ahead and close this - troposphere has actually supported Nested stacks for about as long as they have existed. @ikben's example should give an example how.

tdi commented 7 years ago

@phobologic great I was just doing a small triage here.

bluedusk commented 6 years ago

It would be great to have an example in examples folder.

tammclaughlin commented 5 years ago

Hi, Has anyone got any examples of passing parameters into a nested stack? I can't any documentation on this and tried a few combinations but can't get this to work. Tam

toracle commented 5 years ago

@tammclaughlin I found this SO answer is useful.

Part of my cfn scripts are below:


Child stack 1 which has a useful resource.

t = Template()

Vpc = t.add_resource(VPC(
    'Vpc',
    EnableDnsSupport=True,
    CidrBlock='10.1.0.0/16',
    EnableDnsHostnames=True,
))

t.add_output(Output('Vpc', Value=Ref(Vpc)))

Parent stack.

t = Template()

t.add_resource(Stack(
    'Child1',
    TemplateURL=f'{baseUrl}/child1.template',
))

t.add_resource(Stack(
    'Child2',
    TemplateURL=f'{baseUrl}/child2.template',
    Parameters={
        'Vpc': GetAtt('Child1', 'Outputs.Vpc'),
    }
))

Child stack 2 which want to use a resource of child1.

t = Template()

t.add_parameter(Parameter(
    'Vpc',
    Type='String',
    Description='Vpc Ref'))

t.add_resource(elb.TargetGroup(
    'TargetGroup1',
    ...
    VpcId=Ref('Vpc'),  # finally I can reference a sibling stack's resource
))