Skip to content

Conversation

@alvinjaison
Copy link

Description

Added support for EC2 Instance Connect Endpoint (EICE) in the VPC module.
This allows users to securely SSH or RDP into instances in private subnets without using a bastion host or exposing public IPs.
Also added a fully self-contained example under examples/ec2-instance-connect-endpoint/.


Motivation and Context

AWS recently introduced EC2 Instance Connect Endpoint, which simplifies secure connectivity to private subnets.
Currently, the VPC module does not support this resource natively, requiring users to define it manually.
This feature:

  • Standardizes secure SSH/RDP connectivity patterns
  • Reduces boilerplate for creating endpoints in private subnets
  • Exposes a simple boolean variable create_instance_connect_endpoint for optional usage

Closes: #1253


Breaking Changes

No breaking changes.

  • Feature is optional (create_instance_connect_endpoint = false by default)
  • All existing variables, resources, and examples remain unchanged

How Has This Been Tested?

  • Added a new example in examples/ec2-instance-connect-endpoint/ demonstrating usage
  • Validated the new feature by running:
cd examples/ec2-instance-connect-endpoint
terraform init
terraform apply
terraform destroy

Example Usage

module "vpc" {
  source = "../../"

  name = "example-vpc"
  cidr = "10.0.0.0/16"

  azs             = ["us-east-1a", "us-east-1b"]
  private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
  public_subnets  = ["10.0.101.0/24", "10.0.102.0/24"]

  enable_nat_gateway = true
  single_nat_gateway = true

  create_instance_connect_endpoint      = true
  instance_connect_subnet_id            = element(module.vpc.private_subnets, 0)
  instance_connect_security_group_ids   = [aws_security_group.allow_ssh.id]
  instance_connect_preserve_client_ip   = false
}

resource "aws_security_group" "allow_ssh" {
  name        = "allow-ssh"
  description = "Allow SSH access for EC2 Instance Connect"
  vpc_id      = module.vpc.vpc_id

  ingress {
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

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

@alvinjaison alvinjaison marked this pull request as draft October 25, 2025 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature to create EC2 Instance Connect endpoint

1 participant