pulumi-azure icon indicating copy to clipboard operation
pulumi-azure copied to clipboard

WindowsFunctionApp with existing AppServicePlans

Open ranjeetkpGit opened this issue 1 year ago • 10 comments

Hi, We have existing AppServicePlans created with AppServicePlan(Native) and Plan (Classic) components but when referencing them in WindowsFunctionApp, getting following error. WindowsFunctionApp expects 'serverFarms' (We get serverFarms when creating new plans using ServicePlan component) but we get 'serverfarms' from existing AppServicePlans Is there any way we can create WindowsFunctionApp with existing AppServicePlan ? We are using C# and .NET 8 to create Azure resources.

image

ranjeetkpGit avatar Mar 29 '24 15:03 ranjeetkpGit

Hi @ranjeetkpGit

Could you expand on how you're getting the value for the resource ID from Pulumi - please share some example Pulumi code if at all possible. It looks like the error you've shared is possibly from within your function app rather that from you Pulumi code.

Some resource id segments are case insensitive, and Azure sometimes returns different casing too. It's possible that the library producing this error is being overly strict, though this should also be fairly easy to work around with a string replacement if in doubt.

danielrbradley avatar Apr 02 '24 10:04 danielrbradley

Hi @danielrbradley ,

Thanks for reply. I am creating WindowsFunctionApp (Pulumi Classic) as below

        private WindowsFunctionApp CreateFunctionResource(string appName, Plan appServicePlan, FunctionSettings functionSettings, InputMap<string> settings = null, int maxScaleOutLimit = 0)
        {
            var configurations = new InputMap<string>
            {
                ................
                ................         
            };

            if (settings != null)
            {
                configurations.AddRange(settings);
            }
            var funcAppArgs = new WindowsFunctionAppArgs
            {
                ResourceGroupName = _coreSettings.ResourceGroup,
                ServicePlanId = appServicePlan.Id,
                Name = appName,
                FunctionsExtensionVersion = _coreSettings.Functions.ExtensionVersion, // v4
                Identity = new WindowsFunctionAppIdentityArgs
                {
                    Type =  "SystemAssigned"
                },
                StorageAccountName = _storageAccountName,
                StorageAccountAccessKey = _storageAccountKey,
                AppSettings = configurations,
                SiteConfig = new WindowsFunctionAppSiteConfigArgs
                {
                    AlwaysOn = functionSettings.IsDedicatedPlan(),
                    AppScaleLimit = maxScaleOutLimit,
                    ApplicationStack = new WindowsFunctionAppSiteConfigApplicationStackArgs
                    {
                      DotnetVersion  = _coreSettings.Functions.DotnetFrameworkVersion, // v8.0
                      UseDotnetIsolatedRuntime = true
                    }
                }
            };
            var functionApp = new WindowsFunctionApp($"{appName}", funcAppArgs);
            return functionApp;
        }
        private Plan CreateAppServicePlan(FunctionSettings functionSettings, string planName)
        {
            var appServicePlan = new Plan(planName, new PlanArgs
            {
                Location = _coreSettings.Region,
                ResourceGroupName = _coreSettings.ResourceGroup,
                Kind = "FunctionApp",
                Name = planName,
                Sku = new PlanSkuArgs
                {
                    Tier = functionSettings.SkuTier,
                    Size = functionSettings.SkuName   // Consumption Plan
                }
            });
            return appServicePlan;
        }

image

If a function app with same name created with FunctionApp (classic) already exists WindowsFunctionApp gives following error image

ranjeetkpGit avatar Apr 02 '24 16:04 ranjeetkpGit

Hi @ranjeetkpGit! This issue may have been fixed in the latest provider version, see this upstream issue. Could you try upgrading Azure Classic to v5.72.0?

thomas11 avatar Apr 17 '24 11:04 thomas11

Hi @ranjeetkpGit! This issue may have been fixed in the latest provider version, see this upstream issue. Could you try upgrading Azure Classic to v5.72.0?

Hi @thomas11 Thanks for reply. As FunctionApp (classic) supports till .NET 6 only, Is there any way we can upgrade it to WindowsFunctionApp without deleting existing resources?

ranjeetkpGit avatar Apr 22 '24 19:04 ranjeetkpGit

Hi @ranjeetkpGit! This issue may have been fixed in the latest provider version, see this upstream issue. Could you try upgrading Azure Classic to v5.72.0?

Hi @thomas11 Thanks for reply. As FunctionApp (classic) supports till .NET 6 only, Is there any way we can upgrade it to WindowsFunctionApp without deleting existing resources?

Hi @ranjeetkpGit, the issue title and your code sample show that you're already using WindowsFunctionApp. Is that not correct?

thomas11 avatar Apr 23 '24 05:04 thomas11

@thomas11, This code is to upgrade existing FunctionApp (created with FunctionApp (.NET 6)) to .NET 8 using WindowsFunctionApp. Instead of updating existing FunctionApp it shows error given in screenshot

ranjeetkpGit avatar Apr 23 '24 05:04 ranjeetkpGit

I see. Could you try upgrading Azure Classic to v5.72.0? Or is there an issue preventing that?

thomas11 avatar Apr 23 '24 07:04 thomas11

In see. Could you try upgrading Azure Classic to v5.72.0? Or is there an issue preventing that? Upgraded Azure classic to v5.73.0 AppServicePlan case issue resolved but getting same issue when upgrading image

ranjeetkpGit avatar Apr 23 '24 10:04 ranjeetkpGit

I'm not familiar with this specific case, but after changing your code from FunctionApp to WindowsFunctionApp, you probably need to run pulumi refresh. This will add the existing app to your Pulumi state.

If that's not sufficient, you'll need to import the app via its Azure id that you can find in the Azure portal.

thomas11 avatar Apr 23 '24 17:04 thomas11

@thomas11 I've been looking at this as well. I'm using the latest Azure Classic and when you try to import the Plan resource (https://www.pulumi.com/registry/packages/azure/api-docs/appservice/plan) You get this error:

Preview failed: importing /subscriptions/32b9cb2e-69be-4040-80a6-02cd6b2cc5ec/resourceGroups/rg954bd9e9/providers/Microsoft.Web/serverfarms/piers-appservice-plan: ID was missing the `serverFarms` element

Which feels like it's linked to this issue: https://github.com/pulumi/pulumi-azure/issues/1879

which as guin pointed out is linked to this issue: https://github.com/hashicorp/terraform-provider-azurerm/issues/19600

which has been closed as stale.

pierskarsenbarg avatar Apr 25 '24 14:04 pierskarsenbarg

@pierskarsenbarg do you happen to have a full repro? I think I know how to fix it but cannot verify the fix without a bunch of manual setup.

thomas11 avatar May 10 '24 10:05 thomas11

I've got the code for it... let me put a repo together that you can just clone and work with

pierskarsenbarg avatar May 10 '24 10:05 pierskarsenbarg

I can't replicate this anymore. I'm not sure why. Trying v5.73.0 (which was probably the version I was on when I tried it) as well as v5.68.0 which is what the customer seemed to be on.

Let me go back to the customer and see if this is still an issue

pierskarsenbarg avatar May 10 '24 11:05 pierskarsenbarg

@pierskarsenbarg any update here on whether the customer is still seeing this issue?

mjeffryes avatar Jun 11 '24 19:06 mjeffryes

closing for now since we can seem to find a program to reproduce

mjeffryes avatar Jun 24 '24 23:06 mjeffryes