swift-machine-98066
09/21/2022, 9:00 PMpulumi.StringMap
trying to process it in another stack but getting a pointer address instead of the value. trying some thing along the lines of
stackName := config.Require(ctx, "network:vpc")
region := config.Require(ctx, "aws:region")
s := fmt.Sprintf("%s-%s-subnets", region, stackName)
subnets := other.GetStringOutput(pulumi.String(s))
fmt.Println(string(subnets.ToStringOutput()))
some reason ToStringOutput only returns a pulumi.StringOutput and not a string like I would expect it to be .flaky-arm-38472
09/22/2022, 2:04 AMswift-machine-98066
09/22/2022, 12:28 PM{
"appsubnet1": "subnet-0f13eee47334ba908",
"appsubnet2": "subnet-0abfb3303f52ff8da",
"appsubnet3": "subnet-0025bfd931231a002",
"datasubnet1": "subnet-0144df74657bbe02b",
"datasubnet2": "subnet-0c8fab9ea0ba72507",
"datasubnet3": "subnet-05f5adb7c8fb4427e",
"publicsubnet1": "subnet-02db54b375451331f",
"publicsubnet2": "subnet-0ea9b849dd585d88e",
"publicsubnet3": "subnet-0c8c0a5b1824a8a93"
}
bored-table-20691
09/22/2022, 4:25 PMswift-machine-98066
09/22/2022, 7:18 PMunc (v *vpcSetup) Export() {
v.CREATE.ctx.Export(fmt.Sprintf("vpc-%s-name", v.Items().conf.Name), pulumi.String(v.Items().conf.Name))
v.CREATE.ctx.Export(fmt.Sprintf("vpc-%s-id", v.Items().conf.Name), v.Items().vpc.ID())
s := make(map[string]string, len(v.Items().subnets))
for name, subnet := range v.Items().subnets {
n := strings.Split(name, "_")
s[n[1]] = fmt.Sprintf("%s", subnet.ID())
}
sJ, _ := json.Marshal(s)
v.CREATE.ctx.Export(fmt.Sprintf("%s_subnets", v.Items().conf.Name), pulumi.String(string(sJ)))
rt := make(map[string]string, len(v.Items().routeTables))
for name, routeTable := range v.Items().routeTables {
n := strings.Split(name, "_")
rt[n[1]] = fmt.Sprintf("%s", routeTable.ID())
}
rtJ, _ := json.Marshal(rt)
v.CREATE.ctx.Export(fmt.Sprintf("%s_route-tables", v.Items().conf.Name), pulumi.String(string(rtJ)))
}
that only gives me a json object of pointersbored-table-20691
09/23/2022, 4:48 AM... make an array of all the subnet IDs ...
idMap := pulumi.All(subnetIDs).ApplyT(func(ids []interface{}) string {
... cast it to a string and build a map ...
... marshal to json
... return the json
}
ctx.Export("...", idMap)
swift-machine-98066
09/23/2022, 1:15 PMfunc main() {
networkSubnets := make(map[string]string, 10)
pulumi.Run(func(ctx *pulumi.Context) error {
conf := config.New(ctx, "")
stack, err := pulumi.NewStackReference(ctx, "boost/network/dev", nil)
if err != nil {
return fmt.Errorf("error retrieveing stack reference: %v", err)
}
stackName := conf.Require("vpc")
region := conf.Require("aws-region")
s := fmt.Sprintf("%s-%s_subnets", stackName, region)
outputs := stack.GetOutput(pulumi.String(s))
sj := pulumi.All(outputs).ApplyT(func(subnets []interface{}) string {
for name, subnet := range subnets[0].(map[string]interface{}) {
fmt.Println("Name:", name, "=>", "Subnet:", subnet)
// HIT THIS WITH MY BIG ASS HAMMER
networkSubnets[name] = subnet.(string)
}
s, _ := json.Marshal(networkSubnets)
return string(s)
})
fmt.Println(sj)
return nil
})
}
and getting this as output
Type Name Plan Info
+ pulumi:pulumi:Stack stack-test-dev create 10 messages
Diagnostics:
pulumi:pulumi:Stack (stack-test-dev):
{0x140002f4bd0}
Name: appsubnet1 => Subnet: subnet-0f13eee
Name: appsubnet2 => Subnet: subnet-0abfb33
Name: datasubnet1 => Subnet: subnet-0144df
Name: datasubnet3 => Subnet: subnet-05f5ad
Name: appsubnet3 => Subnet: subnet-0025bfd
Name: publicsubnet3 => Subnet: subnet-0c8c
Name: datasubnet2 => Subnet: subnet-0c8fab
Name: publicsubnet1 => Subnet: subnet-02db
Name: publicsubnet2 => Subnet: subnet-0ea
Seems that the pulumi.All().ApplyT happens after the fun. So its not possible to use a stack reference in a this aspect with out building all additional information inside a applyT. So for us to get the subnets from out network stack for our eks clusters we can't do that unless we build a fuction that creates the cluster inside the applyt