victorious-ability-58329
07/05/2023, 4:50 PMusing Pulumi;
using AzureNative = Pulumi.AzureNative;
using Random = Pulumi.Random;
using System.Collections.Generic;
using System;
using System.Text;
using System.Threading.Tasks;
using Pulumi.AzureNative.Resources;
using System.Text.Json;
namespace iac.AzureStack
{
public class Program
{
// Import the program's configuration settings.
static Pulumi.Config config = new Pulumi.Config();
static async Task<int> Main(string[] args)
{
return await Pulumi.Deployment.RunAsync(() =>
{
var tags = config.RequireObject<JsonElement>("resourceGroupTags");
var rgArgs = new AzureResourceGroupArgs
{
ResourceGroupName = config.Require(StackConstants.ResourceGroupConstants.Name),
ResourceGroupTags = config.RequireObject<Dictionary<string, string>>(
"resourceGroupTags"
),
};
// Create a resource group for all resources.
var newResourceGroup = new AzGrusResourceGroup(
rgArgs.ResourceGroupName.ToString(),
rgArgs
);
return Task.FromResult(0);
});
}
}
}
Is it possible not to have everything wrapped in a return await? Like creating different functions in the program.cs for each component?
Here is the code in my resourcegroup.cs file
using System;
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Pulumi.AzureNative.Resources;
using Pulumi.AzureNative.Resources.Inputs;
namespace IaC.AzureStack;
class AzureResourceGroupArgs
{
public Input<string> ResourceGroupName { get; set; } = null!;
public Dictionary<string, string> ResourceGroupTags { get; set; } = null!;
}
class AzResourceGroup : ComponentResource
{
public AzResourceGroup(
string name,
AzureResourceGroupArgs args,
ComponentResourceOptions? options = null
)
: base("custom:azure:ResourceGroup", name, options)
{
var newResourceGroup = new ResourceGroup(
name,
new ResourceGroupArgs
{
ResourceGroupName = args.ResourceGroupName,
Tags = args.ResourceGroupTags,
},
new CustomResourceOptions { Parent = this }
);
this.ResourceGroupName = newResourceGroup.Name;
}
[Output]
public Output<string> ResourceGroupName { get; set; }
}