Skip to content

Conversation

@rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Oct 22, 2025

Previously, construct.env was declared in the IResource interface.

Downside is that IResource also:

  • requires providing stack: Stack (which is a bit pointless to begin with since we can always call Stack.of(x)); and
  • applyRemovalPolicy() which doesn't belong on this interface but now is required to implement.

Therefore, we extract IResource#env out to its own interface, IEnvironmentAware; make IXxxRef extend that interface, simplify IResourceWithPolicy to only be IEnvironmentAware and not an entire IResource.

Lessening the requirements on IResourceWithPolicy also lessens its guarantees, which makes that a breaking change. In order to make this code change, we do the following:

  • Introduce IResourceWithPolicyV2 to be the version of IResourceWithPolicy we should have had.
  • Accept IResourceWithPolicyV2 everywhere
  • Make IResourceWithPolicy extend IResourcWithPolicyV2
                   ┌──────────────────────────┐                     
                   │    IEnvironmentAware     │                     
                   └──────────────────────────┘                     
                                 ▲                                  
             ┌───────────────────┴────────────────────┐             
             │                                        │             
┌──────────────────────────┐            ┌──────────────────────────┐
│  IResourceWithPolicyV2   │            │        IResource         │
└──────────────────────────┘            └──────────────────────────┘
              ▲                                       ▲             
              └──────────────────┬────────────────────┘             
                                 │                                  
                   ┌──────────────────────────┐                     
                   │   IResourceWithPolicy    │                     
                   └──────────────────────────┘                     

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Previously, `construct.env` was declared in the `IResource` interface.

Downside is that `IResource` also:

- requires providing `stack: Stack` (which is a bit pointless to begin
  with since we can always call `Stack.of(x)`); and
- `applyRemovalPolicy()` which doesn't belong on this interface but
  now is required to implement.

Therefore, we extract `IResource#env` out to its own interface,
`IEnvironmentable`, make `IXxxRef` extend that interface.
@rix0rrr rix0rrr requested a review from a team as a code owner October 22, 2025 12:16
@aws-cdk-automation aws-cdk-automation requested a review from a team October 22, 2025 12:16
@github-actions github-actions bot added the p2 label Oct 22, 2025
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Oct 22, 2025
@rix0rrr rix0rrr changed the title chore: dedicated interface to retrieve a construct's environment chore: IEnvironmentAware interface to retrieve a construct's environment Oct 22, 2025
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Oct 27, 2025
@rix0rrr rix0rrr changed the title chore: IEnvironmentAware interface to retrieve a construct's environment feat: IEnvironmentAware interface to retrieve a construct's environment Oct 28, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@rix0rrr rix0rrr added pr-linter/exempt-readme The PR linter will not require README changes pr-linter/exempt-integ-test The PR linter will not require integ test changes labels Oct 28, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review October 28, 2025 10:15

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Oct 28, 2025
@mrgrain mrgrain changed the title feat: IEnvironmentAware interface to retrieve a construct's environment feat(core): IEnvironmentAware interface to retrieve a construct's environment Oct 28, 2025
@mergify
Copy link
Contributor

mergify bot commented Oct 28, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify
Copy link
Contributor

mergify bot commented Oct 28, 2025

This pull request has been removed from the queue for the following reason: checks failed.

The merge conditions cannot be satisfied due to failing checks:

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio requeue comment.

@mergify
Copy link
Contributor

mergify bot commented Oct 28, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify
Copy link
Contributor

mergify bot commented Oct 28, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 8ee5d4b into main Oct 28, 2025
18 of 19 checks passed
@mergify mergify bot deleted the huijbers/environmentable branch October 28, 2025 16:10
@github-actions
Copy link
Contributor

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

contribution/core This is a PR that came from AWS. p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes pr-linter/exempt-readme The PR linter will not require README changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants