https://pulumi.com logo
#golang
Title
# golang
b

blue-computer-71271

07/01/2020, 6:11 PM
hi cross posting here since this is probably specific to the golang sdk https://pulumi-community.slack.com/archives/C84L4E3N1/p1593617389089700
l

lemon-agent-27707

07/01/2020, 6:48 PM
Typically the answer here is to use
.Apply
to access the raw values. Can you explain a little more about what you're trying to accomplish? It might be worth reading through the programming model docs if you haven't already: https://www.pulumi.com/docs/intro/concepts/programming-model/#apply
This example in the AWS docs might be a useful example: https://www.pulumi.com/docs/reference/pkg/aws/apigateway/stage/#example-usage
Copy code
_, err = apigateway.NewMethodSettings(ctx, "methodSettings", &apigateway.MethodSettingsArgs{
            MethodPath: pulumi.All(testResource.PathPart, testMethod.HttpMethod).ApplyT(func(_args []interface{}) (string, error) {
                pathPart := _args[0].(string)
                httpMethod := _args[1].(string)
                return fmt.Sprintf("%v%v%v", pathPart, "/", httpMethod), nil
            }).(pulumi.StringOutput),
            RestApi: testRestApi.ID(),
            Settings: &apigateway.MethodSettingsSettingsArgs{
                LoggingLevel:   pulumi.String("INFO"),
                MetricsEnabled: pulumi.Bool(true),
            },
            StageName: testStage.StageName,
        })
Notice the coordination of resources via .All, and then combining the result in .Apply to create a formatted URL
b

blue-computer-71271

07/01/2020, 8:38 PM
yes I had a ApplyStringArray() but that still results in StringArrayOutput. out do you turn that into a core go []string or a pulumi StringArray (which is a type alias to []string iirc)?
i'm not sure how i can get the raw value with Apply since it never returns one. or i'm missing something in the api
all results seem to be output types
l

lemon-agent-27707

07/01/2020, 8:53 PM
Happy to help if you explain a little bit more about your use case, or perhaps share some sample code that shows what you're trying to accomplish.
Given that all pulumi resources accept outputs as parameters, typically you use apply to transform the value into the shape that you need for another resource. Are you trying to use an output outside of the context of a pulumi program?
b

blue-computer-71271

07/01/2020, 9:09 PM
i threw away the specific code but as simple as taking a list of strings from an output and then using them in a function one at a time. is the answer here that i need to do those operations inside an Apply()?
l

lemon-agent-27707

07/01/2020, 9:31 PM
Typically, yes.
b

blue-computer-71271

07/01/2020, 10:30 PM
okay that wasn't super obvious but that makes sense, i think
this seems challenging even within the pulumi ecosystem. here's an example of what i'd like to do in a component resosource. https://gist.github.com/travisgroth/e9f173d137ced07d77f0aac4e9106aeb
the next resource needs a unique name so i'd like to use the name of a dependency to compose it but it's an Output that i can't get access to the raw string of
if i put that in an Apply, i can't (i think?) return the newly accumulated resources or propagate the error
l

lemon-agent-27707

07/02/2020, 8:28 PM
Ah, overlap with component resources names? I have found myself doing things like
component.name + resource.name
or
component.name + arrayIndex
b

blue-computer-71271

07/02/2020, 8:57 PM
yeah you have to carry around a bare string. it'd be really nice to be able to get them out of the Outputs outside of an apply. it makes it hard to break down the logic
or let NewXXXX names be StringInput so they could accept Outputs
that would also let you build a dependency tree naturally. you can see in that snippet i wound up having to create my own resource array for dependencies that i could carry through the execution path
l

lemon-agent-27707

07/02/2020, 9:01 PM
Would be great to put some detail on this issue https://github.com/pulumi/pulumi/issues/1631
Some resources do accept a
name
property in their inputs, but this does things like override autonaming. So you have to worry about adding entropy yourself.
b

blue-computer-71271

07/02/2020, 9:02 PM
right the Name fields in the corresponding arguments struct isn't so much what i'm worrying about. the internal name is where i have to add my own namespacing
and afaict those are always strings
i see how to make this work but it turns into some pretty long methods so you can keep all the requisite context around
3 Views