【问题标题】:How to connect WebAppAzureStorageAccounts to WebApp using Pulumi Azure Native如何使用 Pulumi Azure Native 将 WebAppAzureStorageAccounts 连接到 WebApp
【发布时间】:2021-04-01 04:44:22
【问题描述】:

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

我定义了一个WebApp 和一个WebAppAzureStorageAccounts

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

error: parent resource does not exist for resource

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

我希望在 WebApp SiteConfigArgs 上有一个名为 StorageAccountsPathMappings 的属性

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

--- 更新---

一些代码 sn-ps... 我将 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 的 sn-p

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

然后sn-ps这些组件的用法


      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 之间没有任何引用,我在网上找不到示例。

【问题讨论】:

  • 能否分享您的代码?
  • 添加了一些代码 sn-ps。谢谢。

标签: azure-resource-manager pulumi


【解决方案1】:

如果我正确阅读了您的代码,您可以为WebAppAzureStorageAccounts 资源分配一个任意名称。相反,您应该将 Name 属性分配给您的 Web 应用程序(父资源)的名称。这不是 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所示。

【讨论】:

  • 哦,伙计,我有另一个组件WebAppDiagnosticLogsConfigurationComponent 正是这样做的......为什么我不知道这里的模式我不知道。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-09-28
  • 2019-06-29
  • 2021-05-23
  • 1970-01-01
  • 1970-01-01
  • 2022-01-26
  • 2021-09-04
相关资源
最近更新 更多