salmon-account-74572
02/26/2021, 8:00 PMApplyT
and ApplyString
variations of this snippet:
ipAddrList[0] = bastion.PrivateIp.ApplyString(func(ipAddr string) string {
return string(ipAddr)
})
What am I missing?broad-dog-22463
02/26/2021, 8:05 PMsalmon-account-74572
02/26/2021, 8:17 PMcannot use bastion.PrivateIp.ApplyString((func(ipAddr string) string literal)) (value of type pulumi.StringOutput) as string value in assignment
broad-dog-22463
02/26/2021, 8:18 PMsalmon-account-74572
02/26/2021, 8:42 PMpulumi preview
and it reported the same error ("cannot use bastion.PrivateIp.OutputState.ApplyString(func literal) (type pulumi.StringOutput) as type string in assignment")broad-dog-22463
02/26/2021, 9:03 PMbillowy-army-68599
ipAddrList[0]
as a type?lemon-agent-27707
02/26/2021, 9:21 PMipAddrList
is a []string
and you are trying to assign a pulumi.StringOutput
to one of it's elements which would not work.
If you share a full code snippet with context I'm sure we can get something working.billowy-army-68599
salmon-account-74572
02/26/2021, 10:03 PM// Launch an EC2 instance to serve as bastion host
bastion, err := ec2.NewInstance(ctx, "bastion", &ec2.InstanceArgs{
Ami: pulumi.String(amiID.Id),
InstanceType: pulumi.String("t2.small"),
AssociatePublicIpAddress: pulumi.Bool(true),
KeyName: pulumi.String("ssh_key_name"),
SubnetId: pulumi.String(subnets.Ids[0]),
VpcSecurityGroupIds: pulumi.StringArray{bastionSecGrp.ID()},
Tags: pulumi.StringMap{
"Name": pulumi.String("ans-int-bastion"),
},
})
if err != nil {
log.Printf("error launching bastion instance: %s", err.Error())
}
// Get IP address of bastion as a string
ipAddrList[0] = bastion.PrivateIp.ApplyString(func(s string) string {
return fmt.Sprintf("%s", s)
})
The ultimate goal---and perhaps I'm going about this the wrong way---is to get Pulumi to write out the IP addresses of the instances it launched into a file that could be used with something like Ansible. My thought process was that I'd gather the IP addresses as elements in a string array, then write the array elements to a file.lemon-agent-27707
02/27/2021, 3:28 PMsalmon-account-74572
02/28/2021, 7:53 PMstrings.Join
wouldn't be needed if I wanted each element on a separate line?lemon-agent-27707
02/28/2021, 9:23 PMstrings.Join
was just the way I chose to do string formatting for example purposessalmon-account-74572
03/01/2021, 2:50 PMApplyString
function (see line 53 of the gist) but it doesn't seem to work.lemon-agent-27707
03/01/2021, 3:38 PMApplyString
returns another Output which is why you are seeing this behavior. You'll need to do any printing from within an apply.salmon-account-74572
03/01/2021, 3:46 PMtmp := bastion.PrivateIp.ApplyT(func(v string) string {
res := v
fmt.Fprintln(f, v)
return res
})
lemon-agent-27707
03/01/2021, 4:09 PMMaybe I should switch to using the Automation API,Using automation api would definitely make it pretty easy to take stack outputs and write them to a file.
salmon-account-74572
03/01/2021, 4:47 PMctx.Export
statement (per your gist), but the file was still empty. I think I'm just going to rewrite it using the Automation API.