gpt4 book ai didi

amazon-ec2 - Terraform 失败 remote-exec (aws/ec2)

转载 作者:行者123 更新时间:2023-12-03 17:14:00 24 4
gpt4 key购买 nike

尝试执行 shell 脚本时,在 terraform 连接中抛出配置器“remote-exec”未建立

我正在为 ubuntu-xenial-16.04 使用 ami所以用户是ubuntu

这是我用来执行 shell 脚本的最后一段代码:

resource "aws_instance" "secondary_zone" {
count = 1
instance_type = "${var.ec2_instance_type}"
ami = "${data.aws_ami.latest-ubuntu.id}"
key_name = "${aws_key_pair.deployer.key_name}"
subnet_id = "${aws_subnet.secondary.id}"
vpc_security_group_ids = ["${aws_security_group.server.id}"]
associate_public_ip_address = true

provisioner "remote-exec" {
inline = ["${template_file.script.rendered}"]
}

connection {
type = "ssh"
user = "ubuntu"
private_key = "${file("~/.ssh/id_rsa")}"
}
}

这是控制台中的内容:
aws_instance.secondary_zone (remote-exec): Connecting to remote host via SSH...
aws_instance.secondary_zone (remote-exec): Host: x.x.x.x
aws_instance.secondary_zone (remote-exec): User: ubuntu
aws_instance.secondary_zone (remote-exec): Password: false
aws_instance.secondary_zone (remote-exec): Private key: true
aws_instance.secondary_zone (remote-exec): SSH Agent: false
aws_instance.secondary_zone (remote-exec): Checking Host Key: false

感谢您的帮助...

最佳答案

我遇到过同样的问题。在您的连接块中尝试指定主机。

  connection {
type = "ssh"
user = "ubuntu"
private_key = "${file("~/.ssh/id_rsa")}"
host = self.public_ip
}

我还必须创建一个路由和网关并将它们关联到我的 vpc。我仍在学习 terraform,但这对我有用。
resource "aws_internet_gateway" "test-env-gw" {
vpc_id = aws_vpc.test-env.id
}

resource "aws_route_table" "route-table-test-env" {
vpc_id = aws_vpc.test-env.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.test-env-gw.id
}
}

resource "aws_route_table_association" "subnet-association" {
subnet_id = aws_subnet.us-east-2a-public.id
route_table_id = aws_route_table.route-table-test-env.id
}

关于amazon-ec2 - Terraform 失败 remote-exec (aws/ec2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55878755/

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