Error: Unsupported argument
on main.tf line 3, in module "ec2_test":
3: ec2_count = 2
An argument named "ec2_count" is not expected here.
Error: Unsupported argument
on main.tf line 4, in module "ec2_test":
4: ami_id = "ami-123"
An argument named "ami_id" is not expected here.
Error: Unsupported argument
on main.tf line 5, in module "ec2_test":
5: instance_type = "t2.micro"
An argument named "instance_type" is not expected here.当我从本地使用该模块时,相同的模块工作正常。当我尝试使用上传到bitbucket的模块并在main.tf中将URL作为源时,就会出现问题。Terraform init工作得很好,它将回购复制到.terraform/modules/ec2,但是在Terraform应用上,它给出了上面的错误。
下面提到的是ec2的模块和Bitbucket私有回购instance.tf中各自的var文件:
provider "aws"{
region = var.region
}
resource "aws_instance" "ec2" {
count = var.ec2_count
ami = var.ami_id
instance_type = var.instance_type
subnet_id = var.subnet_id
vpc_security_group_ids = var.security_grp
tags = {
Name = "Terraform_module_test"
}
}var.tf
variable "ec2_count" {
default = "1"
}
variable "ami_id" {}
variable "instance_type" {
default = "t2.micro"
}
variable "subnet_id" {}
variable "security_grp" {}
variable "region" {}从其中访问模块的main.tf
module "ec2_test" {
source = "git@bitbucket.org:private-repo/terraform.git/modules_terraform/ec2"
ec2_count = 2
ami_id = "ami-123"
instance_type = "t2.micro"
subnet_id = "subnet-123"
security_grp = ["sg-123"]
region = "ap-southeast-1"
}发布于 2020-07-22 16:39:10
有几个Terraform支持的模块源必须区分源代码将来自的存储库或包以及存储库或包中的路径。Git源代码就是其中的一个例子,因为Git协议首先需要检索整个存储库(使用git clone),然后才从本地工作树访问子目录。
模块源代码文档讨论了包子目录中的模块中的语法。
当模块的源是版本控制存储库或存档文件(通常是“包”)时,模块本身可能位于相对于包根目录的子目录中。 Terraform解释了一个特殊的双斜杠语法,以指示在该点之后的剩余路径是包中的一个子目录。
应用该示例,必须使用//标记将存储库路径与子目录路径分离:
source = "git@bitbucket.org:private-repo/terraform.git//modules_terraform/ec2"以上所述将导致Terraform在//之前首先克隆存储库部分。
git clone git@bitbucket.org:private-repo/terraform.git然后,...and从生成的git工作树的modules_terraform/ec2子目录加载模块。
https://stackoverflow.com/questions/63029228
复制相似问题