static FunctionApp CreateFuncsApp(ResourceGroup rg, Plan appServicePlan, Account storage, Container imagesContainer, SqlServer sqlServer, Output <string> connStr) { var appInsights = new Insights("ai-funcs-", new InsightsArgs { ResourceGroupName = rg.Name, ApplicationType = "web", }); var func = new FunctionApp("funcs-", new FunctionAppArgs { ResourceGroupName = rg.Name, AppServicePlanId = appServicePlan.Id, Version = "~3", StorageConnectionString = storage.PrimaryConnectionString, AppSettings = { { "APPINSIGHTS_INSTRUMENTATIONKEY", appInsights.InstrumentationKey }, { "WEBSITE_RUN_FROM_PACKAGE", "1" }, // Using manual az webapp deploy to take care of this https://github.com/Azure/app-service-announcements/issues/110 { "Container", imagesContainer.Name }, }, ConnectionStrings = { new FunctionAppConnectionStringsArgs { Name = "Default", Type = "SQLAzure", Value = connStr, } }, }); return(func); }
static FunctionApp CreateFuncsApp(ResourceGroup rg, Plan appServicePlan, Account storage, Container imagesContainer, SqlServer sqlServer, Output <string> connStr) { var appInsights = new Insights("ai-funcs-", new InsightsArgs { ResourceGroupName = rg.Name, ApplicationType = "web", }); var func = new FunctionApp("funcs-", new FunctionAppArgs { ResourceGroupName = rg.Name, AppServicePlanId = appServicePlan.Id, Version = "~3", StorageConnectionString = storage.PrimaryConnectionString, AppSettings = { { "APPINSIGHTS_INSTRUMENTATIONKEY", appInsights.InstrumentationKey }, { "Container", imagesContainer.Name }, }, ConnectionStrings = { new FunctionAppConnectionStringsArgs { Name = "Default", Type = "SQLAzure", Value = connStr, } }, }); return(func); }
public MyStack() { // Create an Azure Resource Group var resourceGroup = new ResourceGroup("pulumiresourcegroup"); // Create an Azure Storage Account var storageAccount = new Account("pulumistorage", new AccountArgs { ResourceGroupName = resourceGroup.Name, AccountReplicationType = "LRS", AccountTier = "Standard" }); // Create AppService Plan var appServicePlan = new Plan("asp", new PlanArgs { ResourceGroupName = resourceGroup.Name, Kind = "FunctionApp", Sku = new PlanSkuArgs { Tier = "Dynamic", Size = "Y1", } }); // Create Container var container = new Container("zips", new ContainerArgs { StorageAccountName = storageAccount.Name, ContainerAccessType = "private" }); // Create BlobStorage var blob = new Blob("zip", new BlobArgs { StorageAccountName = storageAccount.Name, StorageContainerName = container.Name, Type = "Block", Source = new FileArchive("./functions/bin/Debug/netcoreapp3.1/publish") }); var codeBlobUrl = SharedAccessSignature.SignedBlobReadUrl(blob, storageAccount); // Create FunctionApp var app = new FunctionApp("function-app", new FunctionAppArgs { ResourceGroupName = resourceGroup.Name, AppServicePlanId = appServicePlan.Id, AppSettings = { { "runtime", "dotnet" }, { "WEBSITE_RUN_FROM_PACKAGE", codeBlobUrl }, }, StorageAccountName = storageAccount.Name, StorageAccountAccessKey = storageAccount.PrimaryAccessKey, Version = "~3" }); this.Endpoint = Output.Format($"https://{app.DefaultHostname}/api/Hello?name=Pulumi"); }
public ArchiveFunctionApp(string name, ArchiveFunctionAppArgs args, ResourceOptions?options = null) : base("examples:azure:ArchiveFunctionApp", name, options) { var opts = CustomResourceOptions.Merge(options, new CustomResourceOptions { Parent = this }); var storageAccount = new Account($"sa{args.Location}", new AccountArgs { ResourceGroupName = args.ResourceGroupName, Location = args.Location, AccountReplicationType = "LRS", AccountTier = "Standard", }, opts); var appServicePlan = new Plan($"asp-{args.Location}", new PlanArgs { ResourceGroupName = args.ResourceGroupName, Location = args.Location, Kind = "FunctionApp", Sku = new PlanSkuArgs { Tier = "Dynamic", Size = "Y1", }, }, opts); var container = new Container($"zips-{args.Location}", new ContainerArgs { StorageAccountName = storageAccount.Name, ContainerAccessType = "private", }, opts); var blob = new ZipBlob($"zip-{args.Location}", new ZipBlobArgs { StorageAccountName = storageAccount.Name, StorageContainerName = container.Name, Type = "block", Content = args.Archive, }, opts); var codeBlobUrl = SharedAccessSignature.SignedBlobReadUrl(blob, storageAccount); args.AppSettings.Add("runtime", "dotnet"); args.AppSettings.Add("WEBSITE_RUN_FROM_PACKAGE", codeBlobUrl); var app = new FunctionApp($"app-{args.Location}", new FunctionAppArgs { ResourceGroupName = args.ResourceGroupName, Location = args.Location, AppServicePlanId = appServicePlan.Id, AppSettings = args.AppSettings, StorageConnectionString = storageAccount.PrimaryConnectionString, Version = "~2", }, opts); this.AppId = app.Id; }
static Task <int> Main() { return(Deployment.RunAsync(() => { var resourceGroup = new ResourceGroup("functions-rg"); var storageAccount = new Account("sa", new AccountArgs { ResourceGroupName = resourceGroup.Name, AccountReplicationType = "LRS", AccountTier = "Standard", }); var appServicePlan = new Plan("asp", new PlanArgs { ResourceGroupName = resourceGroup.Name, Kind = "FunctionApp", Sku = new PlanSkuArgs { Tier = "Dynamic", Size = "Y1", }, }); var container = new Container("zips", new ContainerArgs { StorageAccountName = storageAccount.Name, ContainerAccessType = "private", }); var blob = new ZipBlob("zip", new ZipBlobArgs { StorageAccountName = storageAccount.Name, StorageContainerName = container.Name, Type = "block", Content = new FileArchive("./functions/bin/Debug/netcoreapp3.0/publish"), }); var codeBlobUrl = SharedAccessSignature.SignedBlobReadUrl(blob, storageAccount); var app = new FunctionApp("app", new FunctionAppArgs { ResourceGroupName = resourceGroup.Name, AppServicePlanId = appServicePlan.Id, AppSettings = { { "runtime", "dotnet" }, { "WEBSITE_RUN_FROM_PACKAGE", codeBlobUrl }, }, StorageConnectionString = storageAccount.PrimaryConnectionString, Version = "~3", }); return new Dictionary <string, object> { { "endpoint", Output.Format($"https://{app.DefaultHostname}/api/Hello?name=Pulumi") }, }; })); }
public ArchiveFunctionApp(string name, ArchiveFunctionAppArgs args, ComponentResourceOptions?options = null) : base("examples:azure:ArchiveFunctionApp", name, options) { var opts = new CustomResourceOptions { Parent = this }; var storageAccount = new Account("sa", new AccountArgs { ResourceGroupName = args.ResourceGroupName, AccountReplicationType = "LRS", AccountTier = "Standard", }, opts); var appServicePlan = new Plan("asp", new PlanArgs { ResourceGroupName = args.ResourceGroupName, Kind = "FunctionApp", Sku = new PlanSkuArgs { Tier = "Dynamic", Size = "Y1", }, }, opts); var container = new Container("zips", new ContainerArgs { StorageAccountName = storageAccount.Name, ContainerAccessType = "private", }, opts); var blob = new Blob("zip", new BlobArgs { StorageAccountName = storageAccount.Name, StorageContainerName = container.Name, Type = "Block", Source = args.Archive }, opts); var codeBlobUrl = SharedAccessSignature.SignedBlobReadUrl(blob, storageAccount); var app = new FunctionApp("app", new FunctionAppArgs { ResourceGroupName = args.ResourceGroupName, AppServicePlanId = appServicePlan.Id, AppSettings = { { "runtime", "dotnet" }, { "WEBSITE_RUN_FROM_PACKAGE", codeBlobUrl }, }, StorageConnectionString = storageAccount.PrimaryConnectionString, Version = "~2" }, opts); }
public HelloworldStack() { var resourceGroup = new ResourceGroup("main", new ResourceGroupArgs { Location = "uksouth" }); var function = new FunctionApp("helloworld", new FunctionAppArgs { Location = "uksouth", ResourceGroupName = resourceGroup.Name, }); this.Url = Output.Format($"https://{function.DefaultHostname}/api/hello"); }
public static async Task <IActionResult> CreateFunctionApp( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "functionapp")] HttpRequest req, [CosmosDB( databaseName: "FunctionAppDB", collectionName: "FunctionApp", CreateIfNotExists = true, ConnectionStringSetting = "CosmosDBConnection")] IAsyncCollector <FunctionApp> functionApp, [ResourceDeployment("CLIENT_ID", "CLIENT_PASS", "TENANT_ID")] IAsyncCollector <ResourceDeploymentContext> deployment, ILogger log) { try { string requestBody = new StreamReader(req.Body).ReadToEnd(); FunctionApp input = JsonConvert.DeserializeObject <FunctionApp>(requestBody); if (input.Id == null) { input.Id = Guid.NewGuid().ToString(); } if (input.TemplateURL == null) { input.TemplateURL = "https://raw.githubusercontent.com/azure/azure-quickstart-templates/master/101-function-app-create-dynamic/azuredeploy.json"; } input.CreatedDate = DateTimeOffset.Now; var parameter = JsonConvert.SerializeObject(new TemplateParameter(input.Name)); var deploymentContext = new ResourceDeploymentContext("functionAppDeploy", input.TemplateURL, parameter, input.ResourceGroup, input.Location); await deployment.AddAsync(deploymentContext); // This execute deployment log.LogInformation($"FunctionApp {input.Name} has been created."); // If success you write cosmos db record for managing functions apps. await functionApp.AddAsync(input); return((ActionResult) new OkObjectResult(JsonConvert.SerializeObject(input))); } catch (Exception e) { log.LogInformation($"CreateFunctionApp: Error: {e.Message} : {e.StackTrace}"); return((ActionResult) new System.Web.Http.ExceptionResult(e, true)); } }
static void SetFirewallRulesToAccessSqlServer(ResourceGroup resourceGroup, FunctionApp functionApp, SqlServer sqlServer) { functionApp.OutboundIpAddresses.Apply(outboundIpAddresses => { return(outboundIpAddresses .Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries) .Select(ip => { return new FirewallRule($"{ip}.", new FirewallRuleArgs { ResourceGroupName = resourceGroup.Name, ServerName = sqlServer.Name, StartIpAddress = ip, EndIpAddress = ip }); }) .ToList()); }); }
static Task <int> Main() { return(Deployment.RunAsync(() => { // Create an Azure Resource Group var resourceGroup = new ResourceGroup("doaw20-rg"); // Create an Azure Storage Account var storageAccount = new Account("doaw20st", new AccountArgs { ResourceGroupName = resourceGroup.Name, AccountReplicationType = "LRS", AccountTier = "Standard", //EnableHttpsTrafficOnly = true }); var appServicePlan = new Plan("doaw20-asp", new PlanArgs { ResourceGroupName = resourceGroup.Name, Kind = "FunctionApp", Sku = new PlanSkuArgs { Tier = "Dynamic", Size = "Y1" } }); var container = new Container("zips", new ContainerArgs { StorageAccountName = storageAccount.Name, ContainerAccessType = "private" }); var blob = new ZipBlob("zip", new ZipBlobArgs { StorageAccountName = storageAccount.Name, StorageContainerName = container.Name, Type = "block", Content = new FileArchive("../HelloFunc/bin/Debug/netcoreapp3.1/publish") }); var codeBlobUrl = SharedAccessSignature.SignedBlobReadUrl(blob, storageAccount); var app = new FunctionApp("doaw20-app", new FunctionAppArgs { ResourceGroupName = resourceGroup.Name, AppServicePlanId = appServicePlan.Id, AppSettings = { { "runtime", "dotnet" }, { "WEBSITE_RUN_FROM_PACKAGE", codeBlobUrl } }, StorageConnectionString = storageAccount.PrimaryConnectionString, Version = "~3" }); // Export the connection string for the storage account return new Dictionary <string, object?> { { "connectionString", storageAccount.PrimaryConnectionString }, { "endpoint", Output.Format($"https://{app.DefaultHostname}/api/HelloPulumi?name=DevOps@Work20") } }; })); }
public FunctionController(IFactoryConnection connection) { _connection = connection; _FunctionApp = new FunctionApp(connection); }
private FunctionApp FunctionApp(string name, InputMap <string> appSettings, SubscriptionFilterConfig?subscriptionFilterConfig = null) { var storageAccount = new Pulumi.Azure.Storage.Account(name, new Pulumi.Azure.Storage.AccountArgs { ResourceGroupName = _resourceGroup.Name, Location = _resourceGroup.Location, AccountTier = "Standard", AccountReplicationType = "LRS", }); var plan = new Plan(name, new PlanArgs { Location = _resourceGroup.Location, ResourceGroupName = _resourceGroup.Name, Kind = "FunctionApp", Sku = new Pulumi.Azure.AppService.Inputs.PlanSkuArgs { Tier = "Dynamic", Size = "Y1", }, }); var serviceBusSubscription = new Subscription(name, new SubscriptionArgs() { Name = name, NamespaceName = _serviceBusNamespace.Name, TopicName = _serviceBusTopic.Name, ResourceGroupName = _resourceGroup.Name, MaxDeliveryCount = 10 }); if (subscriptionFilterConfig != null) { var typesList = new List <string>(); typesList.AddRange(subscriptionFilterConfig.MessageTypes); if (subscriptionFilterConfig.AssemblyToScan != null) { var handlerTypes = subscriptionFilterConfig.AssemblyToScan.GetTypes() .Where(t => t.GetInterfaces() .Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IRequestHandler <>))).ToList(); Console.Out.WriteLine("Got handler Types: " + string.Join(' ', handlerTypes.Select(t => t.Name))); var messageTypes = handlerTypes.Select(ht => ht.GetInterfaces() .FirstOrDefault(i => i.GetGenericTypeDefinition() == typeof(IRequestHandler <>)) .GenericTypeArguments.First() ) .ToList(); Console.Out.WriteLine("Got message Types: " + string.Join(' ', messageTypes.Select(t => t.Name))); typesList.AddRange(messageTypes.Select(t => t.Name)); } if (typesList.Any()) { var filterExpression = string.Join(" OR ", typesList.Select(t => $"sys.Label='{t}'")); Console.Out.WriteLine("Creating Filter Expression: " + filterExpression); var subFilter = new SubscriptionRule(name, new SubscriptionRuleArgs() { ResourceGroupName = _resourceGroup.Name, NamespaceName = _serviceBusNamespace.Name, TopicName = _serviceBusTopic.Name, SubscriptionName = name, FilterType = "SqlFilter", SqlFilter = filterExpression }); } } // create a new app settings input map - avoids adding the exception for having the same key but different value on the next function app var funcAppSettings = InputMap <string> .Merge(appSettings, new InputMap <string>() { { "ServiceBusSubscription", serviceBusSubscription.Name }, { "WEBSITE_RUN_FROM_PACKAGE", "1" } }); var functionApp = new FunctionApp($"magicbus-{name}", new FunctionAppArgs() { Name = $"magicbus-{name}", ResourceGroupName = _resourceGroup.Name, HttpsOnly = true, Version = "~3", AppServicePlanId = plan.Id, StorageAccountName = storageAccount.Name, StorageAccountAccessKey = storageAccount.PrimaryAccessKey, AppSettings = funcAppSettings, }); return(functionApp); }
// LINQPad script entry point // when deployed as an Azure Function this method is not used public static async Task <int> MainAsync(object userQuery, string[] args) { var hasConsoleInput = false; if ("LPRun.exe".Equals(Process.GetCurrentProcess().MainModule.ModuleName, StringComparison.OrdinalIgnoreCase)) { hasConsoleInput = Environment.UserInteractive; // pipe trace to console Trace.Listeners.Add(new ConsoleTraceListener()); } if (userQuery == null) { throw new ArgumentNullException("User query cannot be null. You should pass 'this' here.", nameof(userQuery)); } var userQueryTypeInfo = new UserQueryTypeInfo(userQuery); var currentQuery = Util.CurrentQuery; if (currentQuery == null) { throw new InvalidOperationException("This script must be run from wthin a LINQPad context (either via LINQPad or LPRun)."); } var currentQueryInfo = new QueryInfo(currentQuery); var currentQueryPath = Util.CurrentQueryPath; if (currentQueryPath == null) { throw new InvalidOperationException("A file name is required (save your LINQPad query to disk). Without it, we cannot establish a context for your functions."); } var currentQueryPathInfo = new QueryPathInfo(currentQueryPath); // ======== args = args ?? new string[0]; // note: `args` can be null if (args.Length == 0) { if (FirstRun.ShouldPrompt()) { FirstRun.Prompt(); } // ================================ var workingDirectory = Path.Combine(Env.GetLocalAppDataDirectory(), currentQueryPathInfo.InstanceId); Debug.WriteLine($"workingDirectory: {workingDirectory}"); FunctionApp.Deploy(workingDirectory); // ================================ Compiler.Compile(new UserQueryTypeInfo(userQuery), currentQueryInfo, new CompilationOptions(currentQueryPath) { OutDir = workingDirectory, }, currentQueryInfo); // ================================ StorageEmulator.StartOrInstall(); // todo: if AzureWebJobsStorage or AzureWebJobsDashboard is set elsewhere, like app.config we shouldn't override them like this if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("AzureWebJobsStorage"))) { Environment.SetEnvironmentVariable("AzureWebJobsStorage", "UseDevelopmentStorage=true"); } if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("AzureWebJobsDashboard"))) { Environment.SetEnvironmentVariable("AzureWebJobsDashboard", "UseDevelopmentStorage=true"); } // ================================ var lastWriteTime = File.GetLastWriteTimeUtc(currentQueryPathInfo.QueryPath); using (var fs = new FileSystemWatcher(currentQueryPathInfo.QueryDirectoryName, currentQueryPathInfo.QueryFileName)) { var stream = new BlockingCollection <int>(); ThreadPool.QueueUserWorkItem(_ => { foreach (var x in stream.GetConsumingEnumerable()) { Thread.Sleep(250); // hold, for just a moment... var lastWriteTime2 = File.GetLastWriteTimeUtc(currentQueryPathInfo.QueryPath); if (lastWriteTime < lastWriteTime2) { Debug.WriteLine("Recompiling..."); Util.RunAndWait(currentQueryPathInfo.QueryPath, new[] { "-compile", "-out-dir", workingDirectory }); Debug.WriteLine("Recompiled!"); lastWriteTime = lastWriteTime2; } } }); fs.Changed += (sender, e) => stream.Add(0); fs.EnableRaisingEvents = true; await JobHost.LaunchAsync(workingDirectory); stream.CompleteAdding(); } // ================================ return(0); } else { try { var options = CommandLine.Parse(args, new Options { }); if (options.compile) { var compilationOptions = new CompilationOptions(currentQueryPath); compilationOptions.OutDir = options.out_dir == null?Path.Combine(compilationOptions.QueryDirectoryName, compilationOptions.QueryName + "_" + userQueryTypeInfo.Id) : Path.GetFullPath(options.out_dir); Compiler.Compile(userQueryTypeInfo, currentQueryInfo, compilationOptions, currentQueryInfo); Trace.WriteLine($"Done. Output written to '{compilationOptions.OutDir}'"); return(0); } else if (options.publish) { var compilationOptions = new CompilationOptions(currentQueryPath); compilationOptions.OutDir = Path.Combine(compilationOptions.QueryDirectoryName, compilationOptions.QueryName + "_" + userQueryTypeInfo.Id + "_" + Environment.TickCount); try { Compiler.Compile(userQueryTypeInfo, currentQueryInfo, compilationOptions, currentQueryInfo); var publishSettingsFileNames = FileUtil.ResolveSearchPatternUpDirectoryTree(compilationOptions.QueryDirectoryName, "*.PublishSettings").ToList(); if (1 != publishSettingsFileNames.Count) { if (1 < publishSettingsFileNames.Count) { throw new InvalidOperationException($"Aborted. Found two or more '*.PublishSettings' files. " + string.Join(", ", publishSettingsFileNames)); } else { throw new InvalidOperationException($"Aborted. Cannot find a '*.PublishSettings' file in '{compilationOptions.QueryDirectoryName}' or any of it's parents"); } } var kudu = KuduClient.FromPublishProfile(publishSettingsFileNames[0]); var appSettings = kudu.GetSettings(); if (appSettings.TryGetValue("WEBSITE_SITE_NAME", out var siteName) && appSettings.TryGetValue("WEBSITE_SLOT_NAME", out var slotName)) { Trace.WriteLine($"Publishing to '{siteName}' ({slotName})..."); } else { Trace.WriteLine($"Site '{kudu.Host}' metadata is missing"); } // this setting needs to be changed using the az command line // https://docs.microsoft.com/en-us/azure/azure-functions/set-runtime-version#view-and-update-the-runtime-version-using-azure-cli // using the Kudu settings API doesn't update the application app settings if (appSettings.TryGetValue("FUNCTIONS_EXTENSION_VERSION", out var functionsExtensionVersion)) { if (functionsExtensionVersion != "~1") { var text = "The Azure Functions runtime version 1.x is required. Would you like to change the FUNCTIONS_EXTENSION_VERSION setting to ~1?"; var caption = "Azure Functions Runtime"; if (MessageBox.ShowYesNoQuestion(text, caption)) { var result = await Az.RunAsunc("functionapp", "list", "--query", $"[?name=='{siteName}']"); if (result.Output.Count() != 1) { throw new InvalidOperationException($"Aborted. Cannot find Azure Function App '{siteName}'"); } var functionApp = result.Output[0]; var g = (string)functionApp["resourceGroup"]; var result2 = await Az.RunAsunc("functionapp", "config", "appsettings", "set", "-g", g, "-n", siteName, "--settings", "FUNCTIONS_EXTENSION_VERSION=~1"); if (result2.ExitCode != 0) { throw new InvalidOperationException($"Aborted. Cannot configure Azure Function App '{siteName}'"); } } else { throw new InvalidOperationException("Aborted. Azure Functions runtime version 1.x is required"); } } } // need to check for cloud pad function app runtime // if not found, offer to deploy it if (!kudu.VfsExists("site/wwwroot/bin/CloudPad.FunctionApp.dll")) { if (hasConsoleInput) { var text = "It looks like the CloudPad.FunctionApp (runtime) has not been deployed yet. Would you like to deploy this now (you only do this once per Azure Function App)?"; var caption = "Deployment"; if (MessageBox.ShowYesNoQuestion(text, caption)) { Trace.WriteLine($"Deploying runtime... (this will just take a minute)"); kudu.ZipDeployPackage(FunctionApp.PackageUri); } } else { Trace.WriteLine($"Oh no. You have to deploy the CloudPad.FunctionApp runtime first"); return(1); } } Trace.WriteLine($"Deploying script '{currentQueryPathInfo.QueryFileNameWithoutExtension}' ({userQueryTypeInfo.AssemblyName})..."); kudu.ZipUpload(compilationOptions.OutDir); } finally { if (Directory.Exists(compilationOptions.OutDir)) { Directory.Delete(compilationOptions.OutDir, true); } } Trace.WriteLine("Done."); if (options.interactive) { if (hasConsoleInput) { Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } } return(0); } else if (options.pack) { var compilationOptions = new CompilationOptions(currentQueryPath); compilationOptions.OutDir = options.out_dir == null?Path.Combine(compilationOptions.QueryDirectoryName, compilationOptions.QueryName + "_publish") : Path.GetFullPath(options.out_dir); FunctionApp.Deploy(compilationOptions.OutDir); Compiler.Compile(userQueryTypeInfo, currentQueryInfo, compilationOptions, currentQueryInfo); Trace.WriteLine($"Done. Output written to '{compilationOptions.OutDir}'"); return(0); } else if (options.install) { FirstRun.Install(); return(0); } } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); if (hasConsoleInput) { Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } throw; } return(1); } }
public MyStack() { var projectName = Deployment.Instance.ProjectName.ToLower(); var stackName = Deployment.Instance.StackName; #region Resource Group var resourceGroupName = $"{projectName}-{stackName}-rg"; var resourceGroup = new ResourceGroup(resourceGroupName, new ResourceGroupArgs { Name = resourceGroupName }); #endregion #region Azure Storage var storageAccountName = $"{projectName}{stackName}st"; var storageAccount = new Account(storageAccountName, new AccountArgs { Name = storageAccountName, ResourceGroupName = resourceGroup.Name, AccountReplicationType = "LRS", AccountTier = "Standard", AccountKind = "StorageV2", EnableHttpsTrafficOnly = true }); StorageConnectionString = storageAccount.PrimaryConnectionString; #endregion #region Func Blobs var container = new Container("zips", new ContainerArgs { StorageAccountName = storageAccount.Name, ContainerAccessType = "private" }); var lightsBlob = new Blob("lightszip", new BlobArgs { StorageAccountName = storageAccount.Name, StorageContainerName = container.Name, Type = "Block", Source = new FileArchive("../Lights/bin/Debug/netcoreapp3.1/publish") }); var lightsBlobUrl = SharedAccessSignature.SignedBlobReadUrl(lightsBlob, storageAccount); var cacheBlob = new Blob("cachezip", new BlobArgs { StorageAccountName = storageAccount.Name, StorageContainerName = container.Name, Type = "Block", Source = new FileArchive("../Cache/bin/Debug/netcoreapp3.1/publish") }); var cacheBlobUrl = SharedAccessSignature.SignedBlobReadUrl(cacheBlob, storageAccount); #endregion #region AppService Plan var planName = $"{projectName}-{stackName}-plan"; var appServicePlan = new Plan(planName, new PlanArgs { Name = planName, ResourceGroupName = resourceGroup.Name, Kind = "FunctionApp", Sku = new PlanSkuArgs { Tier = "Dynamic", Size = "Y1" } }); #endregion #region Lights var lightsName = $"{projectName}-{stackName}-func-lights"; var lightsFunc = new FunctionApp(lightsName, new FunctionAppArgs { Name = lightsName, ResourceGroupName = resourceGroup.Name, AppServicePlanId = appServicePlan.Id, AppSettings = { { "runtime", "dotnet" }, { "WEBSITE_RUN_FROM_PACKAGE", lightsBlobUrl } }, StorageAccountAccessKey = storageAccount.PrimaryAccessKey, StorageAccountName = storageAccount.Name, Version = "~3" }); LightsFunc = lightsFunc.DefaultHostname; #endregion #region Cache var cacheName = $"{projectName}-{stackName}-func-cache"; var cacheFunc = new FunctionApp(cacheName, new FunctionAppArgs { Name = cacheName, ResourceGroupName = resourceGroup.Name, AppServicePlanId = appServicePlan.Id, AppSettings = { { "runtime", "dotnet" }, { "WEBSITE_RUN_FROM_PACKAGE", cacheBlobUrl } }, StorageAccountAccessKey = storageAccount.PrimaryAccessKey, StorageAccountName = storageAccount.Name, Version = "~3" }); CacheFunc = cacheFunc.DefaultHostname; #endregion }
private Output <string> getEndpoint(FunctionApp app, Output <string> rootPath) { return(Output.Format($"https://{app.DefaultHostname}/{rootPath}")); }
public AzureStack() { var config = new Pulumi.Config(); var deployTo = config.Require("DeployTo"); // Create an Azure Resource Group var resourceGroupName = $"rg-ne-rpc-demo-{deployTo}"; var resourceGroup = new ResourceGroup(resourceGroupName, new ResourceGroupArgs { Name = resourceGroupName }); // Create an Azure Storage Account var storageAccount = new Account($"nerpcdemo{deployTo}", new AccountArgs { ResourceGroupName = resourceGroup.Name, AccountReplicationType = "LRS", AccountTier = "Standard" }); // Container for deployment artefacts var zipContainer = new Container("zips", new ContainerArgs { StorageAccountName = storageAccount.Name, ContainerAccessType = "private" }); var dataContainer = new Container("data", new ContainerArgs { StorageAccountName = storageAccount.Name, ContainerAccessType = "private", Name = "data" }); var appServicePlan = new Plan($"plan-{deployTo}", new PlanArgs { ResourceGroupName = resourceGroup.Name, Kind = "FunctionApp", Sku = new PlanSkuArgs { Tier = "Dynamic", Size = "Y1", } }); var blob = new Blob("azure-func", new BlobArgs { StorageAccountName = storageAccount.Name, StorageContainerName = zipContainer.Name, Type = "Block", Source = new FileArchive("../azure-func/publish") }); var codeBlobUrl = SharedAccessSignature.SignedBlobReadUrl(blob, storageAccount); var app = new FunctionApp("app", new FunctionAppArgs { ResourceGroupName = resourceGroup.Name, AppServicePlanId = appServicePlan.Id, AppSettings = { { "runtime", "dotnet" }, { "WEBSITE_RUN_FROM_PACKAGE", codeBlobUrl }, { "QuoteServerHost", "https://vn651r8t22.execute-api.eu-west-2.amazonaws.com/Prod" }, { "DataConnectionString", storageAccount.PrimaryBlobConnectionString }, { "DataContainer", dataContainer.Name } }, StorageAccountName = storageAccount.Name, StorageAccountAccessKey = storageAccount.PrimaryAccessKey, Version = "~3" }); this.StorageAccountName = storageAccount.Name; this.Endpoint = Output.Format($"https://{app.DefaultHostname}/api/lookup"); this.DataContainer = dataContainer.Name; }
public FunctionsStack() { var resourceGroup = new ResourceGroup("functions-rg"); var storageAccount = new Account("sa", new AccountArgs { ResourceGroupName = resourceGroup.Name, AccountReplicationType = "LRS", AccountTier = "Standard" }); var appServicePlan = new Plan("functions-linux-asp", new PlanArgs { ResourceGroupName = resourceGroup.Name, // Run on Linux Kind = "Linux", // Premium SKU Sku = new PlanSkuArgs { Tier = "PremiumV2", Size = "P1v2" }, // For Linux, you need to change the plan to have Reserved = true property. Reserved = true }); var container = new Container("zips", new ContainerArgs { StorageAccountName = storageAccount.Name, ContainerAccessType = "private" }); var blob = new Blob("zip", new BlobArgs { StorageAccountName = storageAccount.Name, StorageContainerName = container.Name, Type = "Block", Source = new FileArchive("./functions") }); var codeBlobUrl = SharedAccessSignature.SignedBlobReadUrl(blob, storageAccount); // Application insights var insights = new Insights("functions-ai", new InsightsArgs { ResourceGroupName = resourceGroup.Name, ApplicationType = "web" }); var app = new FunctionApp("app", new FunctionAppArgs { ResourceGroupName = resourceGroup.Name, AppServicePlanId = appServicePlan.Id, AppSettings = { { "runtime", "python" }, { "FUNCTIONS_WORKER_RUNTIME", "python" }, { "WEBSITE_RUN_FROM_PACKAGE", codeBlobUrl }, { "APPLICATIONINSIGHTS_CONNECTION_STRING", Output.Format($"InstrumentationKey={insights.InstrumentationKey}") } }, StorageAccountName = storageAccount.Name, StorageAccountAccessKey = storageAccount.PrimaryAccessKey, Version = "~3", OsType = "linux", SiteConfig = new FunctionAppSiteConfigArgs { AlwaysOn = true, LinuxFxVersion = "DOCKER|mcr.microsoft.com/azure-functions/python:2.0" } }); this.Endpoint = Output.Format($"https://{app.DefaultHostname}/api/Hello?name=Pulumi"); }
public Step3Start() { const string prefix = Common.Prefix; var config = new Config(); var location = config.Get("location") ?? "australiaeast"; #region Resource Group var resourceGroup = new ResourceGroup($"{prefix}-{Deployment.Instance.StackName}", new ResourceGroupArgs() { Name = $"{prefix}-{Deployment.Instance.StackName}", Location = location }); var name = $"{prefix}{Deployment.Instance.StackName}web"; #endregion #region Static Website var staticWebsiteStorageAccount = new Pulumi.Azure.Storage.Account( name, new Pulumi.Azure.Storage.AccountArgs { Name = name, ResourceGroupName = resourceGroup.Name, EnableHttpsTrafficOnly = true, AccountReplicationType = "LRS", AccountTier = "Standard", AccountKind = "StorageV2", AccessTier = "Hot" }); WebContainer = staticWebsiteStorageAccount.PrimaryBlobConnectionString.Apply(async v => await EnableStaticSites(v)); StaticWebsiteConnection = staticWebsiteStorageAccount.PrimaryBlobConnectionString; #endregion #region Cosmos DB var cosmosDatabaseOutput = CosmosDatabase.Run( resourceGroup.Name, prefix, resourceGroup.Location); #endregion #region Azure Function #region Storage Account var storageAccount = new Account($"sa{prefix}{Deployment.Instance.StackName}", new AccountArgs { Name = $"sa{prefix}{Deployment.Instance.StackName}", ResourceGroupName = resourceGroup.Name, Location = resourceGroup.Location, AccountReplicationType = "LRS", AccountTier = "Standard" }); #endregion #region App Service Plan var appServicePlan = new Plan($"asp-{prefix}{Deployment.Instance.StackName}", new PlanArgs { Name = $"asp-{prefix}{Deployment.Instance.StackName}", ResourceGroupName = resourceGroup.Name, Location = resourceGroup.Location, Kind = "FunctionApp", Sku = new PlanSkuArgs { Tier = "Dynamic", Size = "Y1" } }); #endregion #region Storage Container var container = new Container($"func-code", new ContainerArgs { StorageAccountName = storageAccount.Name, ContainerAccessType = "private", }); #endregion #region Function Zip Blob var functionAppFileLocation = "../TeamTimeZones/bin/Debug/netcoreapp3.1/publish/"; var blob = new Blob($"func", new BlobArgs { StorageAccountName = storageAccount.Name, StorageContainerName = container.Name, Type = "block", Source = new FileArchive(functionAppFileLocation), }); #endregion #region Function App var codeBlobUrl = SharedAccessSignature.SignedBlobReadUrl(blob, storageAccount); var app = new FunctionApp($"app-{prefix}", new FunctionAppArgs { Name = $"app-{prefix}", ResourceGroupName = resourceGroup.Name, Location = resourceGroup.Location, AppServicePlanId = appServicePlan.Id, StorageConnectionString = storageAccount.PrimaryConnectionString, Version = "~3", AppSettings = new InputMap <string> { { "runtime", "dotnet" }, { "WEBSITE_RUN_FROM_PACKAGE", codeBlobUrl }, { "db-account-endpoint", cosmosDatabaseOutput["db-account-endpoint"].Apply(x => x.ToString()) }, { "db-account-key", cosmosDatabaseOutput["db-account-key"].Apply(x => x.ToString()) } }, SiteConfig = new FunctionAppSiteConfigArgs { Cors = new FunctionAppSiteConfigCorsArgs { AllowedOrigins = "*" } } }); this.FunctionAppEndPoint = app.DefaultHostname; #endregion #endregion }
public MyStack() { ProjectStack = $"{Deployment.Instance.ProjectName}-{Deployment.Instance.StackName}"; StackSuffix = Regex.Replace(Deployment.Instance.StackName, "[^a-z0-9]", string.Empty, RegexOptions.IgnoreCase); var stagingModelVersion = GetModelVersionForStagingSlot(); var productionModelVersion = GetModelVersionForProductionSlot() ?? stagingModelVersion; Console.WriteLine($"ML Model Version. Staging: {stagingModelVersion} Prod: {productionModelVersion}"); var resourceGroup = new ResourceGroup(ProjectStack); var storageAccount = new Account("sa" + StackSuffix.ToLowerInvariant(), new AccountArgs { ResourceGroupName = resourceGroup.Name, AccountReplicationType = "LRS", AccountTier = "Standard" }); var appServicePlan = new Plan("asp" + StackSuffix.ToLowerInvariant(), new PlanArgs { ResourceGroupName = resourceGroup.Name, Kind = "FunctionApp", Sku = new PlanSkuArgs { Tier = "Dynamic", Size = "Y1", } }); var container = new Container("cntzip" + StackSuffix.ToLowerInvariant(), new ContainerArgs { StorageAccountName = storageAccount.Name, ContainerAccessType = "private" }); var blob = new Blob("blobzip" + StackSuffix.ToLowerInvariant(), new BlobArgs { StorageAccountName = storageAccount.Name, StorageContainerName = container.Name, Type = "Block", Source = new FileArchive("../ml/Predictor/bin/Release/netcoreapp3.1/publish/") }); var codeBlobUrl = SharedAccessSignature.SignedBlobReadUrl(blob, storageAccount); var appInsights = new Insights("fxai" + StackSuffix.ToLowerInvariant(), new InsightsArgs { ResourceGroupName = resourceGroup.Name, ApplicationType = "web" }); var valuesMap = new InputMap <string>() { { "runtime", "dotnet" }, { "WEBSITE_RUN_FROM_PACKAGE", codeBlobUrl }, { "AzureWebJobsStorage", storageAccount.PrimaryConnectionString }, { "ML_MODEL_URI", productionModelVersion }, { "APPINSIGHTS_INSTRUMENTATIONKEY", appInsights.InstrumentationKey } }; var app = new FunctionApp("fxapp" + StackSuffix.ToLowerInvariant(), new FunctionAppArgs { ResourceGroupName = resourceGroup.Name, AppServicePlanId = appServicePlan.Id, AppSettings = valuesMap, SiteConfig = new FunctionAppSiteConfigArgs { Cors = new FunctionAppSiteConfigCorsArgs { AllowedOrigins = new InputList <string> { "http://localhost:5500" }, SupportCredentials = true } }, StorageAccountName = storageAccount.Name, StorageAccountAccessKey = storageAccount.PrimaryAccessKey, Version = "~3" }); var stagingSlot = new FunctionAppSlot("staging", new FunctionAppSlotArgs { Name = "staging", ResourceGroupName = resourceGroup.Name, AppServicePlanId = appServicePlan.Id, StorageAccountName = storageAccount.Name, StorageAccountAccessKey = storageAccount.PrimaryAccessKey, FunctionAppName = app.Name, Version = "~3", SiteConfig = new FunctionAppSlotSiteConfigArgs { Cors = new FunctionAppSlotSiteConfigCorsArgs { AllowedOrigins = new InputList <string> { "http://localhost:5500" }, SupportCredentials = true } }, AppSettings = { { "runtime", "dotnet" }, { "WEBSITE_RUN_FROM_PACKAGE", codeBlobUrl }, { "AzureWebJobsStorage", storageAccount.PrimaryConnectionString }, { "ML_MODEL_URI", stagingModelVersion }, { "APPINSIGHTS_INSTRUMENTATIONKEY", appInsights.InstrumentationKey } }, }); StorageConnectionString = Output.Format($"{storageAccount.PrimaryConnectionString}"); StaginEndpoint = Output.Format($"https://{stagingSlot.DefaultHostname}"); Endpoint = Output.Format($"https://{app.DefaultHostname}"); ModelVersion = Output.Format($"{productionModelVersion}"); }
public AzureApplications(Construct scope, string id) : base(scope, id) { // Update organization name const string orgName = "jet"; // define resources here var azureProvider = new AzurermProvider(this, "AzureRm", new AzurermProviderConfig { Features = new[] { new AzurermProviderFeatures() } }); var resourceGroup = new ResourceGroup(this, "basket", new ResourceGroupConfig { Name = "basket", Location = "canadaeast", Provider = azureProvider }); var appServicePlan = new AppServicePlan(this, "appServicePlan", new AppServicePlanConfig { Name = $"{orgName}-appServicePlan", Kind = "Linux", Reserved = true, ResourceGroupName = resourceGroup.Name, Location = resourceGroup.Location, Sku = new IAppServicePlanSku[] { new AppServicePlanSku { Size = "P1V2", Tier = "Premium" } }, DependsOn = new ITerraformDependable[] { resourceGroup } }); var appService = new AppService(this, "appService", new AppServiceConfig { Name = $"{orgName}-appService", AppServicePlanId = appServicePlan.Id, Location = resourceGroup.Location, ResourceGroupName = resourceGroup.Name, ClientAffinityEnabled = false, HttpsOnly = true, DependsOn = new ITerraformDependable[] { appServicePlan }, AppSettings = new Dictionary <string, string> { { "Environment", "Production" }, } }); var appServiceSlot = new AppServiceSlot(this, "appServiceSlot", new AppServiceSlotConfig { Name = $"{orgName}-appServiceSlot", AppServicePlanId = appServicePlan.Id, Location = resourceGroup.Location, ResourceGroupName = resourceGroup.Name, AppServiceName = appService.Name, HttpsOnly = true, DependsOn = new ITerraformDependable[] { appService }, AppSettings = new Dictionary <string, string> { { "Environment", "Production" } } }); var storageAccount = new StorageAccount(this, "ssd", new StorageAccountConfig { Name = $"{orgName}ssd", Location = resourceGroup.Location, ResourceGroupName = resourceGroup.Name, AccountKind = "StorageV2", AccountReplicationType = "LRS", AccountTier = "Premium" }); var functionApp = new FunctionApp(this, "functionApp", new FunctionAppConfig { Name = $"{orgName}-functionApp", AppServicePlanId = appServicePlan.Id, Location = resourceGroup.Location, ResourceGroupName = resourceGroup.Name, Version = "3", StorageAccountName = storageAccount.Name, StorageAccountAccessKey = storageAccount.PrimaryAccessKey, OsType = "linux", SiteConfig = new IFunctionAppSiteConfig[] { new FunctionAppSiteConfig { AlwaysOn = true } }, AppSettings = new Dictionary <string, string>() { { "WEBSITE_RUN_FROM_PACKAGE", "" }, { "FUNCTIONS_WORKER_RUNTIME", "dotnet" } }, DependsOn = new ITerraformDependable[] { appServicePlan, storageAccount } }); // Grab tenant Id from azure and update tenantId for keyVault // $ az account list // Uncomment below lines // var keyVault = new KeyVault(this, "keyvault", new KeyVaultConfig // { // Name = $"{orgName}-keyvault-1", // Location = resourceGroup.Location, // ResourceGroupName = resourceGroup.Name, // SkuName = "standard", // TenantId = "<replace_tenant_id>" // }); var cosmosdbAccount = new CosmosdbAccount(this, "cosmosdb", new CosmosdbAccountConfig { Name = $"{orgName}-cosmosdb", Location = resourceGroup.Location, ResourceGroupName = resourceGroup.Name, OfferType = "Standard", Kind = "GlobalDocumentDB", GeoLocation = new ICosmosdbAccountGeoLocation[] { new CosmosdbAccountGeoLocation { Location = resourceGroup.Location, FailoverPriority = 0, ZoneRedundant = false } }, ConsistencyPolicy = new ICosmosdbAccountConsistencyPolicy[] { new CosmosdbAccountConsistencyPolicy { ConsistencyLevel = "Session" } } }); var appServiceOutput = new TerraformOutput(this, "appweburl", new TerraformOutputConfig { Value = $"https://{appService.Name}.azurewebsites.net" }); var functionAppOutput = new TerraformOutput(this, "fnWebUrl", new TerraformOutputConfig { Value = $"https://{functionApp.Name}.azurewebsites.net" }); var cosmosDbOutput = new TerraformOutput(this, "cosmosDbURL", new TerraformOutputConfig { Value = cosmosdbAccount.Endpoint }); }
public ArchiveFunctionApp(string name, ArchiveFunctionAppArgs args, ComponentResourceOptions?options = null) : base("myteam:azure:ArchiveFunctionApp", name, options) { var opts = new CustomResourceOptions { Parent = this }; var prefix = args.Prefix; //Create storage account var storageAccount = new Account($"sa{prefix}{Deployment.Instance.StackName}", new AccountArgs { Name = $"sa{prefix}{Deployment.Instance.StackName}", ResourceGroupName = args.ResourceGroupName, Location = args.FunctionAppLocation, AccountReplicationType = "LRS", AccountTier = "Standard" }, opts); //Create an app server plan var appServicePlan = new Plan($"asp-{prefix}{Deployment.Instance.StackName}", new PlanArgs { Name = $"asp-{prefix}{Deployment.Instance.StackName}", ResourceGroupName = args.ResourceGroupName, Location = args.FunctionAppLocation, Kind = "FunctionApp", Sku = new PlanSkuArgs { Tier = "Dynamic", Size = "Y1" } }, opts); var container = new Container($"func-code", new ContainerArgs { StorageAccountName = storageAccount.Name, ContainerAccessType = "private", }, opts); var blob = new Blob($"func", new BlobArgs { StorageAccountName = storageAccount.Name, StorageContainerName = container.Name, Type = "Block", Source = new FileArchive(args.FunctionAppFileLocation), }, opts); var codeBlobUrl = SharedAccessSignature.SignedBlobReadUrl(blob, storageAccount); //Create Function Application args.AppSettings.Add("runtime", "dotnet"); args.AppSettings.Add("WEBSITE_RUN_FROM_PACKAGE", codeBlobUrl); var app = new FunctionApp($"app-{prefix}", new FunctionAppArgs { Name = $"app-{prefix}", ResourceGroupName = args.ResourceGroupName, Location = args.FunctionAppLocation, AppServicePlanId = appServicePlan.Id, StorageAccountName = storageAccount.Name, StorageAccountAccessKey = storageAccount.PrimaryAccessKey, Version = "~3", AppSettings = args.AppSettings, SiteConfig = new FunctionAppSiteConfigArgs { Cors = new FunctionAppSiteConfigCorsArgs { AllowedOrigins = "*" } } }, opts); this.AppId = app.Id; this.DefaultHostname = app.DefaultHostname; }
public MyStack() { // Get Pulumi Configs var config = new Config(); var appServicePlanSize = config.Get("appServicePlanSize") ?? "S1"; var appServicePlanTier = config.Get("appServicePlanTier") ?? "Standard"; var deploymentAgentOId = config.Get("deploymentAgentOId") ?? "11111111-1011-1111-1111-111111111111"; var env = config.Get("env") ?? "test"; var location = config.Get("location") ?? "WestEurope"; var tenantId = config.Get("tenantId") ?? "11111111-1011-1111-1111-111111111111"; // Create an Azure Resource Group var resourceGroup = new ResourceGroup($"{ResourceGroupBaseName}-{env}", new ResourceGroupArgs { Location = location, Name = $"{ResourceGroupBaseName}-{env}", }); // Create an Azure Storage Account var storageAccount = new Account($"{StorageAccountBaseName}{env}", new AccountArgs { Name = $"{StorageAccountBaseName}{env}", ResourceGroupName = resourceGroup.Name, AccountReplicationType = "LRS", AccountTier = "Standard" }); // Create an App Service Plan var appServicePlan = new Plan($"{AppServicePlanBaseName}-{env}", new PlanArgs { Location = resourceGroup.Location, MaximumElasticWorkerCount = 1, Name = $"{AppServicePlanBaseName}-{env}", ResourceGroupName = resourceGroup.Name, Sku = new PlanSkuArgs { Size = appServicePlanSize, Tier = appServicePlanTier } }); // Get Function App Settings var appSettings = GetAppSettingsMap(config); // Create a Function App var functionApp = new FunctionApp($"{FunctionAppBaseName}-{env}", new FunctionAppArgs { Name = $"{FunctionAppBaseName}-{env}", StorageAccountName = storageAccount.Name, AppServicePlanId = appServicePlan.Id, Location = resourceGroup.Location, ResourceGroupName = resourceGroup.Name, StorageAccountAccessKey = storageAccount.PrimaryAccessKey, Identity = new FunctionAppIdentityArgs { Type = "SystemAssigned" }, Version = "~3", AppSettings = appSettings, SiteConfig = new FunctionAppSiteConfigArgs { AlwaysOn = true, Use32BitWorkerProcess = false, WebsocketsEnabled = false } }); // Create keyvault var keyvault = new KeyVault($"{KeyvaultBaseName}-{env}", new KeyVaultArgs { Location = resourceGroup.Location, Name = $"{KeyvaultBaseName}-{env}", ResourceGroupName = resourceGroup.Name, SkuName = "standard", TenantId = tenantId }); // Set Access Policies var functionKeyvaultAccessPolicy = new AccessPolicy($"{KeyvaultBaseName}-{env}-fn-policy", new AccessPolicyArgs { ObjectId = functionApp.Identity.Apply(identity => identity?.PrincipalId ?? "11111111-1011-1111-1111-111111111111"), KeyVaultId = keyvault.Id, TenantId = tenantId, KeyPermissions = new string[] { "get", "list" }, SecretPermissions = new string[] { "get", "list", "set", "delete" }, CertificatePermissions = new string[] { "get", "list" }, }); var deplymentAgentKeyvaultAccessPolicy = new AccessPolicy($"{KeyvaultBaseName}-{env}-agent-policy", new AccessPolicyArgs { ObjectId = deploymentAgentOId, KeyVaultId = keyvault.Id, TenantId = tenantId, KeyPermissions = new string[] { "get", "list" }, SecretPermissions = new string[] { "get", "list", "set", "delete" }, CertificatePermissions = new string[] { "get", "list" }, }); // Add Storage Account Secret var storageAccountSecret = new Secret($"{KeyvaultBaseName}-{env}-secret", new SecretArgs { KeyVaultId = keyvault.Id, Name = "StorageAccountConnectionString", Value = storageAccount.PrimaryConnectionString }); // Export the Function App Url this.FunctionAppUrl = functionApp.DefaultHostname.Apply(hostName => $"https://{hostName}"); }
public FunctionStack() { //Read the WebStorage Connection String from Config var config = new Config(); var azWebJobsStorage = config.Require("AzWebJobsStorage"); // Create an Azure Resource Group var resourceGroup = new ResourceGroup("pulumi-func-rg"); // Create an Azure Storage Account var storageAccount = new Account("funcstorage", new AccountArgs { ResourceGroupName = resourceGroup.Name, AccountReplicationType = "LRS", AccountTier = "Standard" }); //Create an App Service Plan var appServicePlan = new Plan("funcasp", new PlanArgs { ResourceGroupName = resourceGroup.Name, Kind = "FunctionApp", Sku = new PlanSkuArgs { Tier = "Dynamic", Size = "Y1", } }); //Create a Storage Container var container = new Container("funczips", new ContainerArgs { StorageAccountName = storageAccount.Name, ContainerAccessType = "private" }); //Create a Blog for pushing zip files var blob = new Blob("funczip", new BlobArgs { StorageAccountName = storageAccount.Name, StorageContainerName = container.Name, Type = "Block", Source = new FileArchive("../bin/Debug/netcoreapp3.1/publish") }); var codeBlobUrl = SharedAccessSignature.SignedBlobReadUrl(blob, storageAccount); //Create a function app and deploy the function package var app = new FunctionApp("bdotnet-demo-func", new FunctionAppArgs { ResourceGroupName = resourceGroup.Name, AppServicePlanId = appServicePlan.Id, AppSettings = { { "runtime", "dotnet" }, { "WEBSITE_RUN_FROM_PACKAGE", codeBlobUrl }, { "AzureWebJobsStorage", azWebJobsStorage } }, StorageConnectionString = storageAccount.PrimaryConnectionString, Version = "~3" }); this.Endpoint = Output.Format($"https://{app.DefaultHostname}/api/TriggerBookVacation"); }
public AzureStack() : base(new StackOptions { ResourceTransformations = { Transformations.AddLocation, Transformations.AddTags } }) { var resourceGroup = new ResourceGroup("rg-cloud-eng-pipelines", new ResourceGroupArgs { Name = "rg-cloud-eng-pipelines" }); var plan = new Plan("asp-cloud-eng-trigger", new PlanArgs { ResourceGroupName = resourceGroup.Name, Kind = "FunctionApp", Sku = new PlanSkuArgs { Tier = "Dynamic", Size = "Y1" } }); var storageAccount = new Account("sacengpipelinetrigger", new AccountArgs { Name = "sacengpipelinetrigger", ResourceGroupName = resourceGroup.Name, AccountReplicationType = "LRS", AccountTier = "Standard", AccountKind = "StorageV2" }); var appInsights = new Insights("cloud-eng-pipeline-trigger", new InsightsArgs { Name = "cloud-eng-pipeline-trigger", Location = resourceGroup.Location, ResourceGroupName = resourceGroup.Name, ApplicationType = "web", }); var app = new FunctionApp($"cloud-eng-pipeline-trigger", new FunctionAppArgs { Name = "cloud-eng-pipeline-trigger", ResourceGroupName = resourceGroup.Name, AppServicePlanId = plan.Id, StorageAccountName = storageAccount.Name, StorageAccountAccessKey = storageAccount.PrimaryAccessKey, Version = "~3", SiteConfig = new FunctionAppSiteConfigArgs { Http2Enabled = true, ScmType = "VSTSRM" }, AppSettings = new InputMap <string> { { "WEBSITE_RUN_FROM_PACKAGE", "1" }, { "APPINSIGHTS_INSTRUMENTATIONKEY", appInsights.InstrumentationKey }, { "APPLICATIONINSIGHTS_CONNECTION_STRING", appInsights.ConnectionString } } }); FunctionAppName = app.Name; HostName = app.DefaultHostname; }
public AzureFunctionStack() { bool newResourceGroup = false; bool newappServicePlan = false; ResourceGroup resourceGroup; if (newResourceGroup) { resourceGroup = new ResourceGroup("linux-app-service"); } else { resourceGroup = ResourceGroup.Get("linux-app-service", "/subscriptions/ae9255af-d099-4cdc-90a7-241ccb29df68/resourceGroups/linux-app-service"); } var storageAccount = new Account("stefsapulumi", new AccountArgs { ResourceGroupName = resourceGroup.Name, AccountReplicationType = StorageAccountReplicationTypes.LocallyRedundantStorage, AccountTier = StorageAccountTiers.Standard }); Plan appServicePlan; if (newappServicePlan) { appServicePlan = new Plan("linux-app-service-plan", new PlanArgs { ResourceGroupName = resourceGroup.Name, // Possible values are `Windows` (also available as `App`), `Linux`, `elastic` (for Premium Consumption) and `FunctionApp` (for a Consumption Plan). Kind = AppServicePlanSkuKinds.Linux, Sku = new PlanSkuArgs { Tier = AppServicePlanTiers.PremiumV2, Size = AppServicePlanSkuSizes.PremiumV2Small }, // For Linux, you need to change the plan to have Reserved = true property. Reserved = true }); } else { appServicePlan = Plan.Get("linux-app-service-plan", "/subscriptions/ae9255af-d099-4cdc-90a7-241ccb29df68/resourceGroups/linux-app-service/providers/Microsoft.Web/serverfarms/linux-app-service-plan"); } var container = new Container("azure-function-zips", new ContainerArgs { StorageAccountName = storageAccount.Name, ContainerAccessType = ContainerAccessTypes.Private }); string currentDirectory = Directory.GetCurrentDirectory(); Console.WriteLine($"currentDirectory = {currentDirectory}"); var rootDirectory = Directory.GetParent(currentDirectory); Console.WriteLine($"rootDirectory = {rootDirectory}"); string functionsAppPublishDirectory = Path.Combine(rootDirectory.FullName, "publish"); Console.WriteLine($"functionsAppPublishDirectory = {functionsAppPublishDirectory}"); var blob = new Blob("azure-function-zip", new BlobArgs { StorageAccountName = storageAccount.Name, StorageContainerName = container.Name, Type = BlobTypes.Block, // The published folder contains a 'zip' file Source = new FileArchive(functionsAppPublishDirectory) }); var codeBlobUrl = SharedAccessSignature.SignedBlobReadUrl(blob, storageAccount); var insights = new Insights("stef-ai-fa-l-v3p", new InsightsArgs { ResourceGroupName = resourceGroup.Name, ApplicationType = InsightsApplicationTypes.Web }); var functionApp = new FunctionApp("stef-function-app-linux-v3p", new FunctionAppArgs { ResourceGroupName = resourceGroup.Name, AppServicePlanId = appServicePlan.Id, AppSettings = { { "runtime", FunctionAppWorkerRuntimes.DotNet }, { "DOCKER_REGISTRY_SERVER_URL", "https://index.docker.io" }, { "WEBSITE_ENABLE_SYNC_UPDATE_SITE", "true" }, { "WEBSITES_ENABLE_APP_SERVICE_STORAGE", "true" }, { "WEBSITE_RUN_FROM_PACKAGE", codeBlobUrl }, /* * App Insights configuration will use the APPLICATIONINSIGHTS_CONNECTION_STRING app setting if it is set. * APPINSIGHTS_INSTRUMENTATIONKEY is the fallback and continues to work as-is. */ { "APPLICATIONINSIGHTS_CONNECTION_STRING", Output.Format($"InstrumentationKey={insights.InstrumentationKey}") } }, // "storage_connection_string": [DEPRECATED] Deprecated in favor of `storage_account_name` and `storage_account_access_key` StorageAccountName = storageAccount.Name, StorageAccountAccessKey = storageAccount.PrimaryAccessKey, // StorageConnectionString = storageAccount.PrimaryConnectionString, // Make sure a version 3 functionApp is created based on a 3.0 docker image Version = FunctionAppVersions.V3, OsType = FunctionAppOsTypes.Linux, SiteConfig = new FunctionAppSiteConfigArgs { LinuxFxVersion = FunctionAppSiteConfigLinuxFxVersions.DotNetV3, AlwaysOn = false, WebsocketsEnabled = false }, }); Endpoint = Output.Format($"https://{functionApp.DefaultHostname}/api/MyHttpTriggerFunction"); }