I noticed that when trying to use `ctx.Export` ins...
# golang
e
I noticed that when trying to use
ctx.Export
inside of an
.ApplyT
function, the export doesn't happen. Is this the expected behavior? Here's a code example:
Copy code
aksVNet.ID().ToStringOutput().ApplyT(func(id string) error {
	applicationAKSSubnetID := fmt.Sprintf("%s/subnets/Application", id)

	var clusterInput *aks.ClusterInput
	if err := cfg.TryObject(appAKSClusterConfigKey, &clusterInput); err != nil {
		return err
	}

	cluster, err = aks.CreateAKSCluster(ctx,
		clusterInput,
		applicationAKSSubnetID,
		commonTags)
	if err != nil {
		return err
	}
	
	ctx.Export("clusterName", cluster.Name)

	return nil
})
b
In general you should avoid creating resources and exports in apply
e
I do try to avoid it but there are times when I need a string value of a
pulumi.StringOutput
that I haven't found another way to access without
.ApplyT
you can see in the example that I'm trying to get a newly created VNet ID so I can build the subnet info. I wasn't been able to get the subnet ID directly
Is there a way to get a specific subnet's ID directly, even if it's a
pulumi.StringOutput
type? I could refactor our code to not need the plain string if it's possible.
b
Which provider are you using?
l
Exporting values from within apply is not supported and will not work.
👍 1
You can accomplish the same thing by running an apply, returning the value you want to export, and exporting the output returned by the apply. Some pseudocode:
Copy code
idOutput := val.Apply( v => ...someTransform.. return v.id);
ctx.export("idOutput", idOutput)
e
Sorry for the slow reply. I was able to get back to this today and ended up refactoring some functions to use
pulumi.StringInput
as a parameter instead of
String
I was able to avoid using
ApplyT
after making that switch. Thanks for the guidance on this
partypus 1