terraform-aws-modules / terraform-aws-ec2-instance

Terraform module to create AWS EC2 instance(s) resources 🇺🇦
https://registry.terraform.io/modules/terraform-aws-modules/ec2-instance/aws
Apache License 2.0
758 stars 1.88k forks source link

Provisioned EC2 Instances not reachable #355

Closed onlinejudge95 closed 1 year ago

onlinejudge95 commented 1 year ago

Description

My EC2 instance created via this module is up and status checks have passed when checked through the EC2 console but unable to connect to them via putty and/or EC2 Instance Connect.

⚠️ Note

Before you submit an issue, please perform the following first:

  1. Remove the local .terraform directory (! ONLY if state is stored remotely, which hopefully you are following that best practice!): rm -rf .terraform/
  2. Re-initialize the project root to pull down modules: terraform init
  3. Re-attempt your terraform plan or apply and check if the issue still persists

Versions

Your version of Terraform is out of date! The latest version is 1.5.5. You can update by downloading from https://www.terraform.io/downloads.html

- Provider version(s):

Terraform v1.5.3 on windows_386

Your version of Terraform is out of date! The latest version is 1.5.5. You can update by downloading from https://www.terraform.io/downloads.html


## Reproduction Code [Required]

<!-- REQUIRED -->

Steps to reproduce the behavior:

Run the following snippet of code

data "aws_ami" "ubuntu" { most_recent = true filter { name = "name" values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] } filter { name = "virtualization-type" values = ["hvm"] } owners = ["099720109477"] # Canonical } variable "instances" { type = list(string) default = ["master-node", "worker-node-1", "worker-node-2"] } module "instance_key_pair" { source = "terraform-aws-modules/key-pair/aws" version = "2.0.2" key_name = "infra-management-key" public_key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMhQdG9PKSfS155RjbJdD5hTMxEU0pzVGExfki4/ldQJ" tags = { "Created By" = "Infrastructure Management User" } } module "instance_security_group" { source = "terraform-aws-modules/security-group/aws" version = "5.1.0" name = "instance-security-group" description = "Security Group for instance" vpc_id = data.aws_vpc.default_vpc.id ingress_with_cidr_blocks = [ { from_port = 22 to_port = 22 protocol = "tcp" description = "Adds rule for SSH" cidr_blocks = "0.0.0.0/32" } ] egress_with_cidr_blocks = [ { from_port = 0 to_port = 0 protocol = "-1" description = "Adds egress rule" cidr_blocks = "0.0.0.0/32" } ] } module "ec2_instance_profile" { source = "s3::https://terraform-registry-wecoach.s3.ap-south-1.amazonaws.com/terraform-aws-ec2-instance-profile" name = "instance-profile" attach_cwagent_policy = true attach_ssm_policy = true policy_arns = [ "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryFullAccess", "arn:aws:iam::aws:policy/AmazonEC2FullAccess", "arn:aws:iam::aws:policy/AmazonS3FullAccess", "arn:aws:iam::aws:policy/IAMFullAccess", "arn:aws:iam::aws:policy/CloudWatchFullAccess", "arn:aws:iam::aws:policy/AmazonSSMFullAccess", ] tags = { "Created By" = "Infrastructure Management User" } } module "ec2_instance" { source = "terraform-aws-modules/ec2-instance/aws" version = "5.3.1" for_each = toset(var.instances) ami = data.aws_ami.ubuntu.id associate_public_ip_address = true monitoring = true instance_type = "t3a.small" key_name = module.instance_key_pair.key_pair_name user_data = file("user_data.sh") vpc_security_group_ids = [module.instance_security_group.security_group_id] iam_instance_profile = module.ec2_instance_profile.profile_name tags = { "Created By" = "Infrastructure Management User" "Name" = each.key } }



## Expected behavior
Expected the launched EC2 VM to be ready to connect via either PuTTY and/or EC2 Instance Connect.

## Actual behavior
Unable to connect to the instance but the instance is up and running as checked from EC2 Console.

## Additional context
- Codebase for `module.ec2_instance_profile` refer [this](https://github.com/onlinejudge95/terraform-aws-ec2-instance-profile) as source
- ![Screenshot 2023-08-17 172051](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/assets/44158581/a810f2a3-85ad-4439-b27e-e220016101e9)
sampath6851 commented 1 year ago

Hey Have you checked with your Inbound rules such as SSH, All tcp - any where

onlinejudge95 commented 1 year ago

I fixed it by updating my security group, For some reason I had misspelled /0 with /32

github-actions[bot] commented 1 year ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.