resource "aws_instance" "appserver1" {
ami = var.imageid
instance_type = var.instancetype
key_name = var.key
security_groups = [aws_security_group.allow_all.name]
connection {
user = "ubuntu"
private_key = file(var.privatekeypath)
}
provisioner "remote-exec" {
inline = [
"sudo apt-get update",
"sudo apt-get install tomcat7 -y"
]
}
}
"起程拓殖validate"给我错误:
错误:缺少必需的参数
主要。第52行,在资源"aws_instance"appserver1"52:连接{
参数"host",但是没有找到定义。
您必须在provisioner
块中指定连接细节。例如:
resource "aws_instance" "appserver1" {
ami = var.imageid
instance_type = var.instancetype
key_name = var.key
security_groups = [aws_security_group.allow_all.name]
provisioner "remote-exec" {
connection {
type = "ssh"
user = "ubuntu"
private_key = file(var.privatekeypath)
host = self.public_ip
}
inline = [
"sudo apt-get update",
"sudo apt-get install tomcat7 -y"
]
}
}
但是在您的情况下,使用user_data会更合适。
在启动部署实例时,可以使用userdataEC2 userdata选项来安装tomcat,而不是使用连接。
我不认为在实例配置中提供连接块会起作用