Skip to content

Commit 91a62a0

Browse files
authored
Merge pull request #4 from rhythmictech/eng-4729
eng-4729: adding self-service support to Rhythmic ClientVPN module
2 parents c470064 + b7be61b commit 91a62a0

4 files changed

Lines changed: 53 additions & 2 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ module "vpn" {
5555
|------|--------|---------|
5656
| <a name="module_saml_is_defined"></a> [saml\_is\_defined](#module\_saml\_is\_defined) | rhythmictech/errorcheck/terraform | ~> 1.2 |
5757
| <a name="module_saml_not_defined_twice"></a> [saml\_not\_defined\_twice](#module\_saml\_not\_defined\_twice) | rhythmictech/errorcheck/terraform | ~> 1.2 |
58+
| <a name="module_self_service_saml_not_defined_twice"></a> [self\_service\_saml\_not\_defined\_twice](#module\_self\_service\_saml\_not\_defined\_twice) | rhythmictech/errorcheck/terraform | ~> 1.2 |
5859

5960
## Resources
6061

@@ -66,6 +67,7 @@ module "vpn" {
6667
| [aws_ec2_client_vpn_endpoint.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_client_vpn_endpoint) | resource |
6768
| [aws_ec2_client_vpn_network_association.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_client_vpn_network_association) | resource |
6869
| [aws_ec2_client_vpn_route.additional](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_client_vpn_route) | resource |
70+
| [aws_iam_saml_provider.self_service](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_saml_provider) | resource |
6971
| [aws_iam_saml_provider.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_saml_provider) | resource |
7072
| [aws_security_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource |
7173

@@ -83,6 +85,8 @@ module "vpn" {
8385
| <a name="input_name"></a> [name](#input\_name) | Name to associate with various resources | `string` | n/a | yes |
8486
| <a name="input_saml_metadata_document"></a> [saml\_metadata\_document](#input\_saml\_metadata\_document) | Optional SAML metadata document. Must include this or `saml_provider_arn` | `string` | `null` | no |
8587
| <a name="input_saml_provider_arn"></a> [saml\_provider\_arn](#input\_saml\_provider\_arn) | Optional SAML provider ARN. Must include this or `saml_metadata_document` | `string` | `null` | no |
88+
| <a name="input_self_service_saml_metadata_document"></a> [self\_service\_saml\_metadata\_document](#input\_self\_service\_saml\_metadata\_document) | Optional SAML metadata document for the self-service portal. Must include this or `self_service_saml_provider_arn` to enable self-service; omit both to disable. | `string` | `null` | no |
89+
| <a name="input_self_service_saml_provider_arn"></a> [self\_service\_saml\_provider\_arn](#input\_self\_service\_saml\_provider\_arn) | Optional ARN of an existing IAM SAML provider for the self-service portal. Must include this or `self_service_saml_metadata_document` to enable self-service; omit both to disable. | `string` | `null` | no |
8690
| <a name="input_server_certificate_arn"></a> [server\_certificate\_arn](#input\_server\_certificate\_arn) | ARN of ACM certificate to use with Client VPN | `string` | n/a | yes |
8791
| <a name="input_split_tunnel_enabled"></a> [split\_tunnel\_enabled](#input\_split\_tunnel\_enabled) | Whether to enable split tunneling | `bool` | `true` | no |
8892
| <a name="input_tags"></a> [tags](#input\_tags) | Map of strings containing tags for AWS resources | `map(string)` | `{}` | no |
@@ -93,6 +97,7 @@ module "vpn" {
9397
| Name | Description |
9498
|------|-------------|
9599
| <a name="output_vpn_dns_name"></a> [vpn\_dns\_name](#output\_vpn\_dns\_name) | DNS name to be used by clients when establishing VPN session |
100+
| <a name="output_self_service_saml_provider_arn"></a> [self\_service\_saml\_provider\_arn](#output\_self\_service\_saml\_provider\_arn) | ARN of the IAM SAML provider created for the self-service portal (null if not created by this module) |
96101
| <a name="output_vpn_endpoint_security_groups"></a> [vpn\_endpoint\_security\_groups](#output\_vpn\_endpoint\_security\_groups) | VPN endpoint security groups |
97102
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
98103

main.tf

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ resource "aws_iam_saml_provider" "this" {
2626
saml_metadata_document = var.saml_metadata_document
2727
}
2828

29+
resource "aws_iam_saml_provider" "self_service" {
30+
count = var.self_service_saml_metadata_document != null ? 1 : 0
31+
32+
name = "${var.name}-self-service"
33+
saml_metadata_document = var.self_service_saml_metadata_document
34+
}
35+
2936
resource "aws_ec2_client_vpn_endpoint" "this" {
3037
description = "Client VPN"
3138
client_cidr_block = var.client_cidr_block
@@ -37,8 +44,9 @@ resource "aws_ec2_client_vpn_endpoint" "this" {
3744
tags = local.tags
3845

3946
authentication_options {
40-
type = "federated-authentication"
41-
saml_provider_arn = try(aws_iam_saml_provider.this[0].arn, var.saml_provider_arn)
47+
type = "federated-authentication"
48+
saml_provider_arn = try(aws_iam_saml_provider.this[0].arn, var.saml_provider_arn)
49+
self_service_saml_provider_arn = try(aws_iam_saml_provider.self_service[0].arn, var.self_service_saml_provider_arn, null)
4250
}
4351

4452
connection_log_options {

outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ output "vpn_endpoint_security_groups" {
77
description = "VPN endpoint security groups"
88
value = aws_ec2_client_vpn_endpoint.this.security_group_ids
99
}
10+
11+
output "self_service_saml_provider_arn" {
12+
description = "ARN of the IAM SAML provider created for the self-service portal (null if not created by this module)"
13+
value = try(aws_iam_saml_provider.self_service[0].arn, null)
14+
}

variables.tf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,39 @@ module "saml_not_defined_twice" {
123123
error_message = "Must not define both `saml_metadata_document` and `saml_provider_arn`."
124124
}
125125

126+
variable "self_service_saml_metadata_document" {
127+
default = null
128+
description = "Optional SAML metadata document for the self-service portal. Must include this or `self_service_saml_provider_arn` to enable self-service; omit both to disable."
129+
type = string
130+
}
131+
132+
variable "self_service_saml_provider_arn" {
133+
default = null
134+
description = "Optional ARN of an existing IAM SAML provider for the self-service portal. Must include this or `self_service_saml_metadata_document` to enable self-service; omit both to disable."
135+
type = string
136+
137+
validation {
138+
error_message = "Invalid self-service SAML provider ARN."
139+
140+
condition = (
141+
var.self_service_saml_provider_arn == null ||
142+
try(length(regexall(
143+
"^arn:aws:iam::(?P<account_id>\\d{12}):saml-provider/(?P<provider_name>[\\w+=,\\.@-]+)$",
144+
var.self_service_saml_provider_arn
145+
)) > 0,
146+
false
147+
))
148+
}
149+
}
150+
151+
module "self_service_saml_not_defined_twice" {
152+
source = "rhythmictech/errorcheck/terraform"
153+
version = "~> 1.2"
154+
155+
assert = !(var.self_service_saml_metadata_document != null && var.self_service_saml_provider_arn != null)
156+
error_message = "Must not define both `self_service_saml_metadata_document` and `self_service_saml_provider_arn`."
157+
}
158+
126159
variable "server_certificate_arn" {
127160
description = "ARN of ACM certificate to use with Client VPN"
128161
type = string

0 commit comments

Comments
 (0)