Another Go newbie question here: I'm hoping someon...
# golang
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
) 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
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
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.
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
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).
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
is a
which implements
but not
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.
@lemon-agent-27707 Here's the full Go code I'm using.
can you also share your go.mod?
Copy code
module aws-get-azs

go 1.14

require (
	<|> v2.0.0
	<|> v2.0.0
Looks like I might have a local fix.
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:
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?
@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
<|> 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.
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
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
to create AWS tags are broken. I'll create a separate thread to discuss that.
👍 1