microscopic-cpu-38113
06/05/2024, 8:36 AMlively-crayon-44649
06/05/2024, 8:43 AMDiff
implementation look like?microscopic-cpu-38113
06/05/2024, 8:44 AMasync diff(id: string, olds: any, news?: any) {
const changes = Object.keys(news).some(key => {
// Skip the comparison for the 'updated_at' property
if (key === "updated_at") {
return false;
}
return JSON.stringify(olds[key]) !== JSON.stringify(news[key]);
});
return {
changes
}
}
the output shows "updated_at" was updated each time after the apply, so I tried to skip itlively-crayon-44649
06/05/2024, 8:50 AMstringify
will not be stable if key orders in the nested JSON are not stable (for instance)microscopic-cpu-38113
06/05/2024, 8:52 AMlively-crayon-44649
06/05/2024, 8:55 AMupdated_at
from the equation helped.lively-crayon-44649
06/05/2024, 8:56 AMread
shouldn't affect this I don't think. diff
is going to be called with old data (from the Pulumi state -- nothing to do with the "cloud" state, which is what read
returns) and the new "goal state" (what you've written in the program)microscopic-cpu-38113
06/05/2024, 8:56 AMlively-crayon-44649
06/05/2024, 8:57 AMJSON.stringify(olds[key])
and JSON.stringify(news[key])
will shed some light.microscopic-cpu-38113
06/05/2024, 10:43 AM~ pulumi-nodejs:dynamic:Resource: (update)
[id=string]
[urn=string]
allowRuleId : "string"
app : "string"
appLauncherVisible: false
blockRuleId : "string"
private_address : "domain"
tenantId : "string"
--outputs:--
- allowRuleId : "string"
- app : "string"
- appLauncherVisible : false
+ app_launcher_visible: false
+ aud : "string"
- blockRuleId : "string"
+ created_at : "0001-01-01T00:00:00Z"
+ gateway_rules : [
+ [0]: {
+ id: "string"
}
+ [1]: {
+ id: "string"
}
]
+ id : "string"
+ name : "string"
+ uid : "string"
+ updated_at : "2024-06-05T10:39:16Z"
I've added a read method and this is the new log, is it due to a change in the output that forces an update? Is this something that I need to change in the return or outs in the create/ update method?microscopic-cpu-38113
06/05/2024, 10:45 AMJSON.stringify(olds[key])
and JSON.stringify(news[key])
in the diff method? it doesn't seem to display anything in the plan. I tried console.log(changes) before but no luck:
async diff(id: string, olds: any, news?: any) {
const changes = Object.keys(news).some(key => {
// Skip the comparison for the 'updated_at' property
if (key === "updated_at") {
return false;
}
return JSON.stringify(olds[key]) !== JSON.stringify(news[key]);
});
console.log(changes)
return {
changes
}
}
lively-crayon-44649
06/05/2024, 10:46 AMconsole.log
and pass --logflow --logtostderr
to the pulumi
commands, do you see the logs?microscopic-cpu-38113
06/05/2024, 10:59 AMlively-crayon-44649
06/05/2024, 12:29 PMlively-crayon-44649
06/05/2024, 12:29 PMmicroscopic-cpu-38113
06/05/2024, 1:34 PMlively-crayon-44649
06/05/2024, 2:18 PMmicroscopic-cpu-38113
06/05/2024, 4:09 PM~ pulumi-nodejs:dynamic:Resource: (refresh)
[id=string]
[urn=urn:pulumi:string]
--outputs:--
+ app : "string"
- appId : "string"
+ appLauncherVisible: true
+ private_address : "string"
+ tags : [
+ [0]: "string"
+ [1]: "string"
]
+ type : "private_dns"
The logs above is shown in the plan, I suppose I need to add these attributes in the outputs of create or update?lively-crayon-44649
06/06/2024, 8:36 AMDiff
. When Pulumi calls Diff
, it passes two things:
⢠"Old" -- this is the inputs Pulumi has in its state file (so in essence, the last time it ran the program, what the inputs were)
⢠"New" -- this is the inputs that are now specified in the program (so in essence, what the "code says now")
So:
⢠If some of your inputs are outputs of other resources, those resources may change and trigger your diff, but your outputs are not going to be involved, if that makes sense.
⢠Your diff will be comparing those two sets of inputs and working out if there is a changelively-crayon-44649
06/06/2024, 8:37 AMRead
is used in a few cases. Two common ones are:
⢠When you perform an import
, Pulumi tries to Read
the state of the resource you are importing from the cloud provider.
⢠When you perform a refresh
, Pulumi tries to Read
all your resources and compare what it finds with what it has in statemicroscopic-cpu-38113
06/07/2024, 9:36 AMeventSink::Info(<{%reset%}>Key: allowRuleId, Old Value: undefined, New Value: "string"
eventSink::Info(<{%reset%}>Key: app, Old Value: undefined, New Value: "string"
eventSink::Info(<{%reset%}>Key: appLauncherVisible, Old Value: undefined, New Value: true
eventSink::Info(<{%reset%}>Key: blockRuleId, Old Value: undefined, New Value: "string"
eventSink::Info(<{%reset%}>Key: tenantId, Old Value: undefined, New Value: "string"
finally managed to print out the keys and I think this is the root cause, I suppose I need to add those keys as part of the output in my create method?lively-crayon-44649
06/07/2024, 9:40 AMcreate
will end up in state, yes (as will update
), and those are the values that will come in as old
each time diff
is called (with new
being those in the current version of the program)microscopic-cpu-38113
06/07/2024, 10:55 AMlively-crayon-44649
06/07/2024, 10:59 AM