terrain aws ec2 ssh

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

我有这个Terraform脚本:

provider "aws" {
  region = "us-weast-1"
}


resource "aws_security_group" "allow_all" {
  name        = "allow_all"
  description = "Allow all inbound traffic"


  ingress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }

  egress {
    from_port       = 0
    to_port         = 0
    protocol        = "-1"
    cidr_blocks     = ["0.0.0.0/0"]
  }

  vpc_id = "vpc-154c1701"

}


resource "aws_instance" "wso2-testing" {
  ami           = "ami-0f9cf087c1f27d9b1"
  instance_type = "t2.small"
  key_name = "mykeypair"
  vpc_security_group_ids = ["${aws_security_group.allow_all.id}"]

    }

机器创建正确,但是我无法通过ssh使用我的密钥对连接到ec2实例。我总是有错误:

ssh: connect to host x.x.x.x port 22: Operation timed out

[VPC es aws默认为Internet网关

amazon-web-services terraform
2个回答
0
投票

您需要将自己的IP添加到安全组的入站规则中。检查我的博客或git示例https://sv-technical.blogspot.com/2019/12/terraform.htmlhttps://github.com/svermaji/terraform


0
投票

您可以使用以下代码段将自己的IP添加到安全组:

© www.soinside.com 2019 - 2024. All rights reserved.