无法将应用程序服务计划 ID 作为变量提供给 Terraform 模块
unable to supply app service plan id as variable to the terraform module
我正在尝试通过模块创建应用服务,在根模块中,我正在调用应用服务计划子模块以获取应用服务计划 ID。但不幸的是我收到以下错误。
错误:变量名无效
│
│ 在 ../../modules/appservice/variable.tf 第 17 行,在变量“var.app_service_plan”中:
│ 17: 变量“var.app_service_plan”{
│
│ 名称必须以字母或下划线开头,只能包含字母、数字、下划线和破折号。
这是我的代码
appservice module:
appservice.tf:
resource "azurerm_app_service" "appservice" {
for_each = var.appservicename
name = each.value.appservices
location = var.appservice_location
resource_group_name = var.appservice_resourcegroup
app_service_plan_id = var.app_service_plan
}
variable.tf:
variable "appservices" {
type = map(object({
appservicename = string
}))
}
variable "appservice_location" {
type = string
}
variable "appservice_resourcegroup" {
type = string
}
variable "var.app_service_plan" {
type = string
}
root module:
main.tf:
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=2.68.0"
}}}
provider "azurerm" {
features {
}}
module "resourcegroup" {
source = "../../modules/resourcegroup/"
rg_name = "terraarmrg1234"
rg_location = "South India"
}
module "Vnet" {
source = "../../modules/Vnet/"
vnet_name = "terravnet1"
vnet_address_space = ["10.0.0.0/16"]
subnet1_name = "terravnet1subnet1"
address_prefixes = ["10.0.1.0/24"]
}
module "asp" {
source = "../../modules/asp"
plan_count = "2"
aspname = "azterrasp1"
}
module "appservice" {
source = "../../modules/appservice"
appservices = {
"appservice1" = {
appservicename = "appservice1"},
"appservice2" = {
appservicename = "appservice2"}}
appservice_location = module.resourcegroup.rg.location
appservice_resourcegroup = module.resourcegroup.rg.name
app_service_plan = module.asp[0].asp.id }
如果我遗漏了什么,有人可以帮助我吗..在此先感谢。
错误的是你的变量名:
variable "var.app_service_plan" {
大概应该是:
variable "app_service_plan" {
因为您没有在定义中为变量名添加前缀 var.
我正在尝试通过模块创建应用服务,在根模块中,我正在调用应用服务计划子模块以获取应用服务计划 ID。但不幸的是我收到以下错误。
错误:变量名无效 │ │ 在 ../../modules/appservice/variable.tf 第 17 行,在变量“var.app_service_plan”中: │ 17: 变量“var.app_service_plan”{ │ │ 名称必须以字母或下划线开头,只能包含字母、数字、下划线和破折号。
这是我的代码
appservice module:
appservice.tf:
resource "azurerm_app_service" "appservice" {
for_each = var.appservicename
name = each.value.appservices
location = var.appservice_location
resource_group_name = var.appservice_resourcegroup
app_service_plan_id = var.app_service_plan
}
variable.tf:
variable "appservices" {
type = map(object({
appservicename = string
}))
}
variable "appservice_location" {
type = string
}
variable "appservice_resourcegroup" {
type = string
}
variable "var.app_service_plan" {
type = string
}
root module:
main.tf:
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=2.68.0"
}}}
provider "azurerm" {
features {
}}
module "resourcegroup" {
source = "../../modules/resourcegroup/"
rg_name = "terraarmrg1234"
rg_location = "South India"
}
module "Vnet" {
source = "../../modules/Vnet/"
vnet_name = "terravnet1"
vnet_address_space = ["10.0.0.0/16"]
subnet1_name = "terravnet1subnet1"
address_prefixes = ["10.0.1.0/24"]
}
module "asp" {
source = "../../modules/asp"
plan_count = "2"
aspname = "azterrasp1"
}
module "appservice" {
source = "../../modules/appservice"
appservices = {
"appservice1" = {
appservicename = "appservice1"},
"appservice2" = {
appservicename = "appservice2"}}
appservice_location = module.resourcegroup.rg.location
appservice_resourcegroup = module.resourcegroup.rg.name
app_service_plan = module.asp[0].asp.id }
如果我遗漏了什么,有人可以帮助我吗..在此先感谢。
错误的是你的变量名:
variable "var.app_service_plan" {
大概应该是:
variable "app_service_plan" {
因为您没有在定义中为变量名添加前缀 var.