question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cross stack vpc causes unresolved resource dependencies error

See original GitHub issue

Hi, creating a vpc in a child stack (not nested), and creating some resources, that depend on the vpc, in another child stack will result in a ValidationError. I was able to reproduce this with application loadbalancers (only internet facing) aswell as an aurora cluster (public and private).

Reproduction Steps

import cdk = require('@aws-cdk/core');
import { NetworkStack } from './Network-stack';
import { InstancesStack } from './Instances-stack';

export class TestStack extends cdk.Stack {
    constructor(scope: cdk.App, id: string, props: cdk.StackProps) {
        super(scope, id, props);
        const network = new NetworkStack(this, "NetworkStack", props);

        new InstancesStack(this, "Instances", {
            env: props.env,
            network: network
        });
    }
}
import cdk = require('@aws-cdk/core');
import ec2 = require('@aws-cdk/aws-ec2');

export class NetworkStack extends cdk.Stack {
    public readonly vpc: ec2.Vpc;

    constructor(scope: cdk.Stack, id: string, props: cdk.StackProps) {
        super(scope, id, props);

        this.vpc = new ec2.Vpc(this, "vpc", {
            cidr: "10.0.0.0/16",
            maxAzs: 3,
            subnetConfiguration: [
                {
                    cidrMask: 20,
                    subnetType: ec2.SubnetType.PRIVATE,
                    name: "subnet-private"
                },
                {
                    cidrMask: 20,
                    subnetType: ec2.SubnetType.PUBLIC,
                    name: "subnet-public"
                }
            ],
            natGateways: 2
        });
    }
}
import cdk = require('@aws-cdk/core'); 
import loadbalancer = require('@aws-cdk/aws-elasticloadbalancingv2');
import { NetworkStack } from './Network-stack';
 
export interface theseProps extends cdk.StackProps { 
    network: NetworkStack
} 
 
export class InstancesStack extends cdk.Stack {
 
    constructor(scope: cdk.Stack, id: string, props: theseProps) { 
        super(scope, id, props);
        
        new loadbalancer.ApplicationLoadBalancer(this, "testLB", {
            vpc: props.network.vpc,
            internetFacing: true
        });
    } 
}

Error Log

cdk deploy *
TestStack
TestStack: deploying...
TestStack: creating CloudFormation changeset...

 ✅  TestStack (no changes)

Stack ARN:
arn:aws:cloudformation:eu-west-1:123456789:stack/TestStack/f7358b50-ec24-11e9-8e0e-02c03455965c
TestStackNetworkStackE68E9FD0
TestStackNetworkStackE68E9FD0: deploying...
TestStackNetworkStackE68E9FD0: creating CloudFormation changeset...
...

 ✅  TestStackNetworkStackE68E9FD0

Outputs:
TestStackNetworkStackE68E9FD0.ExportsOutputRefvpcsubnetpublicSubnet1SubnetF125D982384FC8F2 = subnet-05bb64c9b53308b7c
TestStackNetworkStackE68E9FD0.ExportsOutputRefvpcA2121C384D1B3CDE = vpc-02997d94566f805bf
TestStackNetworkStackE68E9FD0.ExportsOutputRefvpcsubnetpublicSubnet2Subnet2731CC5E2E3D2FF3 = subnet-0b862d79b52959ec6
TestStackNetworkStackE68E9FD0.ExportsOutputRefvpcsubnetpublicSubnet3Subnet7494E9BC8FCFC236 = subnet-03944fc3ed16a79b4

Stack ARN:
arn:aws:cloudformation:eu-west-1:123456789:stack/TestStackNetworkStackE68E9FD0/2d351770-ec25-11e9-9415-06982f8c16e4
TestStackInstancesF0B37D31
TestStackInstancesF0B37D31: deploying...
TestStackInstancesF0B37D31: creating CloudFormation changeset...

 ❌  TestStackInstancesF0B37D31 failed: ValidationError: Template format error: Unresolved resource dependencies [vpcsubnetpublicSubnet3DefaultRoute3905C18B, vpcsubnetpublicSubnet2DefaultRoute7436D83A, vpcsubnetpublicSubnet1Defau
ltRouteA1448C8B] in the Resources block of the template
Template format error: Unresolved resource dependencies [vpcsubnetpublicSubnet3DefaultRoute3905C18B, vpcsubnetpublicSubnet2DefaultRoute7436D83A, vpcsubnetpublicSubnet1DefaultRouteA1448C8B] in the Resources block of the template  

Environment

  • CLI Version : 1.16.232
  • Framework Version: 1.12.0
  • OS : Windows 10
  • Language : TypeScript

This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
eladbcommented, Nov 27, 2019

Apologies for the confusion, managed to reproduce this in 1.18.0:

import { Stack, App } from '@aws-cdk/core';
import ec2 = require('@aws-cdk/aws-ec2');
import elb = require('@aws-cdk/aws-elasticloadbalancingv2');

const app = new App();

const root = new Stack(app, 'Root');

const stack1 = new Stack(root, 'Network');
const vpc = new ec2.Vpc(stack1, 'Vpc');

const stack2 = new Stack(root, 'Instances');
new elb.ApplicationLoadBalancer(stack2, 'LoadBalancer', { 
  vpc, 
  internetFacing: true 
});

app.synth();

Validated that this is going to be resolved by #5211

0reactions
cmckni3commented, Dec 9, 2019

I can confirm this is fixed in master. I did a full build and linked dependencies into a project last night.

cdk deploy worked perfectly with cross stack VPCs. No more template reference error could not reference MyAppVPCRoute. 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

SOLVED AWS CloudFormation Create stack. Unresolved ...
I have googled for a bit and I have no idea what I am supposed to fix. AFAIK, all the dependencies in the...
Read more >
Template format error: Unresolved resource dependencies in ...
The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [ApiGatewayRestApi] in the Resources block of the template.
Read more >
Handling circular dependency errors in AWS CloudFormation
When you get a circular dependency error, the first step is to examine the resources that are outlined and ensure that AWS CloudFormation ......
Read more >
How to fix / why are Conditions causing Unresolved resource ...
I'm working on breaking my CloudFormation templates into functional stacks. Not yet to the point of doing any nesting, just doing everything ...
Read more >
Troubleshooting CloudFormation - 亚马逊云科技
Delete stack fails · Dependency error · Error parsing parameter when passing a list · Insufficient IAM permissions · Invalid value or unsupported...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found