sparse-intern-71089
01/10/2023, 2:21 AMbillowy-army-68599
bucket.BucketName.Apply(name => JSON STRING HERE)abundant-dawn-11116
01/10/2023, 5:33 AM"value":"Calling [ToString] on an [Output<T>] is not supported.\n\nTo get the value of an Output<T> as an Output<string> consider:\n1. o.Apply(v => $\"prefix{v}suffix\")\n2. Output.Format($\"prefix{hostname}suffix\");\n\nSee <https://pulumi.io/help/outputs> for more details.\nThis function may throw in a future version of Pulumi."}]billowy-army-68599
abundant-dawn-11116
01/10/2023, 6:29 AMstring bucketName;
bucket.BucketName.Apply(bName =>
{
bucketName = bName;
return "";
});bumpy-grass-54508
01/11/2023, 2:51 PMbucket.BucketName is an Output<string> which is sort of like a task or promise - it represents a value that does not necessarily exist yet. you cannot use an Output<string> of a value that does not exist (but may exist in the future) to create a string value that you want "now"
so you setting ContainerDefinitions = someString will not work as you are seeing
luckily, pulumi lets you easily chain and combine Outputs to create other Outputs. ContainerDefinitions is an Input<string> which allows you to pass in a string (for convenience), or Input<string> or an Output<string>
essentially in your first example you are trying to do something like this: (putting it in 2 separate statements to show what types you are working with)
string containerDefs = $@"[ ... ]";
ContainerDefinitions = containerDefs
there is no (good) way to take an Output<string> like bucket.BucketName and get it to appear somewhere in that string containerDefs
what you want to do instead is something like
Output<string> containerDefs = ... something
ContainerDefinitions = containerDefs
and to do that, you have a few options. Apply is one way like @billowy-army-68599 mentioned:
Output<string> containerDefs = bucket.BucketName.Apply(x =>
{
// here, x is a string you can use normally
return $"some string with {x} inside";
});
ContainerDefinitions = containerDefs
you can also use the convenience helper method Output.Format
Output<string> containerDefs = Output.Format($"some string using {bucket.BucketName} inside");
ContainerDefinitions = containerDefs
Output.Format takes in a formattable string and does the Apply for you behind the scenes