我试图通过Terraform创建Azure应用程序配置服务和密钥,但是当我通过我的管道运行我的Terraform时,我得到运行terraform plan
的错误。这是我创建服务和密钥的tf脚本:
resource "azurerm_app_configuration" "appconf" {
name = var.name
location = var.location
resource_group_name = var.resource_group_name
tags = var.tags
sku = "standard"
}
resource "azurerm_app_configuration_key" "MainAPI" {
configuration_store_id = azurerm_app_configuration.appconf.id
key = "MainAPI"
value = var.picking_api_url
type = "kv"
label = var.environment_name
}
# other keys omitted
这是我看到的错误:Error: while parsing resource ID: while parsing resource ID: the number of path segments is not divisible by 2 in "subscriptions/[SubscriptionId]/resourceGroups/[rgName]/providers/Microsoft.AppConfiguration/configurationStores/[AppConfigServiceName]/AppConfigurationKey/MainAPI/Label"
我得到这个错误,不管我是否显式地包括一个label
参数的关键在我的TF脚本。我已经将我的Terraform ARM提供程序版本升级到2.90,以防它是提供程序中的错误,但仍然得到错误。
资源"azurerm_app_configuration_key"
依赖于azurerm_role_assignment
。您还需要为此定义一个资源,以便为app_configuration
分配角色。
下面的代码来自Hashicorp Terraformazurerm_app_configuration_key
文档,演示了如何做到这一点:
resource "azurerm_role_assignment" "appconf_dataowner" { scope = azurerm_app_configuration.appconf.id role_definition_name = "App Configuration Data Owner" principal_id = data.azurerm_client_config.current.object_id } resource "azurerm_app_configuration_key" "test" { configuration_store_id = azurerm_app_configuration.appconf.id key = "appConfKey1" label = "somelabel" value = "a test" depends_on = [ azurerm_role_assignment.appconf_dataowner ] }