gpt4 book ai didi

amazon-web-services - 使用 terraform 连接运行 aws 实例

转载 作者:行者123 更新时间:2023-12-03 08:26:26 25 4
gpt4 key购买 nike

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"
]
}
}

“terraform validate”给我错误:

错误:缺少必需的参数

在 main.tf 第 52 行,资源“aws_instance”“appserver1”中:52:连接{

参数“host”是必需的,但未找到定义。

最佳答案

您必须指定connection provisioner block 中的详细信息。例如:

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会更适合。

关于amazon-web-services - 使用 terraform 连接运行 aws 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66523995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com