_ec2.tf

问题描述 投票:0回答:1

我正在做一个非常简单的Terraform项目。我使用的是windows命令提示符。目前我只有一个EC2实例。这是项目的结构

terraform-project
|_ec2.tf
|_vars.tf
|_test-key
|_test-key.pub
|_.terraform
|_terraform.tfstate

ec2.tf文件如下--。

provider "aws" {
    region = "eu-central-1"
}

resource "aws_key_pair" "test-key"{
    key_name = "test-key"
    public_key = "${file("test-key.pub")}"
}

resource "aws_instance" "my-ec2"{
    ami = "${var.ami}"
    instance_type = "${var.instance_type}"
    key_name = "${aws_key_pair.test-key.key_name}"
    tags = {
        Name = "Terraform"
        Batch = "7am"

    }
}

vars.tf文件如下--。

variable "ami" {
    default = "ami-0233214e13e500f77"
}

variable "instance_type" {
    default = "t2.micro"
}

Terraform Apply工作成功,我可以从AWS管理控制台看到实例。但是当我尝试SSH进入实例时,我得到的是权限问题-。

ssh -i test-key [email protected]
ssh: connect to host 54.xx.xxx.xxx port 22: Permission denied

实例有默认的VPC和安全组。所有的入站和出站流量都是允许的。我在公司的代理后面工作。在开始之前,我在windows命令提示符上设置了代理设置--。

set HTTP_PROXY=http://proxy.companytnet.net:port
set HTTPS_PROXY=http://proxy.companynet.net:port

使用verbose的SSH会出现这种情况。

ssh -vvv -i test-key [email protected]
OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
debug1: Reading configuration data C:\\Users\\M710583/.ssh/config
debug3: Failed to open file:C:/ProgramData/ssh/ssh_config error:2
debug2: resolve_canonicalize: hostname 54.xx.xxx.xxx is address
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to 54.xx.xxx.xxx [54.xx.xxx.xxx] port 22.
debug3: finish_connect - ERROR: async io completed with error: 10013, io:00000256B95289B0
debug1: connect to address 54.xx.xxx.xxx port 22: Permission denied
ssh: connect to host 54.xx.xxx.xxx port 22: Permission denied

我可以通过SSH进入其他服务器和实例,但不能进入用Terraform创建的服务器。我到底做错了什么?

amazon-web-services terraform terraform-provider-aws
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.