this is driving me crazy
# general
f
this is driving me crazy
b
right here, what do you need help with?
f
shot
i chose csharp
cli works, automated api not (intermittently)
code is simple
let me send
my stack for creating shared resources like sql-elastic pool
using System.Threading.Tasks; using Pulumi; using Pulumi.AzureNative.Resources; using Pulumi.AzureNative.Storage; using Pulumi.AzureNative.Storage.Inputs; using Pulumi.AzureNative.Web.Inputs; using Pulumi.AzureNative.Sql; using Pulumi.AzureNative.Web; class MyStack : Stack { public MyStack() { var config = new Pulumi.Config("azure-shared"); // Create an Azure Resource Group // Set Provider and Subscription with variables var _provider = new Pulumi.AzureNative.Provider("Provider", new Pulumi.AzureNative.ProviderArgs() { SubscriptionId = config.Require("subscription") }); var resourceGroup = new ResourceGroup(config.Require("resourceGroupName"), new ResourceGroupArgs { ResourceGroupName = config.Require("resourceGroupName"), Location = config.Require("location") }, new CustomResourceOptions { Provider = _provider //Protect = false, // ImportId = "/subscriptions/" + subscription + "/resourceGroups/" + resourceGroupName } ); var appPlanId = CreateAppServicePlan(config, resourceGroup); CreateDatabase(config); } private Output<string> CreateAppServicePlan(Pulumi.Config config, ResourceGroup resourceGroup) { var appServicePlan = new AppServicePlan(config.Require("appPlanName"), new AppServicePlanArgs { ResourceGroupName = resourceGroup.GetResourceName(), Kind = "App", Sku = new SkuDescriptionArgs { Tier = "Premium", Name = "P1V3", }, Location = config.Require("location"), Name = config.Require("appPlanName") }, new CustomResourceOptions { DependsOn = { resourceGroup } } ); return appServicePlan.Id; } private void CreateDatabase(Pulumi.Config config) { var resourceGroup = new ResourceGroup(config.Require("databaseResourceGroupName"), new ResourceGroupArgs { ResourceGroupName = config.Require("databaseResourceGroupName") }, new CustomResourceOptions { //ImportId = "/subscriptions/" + subscription + "/resourceGroups/" + databaseResourceGroupName } ); var sqlServer = new Server(config.Require("sqlServerName"), new ServerArgs { ServerName = config.Require("sqlServerName"), ResourceGroupName = resourceGroup.GetResourceName(), AdministratorLogin = config.Require("databaseUsername"), AdministratorLoginPassword = config.Require("databasePassword"), Version = "12.0", MinimalTlsVersion = "1.2", PublicNetworkAccess = "Enabled", Location = config.Require("location") }, new CustomResourceOptions { DependsOn = { resourceGroup } } ); new ElasticPool(config.Require("elasticPoolName"), new ElasticPoolArgs { ElasticPoolName = config.Require("elasticPoolName"), ResourceGroupName = resourceGroup.GetResourceName(), ServerName = sqlServer.Name, LicenseType = "LicenseIncluded", MaintenanceConfigurationId = "/subscriptions/" + config.Require("subscription") + "/providers/Microsoft.Maintenance/publicMaintenanceConfigurations/SQL_Default", MaxSizeBytes = 69793218560, PerDatabaseSettings = new Pulumi.AzureNative.Sql.Inputs.ElasticPoolPerDatabaseSettingsArgs { MaxCapacity = 2, MinCapacity = 0.25, }, Location = config.Require("location"), Sku = new Pulumi.AzureNative.Sql.Inputs.SkuArgs { Name = "GP_Gen5", Tier = "GeneralPurpose", Family = "Gen5", Capacity = 2 }, ZoneRedundant = false, }, new CustomResourceOptions { DependsOn = { sqlServer } } ); } }
my code for automated, added to devops Release Pipeline
using Pulumi.Automation; using System; using System.IO; using System.Linq; using System.Reflection; using System.Threading.Tasks; namespace Automation { internal class Program { static async Task Main(string[] args) { // Sequence of parameters to be sent into app // stackName, location, subscription, resourceNameGroup // to destroy our program, we can run "dotnet run destroy" var destroy = args.Any() && args[0] == "destroy"; if (destroy == false) { } var stackName = args.Any() && !string.IsNullOrEmpty(args[0]) ? args[0] : String.Empty; var location = args.Any() && !string.IsNullOrEmpty(args[1]) ? args[1] : String.Empty; var appName = args.Any() && !string.IsNullOrEmpty(args[2]) ? args[2] : String.Empty; var databaseResourceGroupName = args.Any() && !string.IsNullOrEmpty(args[3]) ? args[3] : String.Empty; var sqlServerName = args.Any() && !string.IsNullOrEmpty(args[4]) ? args[4] : String.Empty; var databaseName = args.Any() && !string.IsNullOrEmpty(args[5]) ? args[5] : String.Empty; var databaseUsername = args.Any() && !string.IsNullOrEmpty(args[6]) ? args[6] : String.Empty; var databasePassword = args.Any() && !string.IsNullOrEmpty(args[7]) ? args[7] : String.Empty; var subscription = args.Any() && !string.IsNullOrEmpty(args[8]) ? args[8] : String.Empty; //var sourceDatabaseId = args.Any() && !string.IsNullOrEmpty(args[12]) ? args[12] : String.Empty; var executingDir = new DirectoryInfo(Assembly.GetExecutingAssembly().Location).Parent.FullName; var workingDir = Path.Combine(executingDir, "..", "..", "..", "..", "SmartGov"); var stackArgs = new LocalProgramArgs(stackName, workingDir); var stack = await LocalWorkspace.CreateOrSelectStackAsync(stackArgs); Console.WriteLine("successfully initialized stack"); Console.WriteLine("setting up config..."); await stack.SetConfigAsync("azure-smartgov:stackName", new ConfigValue(stackName)); await stack.SetConfigAsync("azure-smartgov:location", new ConfigValue(location)); await stack.SetConfigAsync("azure-smartgov:appName", new ConfigValue(appName)); await stack.SetConfigAsync("azure-smartgov:databaseResourceGroupName", new ConfigValue(databaseResourceGroupName)); await stack.SetConfigAsync("azure-smartgov:sqlServerName", new ConfigValue(sqlServerName)); await stack.SetConfigAsync("azure-smartgov:databaseName", new ConfigValue(databaseName)); await stack.SetConfigAsync("azure-smartgov:databaseUsername", new ConfigValue(databaseUsername)); await stack.SetConfigAsync("azure-smartgov:databasePassword", new ConfigValue(databasePassword)); await stack.SetConfigAsync("azure-native:location", new ConfigValue(location)); await stack.SetConfigAsync("azure-smartgov:subscription", new ConfigValue(subscription)); //await stack.SetConfigAsync("azure-smartgov:sourceDatabaseId", new ConfigValue(sourceDatabaseId)); Console.WriteLine("config set"); Console.WriteLine("refreshing stack..."); await stack.RefreshAsync(new RefreshOptions { OnStandardOutput = Console.WriteLine }); Console.WriteLine("refresh complete"); if (destroy) { Console.WriteLine("destroying stack..."); await stack.DestroyAsync(new DestroyOptions { OnStandardOutput = Console.WriteLine }); Console.WriteLine("stack destroy complete"); } else { Console.WriteLine("updating stack..."); var result = await stack.UpAsync(new UpOptions { OnStandardOutput = Console.WriteLine }); if (result.Summary.ResourceChanges != null) { Console.WriteLine("update summary:"); foreach (var change in result.Summary.ResourceChanges) Console.WriteLine($" {change.Key}: {change.Value}"); } //Console.WriteLine($"website url: {result.Outputs["WebsiteUrl"].Value}"); } } } }
stack for that is
using System.Threading.Tasks; using Pulumi; using Pulumi.AzureNative.Resources; using Pulumi.AzureNative.Storage; using Pulumi.AzureNative.Storage.Inputs; using Pulumi.AzureNative.Web.Inputs; using Pulumi.AzureNative.Sql; using Pulumi.AzureNative.Web; class MyStack : Stack { public MyStack() { var config = new Pulumi.Config("azure-smartgov"); // Create an Azure Resource Group CreateDatabaseAndCopy(config); var connectionString = CreateDatabaseAndCopy(config); CreateAppService(config, connectionString); } private ConnStringInfoArgs CreateDatabaseAndCopy(Pulumi.Config config) { var database = new Database("diae-smartov-test", new Pulumi.AzureNative.Sql.DatabaseArgs { CreateMode = "Copy", DatabaseName = config.Require("databaseName"), ResourceGroupName = config.Require("databaseResourceGroupName"), ServerName = config.Require("sqlServerName"), ElasticPoolId = "/subscriptions/" + config.Require("subscription") + "/resourceGroups/" + config.Require("databaseResourceGroupName") + "/providers/Microsoft.Sql/servers/" + config.Require("sqlServerName") + "/elasticpools/pool", SourceDatabaseId = "/subscriptions/ad818ed1-a52d-4a5c-8cba-c3e84872abb0/resourceGroups/shared-nonprod-rg/providers/Microsoft.Sql/servers/sql-shared-mca-nonprod/databases/source-smartgov", Location = config.Require("location") }, new CustomResourceOptions { } ); return new ConnStringInfoArgs { Name = "EssConnection", Type = ConnectionStringType.SQLAzure, ConnectionString = Pulumi.Output.Tuple<string, string, string, string>(config.Require("sqlServerName"), config.Require("databaseName"), config.Require("databaseUsername"), config.Require("databasePassword")).Apply(t => { (string server, string database, string username, string pwd) = t; return $"Server= tcp:{server}.database.windows.net;initial catalog={database};userID={username};password={pwd};Min Pool Size=0;Max Pool Size=30;Persist Security Info=true;"; }), }; } private void CreateAppService(Pulumi.Config config, ConnStringInfoArgs connectionString) { new WebApp(config.Require("appName"), new WebAppArgs { ResourceGroupName = config.Require("resourceGroupName"), ServerFarmId = "/subscriptions/" + config.Require("subscription") + "/resourceGroups/" + config.Require("subscription") + "/providers/Microsoft.Web/serverFarms/" + config.Require("appPlanName"), SiteConfig = new SiteConfigArgs { //App Service App Settings AppSettings = { }, // App Service Connection String Settings ConnectionStrings = { new ConnStringInfoArgs { Name = "EssConnection", Type = ConnectionStringType.SQLAzure, ConnectionString = connectionString.ConnectionString } } }, Location = config.Require("location") }); } }
seems Pulumi backend is remembering my resources, because it errors my out with URN
even though I destroy stacks and rd them
on both ends
the issues is intermittend
which is the worste
b
your code is hard to read without backticks around it, but at a glance, are you not calling this function twice?
Copy code
CreateDatabaseAndCopy(config);
        var connectionString = CreateDatabaseAndCopy(config);
f
ye
let me try again
its been a long week
Jaxx
@billowy-army-68599
can we look at this first please
b
this is a community support forum, please don't
@
me - I'm in a meeting
f
sorry didnt know
b
I'm afraid I won't be able to download that zip file, did you stop calling the function twice and try again?
f
yes
look its fine
its late in SA
it worked well when both was combined