Issue
I've a project with multiple stacks, but with common stacks.ts file.
- My 1 stack creates a VPC
- My 2 stack creates a ECS
Stack vpc.tf
export class stack-vpc extends Stack {
constructor(scope: Construct, id: string, props?: props) {
super(scope, id, props);
new ec2.Vpc(this, 'dev-vpc', {
cidr: "10.0.0.0/16",
vpcName: "dev-vpc"
})
}
}
Stack ecs.tf
export interface Istack-ecs extends StackProps {
vpc: ec2.Vpc;
}
export class stack-ecs extends Construct {
constructor(scope: Construct, id: string, props: Istack-ecs) {
super(scope, id);
new ecs.Cluster(this, "fargate", {
vpc: props.vpc,
clusterName: "test",
enableFargateCapacityProviders: true
});
}
}
Here is the stacks.ts file
const app = new cdk.App();
const vpc = new stack-vpc(app, "Dev_VPC_CF", props);
const ecs = new stack-ecs(app, "Dev_ECS_CF", props);
The vpc is creating without any problem, however once I'm putting an ecs to my stack the cdk gives me the error:
[Error at /stack-ecs] Could not find any VPCs matching {"account":"__--__","region":"eu-central-1",
"filter":{"tag:Name":"stack-vpc","isDefault":"false"},
"returnAsymmetricSubnets":true,
"lookupRoleArn":"arn:aws:iam::__--__:role/cdk-hnb659fds-lookup-role-__--__-eu-central-1"}
cdk.context.json is retrieving correct values from my aws credentials, so I can't blame the authentification, so my problem I need to somehow wait until one stack will give me an output so I can use it in my other stacks
Solution
As @fedonev said
The fromLookup methods are for referencing existing deployed resources.
So instead you can do something like this:
- Your
vpcshould exportec2.Vpc Constructwon't work in your case, you need to extend fromcdk.Stack- Since your
ecsinterfaceIstack-ecsalready expecting avpc
const app = new cdk.App();
const your_vpc = new stack-vpc(app, "Dev_VPC_CF", props);
const your_ecs = new stack-ecs(app, "Dev_ECS_CF", {
vpc: your_vpc.vpc // As your props expects one single value
});
your_ecs.addDependency(your_vpc); // Guarantees That your `vpc` will be created firstly
app.synth();
Answered By - Bow Bow
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.