【问题标题】:unable to supply app service plan id as variable to the terraform module无法将应用服务计划 ID 作为变量提供给 terraform 模块
【发布时间】:2022-01-04 05:26:19
【问题描述】:

我正在尝试通过模块创建 appservices,在根模块中,我正在调用 appservice 计划子模块以获取 appservice 计划 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  }

如果我遗漏了什么,有人可以帮助我吗?在此先感谢。

【问题讨论】:

  • 好吧,你的app_service_plan到底是什么?
  • 嗨,Marcin,这里是 app_service_plan = module.asp[0].asp.id
  • module.asp[0].asp.id 到底是什么?遗憾的是,您的问题缺乏细节。
  • 实际上我已经使用 count 创建了 appservice 计划,我在这里引用其中一个,这就是它在状态文件“module”中的样子:“module.asp[0]”,“mode”: “托管”,“类型”:“azurerm_app_service_plan”,“名称”:“asp”,“实例”:[{“index_key”:0,“schema_version”:0,“属性”:{“app_service_environment_id”:“”, "id": "/subscriptions/a8e2fc5d-80b4-420b-984f-1540b4f0fedf/resourceGroups/terraazure1234/providers/Microsoft.Web/serverfarms/azterrasp1-0",

标签: terraform azure-web-app-service terraform-provider-azure


【解决方案1】:

这是你的变量名错误:

variable "var.app_service_plan" {

应该是:

variable "app_service_plan" {

因为您没有在定义中为变量名添加前缀var.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-10
    • 1970-01-01
    • 2020-05-06
    • 2018-09-07
    • 2017-07-20
    • 2018-12-15
    • 1970-01-01
    相关资源
    最近更新 更多