Hello Pulumi people! After using Terraform for a w...
# getting-started
b
Hello Pulumi people! After using Terraform for a while, I just discovered Pulumi and trying out if it's worth migrating! I though encountered an issue with the input/output concept, and the documentation is not enough for me to be unstuck. Let me explain: I would like to do a base setup of our AWS infrastructure, using Go language. I started up by creating a VPC with pulumi and AWS sdk. Then, I wanted to grab the main route table id from that VPC (the one created by default), to associate more routes to it. I failed miserably at that step.
First try: using Sprintf mainRouteTable, err := ec2.LookupRouteTable(ctx, &ec2.LookupRouteTableArgs{ RouteTableId: pulumi.Sprintf("%s", vpc.MainRouteTableId), }) Error: cannot use pulumi.Sprintf("%s", vpc.MainRouteTableId) (value of type pulumi.StringOutput) as *string value in struct literal
Second try: using ApplyString mainRouteTable, err := ec2.LookupRouteTable(ctx, &ec2.LookupRouteTableArgs{ RouteTableId : vpc.MainRouteTableId.ApplyString(func(route string) string { return route }), }) error: cannot use vpc.MainRouteTableId.ApplyString((func(route string) string literal)) (value of type pulumi.StringOutput) as *string value in struct literal
Third and other tries: using Lifting a lot of different ways, for example: mainRouteTable, err := ec2.LookupRouteTable(ctx, &ec2.LookupRouteTableArgs{ RouteTableId: pulumi.String(vpc.MainRouteTableId.ResourceRecordValue()), }) error: vpc.MainRouteTableId.ResourceRecordValue undefined (type pulumi.StringOutput has no field or method ResourceRecordValue)
It seems i have misunderstood the whole concept. Can someone help please?
p
I'm not familiar with the Pulumi Go SDK, but since the vpc.MainRouteTableId is an
Output
and the
ec2.LookupRouteTableArgs.RouteTableId
expects a string I think you need to perform the lookup inside the apply, something like:
Copy code
mainRouteTable, err := vpc.MainRouteTableId.ApplyT(
    func (routeTableId string) (*LookupRouteTableResult, error) {
        return ec2.LookupRouteTable(ctx, &ec2.LookupRouteTableArgs{
            RouteTableId: routeTableId
        })
    }
)
b
Ok! Thank you! Still having a lot of issues but it looks like i'm getting closer assignment mismatch: 2 variables but vpc.MainRouteTableId.OutputState.ApplyT returns 1 values undefined: LookupRouteTableResult err is not a type cannot use routeTableId (type string) as type *string in field value
p
*LookupRouteTableResult
should probably be
*ec2.LookupRouteTableResult
, and yeah I think the ApplyT returns a single value, so it should just be
mainRouteTable := ...
Unfortunately I'm not that familiar with Go
b
Also quite new to Go, but i found out how to do it! It looks like that: mainRouteTable := vpc.MainRouteTableId.ApplyT( func (routeTableId string) (*ec2.LookupRouteTableResult, error) { return ec2.LookupRouteTable(ctx, &ec2.LookupRouteTableArgs{ RouteTableId: &routeTableId, }) }) Thank you for your help! I never tried to do it the other way around (lookup inside of the apply)
🙌 1