此处不需要名为 "instance_type" 的参数...在其他意想不到的论点中



我已经从Udemy课程得到了一些代码,它给出了以下错误。有人能给我指出正确的方向吗?这可能真的很容易,但说实话,我真的很陌生。

Error: Unsupported argument
on lesson100.tf line 83, in module "ec2":
83:   instance_type = "m4.large"
An argument named "instance_type" is not expected here.

Error: Unsupported argument
on lesson100.tf line 85, in module "ec2":
85:   subnet_id = element(data.aws_subnet_ids.all.ids, 0)
An argument named "subnet_id" is not expected here.

Error: Unsupported argument
on lesson100.tf line 87, in module "ec2":
87:   vpc_security_group_ids = ["${module.security_group.this_security_group_id}"]
An argument named "vpc_security_group_ids" is not expected here.

Error: Unsupported argument
on lesson100.tf line 89, in module "ec2":
89:   associate_public_ip_address = true
An argument named "associate_public_ip_address" is not expected here.

完整的代码是

provider "aws" {
region = "eu-west-1"
}
##################################################################
# Data sources to get VPC, subnet, security group and AMI details
##################################################################
data "aws_vpc" "default" {
default = true
}
data "aws_subnet_ids" "all" {
vpc_id = data.aws_vpc.default.id
}
data "aws_ami" "amazon_linux" {
most_recent = true
filter {
name = "name"
values = [
"amzn-ami-hvm-*-x86_64-gp2",
]
}
filter {
name = "owner-alias"
values = [
"amazon",
]
}
}
module "security_group" {
source = "terraform-aws-modules/security-group/aws"
name = "example"
description = "Security group for example usage with EC2 instance"
vpc_id = data.aws_vpc.default.id
ingress_cidr_blocks = ["0.0.0.0/0"]
ingress_rules = ["http-80-tcp", "all-icmp"]
egress_rules = ["all-all"]
}
module "ec2" {
source = "../../"
instance_count = 2
name = "example-normal"
ami = data.aws_ami.amazon_linux.id
instance_type = "m4.large"
subnet_id = element(data.aws_subnet_ids.all.ids, 0)
vpc_security_group_ids = ["${module.security_group.this_security_group_id}"]
associate_public_ip_address = true
}

确保您的ec2模块4变量匹配您传递的4个参数:

  • associate_public_ip_address
  • vpc_security_group_ids
  • subnet_id
  • instance_type