如何使用 Pulumi Azure Native 将 WebAppAzureStorageAccounts 连接到 WebApp

How to connect WebAppAzureStorageAccounts to WebApp using Pulumi Azure Native

我正在尝试使用以下屏幕自动执行可通过 Azure 门户完成的操作。

我定义了一个WebApp and a WebAppAzureStorageAccounts

在尝试构建 WebAppAzureStorageAccounts 时出现以下错误:

error: parent resource does not exist for resource

我认为这是因为我不知道如何将 WebAppAzureStorageAccounts 关联到 WebApp

我期待一个名为 StorageAccountsPathMappings 的 属性 出现在 WebApp SiteConfigArgs

普路米版本:2.23.1
语言 C#
Pulumi.AzureNative: 0.7.1

---更新---

一些代码片段...我将 Pulumi 类 包裹起来,这样我就可以使用具有一些可重用默认值的构建器模式。所以不正常。

  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;
    }
  }

以及来自 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";
      }
    }

然后是这些组件的用法片段


      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();

WebAppAzureStorageAccounts 与 WebApp 之间没有任何引用,我在网上找不到示例。

如果我没看错你的代码,你为 WebAppAzureStorageAccounts 资源指定了一个任意名称。相反,您应该将 Name 属性 分配给您的网络应用程序(父资源)的名称。这不是 Azure API 的最佳命名选择,但评论说 Name of the app.

这里是应该可行的想法:

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

此模式类似于Web Apps的所有子资源,如this example所示。