https://pulumi.com logo
#typescript
Title
# typescript
a

ancient-eve-13947

08/17/2021, 12:33 PM
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

brave-planet-10645

08/17/2021, 12:34 PM
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

ancient-eve-13947

08/17/2021, 12:40 PM
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

brave-planet-10645

08/17/2021, 12:42 PM
That means you'll be constantly changing that output, is that ok?
a

ancient-eve-13947

08/17/2021, 12:43 PM
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

brave-planet-10645

08/17/2021, 12:46 PM
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

ancient-eve-13947

08/17/2021, 12:47 PM
the console
b

brave-planet-10645

08/17/2021, 12:48 PM
So you'll get the git commit in your updates in the console:
(over on the right hand side)
a

ancient-eve-13947

08/17/2021, 12:48 PM
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

brave-planet-10645

08/17/2021, 12:52 PM
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

ancient-eve-13947

08/17/2021, 12:54 PM
trying that now
it works - thanks ❤️
b

brave-planet-10645

08/17/2021, 1:27 PM
🎉 good good