Hello I am in a situation where I have created a b...
# package-authoring
w
Hello I am in a situation where I have created a basic custom component and template just to try out pulumi IDP. However i continue to get the error: "pulumicomponentsindexMyStorageAccount resource 'brutiquzz1234' has a problem: Trying to acquire Deployment.Stack before 'Run' was called." I consulted the AI with what potentiel problems this could be but after sharing my code it said everything looks correct. the component is structured like:
Copy code
using Pulumi;
using Pulumi.AzureNative.Storage;
using AzureNative = Pulumi.AzureNative;

namespace MyComponents;

public class MyStorageAccount : ComponentResource
{
    [Output("storageAccountId")]
    public Output<string> StorageAccountId { get; private set; }

    public MyStorageAccount(string name, MyStorageAccountResourceArgs args, ComponentResourceOptions? opts = null)
        : base("pkg:index:MyStorageAccount", name, opts)
    {
        var storageAccountArgs = new StorageAccountArgs
        {
            AccountName = name, // Ensure 'name' is valid for Azure Storagesss
            EnableHttpsTrafficOnly = true,
            ResourceGroupName = args.ResourceGroupName,
            Sku = new AzureNative.Storage.Inputs.SkuArgs
            {
                Name = SkuName.Standard_LRS,
            },
            Kind = Kind.StorageV2,
            Location = args.Location,
        };

        var storageAccount = new StorageAccount(name, storageAccountArgs);

        StorageAccountId = storageAccount.Id;

        this.RegisterOutputs(new Dictionary<string, object?>
        {
            ["storageAccountId"] = storageAccount.Id,
        });
    }
}
Copy code
using Pulumi;

namespace MyComponents;

public class MyStorageAccountResourceArgs : Pulumi.ResourceArgs
{
    [Input("location", required: true)]
    public Input<string> Location { get; set; } = null!;

    [Input("resourceGroupName", required: true)]
    public Input<string> ResourceGroupName { get; set; } = null!;
}
The entire project can be found in this public repo https://github.com/Brutiquzz/pulumicomponents/blob/main/MyStorageAccount.cs I then package it:
Copy code
git commit -m "v0.0.5"
git tag v0.0.5
git push origin v0.0.5
pulumi package publish github.com/Brutiquzz/pulumicomponents@v0.0.5 
// This succeeds
I then created a template
Copy code
using Brutiquzz.Pulumicomponents;
using Pulumi;

public class MyStack : Pulumi.Stack
{
    public MyStack()
    {
        var config = new Pulumi.Config();
        var region = config.Require("region");

        var args = new MyStorageAccountArgs()
        {
            Location = region,
            ResourceGroupName = "brutiquzz1234"
        };

        var storageAccount = new MyStorageAccount("brutiquzz1234", args, null);

        this.StorageAccountId = storageAccount.StorageAccountId;
    }

    [Output("storageAccountId")] public Output<string> StorageAccountId { get; set; }
}
Copy code
using System.Threading.Tasks;

public class Program
{
    private static async Task<int> Main(string[] args)
    {

        return await Pulumi.Deployment.RunAsync<MyStack>();

    }
}
the project can be found in this public repo https://github.com/Brutiquzz/pulumiexperiment/blob/main/MyPulumiTemplate/MyStack.cs I then do
Copy code
pulumi new <https://github.com/Brutiquzz/pulumiexperiment/MyPulumiTemplate> // succeeds
When the project and stack is created I do
pulumi up
and now i get the error which I can't figure out whats the problem ? Anyone here who can spot something I can't ? 🙂
e
Copy code
new StorageAccount(
This should work regardless, but might be that your not setting the ResourceOptions.parent value when making the StorageAccount to tie it to the component
w
Thanks! That was it! <3
I read that pulumi can generate sdk's in other languages than the component was authorded in. In this case if i wanted to generated a python sdk from this C# based project. What would the steps be ?
e
Look at the blog at https://www.pulumi.com/blog/pulumi-components/ Gives a walkthrough of what's needed
❤️ 1