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

core: support editing CfnResource and Stack dependencies #20418

Closed
1 of 2 tasks
jusdino opened this issue May 19, 2022 · 2 comments
Closed
1 of 2 tasks

core: support editing CfnResource and Stack dependencies #20418

jusdino opened this issue May 19, 2022 · 2 comments
Labels
@aws-cdk/core Related to core CDK functionality effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@jusdino
Copy link
Contributor

jusdino commented May 19, 2022

Describe the feature

Currently, a user has the ability to use CfnResource.addDependsOn() to neatly add explicit dependencies between resources within or across stack boundaries. The catch is that, Node.tryRemoveChild() can then render a CFT completely invalid, since it can remove the referenced resource from a template entirely but a lingering DependsOn value remains set to a logical id that no longer exists. Node.tryRemoveChild() is, of course, in the 'escape hatch' api space, so I wouldn't expect it to gracefully search out any existing dependency references and remove them for me. However, since there is no visibility into already-set dependencies or any ability to gracefully remove individual dependencies, once a depended-on resource is removed, it becomes impossible for a user to salvage the template through the public API, short of something extreme like blindly adding DependsOn overrides to every resource they think might have a reference to the removed resource, possibly causing a lot more damage in the process. Adding some new methods that give a user the visibility and edit-ability to dependencies would be very powerful in a situation like this.

Use Case

Let's say a user has some code:

let foo = CfnResource(this, 'Foo', ...);
let bar = CfnResource(this, 'Bar', ...);
// We need bar deployed first
foo.addDependsOn(bar);

But then they use some construct/aspect/whatever that needs to recreate Bar for some reason:

const stack = Stack.of(this);
stack.node.tryRemoveChild('Bar');
const barReplacement = CfnResource(stack, 'BarReplacement', <some alternate properties or something>);

At this point, the construct that replaced Bar has no way of knowing that it has just irrevocably invalidated the template, because it has no way of seeing that Foo has a DependsOn reference to Bar, and the only possible way to rectify the template is to add foo.addOverride('DependsOn', ...), possibly squashing some other dependencies in the process.

Proposed Solution

Add some new methods to CfnResource that makes it possible to look into the dependency relationships and edit them if they really need to:

foo = stack.tryFindChild('Foo');
if (foo.obtainDependsOn().contains(bar)) {
  foo.removeDependsOn(bar);
fi
foo.addDependsOn(barReplacement);

These new CfnResource.obtainDependsOn() and CfnResource.removeDependsOn() would have to gracefully traverse the resource and assembly dependencies to mirror the behavior of CfnResource.addDependsOn(), for an intuitive user experience.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

any

Environment details (OS name and version, etc.)

any

@jusdino jusdino added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels May 19, 2022
@github-actions github-actions bot added the @aws-cdk/core Related to core CDK functionality label May 19, 2022
@rix0rrr rix0rrr added effort/medium Medium work item – several days of effort p2 and removed needs-triage This issue or PR still needs to be triaged. labels May 23, 2022
@rix0rrr rix0rrr removed their assignment May 23, 2022
mergify bot pushed a commit that referenced this issue Dec 19, 2022
Reopening #20419 from a personal fork to allow maintainer edits. @comcalvi 👋 

Add some new methods to allow a minimal interface for viewing and editing resource-to-resource dependencies that mirrors the behavior of CfnResource.addDependsOn().

Related to #20418 - details for justification are there

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Construct Runtime Dependencies:

* [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
brennanho pushed a commit to brennanho/aws-cdk that referenced this issue Jan 20, 2023
Reopening aws#20419 from a personal fork to allow maintainer edits. @comcalvi 👋 

Add some new methods to allow a minimal interface for viewing and editing resource-to-resource dependencies that mirrors the behavior of CfnResource.addDependsOn().

Related to aws#20418 - details for justification are there

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Construct Runtime Dependencies:

* [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@comcalvi
Copy link
Contributor

Closed by #23383

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

brennanho pushed a commit to brennanho/aws-cdk that referenced this issue Feb 22, 2023
Reopening aws#20419 from a personal fork to allow maintainer edits. @comcalvi 👋 

Add some new methods to allow a minimal interface for viewing and editing resource-to-resource dependencies that mirrors the behavior of CfnResource.addDependsOn().

Related to aws#20418 - details for justification are there

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Construct Runtime Dependencies:

* [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/core Related to core CDK functionality effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

3 participants