Can Assets and Archives safely be created in an Ou...
# dotnet
Can Assets and Archives safely be created in an Output.Apply? I know resources are not meant to be created there but AssetOrArchive does not look to be related. I have not gathered enough info to have a fully reproducible problem (will create a github issue once I do), but I ask because I am having issues dynamically creating an AWS Lambda function based on a StringAsset:
Copy code
Output<string> handlerCode = ... // based on other outputs in the stack
var handlerArchive = handlerCode.Apply(code => (Archive)new AssetArchive(new Dictionary<string, AssetOrArchive>
    ["index.js"] = new StringAsset(code),

var function = new Pulumi.Aws.Lambda.Function("function", new Pulumi.Aws.Lambda.FunctionArgs
    Code = handlerArchive,
    Handler = "index.handler",
    Role = role.Arn,
    Runtime = Pulumi.Aws.Lambda.Runtime.NodeJS14dX,
creating the function works fine, and subsequent
operations sometimes work fine - but in one particular stack I am working on I consistently get this error
Copy code
System.InvalidOperationException: Expected Pulumi.Archive but got System.String deserializing Pulumi.Aws.Lambda.Function.code
   at Pulumi.Serialization.Converter.ConvertObject(String context, Object val, Type targetType)
   at Pulumi.Serialization.Converter.ConvertValue(String context, Value value, Type targetType, ImmutableHashSet`1 resources)
   at Pulumi.Deployment.CompleteResourceAsync(Resource resource, Boolean remote, Func`2 newDependency, ResourceArgs args, ResourceOptions options, ImmutableDictionary`2 completionSources)
   at Pulumi.Deployment.Runner.<>c__DisplayClass9_0.<<WhileRunningAsync>g__HandleCompletion|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Pulumi.Deployment.Runner.WhileRunningAsync()<{%reset%}>)
want to double check I should even be creating this Archive in an Apply or if that is not supported
Not exactly an answer to your question, but you should be able to avoid this. I would try to build a dictionary inside apply and move the resource constructor outside, somewhat similar to
ah that go code does look promising - but it looks like in the go sdk you can add assets and outputs to this map? in c# sdk i believe you can only use a dictionary of AssetOrArchive, so that's why I wrapped the whole archive in an apply instead of just the stringasset:
oops ignore me that is not go code 🤦‍♂️ i mean typescript
yeah it looks like the typescript asset and archive types each take in things like
string | Promise<string>
AssetMap | Promise<AssetMap>
etc, but the c# AssetArchive only takes in a
Dictionary<string, AssetOrArchive>
and StringAsset only accepts a
I have created a github issue with some more info Still working on getting a minimal workable example that actually fails similarly to my stack
ah, that’s a notable difference in the API indeed. I am not sure why it exists.
I updated the github issue but it looks like it isn't a problem with outputs at all. it is
that is rewriting the archive's representation in the state file. output<t> was just a red herring and/or a bad hunch! hah
aha! I think this has been reported before.
Ah, I can see you linked it already
haha inb4 - i can at least for now skip
pulumi refresh
and keep going. i might be able to poke around the refresh implementation at a later point but let me know if i can provide any more info to help out!