generated from rhythmictech/terraform-terraform-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from rhythmictech/init
ENG-1300
- Loading branch information
Showing
13 changed files
with
282 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
latest:^0.13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,92 @@ | ||
locals { | ||
tags = merge( | ||
var.tags, | ||
{ | ||
terraform_module = basename(abspath(path.module)) | ||
} | ||
) | ||
} | ||
|
||
module "tags" { | ||
source = "rhythmictech/tags/terraform" | ||
version = "1.0.0" | ||
resource "aws_cloudwatch_log_group" "vpn" { | ||
name_prefix = "vpn-${var.name}" | ||
retention_in_days = var.cloudwatch_log_retention_days | ||
tags = local.tags | ||
} | ||
|
||
enforce_case = "UPPER" | ||
names = [var.name] | ||
tags = var.tags | ||
resource "aws_cloudwatch_log_stream" "vpn" { | ||
name = "vpn-${var.name}" | ||
log_group_name = aws_cloudwatch_log_group.vpn.name | ||
} | ||
|
||
locals { | ||
# tflint-ignore: terraform_unused_declarations | ||
name = module.tags.name | ||
# tflint-ignore: terraform_unused_declarations | ||
tags = module.tags.tags_no_name | ||
resource "aws_iam_saml_provider" "this" { | ||
count = var.saml_metadata_document != null ? 1 : 0 | ||
|
||
name = var.name | ||
saml_metadata_document = var.saml_metadata_document | ||
} | ||
|
||
resource "aws_ec2_client_vpn_endpoint" "this" { | ||
description = "Client VPN" | ||
client_cidr_block = var.client_cidr_block | ||
server_certificate_arn = var.server_certificate_arn | ||
split_tunnel = var.split_tunnel_enabled | ||
tags = local.tags | ||
|
||
authentication_options { | ||
type = "federated-authentication" | ||
saml_provider_arn = try(aws_iam_saml_provider.this[0].arn, var.saml_provider_arn) | ||
} | ||
|
||
connection_log_options { | ||
enabled = true | ||
cloudwatch_log_group = aws_cloudwatch_log_group.vpn.name | ||
cloudwatch_log_stream = aws_cloudwatch_log_stream.vpn.name | ||
} | ||
} | ||
|
||
resource "aws_security_group" "this" { | ||
name_prefix = var.name | ||
description = "Client VPN network associations" | ||
tags = var.tags | ||
vpc_id = var.vpc_id | ||
|
||
ingress { | ||
description = "Allow self access only by default" | ||
from_port = 0 | ||
protocol = -1 | ||
self = true | ||
to_port = 0 | ||
} | ||
} | ||
|
||
resource "aws_ec2_client_vpn_network_association" "this" { | ||
for_each = toset(var.associated_subnets) #avoid ordering errors by using a for_each instead of count | ||
|
||
client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.this.id | ||
subnet_id = each.key | ||
|
||
security_groups = concat( | ||
[aws_security_group.this.id], | ||
var.additional_security_groups | ||
) | ||
} | ||
|
||
resource "aws_ec2_client_vpn_authorization_rule" "rules" { | ||
count = length(var.authorization_rules) | ||
|
||
access_group_id = var.authorization_rules[count.index].access_group_id | ||
authorize_all_groups = var.authorization_rules[count.index].authorize_all_groups | ||
client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.this.id | ||
description = var.authorization_rules[count.index].description | ||
target_network_cidr = var.authorization_rules[count.index].target_network_cidr | ||
|
||
} | ||
|
||
resource "aws_ec2_client_vpn_route" "additional" { | ||
count = length(var.additional_routes) | ||
|
||
description = try(var.additional_routes[count.index].description, null) | ||
destination_cidr_block = var.additional_routes[count.index].destination_cidr_block | ||
client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.this.id | ||
target_vpc_subnet_id = var.additional_routes[count.index].target_vpc_subnet_id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
output "vpn_dns_name" { | ||
description = "DNS name to be used by clients when establishing VPN session" | ||
value = aws_ec2_client_vpn_endpoint.this.dns_name | ||
} | ||
|
||
output "vpn_endpoint_security_groups" { | ||
description = "VPN endpoint security groups" | ||
|
||
output "tags_module" { | ||
description = "Tags Module in it's entirety" | ||
value = module.tags | ||
value = distinct( | ||
flatten( | ||
[for association in aws_ec2_client_vpn_network_association.this : association.security_groups] | ||
) | ||
) | ||
} |
Oops, something went wrong.