gpt4 book ai didi

ssh - Terraform 无法将 Chef 供应商与 ssh 连接

转载 作者:行者123 更新时间:2023-12-02 14:32:42 25 4
gpt4 key购买 nike

我无法通过私有(private) aws key 对连接 terraform 的 ssh 以进行 Chef 配置 - 错误看起来只是超时:

aws_instance.app (chef): Connecting to remote host via SSH...
aws_instance.app (chef): Host: 96.175.120.236:32:
aws_instance.app (chef): User: ubuntu
aws_instance.app (chef): Password: false
aws_instance.app (chef): Private key: true
aws_instance.app (chef): SSH Agent: true
aws_instance.app: Still creating... (5m30s elapsed)
Error applying plan:

1 error(s) occurred:

* dial tcp 96.175.120.236:32: i/o timeout

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

这是我的 terraform 计划 - 请注意 ssh 设置。key_name 设置设置为我的 AWS key 对名称,而 ssh_for_chef.pem 是私钥
variable "AWS_ACCESS_KEY" {}
variable "AWS_SECRET_KEY" {}

provider "aws" {
region = "us-east-1"
access_key = "${var.AWS_ACCESS_KEY}"
secret_key = "${var.AWS_SECRET_KEY}"
}

resource "aws_instance" "app" {
ami = "ami-88aa1ce0"
count = "1"
instance_type = "t1.micro"
key_name = "ssh_for_chef"
security_groups = ["sg-c43490e1"]
subnet_id = "subnet-75dd96e2"
associate_public_ip_address = true


provisioner "chef" {
server_url = "https://api.chef.io/organizations/xxxxxxx"
validation_client_name = "xxxxxxx-validator"
validation_key = "/home/user01/Documents/Devel/chef-repo/.chef/xxxxxxxx-validator.pem"
node_name = "dubba_u_7"
run_list = [ "motd_rhel" ]
user_name = "user01"
user_key = "/home/user01/Documents/Devel/chef-repo/.chef/user01.pem"
ssl_verify_mode = "false"
}
connection {
type = "ssh"
user = "ubuntu"
private_key = "${file("/home/user01/Documents/Devel/ssh_for_chef.pem")}"
}
}

有任何想法吗?

最佳答案

我不确定我们是否有同样的问题,因为您没有指定是否能够通过 ssh 连接到该实例。
就我而言,我在 VPC 内运行 terraform,并且允许使用安全组进行连接,而该安全组不能与公共(public) IP 一起使用。
解决方案很简单(但您必须使用 terraform v.0.8.0 的新条件插值) -

定义这个变量 - variable use_public_ip { default = true }
然后,在 chef provisioner 的连接部分中,添加以下行 -host = "${var.use_public_ip ? aws_instance.instance.public_ip : aws_instance.instance.private_ip}"
如果您希望使用公共(public) IP,请将变量设置为 true,否则将其设置为 false。

我将它用于 aws -
connection {
user = "ubuntu"
host = "${var.use_public_ip ? aws_instance.instance.public_ip : aws_instance.instance.private_ip}","
}

关于ssh - Terraform 无法将 Chef 供应商与 ssh 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40944288/

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