Skip to content

Commit 28df5f9

Browse files
committed
feat: Add EC2 Instance Connect Endpoint support
1 parent 6d128a0 commit 28df5f9

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ No modules.
264264
| [aws_default_route_table.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/default_route_table) | resource |
265265
| [aws_default_security_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/default_security_group) | resource |
266266
| [aws_default_vpc.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/default_vpc) | resource |
267+
| [aws_ec2_instance_connect_endpoint.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_instance_connect_endpoint) | resource |
267268
| [aws_egress_only_internet_gateway.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/egress_only_internet_gateway) | resource |
268269
| [aws_eip.nat](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eip) | resource |
269270
| [aws_elasticache_subnet_group.elasticache](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_subnet_group) | resource |
@@ -359,6 +360,7 @@ No modules.
359360
| <a name="input_create_flow_log_cloudwatch_iam_role"></a> [create\_flow\_log\_cloudwatch\_iam\_role](#input\_create\_flow\_log\_cloudwatch\_iam\_role) | Whether to create IAM role for VPC Flow Logs | `bool` | `false` | no |
360361
| <a name="input_create_flow_log_cloudwatch_log_group"></a> [create\_flow\_log\_cloudwatch\_log\_group](#input\_create\_flow\_log\_cloudwatch\_log\_group) | Whether to create CloudWatch log group for VPC Flow Logs | `bool` | `false` | no |
361362
| <a name="input_create_igw"></a> [create\_igw](#input\_create\_igw) | Controls if an Internet Gateway is created for public subnets and the related routes that connect them | `bool` | `true` | no |
363+
| <a name="input_create_instance_connect_endpoint"></a> [create\_instance\_connect\_endpoint](#input\_create\_instance\_connect\_endpoint) | Whether to create an EC2 Instance Connect Endpoint | `bool` | `false` | no |
362364
| <a name="input_create_multiple_intra_route_tables"></a> [create\_multiple\_intra\_route\_tables](#input\_create\_multiple\_intra\_route\_tables) | Indicates whether to create a separate route table for each intra subnet. Default: `false` | `bool` | `false` | no |
363365
| <a name="input_create_multiple_public_route_tables"></a> [create\_multiple\_public\_route\_tables](#input\_create\_multiple\_public\_route\_tables) | Indicates whether to create a separate route table for each public subnet. Default: `false` | `bool` | `false` | no |
364366
| <a name="input_create_private_nat_gateway_route"></a> [create\_private\_nat\_gateway\_route](#input\_create\_private\_nat\_gateway\_route) | Controls if a nat gateway route should be created to give internet access to the private subnets | `bool` | `true` | no |
@@ -456,6 +458,9 @@ No modules.
456458
| <a name="input_flow_log_per_hour_partition"></a> [flow\_log\_per\_hour\_partition](#input\_flow\_log\_per\_hour\_partition) | (Optional) Indicates whether to partition the flow log per hour. This reduces the cost and response time for queries | `bool` | `false` | no |
457459
| <a name="input_flow_log_traffic_type"></a> [flow\_log\_traffic\_type](#input\_flow\_log\_traffic\_type) | The type of traffic to capture. Valid values: ACCEPT, REJECT, ALL | `string` | `"ALL"` | no |
458460
| <a name="input_igw_tags"></a> [igw\_tags](#input\_igw\_tags) | Additional tags for the internet gateway | `map(string)` | `{}` | no |
461+
| <a name="input_instance_connect_preserve_client_ip"></a> [instance\_connect\_preserve\_client\_ip](#input\_instance\_connect\_preserve\_client\_ip) | Whether to preserve the client IP address when connecting via EC2 Instance Connect Endpoint | `bool` | `false` | no |
462+
| <a name="input_instance_connect_security_group_ids"></a> [instance\_connect\_security\_group\_ids](#input\_instance\_connect\_security\_group\_ids) | List of security group IDs to associate with the Instance Connect Endpoint | `list(string)` | `[]` | no |
463+
| <a name="input_instance_connect_subnet_id"></a> [instance\_connect\_subnet\_id](#input\_instance\_connect\_subnet\_id) | The ID of the subnet in which to create the Instance Connect Endpoint | `string` | `null` | no |
459464
| <a name="input_instance_tenancy"></a> [instance\_tenancy](#input\_instance\_tenancy) | A tenancy option for instances launched into the VPC | `string` | `"default"` | no |
460465
| <a name="input_intra_acl_tags"></a> [intra\_acl\_tags](#input\_intra\_acl\_tags) | Additional tags for the intra subnets network ACL | `map(string)` | `{}` | no |
461466
| <a name="input_intra_dedicated_network_acl"></a> [intra\_dedicated\_network\_acl](#input\_intra\_dedicated\_network\_acl) | Whether to use dedicated network ACL (not default) and custom rules for intra subnets | `bool` | `false` | no |
@@ -632,6 +637,7 @@ No modules.
632637
| <a name="output_elasticache_subnets_ipv6_cidr_blocks"></a> [elasticache\_subnets\_ipv6\_cidr\_blocks](#output\_elasticache\_subnets\_ipv6\_cidr\_blocks) | List of IPv6 cidr\_blocks of elasticache subnets in an IPv6 enabled VPC |
633638
| <a name="output_igw_arn"></a> [igw\_arn](#output\_igw\_arn) | The ARN of the Internet Gateway |
634639
| <a name="output_igw_id"></a> [igw\_id](#output\_igw\_id) | The ID of the Internet Gateway |
640+
| <a name="output_instance_connect_endpoint_id"></a> [instance\_connect\_endpoint\_id](#output\_instance\_connect\_endpoint\_id) | The ID of the EC2 Instance Connect Endpoint |
635641
| <a name="output_intra_network_acl_arn"></a> [intra\_network\_acl\_arn](#output\_intra\_network\_acl\_arn) | ARN of the intra network ACL |
636642
| <a name="output_intra_network_acl_id"></a> [intra\_network\_acl\_id](#output\_intra\_network\_acl\_id) | ID of the intra network ACL |
637643
| <a name="output_intra_route_table_association_ids"></a> [intra\_route\_table\_association\_ids](#output\_intra\_route\_table\_association\_ids) | List of IDs of the intra route table association |

examples/ec2-instance-connect-endpoint/main.tf

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ provider "aws" {
55
data "aws_availability_zones" "available" {}
66

77
locals {
8-
name = "ex-${basename(path.cwd)}"
9-
region = "us-east-1"
10-
azs = slice(data.aws_availability_zones.available.names, 0, 2)
8+
name = "ex-${basename(path.cwd)}"
9+
region = "us-east-1"
10+
azs = slice(data.aws_availability_zones.available.names, 0, 3)
11+
private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
12+
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]
1113

1214
tags = {
1315
Example = local.name
@@ -23,24 +25,31 @@ locals {
2325
module "vpc" {
2426
source = "../../"
2527

26-
name = local.name
28+
name = "example-vpc"
2729
cidr = "10.0.0.0/16"
2830

2931
azs = local.azs
30-
private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
31-
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]
32+
private_subnets = local.private_subnets
33+
public_subnets = local.public_subnets
3234

3335
enable_nat_gateway = true
3436
single_nat_gateway = true
3537

38+
# EC2 Instance Connect Endpoint configuration
3639
create_instance_connect_endpoint = true
3740
instance_connect_subnet_id = element(local.private_subnets, 0)
3841
instance_connect_security_group_ids = [aws_security_group.allow_ssh.id]
3942
instance_connect_preserve_client_ip = false
4043

41-
tags = local.tags
44+
tags = merge({
45+
Name = "example-vpc"
46+
}, local.tags)
4247
}
4348

49+
################################################################################
50+
# Security Group for EC2 Instance Connect
51+
################################################################################
52+
4453
resource "aws_security_group" "allow_ssh" {
4554
name = "allow-ssh"
4655
description = "Allow SSH access for EC2 Instance Connect"
@@ -59,4 +68,8 @@ resource "aws_security_group" "allow_ssh" {
5968
protocol = "-1"
6069
cidr_blocks = ["0.0.0.0/0"]
6170
}
71+
72+
tags = merge({
73+
Name = "allow-ssh"
74+
}, local.tags)
6275
}

wrappers/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module "wrapper" {
1616
create_flow_log_cloudwatch_iam_role = try(each.value.create_flow_log_cloudwatch_iam_role, var.defaults.create_flow_log_cloudwatch_iam_role, false)
1717
create_flow_log_cloudwatch_log_group = try(each.value.create_flow_log_cloudwatch_log_group, var.defaults.create_flow_log_cloudwatch_log_group, false)
1818
create_igw = try(each.value.create_igw, var.defaults.create_igw, true)
19+
create_instance_connect_endpoint = try(each.value.create_instance_connect_endpoint, var.defaults.create_instance_connect_endpoint, false)
1920
create_multiple_intra_route_tables = try(each.value.create_multiple_intra_route_tables, var.defaults.create_multiple_intra_route_tables, false)
2021
create_multiple_public_route_tables = try(each.value.create_multiple_public_route_tables, var.defaults.create_multiple_public_route_tables, false)
2122
create_private_nat_gateway_route = try(each.value.create_private_nat_gateway_route, var.defaults.create_private_nat_gateway_route, true)
@@ -183,6 +184,9 @@ module "wrapper" {
183184
flow_log_per_hour_partition = try(each.value.flow_log_per_hour_partition, var.defaults.flow_log_per_hour_partition, false)
184185
flow_log_traffic_type = try(each.value.flow_log_traffic_type, var.defaults.flow_log_traffic_type, "ALL")
185186
igw_tags = try(each.value.igw_tags, var.defaults.igw_tags, {})
187+
instance_connect_preserve_client_ip = try(each.value.instance_connect_preserve_client_ip, var.defaults.instance_connect_preserve_client_ip, false)
188+
instance_connect_security_group_ids = try(each.value.instance_connect_security_group_ids, var.defaults.instance_connect_security_group_ids, [])
189+
instance_connect_subnet_id = try(each.value.instance_connect_subnet_id, var.defaults.instance_connect_subnet_id, null)
186190
instance_tenancy = try(each.value.instance_tenancy, var.defaults.instance_tenancy, "default")
187191
intra_acl_tags = try(each.value.intra_acl_tags, var.defaults.intra_acl_tags, {})
188192
intra_dedicated_network_acl = try(each.value.intra_dedicated_network_acl, var.defaults.intra_dedicated_network_acl, false)

0 commit comments

Comments
 (0)