Unexpected cyclic reference with Vpc and DatabaseCluster
If Vpc is created in one stack and a DatabaseCluster in this Vpc in another stack, then I get the cyclic reference error
Reproduction Steps
export class CommonStack extends Stack {
private vpc: IVpc;
private securityGroup: ISecurityGroup;
constructor(parent: App, name: string) {
super(parent, name);
const vpc = new Vpc(this, 'CommonVpc', {
natGateways: 0,
});
this.vpc = vpc;
this.securityGroup = SecurityGroup.fromSecurityGroupId(this, 'VpcDefaultSecurityGroup', vpc.vpcDefaultSecurityGroup);
}
get Vpc(): IVpc {
return this.vpc;
}
get SecurityGroup(): ISecurityGroup {
return this.securityGroup;
}
}
export class DbStack extends Stack {
constructor(parent: App, name: string, options: DbStackOptions) {
super(parent, name);
...
const cluster = new DatabaseCluster(this, "DbCluster", {
engine: options.clusterEngine,
parameterGroup: ParameterGroup.fromParameterGroupName(this, 'ParameterGroup', 'default.aurora-mysql5.7'),
defaultDatabaseName: defaultDbName,
masterUser: {
username: options.rootUserName,
},
instanceProps: {
instanceType: InstanceType.of(options.instanceClass, options.instanceSize),
vpcSubnets: {
subnetType: options.subnetType,
},
vpc,
securityGroup,
}
});
}
}
Error Log
Error: 'DbStack' depends on 'CommonStack' (DbStack -> CommonStack/CommonVpc/PublicSubnet1/Subnet.Ref). Adding this dependency (CommonStack -> DbStack/DbCluster/Resource.Endpoint.Port) would create a cyclic reference.
Environment
- CLI Version : 1.14.0
- Framework Version: 1.14.0
- OS : Windows 10
- Language : TS
This is :bug: Bug Report
@shurmanidze I would recommend creating a security group specifically for your database cluster in the database cluster stack rather than importing a security group from another stack. If you need to allow access to your database cluster you can always do that. For example if you wanted to allow access from the vpc security group you would do something like
...
const dbSecurityGroup = new SecurityGroup(this, 'DbSg');
const cluster = new DatabaseCluster(this, "DbCluster", {
...,
instanceProps: {
securityGroup: dbSecurityGroup,
}
});
}
cluster.connections.allowDefaultPortFrom(props.vpcSecurityGroup);
}
Also, I would recommend against using the vpc default security group. Most security controls recommend making sure the vpc default security group does not allow inbound or outbound traffic. https://docs.aws.amazon.com/securityhub/latest/userguide/securityhub-standards-fsbp-controls.html#fsbp-ec2-2
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.
I am seeing the same issue, with a rds.DatabaseProxy in one stack and the VPC in another stack. How did you resolve this @shurmanidze ?