title: Can't SSH into EC2 instance created with Terraform
body: <p>I am working on a very simple Terraform project. I am using windows command prompt. I only have one EC2 instance for now. This is the project structure -</p>
  
  <pre><code>terraform-project
  |_ec2.tf
  |_vars.tf
  |_test-key
  |_test-key.pub
  |_.terraform
  |_terraform.tfstate
  </code></pre>
  
  <p>The ec2.tf file is as below -</p>
  
  <pre><code>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"
  
      }
  }
  </code></pre>
  
  <p>The vars.tf file is as below -</p>
  
  <pre><code>variable "ami" {
      default = "ami-0233214e13e500f77"
  }
  
  variable "instance_type" {
      default = "t2.micro"
  }
  </code></pre>
  
  <p>Terraform Apply worked successfully and I can see the instance from the AWS management console. But when I try to SSH into the instance I get permission issues-</p>
  
  <pre><code>ssh -i test-key ec2-user@54.xx.xxx.xxx
  ssh: connect to host 54.xx.xxx.xxx port 22: Permission denied
  </code></pre>
  
  <p>The instance has default VPC and security group. All inbound and outbound traffic is allowed. 
  I am working behind a company proxy. Before I started I set the proxy settings on my windows command prompt -</p>
  
  <pre><code>set HTTP_PROXY=http://proxy.companytnet.net:port
  set HTTPS_PROXY=http://proxy.companynet.net:port
  </code></pre>
  
  <p>SSH with verbose gives this:</p>
  
  <pre><code>ssh -vvv -i test-key ec2-user@54.xx.xxx.xxx
  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
  </code></pre>
  
  <p>I able to SSH into other servers and instances but not into the one created with Terraform. What am I doing wrong ? </p>