abundant-dawn-11116
01/10/2023, 2:21 AMbucket.Apply(b=>b.BucketName)
and bucket.BucketName.Apply(v => v)
but neither work. Am I going about this horribly wrong? Thanks in advance.
using System.Collections.Generic;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var bucket = new Aws.S3.Bucket($"bucket", new()
{
Versioning = new BucketVersioningArgs { Enabled = true },
});
var test = new Aws.Ecs.TaskDefinition("test", new()
{
Family="family",
ContainerDefinitions = $@"[{{
...
""environment"": [{{
""name"": ""BUCKETNAME"",
""value"": ""{{bucket.BucketName}}""
}}],
...
}}]"
});
});
billowy-army-68599
01/10/2023, 2:31 AMbucket.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
01/10/2023, 5:45 AMabundant-dawn-11116
01/10/2023, 6:29 AMstring bucketName;
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