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).
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
});
}
}
``` ts
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
});
}
}
``` ts
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
});
}
}
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
This is :bug: Bug Report
This is a blocking issue to organize large infra by nested stacks. Any fix ETA?
Unfortunately we don't have an ETA yet. To work around issues this problem is causing for you, you can try using the escape hatch mechanism.
I ran into this issue as well. It seems like it has something to do with Stacks being initialized inside of other Stacks.
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
@eladb is this set for a 1.19.0 release?
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. 👍
Most helpful comment
Apologies for the confusion, managed to reproduce this in 1.18.0:
Validated that this is going to be resolved by #5211