https://pulumi.com logo
#golang
Title
# golang
s

salmon-account-74572

06/25/2020, 10:27 PM
Another Go newbie question here: I'm hoping someone can help me understand why different resources handle/require different types. More details and sample code threaded below.
In one place of my code, I create a series of subnets (using
ec2.NewSubnet
) across AZs within a region, and then I "capture" the ID of the created subnets in an array (this happens near the end of a
for
loop):
Copy code
pubSubnetIds[idx] = subnet.ID()
Later, I can reference that array when I create a NAT Gateway with `ec2.NewNatGateway`:
Copy code
SubnetId: pubSubnetIds[0],
However, I can't do the same thing with route table associations in a
for
loop:
Copy code
SubnetId: pubSubnetIds[idx],
In that usage, Pulumi reports that "cannot use privSubnetIds[idx] (type pulumi.StringInput) as type pulumi.StringPtrInput in field value". I get that they are different types (apparently), but... a) why are they apparently different types between resources? b) how is someone supposed to know this other than trial-and-error? c) what is the workaround/solution?
I can post/upload more complete Go code if that would be helpful.
w

wet-egg-6347

06/25/2020, 11:00 PM
a) i'd like to know the answer to this myself! b) if you look at the args struct that you're filling in, you can see the expected types c) call ToStringPtrOutput() on your stringoutput
s

salmon-account-74572

06/25/2020, 11:05 PM
WRT to b, I disagree. In looking at the API reference for the NAT Gateway resource, for example, it simply lists SubnetId as "string", not "StringInput" or "StringPtrInput" or anything else.
As for your suggestion to c, that may fix the route table association issue, but will very likely break other places (like the NAT Gateway, which currently works). The issue is, as I understand it thus far, that I have one data source (the list of subnet IDs) and I need to represent that list in two different ways (both StringInput and StringPtrInput).
l

lemon-agent-27707

06/25/2020, 11:31 PM
yes, can you please share the full sample. It would be great to take a look at this.
I think the issue here is that
subnet.ID()
is a
pulumi.IDOutput
which implements
pulumi.StringOutput
and
pulumi.IDPointerOutpur
but not
pulumi.StringPointerOutput
.
Which on the surface looks like a bug to me, but I'd have to double check.
nvm I'm mistaken on that last point. It does indeed implement ToStringPointerOutput. Will be happy to debug based on a complete code sample.
s

salmon-account-74572

06/26/2020, 3:30 PM
@lemon-agent-27707 Here's the full Go code I'm using.
l

lemon-agent-27707

06/26/2020, 3:32 PM
can you also share your go.mod?
s

salmon-account-74572

06/26/2020, 3:33 PM
Copy code
module aws-get-azs

go 1.14

require (
	<http://github.com/pulumi/pulumi-aws/sdk/v2|github.com/pulumi/pulumi-aws/sdk/v2> v2.0.0
	<http://github.com/pulumi/pulumi/sdk/v2|github.com/pulumi/pulumi/sdk/v2> v2.0.0
)
l

lemon-agent-27707

06/26/2020, 4:04 PM
Looks like I might have a local fix.
StringInput
and other input methods that implement the corresponding ptr type don't have the appropriate methods declared on their interfaces even thought the methods are implemented. The type error goes away when I make this change to my SDK locally.
You can give it a try locally if you check out the branch into your $GOPATH and do a replace within your go.mod: https://github.com/pulumi/pulumi/pull/4911
s

salmon-account-74572

06/26/2020, 4:27 PM
OK, I'll see about giving that a try. Thanks!
@lemon-agent-27707 I see your PR was merged, any idea what release will include the fix?
l

lemon-agent-27707

06/30/2020, 6:56 PM
@salmon-account-74572 You should be able to consume the changes immediately by changing the dependency in your go.mod to look like the following and grab the latest commit:
Copy code
<http://github.com/pulumi/pulumi/sdk/v2|github.com/pulumi/pulumi/sdk/v2> v2.5.1-0.20200630183524-a8a20ecb4b1d
and then run
go mod download
Not sure if we're doing a patch release this week, but we'll have a minor version release next week.
s

salmon-account-74572

06/30/2020, 6:59 PM
OK, I have some other projects that have popped up this week, so worst case scenario I can pick up the minor version release next week. Thank you!
@lemon-agent-27707 I updated my
go.mod
and ran
go mod download
, and I can confirm that it did fix the original problem (although VS Code's Go IntelliSense still thinks there's a problem). Unfortunately, now all instances of using
Pulumi.Map
to create AWS tags are broken. I'll create a separate thread to discuss that.
👍 1
5 Views