How can I unset the optional value that have been ...
# typescript
g
How can I unset the optional value that have been set before? I am using SentryProvider (just in case it matters) consider following situation: schema:
Copy code
{ val?: number }
create:
Copy code
const s = { val: 1 }
now I no want
val
to be
undefined
because SentryProvider has an internal functionality depends on the
undefined
value. update:
Copy code
const s = { val: undefined }
the problem is that pulumi won’t pick this change up and does nothing, leaving the original value intact. What can I do in this case?
l
What is SentryProvider? Do you mean
sentry.Provider
? I can't see an Input on sentry.Provider that takes an optional value, so I can't check the code. Is it a provider or a cloud resource that's showing this behaviour?
g
It is this resource https://www.pulumi.com/registry/packages/sentry/api-docs/sentryissuealert/#inputs The problematic property is
environment
. official sentry API says it is nullable (or optinal) So I checked the terraform provider and found it optional. but optional to pulumi means
undefined
not
null
. So I am digging in the terraform provider of the version 11, that’s what pulumi uses https://registry.terraform.io/providers/jianyuan/sentry/0.11.2/docs/resources/issue_alert#environment-6 and it is optional even there. It is still optional in even in the latest version And the new version
14.x
is based on open API spec https://registry.terraform.io/providers/jianyuan/sentry/latest/docs/resources/issue_alert#environment-2 Which makes me wonder if the terraform provider works as expected and it is messed up on pulumi side or not.
If I understand the vague API spect correctly, sending a
null
value should call “select All” https://docs.sentry.io/api/alerts/create-an-issue-alert-rule-for-a-project/
but
undefined
value in pulumi provider won’t trigger the state change
l
Have you tried setting it to null?
g
the type is
pulumi.Input<string> | undefined
not
null
another fun part is that when you create the resource with environment that does not exists yet, it is fine. when you try it second time, you get an API error like
400 map[environment:[This environment has not been created.]]
this whole API is cursed and bugged IMO
wow neither
null
type or `""`(empty string) causes the update! yet pulumi state shows
inputs: ""
but `outputs: “old value that should not be there”
l
Yep. Nulls suck. That API seems to be ORing all those fields together, is that right? If any issue matches, then the alert is sent. And you just want to ignore the
environment
value and send the alert no matter what it is. Can you use the
filter
property and set it to something that always matches everything? Or something that always matches what you want.
And if you need to force an update for some reason, you could change the filter to add a wildcard, or something like that. A change that is meaningful from a JSON-difference point of view, but meaningless from a query results point of view.
I guess you could also extract that bit of code to a .js file and set the value to null there... skip all type checking.
g
I could do something like that and use
replaceOnChanges
to recreate the whole resource
l
Yep that'd work, probably
g
And I did try to pass
null as any
to avoid type checking. IMO there’s somewhere a nullcheck for nullish values because the same behaviour can be expected with
null, undefined, ""
- no changes to state
l
I don't think
null as any
would work the same way as going to JS, and it might work. However I'd say the other solution would be much simpler to implement
g
The API is so bugged that you can use the same condition multiple times 🏭 🤦 so I set
replaceOnChanges:["conditions"]
and
environment: undefined
and this has caused the replacement and expected behaviour.
at this point I’d be much happier if the pulumi state was a database I could query at will instead of a flat JSON file and mumbo jump … sqlite must be reasonably fast for this matter. I need to test the API call manually to trully find out how it behaves … I was able to unset the value via transformation with
null
but that unselected the thing. Not selected All …