I'm having a hard time getting values out of terra...
# golang
a
I'm having a hard time getting values out of terraform remote state (I'm using the tf cloud backend). Working from the example here: https://www.pulumi.com/docs/guides/adopting/from_terraform/ - is there a canonical way to simply get the map of outputs from the remote state into a Go object so I can interpolate them into other resources?
I feel like I'm missing something super basic here
b
hmmm Ive never used this: did you see the examples here? https://github.com/pulumi/pulumi-terraform/tree/master/examples
what's not working about it?
a
maybe this is a fundamental misunderstanding on my part, or my relative inexperience with Go - all I'm trying to do is get a list of subnet IDs from tf remote state into a
[]string
The example given is
Copy code
publicSubnetIds := tfNetState.Outputs.ApplyT(func(args interface{}) ([]string, error) {
			ids := args.(map[string]interface{})["public-subnet-ids"].([]interface{})
			subnetIds := make([]string, len(ids))
			for i, v := range ids {
				subnetIds[i] = v.(string)
			}
			return subnetIds, nil
		}).(pulumi.StringArrayOutput)
Should I not then just be able to
Copy code
for _, v := range publicSubnetIds {
			fmt.Printf("id: %s", v)
		}
? But apparently this object isn't iterable
This is what I mean when I say I feel I'm missing something basic 😅
b
@ambitious-salesmen-39356 you need to range through the IDs inside the apply
in your case,
publicSubnetIds
is still async, so it's not known - it's not iterable because it's not known how long it is: what are you trying to pass the public subnets to?
a
right now just a print statement so I can make sure I'm getting values out =D
I'm just trying to figure out how to work with tf state
my actual objective here is to get lb target group arns for use in kubernetes service objects
b
so, some pseudo code
Copy code
publicSubnetIds := tfNetState.Outputs.ApplyT(func(args interface{}) ([]string, error) {
  // you can print each value here, because the value is resolved
  fmt.Println(id)
}).(pulumi.StringArrayOutput)
ultimately what I think you're going to want to do is:
Copy code
var awsPublicSubnets []ec2.Subnet


publicSubnetIds := tfNetState.Outputs.ApplyT(func(args interface{}) ([]string, error) {
			// do an append inside the apply
		}).(pulumi.StringArrayOutput)
a
that makes sense.
Thanks