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

victorious-dream-50144

03/09/2024, 12:21 PM
Hello, I'm struggling to understand how to inject the standard Golang string representation of an iam role ARN created by pulumi into an ecs container definition. I've tried the following (and many other approaches) but have not been successful. Is anyone able to provide any insight on this?
Copy code
executionRoleArn := executionRole.Arn.ApplyT(func(arn string) string {
		return arn
	})
Copy code
// Container Definition
	containerDefinitionJSON, err := json.Marshal([]interface{}{
		map[string]interface{}{
			"name":             "workerr",
			"image":            "<http://1234567890.dkr.ecr.us-east-2.amazonaws.com/worker:latest|1234567890.dkr.ecr.us-east-2.amazonaws.com/worker:latest>",
			"cpu":              250,
			"essential":        true,
			"memory":           256,
			"executionRoleArn": executionRoleArn,
I've not been able to get past the following error
Copy code
error: an unhandled error occurred: program failed:
    1 error occurred:
        * json: error calling MarshalJSON for type pulumi.StringOutput: Outputs can not be marshaled to JSON
f

few-dress-15522

03/10/2024, 5:44 PM
I’m still fairly new at this, but basically, you can’t get your ARN as a
string
outside of the
ApplyT
. If you need to use it as such, you need to do the work inside the
Apply
function. If your container definition is ultimately going to another Pulumi resource, you probably want to just keep passing everything around as Pulumi outputs and not force resolution to the underlying type.
The Inputs &amp; Outputs docs are a constant reference for me, and the Converting outputs to JSON section might be particularly valuable for your question.
n

numerous-book-75463

03/11/2024, 12:09 PM
You should be able to change
json.Marshal
to
pulumi.JSONMarshal
v

victorious-dream-50144

03/21/2024, 2:29 PM
thanks a ton @few-dress-15522 @numerous-book-75463 very helpful!