Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependencies between constructs and resources #95

Closed
eladb opened this issue Jun 13, 2018 · 2 comments · Fixed by #1583
Closed

Dependencies between constructs and resources #95

eladb opened this issue Jun 13, 2018 · 2 comments · Fixed by #1583
Labels
package/awscl Cross-cutting issues related to the AWS Construct Library pr/breaking-change This PR is a breaking change. It needs to be modified to be allowed in the current major version.

Comments

@eladb
Copy link
Contributor

eladb commented Jun 13, 2018

We have an interface called IDependable, but It's not a nice API and very explicit. I wonder if it will be sufficient to automatically just add all resources that are children of a dependency target instead, so when you do source.addDependency(target), the tree under target is inspected and any construct that has a logicalId under that tree will be automatically added.

@rix0rrr rix0rrr added the design label Jun 22, 2018
@eladb eladb added the pr/breaking-change This PR is a breaking change. It needs to be modified to be allowed in the current major version. label Aug 29, 2018
@eladb eladb changed the title Reconsider IDependable Dependencies between constructs and resources Aug 29, 2018
@eladb eladb added the package/awscl Cross-cutting issues related to the AWS Construct Library label Aug 29, 2018
@buffovich
Copy link

Two strategies might be considered:

  • Propagation as dependencies of all low-level constructs of the composite we depend on to DependsOn section.
    -- Pros: simple, natural, no cryptic artifacts in the resulting CFN document
    -- Cons: bloats (sometimes exponentially) each DependsOn section of individual simple construct or every DependsOn section of a composite if we establish dependencies between composites
  • Creating fake barrier artifacts and put dependencies on those
    Let me describe it in more details. You need to create two nodes in CFN document - entry node for start barrier and exit nodes for completion barrier. If a composite depends on something, in CFN it will be reflected as start barrier node DependsOn this thing. If there are dependencies on the composite then those dependencies are reflected with DependsOn on completion node (barrier).
    -- Pros: potentially better size optimization of the template, more direct mapping between model and representation.
    -- Cons: presence of obscure barrier nodes in the output document, need to write optimizing algorithms to tree-shake useless barrier nodes if they don't have any dependencies, flatten dependency tree if needed to optimize resource usage, resource number limit exhaustion.

In https://github.com/awslabs/cloud-templates-ruby we chose the latter because of some important metrics of the templates we already have. For instance size limit becomes a serious problem for us shall we propagate dependencies. However, it's in no way optimal approach for everybody.

So, looking forward to developments on this front.

@buffovich
Copy link

Oh, and another dimension to consider is nested stacks (they make sense after particular size threshold). However, it introduces value/attribute propagation problems between them.

rix0rrr added a commit that referenced this issue Feb 4, 2019
Constructs can now take a dependency on any other construct.

Before, only `Resource`s could take dependencies, and they would depend
on `IDependable` which had to be implemented explicitly. In this change
we generalize the concept of dependencies from construct trees to other
construct trees; all constructs now take dependencies and also implement
`IDependable`.  The semantics are that any resource in the depending
tree will depend on all resources in the depended tree.

Dependencies are cross-stack aware

If you take a dependency on a construct in another stack, the dependency
does not get rendered in the template, but is instead added as a
dependency between stacks.

Fixes #1568, fixes #95.

BREAKING CHANGE: `resource.addDependency()` has been moved onto
`ConstructNode`. You now write `resource.node.addDependency()`. VPC's
`internetDependency` has been moved to the subnets as
`internetConnectivityEstablished`. Target Group's
`loadBalancerAssociationDependencies` has been renamed to
`loadBalancerAttached`.
moofish32 pushed a commit to moofish32/aws-cdk that referenced this issue Feb 5, 2019
Constructs can now take a dependency on any other construct.

Before, only `Resource`s could take dependencies, and they would depend
on `IDependable` which had to be implemented explicitly. In this change
we generalize the concept of dependencies from construct trees to other
construct trees; all constructs now take dependencies and also implement
`IDependable`.  The semantics are that any resource in the depending
tree will depend on all resources in the depended tree.

Dependencies are cross-stack aware

If you take a dependency on a construct in another stack, the dependency
does not get rendered in the template, but is instead added as a
dependency between stacks.

Fixes aws#1568, fixes aws#95.

BREAKING CHANGE: `resource.addDependency()` has been moved onto
`ConstructNode`. You now write `resource.node.addDependency()`. VPC's
`internetDependency` has been moved to the subnets as
`internetConnectivityEstablished`. Target Group's
`loadBalancerAssociationDependencies` has been renamed to
`loadBalancerAttached`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package/awscl Cross-cutting issues related to the AWS Construct Library pr/breaking-change This PR is a breaking change. It needs to be modified to be allowed in the current major version.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants