Open MintuJ opened 1 year ago
Hi
You should be able to export and import the VPC cross-stack like this:
export class VpcStack extends Stack {
readonly vpc: ec2.IVpc;
constructor(scope: Construct, id: string, props: StackProps = {}) {
super(scope, id, props)
this.vpc = new ec2.Vpc(this, 'Vpc');
}
}
export interface PHZStackProps extends StackProps {
readonly vpc: ec2.IVpc;
}
export class PHZStack extends Stack {
constructor(scope: Construct, id: string, props: PHZStackProps) {
super(scope, id, props)
new route53.PrivateHostedZone(this, 'PHZ', {
vpc: props.vpc,
zoneName: 'foo.com',
})
}
}
Can you elaborate more about your pain points?
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.
Is there a way for PHZStackProps.vpc be initialized if VpcStack is created in a defined either outside the CDK, or in a different CDK package and there is no way to pass VpcStack.vpc in props?
Our team has some tooling that requires each stack to be in different packages. We want to avoid Vpc.fromLookup
since it creates a dependency between the stacks at build time. One option is to use L1 HostedZone construct CfnHostedZone, but we would prefer an L2 construct.
If constructor just requires VpcId which is a string, it can be exported from the VPCStack and referred in the PHZ stack.
Describe the feature
Similar to Cloudformation, enable creation of HostedZones with just VpcId and VpcRegion
Use Case
Creating a PrivateHostedZone requires an IVpc today. If the PrivateHostedZone is in a different stack, the VPC object creation requires a Vpc.fromLookup call that creates a dependency between stack creation.
Eg. For a new service creation in a region:
Proposed Solution
Enable PrivateHostedZone creation with just VpcId and region similar to the Cloudformation template https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-route53-hostedzone.html#cfn-route53-hostedzone-vpcs
This would help remove the dependency by just exporting the VpcId from the VPC stack and referring to it in the PrivateHostedZone stack.
Eg. For a new service creation in a region:
Other Information
No response
Acknowledgements
CDK version used
1.197.0
Environment details (OS name and version, etc.)
MacOs