terraform-cdk
terraform-cdk copied to clipboard
Add Dependency on Custom Construct
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Description
There are scenarios, where a custom construct includes a few resources and one wants to define a dependency on that custom construct. E.g. when dealing with the AWS ApiGateway:

Constructs have the concept of dependencies. We could use this, to add explicit Terraform depends_on:
// ApiRoute contains a handful of resources
const route = new ApiRoute(this, 'route', {
api,
route: 'POST /foo/bar/{baz}',
authorizer: new NodejsFunction(this, 'auth', {
path: path.join(__dirname, 'function', 'authorizer', 'index.ts')
})
})
const deployment = new aws.Apigatewayv2Deployment(this, 'deployment', {
apiId: api.id,
description: 'some deployment'
})
Node.of(route).addDependency(deployment)
References
Would that add depends_on to every resource within the custom construct?
Would that add
depends_onto every resource within the custom construct?
Yes, I think that would be the desired outcome. Would be nice if that was supported without having to create an Aspect. However, saw that a similar issue (https://github.com/hashicorp/terraform-cdk/issues/2727) got closed. So, I'm wondering if that's something where contributions would be accepted? /cc @DanielMSchmidt Asking since there's a similar story in Wing which could use this :) https://github.com/winglang/wing/issues/3225
I think we would accept contributions 👍