terraform-cdk icon indicating copy to clipboard operation
terraform-cdk copied to clipboard

Add Dependency on Custom Construct

Open skorfmann opened this issue 4 years ago • 3 comments

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:

Screenshot 2021-06-18 at 13 00 37

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

skorfmann avatar Jun 18 '21 11:06 skorfmann

Would that add depends_on to every resource within the custom construct?

jsteinich avatar Jun 18 '21 13:06 jsteinich

Would that add depends_on to 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

skorfmann avatar Sep 19 '23 11:09 skorfmann

I think we would accept contributions 👍

DanielMSchmidt avatar Sep 19 '23 12:09 DanielMSchmidt