运行 使用 terraform 连接的 aws 实例
Running aws instance with connection using terraform
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"
]
}
}
“地形验证”给我错误:
错误:缺少必需的参数
在 main.tf 第 52 行,在资源“aws_instance”“appserver1”中:
52:连接{
参数“主机”是必需的,但没有找到定义。
您必须在 provisioner
块中指定 connection 详细信息。例如:
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,而不是使用连接。
我不认为在实例配置中提供连接块会起作用
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"
]
}
}
“地形验证”给我错误:
错误:缺少必需的参数
在 main.tf 第 52 行,在资源“aws_instance”“appserver1”中: 52:连接{
参数“主机”是必需的,但没有找到定义。
您必须在 provisioner
块中指定 connection 详细信息。例如:
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,而不是使用连接。
我不认为在实例配置中提供连接块会起作用