Terraform模块传参失败:FunctionApp变量配置问题排查
问题解决:Terraform模块参数传递错误
错误原因
报错提示service_plan_id和storage_account_access_key不是Function App模块的合法参数,本质是Function App模块的variable.tf未定义这两个输入变量,同时模块内部的main.tf也没有正确引用变量。
修复步骤
1. 完善Function App模块的variable.tf
在../../modules/FunctionApp/test/variable.tf中添加缺失的变量定义:
variable "resourcegroupname" { type = string description = "The name of the resource group" } variable "location" { type = string description = "resources should deploy only on 'eastus' as per the policy" } variable "functionappname" { type = string } variable "storageaccountname"{ type = string description = "The name of the Storage Account" } variable "stack_version" { type = map } # 添加以下两个缺失的变量 variable "service_plan_id" { type = string description = "ID of the App Service Plan to associate with the Function App" } variable "storage_account_access_key" { type = string description = "Primary access key of the Storage Account" }
2. 修正Function App模块的main.tf
模块内部的azurerm_windows_function_app资源错误使用了未定义的裸变量,需要替换为var.前缀的模块输入变量:
resource "azurerm_windows_function_app" "win-fn" { name = var.functionappname resource_group_name = var.resourcegroupname location = var.location storage_account_name = var.storageaccountname # 修正为引用模块输入变量 storage_account_access_key = var.storage_account_access_key service_plan_id = var.service_plan_id site_config { ftps_state = "FtpsOnly" application_stack { node_version = lookup(var.stack_version, "node", null) java_version = lookup(var.stack_version, "java", null) } } }
3. 验证App Service Plan模块的输出
确保ApplicationServicePlan模块的output.tf正确输出了服务计划的ID(app_sp_out对应服务计划的id属性),示例如下:
# ../../modules/ApplicationServicePlan/output.tf output "app_sp_out" { value = azurerm_service_plan.your_service_plan_resource.id }
验证修复
执行terraform init重新初始化模块,再运行terraform plan即可正常检测配置,不再出现参数错误。
内容的提问来源于stack exchange,提问作者Uday Kiran
相关产品推荐
相关产品推荐

