https://pulumi.com logo
Title
w

worried-knife-31967

03/29/2021, 4:00 PM
@glamorous-helmet-50600 I've tried to keep my ComponentResources true to the same pattern as the main pulumi resources. So I create an {name}Args object into the component resource file. That Args object contains all the things you depend on as
Output<T>
parameters. That's possibly specific to C# though
g

glamorous-helmet-50600

03/29/2021, 4:04 PM
Thanks @worried-knife-31967 that's useful, I wonder if it should be Input<T> tho? I'm trying out now with Input<T> being passed in the constructor of my component resource and it appears to be working
But it's a good idea to encapsulate all potential dependencies following that pattern, certainly makes the constructor less messy
w

worried-knife-31967

03/29/2021, 4:05 PM
if it's a hardcoded value, sure... it's a
resourceGroup.Name
as a reference to the original object, so that you get automatic dependency graph. I'm not sure if it converts automatically?
g

glamorous-helmet-50600

03/29/2021, 4:06 PM
A snippet of what I mean:
public class NewApp : ComponentResource 
{
    public Input<string>? ResourceGroup;
    public Input<string> ResourceGroupName;
    public NewApp(string name, Input<string>? group, ComponentResourceOptions opts) : base("NewAppType", name, opts)
    {

        var azureConfig = new Pulumi.Config("azure");
        var location = azureConfig.Require("location");

        if(group != null) {
            ResourceGroupName = group;
        }
        else {
            var resourceGroup = new AzureNextGen.Resources.Latest.ResourceGroup("rg-test-dev3", new AzureNextGen.Resources.Latest.ResourceGroupArgs {
            Location = location,
            ResourceGroupName = "rg-test-dev3"
        });

            ResourceGroupName = resourceGroup.Name;
        }
...
l

little-vegetable-79574

03/30/2021, 12:09 AM
I was also wondering on the best practices to pass resources around. I figured out that
Input<XxxResourceType>
actually works, i.e.
/// <summary>
    /// Resource group.
    /// </summary>
    [Input ("resourceGroup", required: true)]
    public ResourceGroup ResourceGroup { get; set; } = null!;
g

glamorous-helmet-50600

04/02/2021, 7:19 PM
@little-vegetable-79574 That's pretty much what I've been using too 🙂