You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Terraform模块时遇Unsupported argument错误,请求排查

问题原因与解决方法

错误根源

你遇到的“Unsupported argument”错误是变量名称不匹配导致的:

  • 在ec2模块中,定义的变量名为instancetype(无下划线)
  • 但在main.tf调用模块时,传递的参数是instance_type(带下划线)
    Terraform会严格校验模块输入参数的名称,两者不一致就会触发“不支持的参数”错误。

修复方案

有两种方式可以解决,任选其一即可:

方案1:修改模块中的变量名,与调用时的参数名一致

修改ec2模块内的变量定义,将变量名改为instance_type:

locals{
    amiid = "ami-05548f9cecf47b442"
}

variable "instance_type" {
    default = "t2.micro"
}

resource "aws_instance" "ec2-instance" {
    ami= local.amiid
    instance_type = var.instance_type
}

方案2:修改调用模块时的参数名,与模块变量名一致

修改main.tf中的模块调用部分,将参数名改为instancetype:

module "ec2-fst" {
  source = "../../modules/ec2"
  instancetype = "t3.medium"
}

验证修复

修改完成后,执行以下命令验证:

terraform init
terraform plan

此时应该不会再出现“Unsupported argument”错误。

内容的提问来源于stack exchange,提问作者Prakash Vegiraju

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 05:14:51