I am using pulumi with c# and I want to run some c...
# general
i
I am using pulumi with c# and I want to run some c# code ONLY if specific resource is created. how do I do it ?
b
Run it inside an apply for that resource
i
where is the apply ?
b
It exists in an output from the resource in question.
i
suppose I have this command: var sqlserver = new Azure.Sql.SqlServer(“sqlserversolargikk”, new() {…}
what is the apply command ? lets say I want to print the resource name
there is no apply method for variable sqlserver
b
i
I saw this page, but there is no support for the resources I want to create like sqlserver…
b
There is….I can’t write any code as I’m on mobile, but it’s definitely possible
i
will be happy if you could later write a few lines in c# to show how to run console.write(), at resource creation, thanks !
isn’t this what I need ?
it says here that it only support javascript
b
No, you just need to run the console writeline inside an apply
i
I wish I saw the apply…
m
Hi Asaf, let me see if I can get you a good example in C# --
i
I am using azure and not azureNative, does it matter ?
m
Nope, it’s a method that exists on all Pulumi
Output
types. One sec here
What you want is basically this:
Copy code
var someResource = new FooResource("name", new 
{
    // ...
}).SomePropertyOfFoo.Apply(unwrappedValue => {

    // Do something with the value.
    <http://Pulumi.Log.Info|Pulumi.Log.Info>(unwrappedValue);

    // Return the value.
    return unwrappedValue;
});
But the linked example works end to end if a complete example is clearer. That should work for
Azure.Sql.SqlServer
as well — all Pulumi Output values have an
Apply
method that returns the resolved, unwrapped (“raw”) value. The linked doc Lee shared describes this in more detail: https://www.pulumi.com/docs/intro/concepts/inputs-outputs/#apply
i
@miniature-musician-31262, @billowy-army-68599 Thanks for all the reply but I want the code to run ONLY if the resource created now. if it exists I DON’T want the code to run !
b
If you define a resource in your Pulumi program it will always create. If it exists it will only modify it if you change the code
i
by created I mean not existing in the azure cloud
b
Yes I understand. Any resource you define in your Pulumi program will always exist because that’s how Pulumi works
You can’t define a resource in a Pulumi program and then expect it not to exist
i
but the apply is running after the resource is created in the cloud or it is internal to pulumi before running the cloud deploy ?
e
@important-receptionist-30715 this feature is currently unsupported in C#. For python or nodejs you could use dynamic providers to hook a second dynamic resource into the lifecycle chain, but we don't (currently) have dynamic providers for dotnet. There are other plans to support life cycle hooks, which would also cover this.
m
I see, thanks for the clarification. Can I ask, what is it (or what kind of thing is it) that you’re trying to do when the resource is created for the first time, but not thereafter? Depending on what it is, you might be able to use the Command provider, which I believe does expose the kind of interface you may be looking for: https://www.pulumi.com/registry/packages/command/
The first few bullets on the overview page there may speak to what you’re trying to do @important-receptionist-30715
Ah, and looks like Luke pointed this out (using Command) as well in that lifecycle-hooks issue: https://github.com/pulumi/pulumi/issues/1691#issuecomment-1003445778
i
great @miniature-musician-31262 Many thanks for all the replies. My use case is that I run Pulumi in c# with Azure as cloud provider, and I create a APP FUNCTION. if it is the first time, I want upload a LAMBDA function to the APP FUNCTION, either by downloading specific git repository, build and upload, or calling Git action Ci/Cd workflow I want to upload the LAMBDA function only the first time the APP FUNCTION is created
m
Ok. If you have any code you could share, that would help. I think based on what you’re describing that you should be able to use regular Pulumi resources for all of this, but without some code that shows me which Azure resources you’re working with (whether/how you’re using FunctionApp, FunctionAppFunction, etc.), it’s hard to say for sure. A GitHub gist of your program code would probably work.