Search code examples
azure-resource-managerpulumi

How to connect WebAppAzureStorageAccounts to WebApp using Pulumi Azure Native


I am trying to automate what can be done via the Azure portal with the following screen.

enter image description here

I have defined a WebApp and a WebAppAzureStorageAccounts

When trying to construct the WebAppAzureStorageAccounts I get the following error:

error: parent resource does not exist for resource

I think this is because I don't know how to associate the WebAppAzureStorageAccounts to the WebApp.

I was expecting a property named something like StorageAccounts or PathMappings to be on WebApp SiteConfigArgs

Pulumi version: 2.23.1
Language C#
Pulumi.AzureNative: 0.7.1

--- Update ---

Some code snippets... I wrap the Pulumi classes in so I can use the builder pattern with some reusable defaults. So not your normal.

  public class WebAppAzureStorageAccountsComponent
  {

    private readonly string ComponentName;
    public WebAppAzureStorageAccounts? WebAppAzureStorageAccounts;
    public WebAppAzureStorageAccountsArgs WebAppAzureStorageAccountsArgs;
    private bool Built;
    public CustomResourceOptions? CustomResourceOptions { get; set; }

    public WebAppAzureStorageAccountsComponent
    (
      string aComponentName,
      string aShareName,
      AzureStorageInfoValueArgs aAzureStorageInfoValueArgs,
      ResourceGroup aResourceGroup,
      StorageAccountComponent aStorageAccountComponent
    )
    {
      ComponentName = aComponentName;
      WebAppAzureStorageAccountsArgs =
        new WebAppAzureStorageAccountsArgs
        {
          Name = aComponentName,
          ResourceGroupName = aResourceGroup.Name,
          Properties = new InputMap<AzureStorageInfoValueArgs>
          {
            {
              aShareName,
              aAzureStorageInfoValueArgs
            }
          }
        };
    }

    [MemberNotNull(nameof(WebAppAzureStorageAccounts))]
    public WebAppAzureStorageAccounts Build()
    {
      if (Built) throw new MultipleBuildException(nameof(WebAppAzureStorageAccountsComponent));
      Built = true;

      WebAppAzureStorageAccounts =
        new WebAppAzureStorageAccounts
        (
          ComponentName,
          WebAppAzureStorageAccountsArgs,
          CustomResourceOptions
        );

      return WebAppAzureStorageAccounts;
    }
  }

And a snippet from WebAppComponent

    public WebAppComponent
    (
      string aName,
      AppServicePlan aAppServicePlan,
      ResourceGroup aResourceGroup,
      string aEnvironment,
      RegistryComponent? aRegistryComponent = null,
      Input<string>? aImageName = null
    )
    {
      ComponentName = aName;
      RegistryComponent = aRegistryComponent;
      Environment = aEnvironment;

      WebAppArgsBuilder =
        new WebAppArgsBuilder
        (
          ComponentName,
          aResourceGroup.Name
        )
        {
          Kind = "app,linux",
          Location = aResourceGroup.Location,
          ServerFarmId = aAppServicePlan.Id,
        };

      List<NameValuePairArgs> appSettings = BuildAppSettings();
      WebAppArgsBuilder.SiteConfigArgsBuilder.WithAppSettings(appSettings);

      if (aImageName != null)
      {
        WebAppArgsBuilder.SiteConfigArgsBuilder.LinuxFxVersion = Output.Format($"DOCKER|{aImageName}");
        WebAppArgsBuilder.Kind = "app,linux,container";
      }
    }

And then snippets of the usage of these components


      CredentialApiWebAppComponent =
        new WebAppComponent
        (
          $"credential-{AspNetCoreEnvironment}-{Brand}",
          AppServicePlan,
          ResourceGroup,
          AspNetCoreEnvironment,
          RegistryComponent,
          credentialImageName
        );

      CredentialApiWebAppComponent.Build();
    ...
      var TailsAzureStorageInfoValueArgs = new AzureStorageInfoValueArgs
      {
        AccessKey = StorageAccountComponent.PrimaryStorageKey!,
        AccountName = StorageAccountComponent.StorageAccount!.Name!,
        MountPath = "/tails",
        ShareName = "tails",
        Type = AzureStorageType.AzureFiles
      };

      var webAppAzureStorageAccountsComponent =
        new WebAppAzureStorageAccountsComponent
        (
          aComponentName: "TailsMapping",
          aShareName: "tails",
          aAzureStorageInfoValueArgs: TailsAzureStorageInfoValueArgs,
          aResourceGroup: ResourceGroup,
          aStorageAccountComponent: StorageAccountComponent
        );

      webAppAzureStorageAccountsComponent.Build();

There is nothing that references between WebAppAzureStorageAccounts to WebApp and I can't find an example online.


Solution

  • If I read your code correctly, you assign an arbitrary name to the WebAppAzureStorageAccounts resource. Instead, you should assign the Name property to the name of your web app (the parent resource). It's not the best naming choice from the Azure API but the comment says Name of the app.

    Here is the idea that should work:

    var webApp = new WebApp("myapp", new ...);
    var storage = new WebAppAzureStorageAccounts("accounts",
        new WebAppAzureStorageAccountsArgs
        {
            Name = webApp.Name,
            // ...
        });
    

    This pattern is similar to all subresources of Web Apps, as shown in this example.