无法ssh到由terraform

时间:2017-06-23 19:35:36

标签: ssh amazon-ec2 terraform

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

terraform apply

在所有内容停止之前,它会在日志中打印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。试图连接但失败了:

我能够自己进入服务器。 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输出的最后,我得到了这个。我认为这是因为我无法进入,但我不确定。

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

1 个答案:

答案 0 :(得分:1)

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