This message was deleted.
# azure
s
This message was deleted.
b
So like built in resources, ComponentResource has a third constructor parameter which you can pass in dependencies
Give me a sec and I'll show you what I mean
g
I'm a bit confused, thank you 🙂
I'm using C# btw, shouldn't make a difference but
The idea is that I want my component to either use existing resources if they are passed in or create them. The best example is probably passing the resource group name, as a potential input and if it's not there then the component creates once for itself
b
Oh THAT kind of dependency.. I thought you meant using
dependsOn
I mean, you can pass in the component, then use the SDK to check whether they exist or not and if not create them?
For example, if you wanted to do this on a VPC you could run GetVpc() and if it doesn't exist then create the resource
g
I'm sorry I think the scenario I put up is confusing even to myself. I guess what I need is the dependsOn if I can access that resource. Imagine my platform has 10 component resources and I want all of them to be on the same resource group, then I'd use the dependsOn and access whatever is in there from within each component, is that fair? sorry is basic question I'm quite new to pulumi
The same way, if I pass a cosmosDB into the dependsOn then I know I don't need to create a new instance for example, I just need the ability to make the dependency optional
b
So dependsOn is there because we need a way of building the dependency graph when you're not passing outputs. Pulumi is async by default. For example if you need to ensure that a particular resource exists before we start deploying another one.
Does that make sense?
g
Yes
b
And is it what you're looking for?
g
Possibly, if I have a way of accessing that within my component if that makes sense.
Copy code
var resourceGroup = new AzureNextGen.Resources.Latest.ResourceGroup("rg-test-dev", new AzureNextGen.Resources.Latest.ResourceGroupArgs {
            Location = location,
            ResourceGroupName = "rg-test-dev"
        });

        var myComponent = new MyComponent("my-component", new ComponentResourceOptions {
            DependsOn = new InputList<Resource> {
                resourceGroup
            }
        });
So now within MyComponent class, would it be a matter of iterating the inputList and checking for a ResourceGroup type of entry so that I can apply some logic and decide if I need to create one (if none was passed)?
This wouldn't happen within the same stack, but different stacks may have a different infrastructure layout if that makes sense
b
So the ComponentResourceOptions are mainly for Pulumi resources. What you could do is have another parameter called
ResourceGroupName
(for example) and then in myComponent you could run the GetResourceGroup method on the list of resourcegroup names... and you could just do this as a
List<string>
rather than using our
InputList<T>
class
g
Right I see, thanks for the that! I think I need to review what I'm trying to do as it feels I'm over complicating a bit xD