-
Notifications
You must be signed in to change notification settings - Fork 43
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
Conversation
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
Codecov ReportAttention: Patch coverage is
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. |
pkg/tfbridge/provider.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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.
Co-authored-by: Ian Wahbe <ian@wahbe.com>
An alternative to consider is to add a |
Check does not return planed state in bridged providers, alas. |
There was a problem hiding this 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
:
pulumi-terraform-bridge/pf/tfbridge/logging.go
Lines 25 to 28 in de2933b
// 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 { |
Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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 thePreCheckCallback
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