Pulumi Azure Native Provider:将 WebAppApplicationSettings 添加到静态 Web 应用程序 (SWA) 时出现错误 404

问题描述 投票:0回答:1

我正在与 Pulumi Azure Native Provider 合作部署基础架构,在尝试将 WebAppApplicationSettings 添加到 Azure 静态 Web 应用程序 (SWA) 时遇到问题。静态 Web 应用程序本身已成功创建,但当我尝试为 SWA 创建应用程序设置时,收到 404 错误,指示找不到资源。

这是我的代码的相关部分:

静态 Web 应用程序创建

function createStaticSite(
  resourceGroupArgs: RessourceGroupArgs,
  userAssignedIdentity: managedidentity.UserAssignedIdentity
) {
  const rndSwaName = new random.RandomId("swa", {
    byteLength: 8,
    keepers: { keep: resourceGroupArgs.resourceGroupName },
  });

  return new web.StaticSite(
    `swa-`,
    {
      allowConfigFileUpdates: true,
      location: "West Europe",
      branch: "develop",
      name: rndSwaName.hex.apply((v) => `swa${v}`),
      repositoryUrl: "",
      resourceGroupName: resourceGroupArgs.resourceGroupName,
      sku: {
        name: "Standard",
        tier: "Standard",
      },
      stagingEnvironmentPolicy: web.StagingEnvironmentPolicy.Enabled,
      identity: {
        type: "UserAssigned",
        userAssignedIdentities: userAssignedIdentity.id.apply((id) => getId(id)),
      },
      buildProperties: {},
    },
    { dependsOn: [userAssignedIdentity] }
  );
}

    const staticSite = createStaticSite(rgArgs, userAssignedIdentity);
  const setting = createWebApplicationSetting(staticSite, rgArgs);

将应用程序设置添加到静态 Web 应用程序 接下来,我尝试添加应用程序设置:

  function createWebApplicationSetting(
  staticApp: web.StaticSite,
  resourceGroupArgs: RessourceGroupArgs
) {
  return new web.WebAppApplicationSettings(
    "staticWebApplicationSetting",
    {
      name: staticApp.name,
      resourceGroupName: resourceGroupArgs.resourceGroupName,
      properties: {
        ClientId:"...",
        ClientSecret: "...",
      },
    },
    {
      dependsOn: [staticApp],
    }
  );
}

错误: 应用应用程序设置时我总是遇到此错误:

 azure-native:web:WebAppApplicationSettings (staticWebApplicationSetting):
error: autorest/azure: Service returned an error. Status=404 Code="ResourceNotFound" Message="The Resource '' under resource group '' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix"

到目前为止的诊断

  1. 静态 Web 应用程序创建本身已成功记录(在 Azure 中可见...)。
  2. 我已确保 WebAppApplicationSettings 依赖于静态 Web 使用dependsOn的应用程序。

问题 当我尝试使用 Pulumi 中的 Azure Native Provider 将应用程序设置添加到静态 Web 应用程序时,为什么会收到 404 错误?关于引用静态 Web 应用程序资源的正确方法,我是否缺少某些内容?

azure configuration settings pulumi
1个回答
0
投票

在 Azure 中,静态 Web 应用程序有自己的配置和设置 API,并且不像传统的应用程序服务 Web 应用程序那样使用

WebAppApplicationSettings

  • 通过
    buildProperties
    或静态 Web 应用程序级别的其他环境设置来设置环境变量。
function createStaticSite(
  resourceGroupArgs: RessourceGroupArgs,
  userAssignedIdentity: managedidentity.UserAssignedIdentity
) {
  const rndSwaName = new random.RandomId("swa", {
    byteLength: 8,
    keepers: { keep: resourceGroupArgs.resourceGroupName },
  });

  return new web.StaticSite(
    `swa-`,
    {
      allowConfigFileUpdates: true,
      location: "West Europe",
      branch: "develop",
      name: rndSwaName.hex.apply((v) => `swa${v}`),
      repositoryUrl: "",
      resourceGroupName: resourceGroupArgs.resourceGroupName,
      sku: {
        name: "Standard",
        tier: "Standard",
      },
      stagingEnvironmentPolicy: web.StagingEnvironmentPolicy.Enabled,
      identity: {
        type: "UserAssigned",
        userAssignedIdentities: userAssignedIdentity.id.apply((id) => getId(id)),
      },
      buildProperties: {
        appSettings: {
          "ClientId": "...",
          "ClientSecret": "...",
        },
      },
    },
    { dependsOn: [userAssignedIdentity] }
  );
}
  • buildProperties.appSettings
    对象允许您定义充当环境变量的键值对,这类似于您尝试使用
    WebAppApplicationSettings
    实现的目标。

结果:

enter image description here

PS C:\Users\*******\Desktop\ts_test\test2> pulumi up
Previewing update (dev):

     Type                                  Name                                Plan
 +   pulumi:pulumi:Stack                   myproject-dev                       create
 +   ├─ random:index:RandomId              swa                                 create
 +   ├─ azure-native:managedidentity:UserAssignedIdentity myidentity            create
 +   ├─ azure-native:web:StaticSite        teststaticapp01                        create
 +   └─ pulumi:providers:random            default                             create

Resources:
    + 5 to create

Updating (dev):

     Type                                  Name                                Status
 +   pulumi:pulumi:Stack                   myproject-dev                       created
 +   ├─ random:index:RandomId              swa                                 created
 +   ├─ azure-native:managedidentity:UserAssignedIdentity myidentity            created
 +   ├─ azure-native:web:StaticSite        teststaticapp01                        created
 +   └─ pulumi:providers:random            default                             created

Outputs:
    swaName: "teststaticapp01"

Resources:
    + 5 created

Duration: 30s

Permalink: https://app.pulumi.com/myorg/myproject/dev/updates/1
© www.soinside.com 2019 - 2024. All rights reserved.