https://pulumi.com logo
Title
r

rapid-soccer-18092

09/22/2021, 7:54 AM
Quick one. I have an args property of
Input<string>
and I need to assign it to an
object
type in my values object map, but implicit typing doesn't kick in so the assigned value is Input<T>. See below... the
args.DatadogApiKey
is `Input<string>`:
var datadogChart = new Chart("datadog-chart",
                new ChartArgs
                {
                    Chart = "datadog",
                    Version = args.DatadogChartVersion,
                    Namespace = "default",
                    Values = new Dictionary<string, object>
                    {
                        ["datadog"] = new Dictionary<string, object>
                        {
                            ["apiKey"] = args.DatadogApiKey,
                            ["site"] = "<http://datadoghq.eu|datadoghq.eu>"
                        },
                    }
                });
t

tall-librarian-49374

09/22/2021, 7:55 AM
You may need something like
args.DatadogApiKey.Apply(v => (object)v)
r

rapid-soccer-18092

09/22/2021, 7:59 AM
I need the string. This is the best I can do, which is horrendous on the eyes:
string datadogApiKey;
args.DatadogApiKey.Apply(x =>
{
    datadogApiKey = x;
    return x;
});
t

tall-librarian-49374

09/22/2021, 8:02 AM
What is the problem with your original code? Does it fail at runtime?
r

rapid-soccer-18092

09/22/2021, 8:03 AM
Yes, because the value of ["apiKey"] is Input<string> and not string, I assume
t

tall-librarian-49374

09/22/2021, 8:04 AM
What’s the error?
r

rapid-soccer-18092

09/22/2021, 8:06 AM
The helm chart fails because of an invalid API key value
Grpc.Core.RpcException: Status(StatusCode="Unknown", Detail="invocation of kubernetes:helm:template returned an error: failed to generate YAML for specified Helm chart: failed to create chart from template: template: datadog/templates/NOTES.txt:1:56: executing "datadog/templates/NOTES.txt" at <eq .Values.datadog.apiKey "<DATADOG_API_KEY>">: error calling eq: uncomparable type map[string]interface {}: map[]", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1632296140.606362300","description":"Error received from peer ipv4:127.0.0.1:38555","file":"/var/local/git/grpc/src/core/lib/surface/call.cc","file_line":1068,"grpc_message":"invocation of kubernetes:helm:template returned an error: failed to generate YAML for specified Helm chart: failed to create chart from template: template: datadog/templates/NOTES.txt:1:56: executing "datadog/templates/NOTES.txt" at <eq .Values.datadog.apiKey "<DATADOG_API_KEY>">: error calling eq: uncomparable type map[string]interface {}: map[]","grpc_status":2}")
t

tall-librarian-49374

09/22/2021, 8:07 AM
I see. You can’t get string from Input<string>, so you may need an Apply like
Values = args.DatadogApiKey.Apply(apiKey => new Dictionary<string, object>
                    {
                        ["datadog"] = new Dictionary<string, object>
                        {
                            ["apiKey"] = apiKey,
                            ["site"] = "<http://datadoghq.eu|datadoghq.eu>"
                        },
                    })
1
r

rapid-soccer-18092

09/22/2021, 8:14 AM
Thanks. I suppose Values will then be an
Output<T>
Let me play around