Hello! Is there a way to modify `pulumi.InvokeOpti...
# automation-api
l
Hello! Is there a way to modify
pulumi.InvokeOptions
within a stack transformation? I have the following working for setting an explicit provider on all my resources using
pulumi.ResourceOptions
, but trying to do the same with InvokeOptions for functions such as
aws.s3.get_bucket
seems to have no effect, making me wonder if transformations affect functions at all.
Copy code
def stackTransformations(args):
    args.opts = pulumi.ResourceOptions.merge(args.opts, pulumi.ResourceOptions(
        provider = self.deploymentProvider
    ))
    return pulumi.ResourceTransformationResult(args.props, args.opts)

pulumi.runtime.register_stack_transformation(lambda args: stackTransformations(args))
l
They do not affect non-resources:
Transformations can also be applied in bulk to many or all resources in a stack by using Stack Transformations, which are applied to the root stack resource and as a result inherited by all other resources in the stack.
l
Well darn. Is there some way to set InvokeOptions on a mass scale besides transforms?
l
Only via your preferred language's normal methods. Use a base object, wrap the call to the Pulumi functions in some of your own code, something like that.
Changing the provider in a transformation is fairly risky. It is quite likely that eventually, you'll have an exception to the rule, and your transformation will override it. You'll spend a while tracking that down...
You might consider requiring provider to always be passed in, and creating a transformation that throws an exception if it's not. That should be safer.
l
I would tend to agree, but this is part of a dynamic system where one sets the provider for a given instance of the stack. So configuration like this needs to trickle down automatically without changing the underlying Pulumi code.
l
You can still make requirements on the developers of your system. Rather than allowing them to use aws.s3.get_bucket(), you can require them to use yourorg.s3.get_bucket(), which calls aws.s3.get_bucket() with the correct opts.
l
Yep, I think that sounds like a good option for now. Appreciate the tip!