private static FunctionAppArgs Map(string name, ArchiveFunctionAppArgs args) { if (args.AppServicePlanId == null) { var plan = new Plan(name, new PlanArgs { ResourceGroupName = args.ResourceGroupName, Kind = "FunctionApp", Sku = new PlanSkuArgs { Tier = "Dynamic", Size = "Y1" } }); args.AppServicePlanId = plan.Id; } if (args.StorageAccount == null) { args.StorageAccount = new Account(MakeSafeStorageAccountName(name), new AccountArgs { ResourceGroupName = args.ResourceGroupName, AccountReplicationType = "LRS", AccountTier = "Standard", AccountKind = "StorageV2" }); } if (args.StorageContainer == null) { args.StorageContainer = new Container(MakeSafeStorageContainerName(name), new ContainerArgs { StorageAccountName = args.StorageAccount.Apply(a => a.Name), ContainerAccessType = "private" }); } var mapped = new FunctionAppArgs { StorageAccountName = args.StorageAccount.Apply(a => a.Name), StorageAccountAccessKey = args.StorageAccount.Apply(a => a.PrimaryAccessKey), SiteConfig = args.SiteConfig, ResourceGroupName = args.ResourceGroupName, OsType = args.OsType, Name = args.Name, Location = args.Location, Tags = args.Tags, Identity = args.Identity, Enabled = args.Enabled, EnableBuiltinLogging = args.EnableBuiltinLogging, DailyMemoryTimeQuota = args.DailyMemoryTimeQuota, ConnectionStrings = args.ConnectionStrings, ClientAffinityEnabled = args.ClientAffinityEnabled, AuthSettings = args.AuthSettings, AppSettings = args.AppSettings, AppServicePlanId = args.AppServicePlanId, HttpsOnly = args.HttpsOnly, Version = args.Version }; var blob = new Blob(name, new BlobArgs { StorageAccountName = args.StorageAccount.Apply(a => a.Name), StorageContainerName = args.StorageContainer.Apply(a => a.Name), Source = args.Archive.Apply(a => a), Type = "Block" }); if (mapped.AppSettings == null) { mapped.AppSettings = new InputMap <string>(); } mapped.AppSettings.Add("WEBSITE_RUN_FROM_PACKAGE", GetSignedBlobUrl(blob, args.StorageAccount)); return(mapped); }
public static FunctionAppArgs AddAppSetting(this FunctionAppArgs functionAppArgs, (string name, string value) setting)
private FunctionAppParts createFunctionAppParts(string name, ArchiveFunctionAppArgs args, CustomResourceOptions?opts = null) { if (args.Archive == null) { throw new ArgumentNullException("Deployment [archive] must be provided."); } var resourceGroupName = getResourceGroupName(args.ResourceGroup, args.ResourceGroupName); var plan = createIfUndefined(args.Plan, () => { return(new Plan(name, new PlanArgs { ResourceGroupName = resourceGroupName, Location = args.Location, Kind = "FunctionApp", Sku = new PlanSkuArgs { Tier = "Dynamic", Size = "Y1", }, }, opts)); }); var account = createIfUndefined(args.Account, () => { return(new Account(makeSafeName(StorageAccountNameCleanerRegex, name, 24 - 8), new AccountArgs { ResourceGroupName = resourceGroupName, Location = args.Location, AccountKind = "StorageV2", AccountTier = "Standard", AccountReplicationType = "LRS", }, opts)); }); var container = createIfUndefined(args.Container, () => { return(new Container(makeSafeName(StorageContainerNameCleanerRegex, name, 63 - 8), new ContainerArgs { StorageAccountName = account.Name, ContainerAccessType = "private", }, opts)); }); var zipBlob = new Blob(name, new BlobArgs { StorageAccountName = account.Name, StorageContainerName = container.Name, Type = "Block", Source = args.Archive }, opts); var functionArgs = new FunctionAppArgs { ResourceGroupName = resourceGroupName, Location = args.Location, ClientAffinityEnabled = args.ClientAffinityEnabled, EnableBuiltinLogging = args.EnableBuiltinLogging, Enabled = args.Enabled, SiteConfig = args.SiteConfig, Identity = args.Identity, Name = args.Name, //AuthSettings = args.AuthSettings, HttpsOnly = args.HttpsOnly, AppServicePlanId = plan.Id, StorageConnectionString = account.PrimaryConnectionString, Version = getOrDefault(args.Version, FUNCTION_APP_STABLE_RUNTIME_VERSION), AppSettings = combineAppSettings(zipBlob, account, args), }; if (args.ConnectionStrings != null) { functionArgs.ConnectionStrings = args.ConnectionStrings; } if (args.Tags != null) { functionArgs.Tags = args.Tags; } var routePrefix = args.HostSettings?.Extensions?.Http?.RoutePrefix; var rootPath = Output.Format($"{ routePrefix ?? "api" }/"); return(new FunctionAppParts(account, container, zipBlob, plan, functionArgs, rootPath)); }
public FunctionAppParts(Account account, Container container, Blob blob, Plan plan, FunctionAppArgs functionAppArgs, Output <string> rootPath) => (Account, Container, Blob, Plan, FunctionAppArgs, RootPath) = (account, container, blob, plan, functionAppArgs, rootPath);
public FunctionApp(string name, FunctionAppArgs args, ComponentResourceOptions?options = null) : base("infra:functionapp", name, options) { var opts = new CustomResourceOptions { Parent = this }; var appStorage = new StorageAccount(name.Replace("-", ""), new StorageAccountArgs { ResourceGroupName = args.ResourceGroupName, Sku = new SkuArgs { Name = SkuName.Standard_LRS, }, Kind = Pulumi.AzureNative.Storage.Kind.StorageV2, }); var appServicePlan = new AppServicePlan(name, new AppServicePlanArgs { ResourceGroupName = args.ResourceGroupName, Location = args.Location, Kind = "FunctionApp", Sku = new SkuDescriptionArgs { Tier = "Dynamic", Name = "Y1" } }, opts); var container = new BlobContainer("code-container", new BlobContainerArgs { AccountName = appStorage.Name, PublicAccess = PublicAccess.None, ResourceGroupName = args.ResourceGroupName, }); var blob = new Blob($"zip-{DateTime.UtcNow:ddMMyyyyhhmmss}", new BlobArgs { AccountName = appStorage.Name, ContainerName = container.Name, ResourceGroupName = args.ResourceGroupName, Type = BlobType.Block, Source = new FileArchive("../publish") }); var appInsights = new Component("appInsights", new ComponentArgs { ApplicationType = ApplicationType.Web, Kind = "web", ResourceGroupName = args.ResourceGroupName, }); var codeBlobUrl = SignedBlobReadUrl(blob, container, appStorage, args.ResourceGroupName); var accountKeys = Output.Tuple(args.ResourceGroupName, appStorage.Name) .Apply(p => ListStorageAccountKeys.InvokeAsync(new ListStorageAccountKeysArgs { ResourceGroupName = p.Item1, AccountName = p.Item2 })); var storageConnectionString = Output.Format( $"DefaultEndpointsProtocol=https;AccountName={appStorage.Name};AccountKey={accountKeys.Apply(a => a.Keys[0].Value)}"); var app = new WebApp(name, new WebAppArgs { Kind = "FunctionApp", ResourceGroupName = args.ResourceGroupName, ServerFarmId = appServicePlan.Id, SiteConfig = new SiteConfigArgs { AppSettings = new[] { new NameValuePairArgs { Name = "APPLICATIONINSIGHTS_CONNECTION_STRING", Value = Output.Format($"InstrumentationKey={appInsights.InstrumentationKey}"), }, new NameValuePairArgs { Name = "FUNCTIONS_EXTENSION_VERSION", Value = "~3" }, new NameValuePairArgs { Name = "FUNCTIONS_WORKER_RUNTIME", Value = "dotnet-isolated" }, new NameValuePairArgs { Name = "WEBSITE_RUN_FROM_PACKAGE", Value = codeBlobUrl, }, new NameValuePairArgs { Name = "AzureWebJobsStorage", Value = GetConnectionString(args.ResourceGroupName, appStorage.Name) } } } }); var slotConfigNames = new WebAppSlotConfigurationNames(name, new WebAppSlotConfigurationNamesArgs { Name = app.Name, ResourceGroupName = args.ResourceGroupName, AppSettingNames = { "FUNCTIONS_WORKER_RUNTIME", "FUNCTIONS_EXTENSION_VERSION" } }); var stagingSlot = new WebAppSlot($"{name}-slot", new WebAppSlotArgs() { Name = app.Name, Slot = "staging", ResourceGroupName = args.ResourceGroupName, SiteConfig = new SiteConfigArgs { AppSettings = new[] { new NameValuePairArgs { Name = "WEBSITE_ADD_SITENAME_BINDINGS_IN_APPHOST_CONFIG", Value = "1" }, new NameValuePairArgs { Name = "WEBSITE_SWAP_WARMUP_PING_PATH", Value = "/helloworld" } } }, }); this.AppName = app.Name; this.AppId = app.Id; this.DefaultHostname = app.DefaultHostName; }