我将Azure Function App作为Terraform中的模块公开,我希望该模块允许用户扩展配置参数:
<?php
$array=range(1,100);
$rand = array_rand($array,3);
echo "Random number 1: ".$array[$rand[0]]."\n";
echo "Random number 2: ".$array[$rand[1]]."\n";
echo "Random number 3: ".$array[$rand[2]]."\n";
?>
但是,在该示例中,resource "azurerm_function_app" "test" {
name = "${var.prefix}-listener"
resource_group_name = "${var.resource_group_name}"
location = "${var.resource_group_location}"
app_service_plan_id = "${var.app_service_plan_id}"
storage_connection_string = "${var.storage_account_connection_string}"
app_settings = {
HASH = "${data.archive_file.test.output_base64sha256}"
WEBSITE_USE_ZIP = "https://${var.storage_account_name}.blob.core.windows.net/${azurerm_storage_container.test.name}/${azurerm_storage_blob.test.name}${data.azurerm_storage_account_sas.test.sas}"
}
site_config {
always_on = true
}
}
是固定的,我希望可以扩展此地图。像这样:
app_settings
我通过阅读merge function得到了这个主意。但是,我收到一个无效的表达式错误。
这里的正确语法是什么?
答案 0 :(得分:2)
似乎{
和}
导致字符串插值出现问题。您可以将代码更改为
app_settings = "${merge(
map("HASH","${data.archive_file.test.output_base64sha256}"),
map("WEBSITE_USE_ZIP","https://${var.storage_account_name}.blob.core.windows.net/${azurerm_storage_container.test.name}"),/${azurerm_storage_blob.test.name}${data.azurerm_storage_account_sas.test.sas}",
var.app_settings}"
希望这可以解决您的问题。