how can I tell pulumi to generate an output from a...
# typescript
a
how can I tell pulumi to generate an output from a function that is not in the resource dependency tree? in the example below, when I run pulumi up, deployedVersionCommit is never set. everything else runs fine. another similar function whose return value is used by a resource creation works fine, too. so I'm guessing it has to do with this function not being part of the dependency tree. Is there any way to do what I want?
b
You could run it as part of an apply statement
So something like...
Copy code
resource.apply(x => getCommit(x));
(assuming you're getting the sourcesDirectory as part of creating a resource)
Where are you getting
sourcesDirectory
from?
a
sourcesDirectory comes from configuration, with
cfg.require("Sources.Server")
basically, what I want to do is I want to add the full commit to the outputs because it makes it easier to later see which version was deployed by just running
pulumi stack output
b
That means you'll be constantly changing that output, is that ok?
a
I will change it whenever pulumi up is run, that is okay
although the way you ask the question seems to hint that there are some hidden costs to this I might not be aware of?
b
It means that there might be situations where nothing will be changed resource-wise, but because of the change in output it'll be marked as a change
Are you using the console to store the state or are you managing it yourself?
a
the console
b
So you'll get the git commit in your updates in the console:
(over on the right hand side)
a
I think the change is okay: the idea is pulumi up is part of a CD pipeline. whenever it's being run, there will be a new version for certain (because the pipeline is triggered only upon PR merges into master),
that is the commit hash for the repository where the pulumi project is located. but I got multiple repositories and the infrastructure one (holding, amongst other things, the pulumi projects) is not the most relevant for us.
so you are saying I can do this with apply even if sourcesDirectory comes from config?
b
You can mark the config value as an output:
Copy code
const directory = pulumi.output(config.get("sourcedirectory"));
export const gitsha = directory.apply(x => runfunction(x));
I think that will work
a
trying that now
it works - thanks ❤️
b
🎉 good good