我正在创建ec2实例,而在执行Terraform计划时,出现错误Unknown root level key for connection and Provisioner。我正在使用最新版本的terraform。这是我的.tf文件的完整代码。
这是我的错误消息
错误:不支持的块类型
在ec2-dev \ ec2.tf第39行的模块“ ec2__application”中: 39:连接{
这里不应该使用“连接”类型的块。
错误:不支持的块类型
在ec2-dev \ ec2.tf第44行上的在模块“ ec2__application”中: 44:预配器“文件” {
此处不应该包含“ provisioner”类型的块。
错误:不支持的块类型
在ec2-dev \ ec2.tf第49行的模块“ ec2__application”中: 49:预配器“文件” {
此处不应该包含“ provisioner”类型的块。
module "ec2__application" {
source = "terraform-aws-modules/ec2-instance/aws"
version = "1.19.0"
name = "${var.ec2__application["name"]}"
instance_count = "${var.ec2__application["count"]}"
ami = "${data.aws_ami.ami.id}"
private_ip = "${var.ec2__application["private-ip"]}"
instance_type = "${var.ec2__application["type"]}"
key_name = "${var.ec2__application["ssh_key"]}"
monitoring = true
vpc_security_group_ids = ["${other module reference here}"]
subnet_id = "${var.ec2__application["subnet_id"]}"
associate_public_ip_address = false
disable_api_termination = true
tags = {
name = "${var.ec2__application["name"]}"
}
instance_count = "${var.ec2__application["count"]}"
ami = "${data.aws_ami.ami.id}"
instance_type = "${var.ec2__application["type"]}"
subnet_id = "${var.ec2__application["subnet_id"]}"
key_name = "${var.ec2__application["ssh_key"]}"
connection {
type = "ssh"
user = "ec2-user"
private_key = "test.pem"
}
provisioner "file" {
source = "test.sh"
destination = "/tmp/test.sh"
}
provisioner "remote-exec" {
inline = [
"sudo chmod +x /tmp/test.sh",
"sudo su - root 'bash test.sh' &"
]
}
}