Hi, I need some help with transforms. So I have an...
# golang
r
Hi, I need some help with transforms. So I have an ebs.NewVolume where I originally passed nothing to the
KmsKeyId
StringPtrInput
in the
VolumeArgs
. Now, I've updated my code and I'm passing a freshly initialized
StringPtrOutput
with a nil value, but this is causing a diff between my old version and new one, which will delete and re-create my volume. I'm guessing that this diff happens because I first passed in nothing, now I'm actually passing an output, even though its value is
nil
. Is that correct? If so, I'm trying to handle this with a resource transform, but how can I check the value of this output and delete it in an ApplyT and pass that back into the
ResourceTransformResult
This code doesn't compile, but hopefully it shows what I'm trying to do
Copy code
pulumi.Transforms([]pulumi.ResourceTransform{
	func(ctx context.Context, rta *pulumi.ResourceTransformArgs) *pulumi.ResourceTransformResult {
		newProps := rta.Props.ToMapOutput().ApplyT(func(props map[string]any) map[string]any {
			if val, ok := props["kmsKeyId"]; ok && val == nil {
				delete(newProps, "kmsKeyId")
			}
			return props
		}).(pulumi.MapOutput)

		return &pulumi.ResourceTransformResult{
			Props: newProps,
			Opts:  rta.Opts,
		}
	},
}),
or maybe more simply put, how can I modify
rta.Props
and return the result in a transform?
If I can't do this, I guess I could always modify my state files by hand 😬
e
I don't think you can do this with a transform because of https://github.com/pulumi/pulumi/issues/16756. But it should probably be raised on the provider that it shouldn't report a diff for a property being explicitly set to null, and just being unset.
r
Thanks, I’ll look into that issue
I’ve been playing around with the solution in the issue, but I think the easiest path forward is to just modify my stack inputs and make a PR in the provider 😕
e
Posted on the issue, I think this is actually simple because you know its nil. That didn't occur to me at first
r
Oh, that was you on the issue 🙂 Do you prefer the convo in github or here?
e
GitHub is better, keeps the history
r
I’m about to get a bit off topic, so I’ll leave this here for now: I’ve decided to modify my state files so I can use the modified code, but I’m still gettings diffs. So I’ve exported my state, added the following to the input map
kmsKeyId: null
, and re-imported the state. But I’m still getting a diff when I have a nil value for
KmsKeyId
in the
StringPtrOutput
.. am I missing a step?
e
did you edit the inputs and outputs in the state file?
r
the output was already there as
kmsKeyId: ""
.. should I make that
nil
too?
this is getting a bit into provider specifics I guess
aha!
Copy code
"propertyDependencies": {
        "availabilityZone": [],
        "encrypted": [],
        "iops": [],
        "kmsKeyId": [],
        "size": [],
        "tags": [],
        "throughput": [],
        "type": []
    },
that should do it..
hopefully… let’s see…
ok, now the real "aha"...
Copy code
kmsKeyId := pulumi.StringPtrFromPtr(nil)
which just returns
nil
... now we're all good!
Thanks for you help! I'm still new to transforms and thought this would be a nice application
e
Glad you got it worked out