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

feat: add resource urn to context in Check call #1877

Merged
merged 5 commits into from
Apr 18, 2024

Conversation

corymhall
Copy link
Contributor

This PR adds the resource URN to the context in the Check method, along with methods to set and get the URN from context.

The motivation for this change was driven by trying to implement the suggested fix in this
comment
in the aws provider. We want to be able to keep some global state of which resources have been seen by Check, but realized that we don't actually get any identifying information in the PreCheckCallback function.

An alternative approach would be to update the PreCheckCallback signature to also contain the URN, but that would be a breaking change.

re pulumi/pulumi-aws#3788

This PR adds the resource URN to the context in the `Check` method,
along with methods to set and get the URN from context.

The motivation for this change was driven by trying to implement the
suggested fix in [this
comment](pulumi/pulumi-aws#3788 (comment))
in the aws provider. We want to be able to keep some global state of
which resources have been seen by `Check`, but realized that we don't
actually get any identifying information in the `PreCheckCallback`
function.

An alternative approach would be to update the `PreCheckCallback`
signature to also contain the URN, but that would be a breaking change.

re pulumi/pulumi-aws#3788
@corymhall corymhall requested a review from iwahbe April 16, 2024 15:01
Copy link

codecov bot commented Apr 16, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 60.01%. Comparing base (d9452a5) to head (a08f511).

Files Patch % Lines
pf/tfbridge/logging.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1877      +/-   ##
==========================================
+ Coverage   59.99%   60.01%   +0.01%     
==========================================
  Files         327      327              
  Lines       43976    43986      +10     
==========================================
+ Hits        26382    26396      +14     
+ Misses      16102    16098       -4     
  Partials     1492     1492              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@corymhall corymhall added this to the 0.103 milestone Apr 16, 2024
@corymhall corymhall self-assigned this Apr 16, 2024
@corymhall corymhall requested a review from t0yv0 April 16, 2024 15:58
@@ -726,6 +726,7 @@ func (p *Provider) Configure(ctx context.Context,
func (p *Provider) Check(ctx context.Context, req *pulumirpc.CheckRequest) (*pulumirpc.CheckResponse, error) {
ctx = p.loggingContext(ctx, resource.URN(req.GetUrn()))
urn := resource.URN(req.GetUrn())
ctx = WithUrn(ctx, urn)
Copy link
Member

Choose a reason for hiding this comment

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

I'm amenable to this but the question becomes why only in Check? Perhaps you could retrofit p.loggingContext to do this; it's already installed in all the methods pretty much.

pkg/tfbridge/info.go Outdated Show resolved Hide resolved
pkg/tfbridge/info.go Outdated Show resolved Hide resolved
pkg/tfbridge/info.go Outdated Show resolved Hide resolved
@corymhall corymhall requested review from t0yv0 and iwahbe April 17, 2024 15:00
@EronWright
Copy link

An alternative to consider is to add a PostCheckCallback, so that the provider gets the checked inputs that represent the planned state. It could be that the planned state is more useful than the pre-check state. I could imagine that defaulting or transformations happen during check. Food for thought.

@t0yv0
Copy link
Member

t0yv0 commented Apr 18, 2024

Check does not return planed state in bridged providers, alas.

Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

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

As implemented, I don't think this will work for PF based providers. If I'm wrong and it does, then we need to add a quick test to lock in that behavior. If it doesn't, we will need to add support (and a quick test to lock in behavior).

The equivalent method to loggingContext in PF land is initLogging:

// Configures logging. Note that urn is optional but useful to identify logs with resources.
//
// See https://developer.hashicorp.com/terraform/plugin/log/writing
func (p *provider) initLogging(ctx context.Context, sink logging.Sink, urn resource.URN) context.Context {

@corymhall
Copy link
Contributor Author

The equivalent method to loggingContext in PF land is initLogging:

Done!

@corymhall corymhall requested a review from iwahbe April 18, 2024 12:57
Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

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

LGTM

@corymhall corymhall merged commit 4dbf4df into master Apr 18, 2024
11 checks passed
@corymhall corymhall deleted the corymhall/precheckcallback-urn branch April 18, 2024 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants