【问题标题】:unable to ssh into ec2 server created by terraform无法通过 ssh 连接到 terraform 创建的 ec2 服务器
【发布时间】:2017-11-27 11:13:42
【问题描述】:

我正在使用 packer 创建一个安装了 docker 的自定义 AMI。 然后我尝试添加 docker swarm。 不幸的是,它失败了,因为 terraform 无法通过 ssh 连接到任何机器。

地形应用

这会在一切停止之前在日志中打印 100 次:

aws_instance.swarm-manager (remote-exec): Connecting to remote host via SSH...
aws_instance.swarm-manager (remote-exec):   Host: 35.176.154.111
aws_instance.swarm-manager (remote-exec):   User: ubuntu
aws_instance.swarm-manager (remote-exec):   Password: false
aws_instance.swarm-manager (remote-exec):   Private key: true
aws_instance.swarm-manager (remote-exec):   SSH Agent: false

我在浏览器中打开 AWS EC2 控制台并找到堡垒服务器的公共 IP。尝试连接但失败:

我可以自己 ssh 进入服务器。 Terraform 不能访问 EC2 实例。

ssh -i ~/.ssh/terraform-eu-west-2.pem  ubuntu@ec2-35-176-213-56.eu-west-2.compute.amazonaws.com

密钥对

对于 eu-west-2 区域,我创建了一个名为 terraform 的密钥。这被保存为 ~/.ssh/terraform-eu-west-2.pem

我在 Github 上的所有文件

我已将整个 shebang 保存到 github repo。请看一下。

terraform apply 输出的最后,我明白了。我认为这是因为我无法 ssh 进入,但我不确定。

Error applying plan:

4 error(s) occurred:

* aws_instance.swarm-node[2]: 1 error(s) occurred:

* Script exited with non-zero exit status: 125
* aws_instance.swarm-node[0]: 1 error(s) occurred:

* Script exited with non-zero exit status: 125
* aws_subnet.c: 1 error(s) occurred:

* aws_subnet.c: Error creating subnet: InvalidParameterValue: Value (eu-west-2c) for parameter availabilityZone is invalid. Subnets can currently only be created in the following availability zones: eu-we
st-2a, eu-west-2b.
        status code: 400, request id: 5459c120-f60b-4beb-9acb-323c4bc3c06d
* aws_instance.swarm-node[1]: 1 error(s) occurred:

* Script exited with non-zero exit status: 125

错误提示:Subnets can currently only be created in the following availability zones: eu-west-2a, eu-west-2b。但是,如果我将区域从 eu-west-2 更改为 eu-west-2a 我会收到一条错误消息 * provider.aws: Not a valid region: eu-west-2a

【问题讨论】:

标签: ssh amazon-ec2 terraform


【解决方案1】:

您正在混音regions/availability zones。区域 eu-west-2 只有 2 个有效区域:eu-west-2a, eu-west-2b。但是您的 Terraform 代码也在尝试使用无效区域 eu-west-2c。从您的 Terraform 代码或使用区域中删除 c 区域部分,其中也有 c 区域可用(例如 eu-west-1)。

【讨论】:

    猜你喜欢
    • 2020-08-28
    • 2021-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-17
    • 1970-01-01
    • 1970-01-01
    • 2019-10-19
    相关资源
    最近更新 更多