https://pulumi.com logo
Title
d

damp-honey-93158

10/28/2022, 4:58 AM
I'm after some advice... I've got a few situations where we create our own ComponentResource - and it depends on something else that isn't an Output<string>, e.g. a component resource for our deployment of cert-manager (via a Release) depends on the re-injection of a Secret. In these cases I've written code that creates the dependant resource within an Apply() function - but I understand this isn't the best as preview won't see the creation of things within Apply(). What's the general patter to follow to avoid this?
e

echoing-dinner-19531

10/28/2022, 9:38 AM
Yeh that's not ideal. Resources created inside apply often won't show at preview time. Is there a reason you can't just use the Output value directly as an Input here?
d

damp-honey-93158

10/28/2022, 10:17 AM
Typically it's something like this: I create a ComponentResource, within the ctor of that I create other resources. E.g. I created AksCluster and within this class I have Output<ManagedCluster>.
public Output<ManagedCluster> ManagedCluster { get; }
When creating the ManagedCluster instance - I make sure to set the Parent value, so that the Parent of the ManagedCluster is AksCluster:
new CustomResourceOptions() { Parent = this }
Now, later on - I want to create a Helm release, so, I use code like this:
return MyAksCluster.ManagedCluster.Apply(managedCluster => new Release(
            $"{ProjectName}-azure-workload-identity",
            new ReleaseArgs()
            {
                Chart = "workload-identity-webhook",
                Namespace = "azure-workload-identity-system",
                CreateNamespace = true,
                RepositoryOpts = new RepositoryOptsArgs
                {
                    Repo = "<https://azure.github.io/azure-workload-identity/charts>"
                },
                Values = new InputMap<object>()
                {
                    ["azureTenantID"] = tenantId
                },
                SkipAwait = false
            },
            new CustomResourceOptions
            {
                DeleteBeforeReplace = true, DependsOn = managedCluster, Parent = MyAksCluster, Provider = ClusterProvider
            }));
What I've found, at least for C#, is that using the MyAksCluster as a dependency isn't good enough - the pulumi deployment appears to immediately attempt creation of the resource before the cluster even exists. And therefore, I "resolve" via Apply() the ManagedCluster instance - and then use that in the dependency explicitly.
e

echoing-dinner-19531

10/28/2022, 12:18 PM
I think your making things harder because that ManagedCluster is in an Output itself. Can you not return a ManagedCluster directly? You could then just use that in the dependsOn list of the Release. But I do agree that dependencies with components isn't great right now, it something we'd like to improve its just tricky because a load of user will be dependent on the current behaviour. Hopefully we can overhaul it to something more useful for 4.0 at least.