- Newest
- Most votes
- Most comments
This will not work because VPN Clients are NAT'd. The security group rule will never see the VPN Clients CIDR Block
resource "aws_security_group" "opensearch_sg" {
vpc_id = aws_vpc.vpc.id
ingress {
description = "Allow VPN clients to access OpenSearch"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = [aws_ec2_client_vpn_endpoint.client_vpn.client_cidr_block]
}
egress {
description = "Allow all outbound traffic"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "opensearch-sg-${var.environment}"
}
}
Try this
resource "aws_security_group" "opensearch_sg" {
vpc_id = aws_vpc.vpc.id
ingress {
description = "Allow VPN clients to access OpenSearch"
from_port = 443
to_port = 443
protocol = "tcp"
security_groups = [aws_security_group.vpn_security_group.id ]
}
egress {
description = "Allow all outbound traffic"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "opensearch-sg-${var.environment}"
}
}
I see several issues with your setup here and would be helpful if you can share your error. I am going to assume you cant resolve the DNS name for the VPC Endpoint
- No NAT Gateway
- Split TUNNEL = false
- No DNS Resolution for VPN Clients
Currently you have split tunnel=false (By default) so ALL VPN traffic is being sent to your VPC. Your VPN Clients cant access the internet without a NAT gateway. They are also unable to resolve DNS Names because you dont have a DNS Server Set.
If you set your dns_servers = "10.0.0.2" VPC IP +2 this may fix your issue and you can resolve and connect to the private VPC Endpoint. But you have other configuration designs decisions to make.
resource "aws_ec2_client_vpn_endpoint" "client_vpn" {
client_cidr_block = "10.1.0.0/22"
dns_servers = [cidrhost(aws_vpc.vpc.cidr_block, 2)]
server_certificate_arn = local.vpn_server_cert_arn
vpc_id = aws_vpc.vpc.id
security_group_ids = [aws_security_group.vpn_security_group.id]
authentication_options {
type = "certificate-authentication"
root_certificate_chain_arn = local.vpn_server_cert_arn
}
connection_log_options {
enabled = false
}
tags = {
Name = "vpn-${var.environment}"
}
}
The issue you're experiencing with not being able to curl the OpenSearch service endpoint while connected to the VPN client can be resolved by making a few adjustments to your Terraform configuration. Here are the steps to fix the timeout:
-
Ensure proper routing: Add a route in the VPC route table associated with the subnet where OpenSearch is deployed. This route should direct traffic from the VPN client CIDR to the OpenSearch subnet.
-
Adjust security group rules: Modify the OpenSearch security group to allow incoming traffic from the VPN client CIDR block on the HTTPS port (443).
-
Configure OpenSearch network settings: Ensure that OpenSearch is set up to use the VPC endpoint for access.
-
VPN client configuration: Make sure your VPN client is configured to route traffic to the OpenSearch domain through the VPN connection.
Here are the specific changes to make in your Terraform code:
- Add a route to the public route table:
resource "aws_route" "vpn_to_opensearch" { route_table_id = aws_route_table.public.id destination_cidr_block = aws_ec2_client_vpn_endpoint.client_vpn.client_cidr_block gateway_id = aws_internet_gateway.igw.id }
- Modify the OpenSearch security group:
resource "aws_security_group" "opensearch_sg" { # ... (existing configuration) ingress { description = "Allow VPN clients to access OpenSearch" from_port = 443 to_port = 443 protocol = "tcp" cidr_blocks = [aws_ec2_client_vpn_endpoint.client_vpn.client_cidr_block] } # ... (rest of the configuration) }
- Ensure OpenSearch is using VPC access:
resource "aws_opensearch_domain" "opensearch" { # ... (existing configuration) vpc_options { subnet_ids = [aws_subnet.public_subnet_1.id] security_group_ids = [aws_security_group.opensearch_sg.id] } # ... (rest of the configuration) }
After making these changes, apply the updated Terraform configuration. Once the changes are applied, you should be able to curl the OpenSearch service endpoint while connected to the VPN client. If you still experience issues, double-check your VPN client configuration and ensure that it's routing traffic to the OpenSearch domain correctly.
Sources
Access Amazon OpenSearch Service using an OpenSearch Service-managed VPC endpoint (AWS PrivateLink) - Amazon OpenSearch Service
Community | Goodbye Elasticsearch, Hello OpenSearch: A Golang Developer's Journey with Amazon Q (Lessons Learned)
answered 2 years ago
The AI's answer doesn't take in the context of a VPC setup and how DNS and routing works within a VPC
Relevant content
asked 2 years ago
asked a year ago
asked 8 months ago
asked a month ago
- AWS OFFICIALUpdated 3 years ago

Actually DNS resolution works properly. However I can't curl or ping resolved IP address. Also, I have internet access via IGW, but can't connect only to OpenSearch service.
Very strange. You can’t have access via internet gateway without a NAT gateway. Your TF has not DNS servers setup for the VPN?
I’ll setup your TF and come back to you with the answer for it to work