Pulumi python azure 错误的资源名称

Pulumi python azure wrong resource name

我正在尝试通过以下方式创建 sql.ServerVulnerabilityAssessment 资源:

server_vulnerability_assessment=sql.ServerVulnerabilityAssessment('sva',
    storage_container_path       = container_path,
    storage_account_access_key   = storage_account_primary_key,
    resource_group_name          = resource_group.name,
    server_name                  = sql_server.name,
    recurring_scans=sql.VulnerabilityAssessmentRecurringScansPropertiesArgs(
        is_enabled                  = True,
        email_subscription_admins   = False,
        emails                      = [
            "<emails>" # not showing obviously 
        ]
    )
)

container_path = 'https://{}.blob.core.windows.net/{}'.format(storage_account.name,storage_container.name)

我收到错误:

  azure-native:sql:ServerVulnerabilityAssessment (sva):
    error: autorest/azure: Service returned an error. Status=400 Code="DataSecurityInvalidUserSuppliedParameter" Message="\"Invalid parameter 'storageContainerPath'. Value should be a valid blob storage container endpoint (e.g. https://MyAccount.blob.core.windows.net/containername).\""

如果我对值 storage_account.namestorage_container.name 进行硬编码,它可以正常工作。为什么不能在那里检索这两个属性的值?

在 运行 pulumi up 如果我选择显示详细信息,我会得到以下 storageContainerPath:

https://<pulumi.output.Output object at 0x7f1b0c8e9810>.blob.core.windows.net/<pulumi.output.Output object at 0x7f1b0c9236a0>

我做错了什么? 显然我可以对这些值进行硬编码,但为什么它不能以这种方式工作,例如 sql_server.name 它得到正确?

Storage Account 和 Container 名称是 Pulumi 的输出,这意味着它们在程序运行时可能还不知道。您需要使用 Output.all:

格式化路径
container_path = Output.all(storage_account.name, storage_container.name)
                       .apply(lambda l: f"https://{l[0]}.blob.core.windows.net/{l[1]}")

您可以在 Inputs and Outputs 中找到更多解释和示例。