hey guys - newbie here to Pulumi and am working on...
# golang
d
hey guys - newbie here to Pulumi and am working on writing my own Component Package... couple of questions: 1. do my component arguments have to all be of some type of pulumi.Input or will "CopyTo" copy the right values into like normal strings and stuff? the reason I'm asking is because I want to validate input values in my component (not in the caller code every time) for things like "Is this a valid CIDR block?" "Is the CIDR block big enough?" "Is this a valid AZ in this AWS region?" etc. Or is there some other way that I should be doing validation? 2. my component builds several pieces of "core" infrastructure: VPC, Subnets, Route Tables, NAT Gateway, etc. and I want to return a bunch of values in my outputs but I wanted them to be nested so I'd have a main struct that holds members for each resource (VPC, Subnets, etc.) that are of a struct type with the resource struct containing the actual values (eg: ARN, ID, etc.) ... the problem is when I try and do that the CLI spits out an error like:
error: program failed: waiting for RPCs: rpc error: code = Unknown desc = marshaling properties: awaiting input property vpc: cannot marshal an input of type pulumi.StringOutput with element type string as a value of type pulumi.StringOutput
If I flatten it out into a single struct, though, it works fine... 3. do I have to call
ctx.RegisterResourceOutputs
to register outputs at the end? it doesn't seem to have any effect if I comment it out. Or is that used for other languages like NodeJS and .NET? Feel free to DM me or at least tag me so I see any replies... and TIA!!
b
@damp-accountant-65956 1: no, your inputs can be standard input types, but if they are, you won't be able to pass inputs from other resources into your component without using an `ApplyT`: see https://github.com/jaxxstorm/pulumi-awsloadbalancercontroller/blob/main/provider/pkg/provider/awsloadbalancercontroller.go#L22-L33 as an example 2: I'm not sure the answer to this, but your error message doesn't indicate it's a problem with nested outputs, it looks like you're passing the wrong value to the type? 3:
ctx.RegisterOutputs
will tell your component that all outputs have resolved for the UI, but may be used more in the future. See the answer here: https://github.com/pulumi/pulumi/issues/2653#issuecomment-484956028
d
Re #1 is there a better way to check to see if a StringInput is valid (eg: a string is a valid CIDR block or a CIDR block of a certain range? like i want to make sure they pass in a /20 or larger)