Skip to content

Commit 2bffa61

Browse files
committed
feat: Add EC2 Instance Connect Endpoint support
1 parent b3fb14f commit 2bffa61

File tree

5 files changed

+112
-0
lines changed

5 files changed

+112
-0
lines changed

README.md

Lines changed: 10 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 EC2 Instance Connect Endpoint(s) | `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,10 @@ 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_endpoint_create_in_private_subnets"></a> [instance\_connect\_endpoint\_create\_in\_private\_subnets](#input\_instance\_connect\_endpoint\_create\_in\_private\_subnets) | Create EC2 Instance Connect Endpoint(s) in all private subnets if no subnet IDs are provided | `bool` | `true` | no |
462+
| <a name="input_instance_connect_endpoint_subnets"></a> [instance\_connect\_endpoint\_subnets](#input\_instance\_connect\_endpoint\_subnets) | List of subnet IDs where EC2 Instance Connect Endpoint(s) should be created. If null and create\_in\_private\_subnets is true, defaults to private subnets | `list(string)` | `null` | no |
463+
| <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 EC2 Instance Connect Endpoint(s). If null, defaults to no security groups | `list(string)` | `null` | no |
464+
| <a name="input_instance_connect_tags"></a> [instance\_connect\_tags](#input\_instance\_connect\_tags) | Additional tags for EC2 Instance Connect Endpoint resources | `map(string)` | `{}` | no |
459465
| <a name="input_instance_tenancy"></a> [instance\_tenancy](#input\_instance\_tenancy) | A tenancy option for instances launched into the VPC | `string` | `"default"` | no |
460466
| <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 |
461467
| <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 +638,10 @@ No modules.
632638
| <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 |
633639
| <a name="output_igw_arn"></a> [igw\_arn](#output\_igw\_arn) | The ARN of the Internet Gateway |
634640
| <a name="output_igw_id"></a> [igw\_id](#output\_igw\_id) | The ID of the Internet Gateway |
641+
| <a name="output_instance_connect_endpoint_arns"></a> [instance\_connect\_endpoint\_arns](#output\_instance\_connect\_endpoint\_arns) | ARNs of the EC2 Instance Connect Endpoint(s) |
642+
| <a name="output_instance_connect_endpoint_ids"></a> [instance\_connect\_endpoint\_ids](#output\_instance\_connect\_endpoint\_ids) | IDs of the EC2 Instance Connect Endpoint(s) created |
643+
| <a name="output_instance_connect_endpoint_security_group_ids"></a> [instance\_connect\_endpoint\_security\_group\_ids](#output\_instance\_connect\_endpoint\_security\_group\_ids) | Security group IDs associated with the EC2 Instance Connect Endpoint(s) |
644+
| <a name="output_instance_connect_endpoint_subnet_ids"></a> [instance\_connect\_endpoint\_subnet\_ids](#output\_instance\_connect\_endpoint\_subnet\_ids) | Subnet IDs where EC2 Instance Connect Endpoint(s) were created |
635645
| <a name="output_intra_network_acl_arn"></a> [intra\_network\_acl\_arn](#output\_intra\_network\_acl\_arn) | ARN of the intra network ACL |
636646
| <a name="output_intra_network_acl_id"></a> [intra\_network\_acl\_id](#output\_intra\_network\_acl\_id) | ID of the intra network ACL |
637647
| <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 |

main.tf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,20 @@ locals {
1919
vpc_id = try(aws_vpc_ipv4_cidr_block_association.this[0].vpc_id, aws_vpc.this[0].id, "")
2020

2121
create_vpc = var.create_vpc && var.putin_khuylo
22+
23+
# EC2 Instance Connect Endpoint target subnets
24+
instance_connect_target_subnets = (
25+
var.instance_connect_endpoint_subnets != null && length(var.instance_connect_endpoint_subnets) > 0
26+
? var.instance_connect_endpoint_subnets
27+
: (
28+
var.instance_connect_endpoint_create_in_private_subnets && local.len_private_subnets > 0
29+
? aws_subnet.private[*].id
30+
: []
31+
)
32+
)
2233
}
2334

35+
2436
################################################################################
2537
# VPC
2638
################################################################################
@@ -1541,3 +1553,30 @@ resource "aws_default_route_table" "default" {
15411553
var.default_route_table_tags,
15421554
)
15431555
}
1556+
1557+
################################################################################
1558+
# EC2 Instance Connect Endpoint
1559+
################################################################################
1560+
1561+
resource "aws_ec2_instance_connect_endpoint" "this" {
1562+
for_each = var.create_instance_connect_endpoint ? {
1563+
for idx, subnet_id in local.instance_connect_target_subnets : idx => subnet_id
1564+
} : {}
1565+
1566+
subnet_id = each.value
1567+
1568+
security_group_ids = (
1569+
var.instance_connect_security_group_ids != null
1570+
? var.instance_connect_security_group_ids
1571+
: []
1572+
)
1573+
1574+
1575+
tags = merge(
1576+
var.tags,
1577+
var.instance_connect_tags,
1578+
{
1579+
Name = "${var.name}-ec2-instance-connect-${each.key}"
1580+
}
1581+
)
1582+
}

outputs.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,3 +667,27 @@ output "name" {
667667
description = "The name of the VPC specified as argument to this module"
668668
value = var.name
669669
}
670+
671+
################################################################################
672+
# EC2 Instance Connect Endpoint
673+
################################################################################
674+
675+
output "instance_connect_endpoint_ids" {
676+
description = "IDs of the EC2 Instance Connect Endpoint(s) created"
677+
value = try([for v in aws_ec2_instance_connect_endpoint.this : v.id], [])
678+
}
679+
680+
output "instance_connect_endpoint_subnet_ids" {
681+
description = "Subnet IDs where EC2 Instance Connect Endpoint(s) were created"
682+
value = try([for v in aws_ec2_instance_connect_endpoint.this : v.subnet_id], [])
683+
}
684+
685+
output "instance_connect_endpoint_security_group_ids" {
686+
description = "Security group IDs associated with the EC2 Instance Connect Endpoint(s)"
687+
value = try(var.instance_connect_security_group_ids, [])
688+
}
689+
690+
output "instance_connect_endpoint_arns" {
691+
description = "ARNs of the EC2 Instance Connect Endpoint(s)"
692+
value = try([for v in aws_ec2_instance_connect_endpoint.this : v.arn], [])
693+
}

variables.tf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,3 +1678,37 @@ variable "putin_khuylo" {
16781678
type = bool
16791679
default = true
16801680
}
1681+
1682+
################################################################################
1683+
# EC2 Instance Connect Endpoint
1684+
################################################################################
1685+
1686+
variable "create_instance_connect_endpoint" {
1687+
type = bool
1688+
default = false
1689+
description = "Whether to create EC2 Instance Connect Endpoint(s)"
1690+
}
1691+
1692+
variable "instance_connect_endpoint_create_in_private_subnets" {
1693+
type = bool
1694+
default = true
1695+
description = "Create EC2 Instance Connect Endpoint(s) in all private subnets if no subnet IDs are provided"
1696+
}
1697+
1698+
variable "instance_connect_endpoint_subnets" {
1699+
type = list(string)
1700+
default = null
1701+
description = "List of subnet IDs where EC2 Instance Connect Endpoint(s) should be created. If null and create_in_private_subnets is true, defaults to private subnets"
1702+
}
1703+
1704+
variable "instance_connect_security_group_ids" {
1705+
type = list(string)
1706+
default = null
1707+
description = "List of security group IDs to associate with EC2 Instance Connect Endpoint(s). If null, defaults to no security groups"
1708+
}
1709+
1710+
variable "instance_connect_tags" {
1711+
type = map(string)
1712+
default = {}
1713+
description = "Additional tags for EC2 Instance Connect Endpoint resources"
1714+
}

wrappers/main.tf

Lines changed: 5 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,10 @@ 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_endpoint_create_in_private_subnets = try(each.value.instance_connect_endpoint_create_in_private_subnets, var.defaults.instance_connect_endpoint_create_in_private_subnets, true)
188+
instance_connect_endpoint_subnets = try(each.value.instance_connect_endpoint_subnets, var.defaults.instance_connect_endpoint_subnets, null)
189+
instance_connect_security_group_ids = try(each.value.instance_connect_security_group_ids, var.defaults.instance_connect_security_group_ids, null)
190+
instance_connect_tags = try(each.value.instance_connect_tags, var.defaults.instance_connect_tags, {})
186191
instance_tenancy = try(each.value.instance_tenancy, var.defaults.instance_tenancy, "default")
187192
intra_acl_tags = try(each.value.intra_acl_tags, var.defaults.intra_acl_tags, {})
188193
intra_dedicated_network_acl = try(each.value.intra_dedicated_network_acl, var.defaults.intra_dedicated_network_acl, false)

0 commit comments

Comments
 (0)