Output 'VPCId2' not found in stack

86 Views Asked by At

I created an AWS CloudFormation template that calls nested stacks to create an Application Load Balancer, EC2 instance with enable SSM and tomcat ec2 and 3 VPCs.

However, when I upload the root stack I got this error:

Output 'VPCId2' not found in stack 'arn:aws:cloudformation:us-east-1:465521475937:stack/root-VPCStack-146FM0ZNW6Y5S/60d8eaf0-dd0f-11ed-a4d3-12bfe4263bc1' for ALB

This is my root stack:

AWSTemplateFormatVersion: 2010-09-09

Description: Root template 2

Parameters:

  KeyName:
    Type: String
    Default: demo
  
  ManagementVPCBlock: 
    Type: String
    Default: "10.0.0.0/24"

  ManagementPublicSubnet01Block:
    Type: String
    Default: "10.0.0.0/28" 

  APPVPCBlock:
    Type: String
    Default: "10.0.1.0/24"

  APPPrivateSubnet02Block:
    Type: String
    Default: "10.0.1.0/28"

  APPPublicSubnet03Block:
    Type: String
    Default: "10.0.1.16/28"

  DBVPCBlock:
    Type: String
    Default: "10.0.2.0/24"

  DBPrivateSubnet04Block:
    Type: String
    Default: 10.0.2.0/28  

  APPPublicSubnet05Block:
    Type: String
    Default: "10.0.1.32/28"

  AccepterRegion:
    Description: enter the region 
    Type: String

  AccepterAccountID: 
    Description: enter the accountId 
    Type: String

  
  
Resources:

  VPCStack: 
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: https://stackbucket-s3bucket-1esv04po5wsk9.s3.amazonaws.com/NestedStack/VPC.yaml
      Parameters:
        ManagementVPCBlock: !Ref ManagementVPCBlock
        ManagementPublicSubnet01Block: !Ref ManagementPublicSubnet01Block
        APPVPCBlock: !Ref APPVPCBlock
        APPPrivateSubnet02Block: !Ref APPPrivateSubnet02Block
        APPPublicSubnet03Block: !Ref APPPublicSubnet03Block
        DBVPCBlock: !Ref DBVPCBlock
        DBPrivateSubnet04Block: !Ref DBPrivateSubnet04Block
        AccepterRegion: !Ref AccepterRegion
        AccepterAccountID: !Ref AccepterAccountID

      TimeoutInMinutes: 5


  ALBStack: 
    Type: AWS::CloudFormation::Stack 
    Properties:
      TemplateURL: https://stackbucket-s3bucket-1esv04po5wsk9.s3.amazonaws.com/NestedStack/ALB.yaml
      Parameters:
        VPCId: !GetAtt VPCStack.Outputs.VPCId2
        PublicSubnet1Id: !GetAtt VPCStack.Outputs.PublicSubnet1Id
        PublicSubnet2Id: !GetAtt VPCStack.Outputs.PublicSubnet2Id  
      TimeoutInMinutes: 5


  SSMStack:
    Type: AWS::CloudFormation::Stack 
    Properties:
      TemplateURL: https://stackbucket-s3bucket-1esv04po5wsk9.s3.amazonaws.com/NestedStack/SSM.yaml
      Parameters:
        VPCId: !GetAtt VPCStack.Outputs.VPCId1
        PublicSubnetId: !GetAtt VPCStack.Outputs.PublicSubnetId
      TimeoutInMinutes: 5


  TomcatEC2Stack:
    Type: AWS::CloudFormation::Stack 
    Properties:
      TemplateURL: https://stackbucket-s3bucket-1esv04po5wsk9.s3.amazonaws.com/NestedStack/TomcatEC2.yaml
      Parameters:
        VPCId: !GetAtt VPCStack.Outputs.VPCId2
        PrivateSubnetId: !GetAtt VPCStack.Outputs.PrivateSubnetId1
        KeyName: !Ref KeyName
      TimeoutInMinutes: 5


Outputs:
  StackRef:
    Value: !Ref VPCStack
  outputfromNestedStack:
    Value: !GetAtt VPCStack.Outputs.VPCId1
    Value: !GetAtt VPCStack.Outputs.PublicSubnetId
    Value: !GetAtt VPCStack.Outputs.VPCId2
    Value: !GetAtt VPCStack.Outputs.PrivateSubnetId1
    Value: !GetAtt VPCStack.Outputs.PublicSubnet1Id
    Value: !GetAtt VPCStack.Outputs.PublicSubnet2Id
    Value: !GetAtt VPCStack.Outputs.VPCId3
    Value: !GetAtt VPCStack.Outputs.PrivateSubnetId2

I'm stuck here. Please help.

1

There are 1 best solutions below

0
jarmod On BEST ANSWER

Your VPCStack outputs appear to be as follows:

 Outputs:

    VPCId:
      Value: !Ref ManagementVPC

    PublicSubnetId:
      Value: !Ref ManagementPublicSubnet

    VPCId:
      Value: !Ref APPVPC

    PrivateSubnetId:
      Value: !Ref PrivateSubnet

    PublicSubnet1Id:
      Value: !Ref PublicSubnet1

    PublicSubnet2Id:
      Value: !Ref PublicSubnet2

    VPCId:
      Value: !Ref DBVPC

    PrivateSubnetId:
      Value: !Ref PrivateSubnet

You are outputting all 3 VPC IDs with the same name VPCId but they need to be different e.g.

 Outputs:

    VPCId1:
      Value: !Ref ManagementVPC

    PublicSubnetId:
      Value: !Ref ManagementPublicSubnet

    VPCId2:
      Value: !Ref APPVPC

    PrivateSubnetId:
      Value: !Ref PrivateSubnet

    PublicSubnet1Id:
      Value: !Ref PublicSubnet1

    PublicSubnet2Id:
      Value: !Ref PublicSubnet2

    VPCId3:
      Value: !Ref DBVPC

    PrivateSubnetId:
      Value: !Ref PrivateSubnet