gpt4 book ai didi

terraform-provider-azure - terraform 计划返回错误 : Unsupported argument

转载 作者:行者123 更新时间:2023-12-03 21:53:14 55 4
gpt4 key购买 nike

我有以下三个文件,如下所示:
main.tf、variables.tf 和 dev.auto.tfvars

来自 的片段主文件

module "sql_vms" {
source = "git::git@github.com:xxxxxxxxxxxx/terraform-modules//azure/"
rg_name = var.resource_group_name
location = module.resource_group.external_rg_location
vnet_name = var.virtual_network_name
subnet_name = var.sql_subnet_name
app_nsg = var.application_nsg
vm_count = var.count_vm
base_hostname = var.sql_host_basename
sto_acc_suffix = var.storage_account_suffix
vm_size = var.virtual_machine_size
vm_publisher = var.virtual_machine_image_publisher
vm_offer = var.virtual_machine_image_offer
vm_sku = var.virtual_machine_image_sku
vm_img_version = var.virtual_machine_image_version
username = var.username
password = var.password
}

来自 的片段变量.tf
variable "app_subnet_name" {
type = string
}

variable "sql_subnet_name" {
type = string
}

来自 的片段dev.auto.tfvars
app_subnet_name = "subnet_1"

sql_subnet_name = "subnet_2"

application_nsg = "test_nsg"

但是,我收到如下错误
Error: Unsupported argument

on main.tf line 7, in module "sql_vms":
7: subnet_name = var.sql_subnet_name

An argument named "subnet_name" is not expected here.


Error: Unsupported argument

on main.tf line 8, in module "sql_vms":
8: app_nsg = var.application_nsg

An argument named "app_nsg" is not expected here.

我的模块目录结构如下所示
$ ls -R terraform-modules/
terraform-modules/:
aws azure gcp

terraform-modules/aws:
alb ec2-instance-rhel

terraform-modules/aws/alb:

terraform-modules/aws/ec2-instance-rhel:
main.tf

terraform-modules/azure:
compute resourcegroup sqlserver

terraform-modules/azure/compute:
main.tf README.md variable.tf

terraform-modules/azure/resourcegroup:
data.tf outputs.tf variables.tf

terraform-modules/azure/sqlserver:
main.tf README.md variables.tf

terraform-modules/gcp:
compute

terraform-modules/gcp/compute:
main.tf

知道这里出了什么问题吗?

最佳答案

如果您从 Terraform 开始,如果您的模块参数引用资源属性而不是变量名称,您将收到错误消息(“ 此处不需要名为“example”的参数 ”),请参阅下面举个例子:
要从模块调用的 Terraform 模块“example_mod.tf”示例:

variable "sg_name" { }   # Usually in a separate file
variable "sg_desc" { } # called variables.tf

resource "example_resource" "example_name" {
name = var.sg_name
description = var.sg_desc
...
}
正确方法:
module "my_module" {
source = "./modules/example_mod.tf"

sg_name = "whatever" # NOTE the left hand side "sg_name" is the variable name
sg_desc = "whatever"
...
}
错误的方式:(给出错误“此处不需要名为“名称”的参数”)
module "my_module" {
source = "./modules/example_mod.tf"

name = "whatever" # WRONG because the left hand side "name" is a resource property
description = "whatever" # WRONG for the same reason
...
}

关于terraform-provider-azure - terraform 计划返回错误 : Unsupported argument,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62361263/

55 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com