Skip to content

Commit

Permalink
adds client_config_options to aws_ec2_client_vpn_endpoint hashicorp#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsFronius committed Apr 16, 2021
1 parent 382206d commit 820d192
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
57 changes: 57 additions & 0 deletions aws/resource_aws_ec2_client_vpn_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,24 @@ func resourceAwsEc2ClientVpnEndpoint() *schema.Resource {
},
},
},
"client_connect_options": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Required: true,
},
"lambda_function_arn": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateArn,
},
},
},
},
"connection_log_options": {
Type: schema.TypeList,
Required: true,
Expand Down Expand Up @@ -166,6 +184,19 @@ func resourceAwsEc2ClientVpnEndpointCreate(d *schema.ResourceData, meta interfac
req.AuthenticationOptions = authRequests
}

if v, ok := d.GetOk("client_connect_options"); ok {
clientConnSet := v.([]interface{})
attrs := clientConnSet[0].(map[string]interface{})
clientConnOpts := &ec2.ClientConnectOptions{
Enabled: aws.Bool(attrs["enabled"].(bool)),
}
if attrs["enabled"].(bool) && attrs["lambda_function_arn"].(string) != "" {
clientConnOpts.LambdaFunctionArn = aws.String(attrs["lambda_function_arn"].(string))
}

req.ClientConnectOptions = clientConnOpts
}

if v, ok := d.GetOk("connection_log_options"); ok {
connLogSet := v.([]interface{})
attrs := connLogSet[0].(map[string]interface{})
Expand Down Expand Up @@ -243,6 +274,8 @@ func resourceAwsEc2ClientVpnEndpointRead(d *schema.ResourceData, meta interface{
return fmt.Errorf("error setting authentication_options: %w", err)
}

err = d.Set("client_connect_options", flattenClientConnectOptions(result.ClientVpnEndpoints[0].ClientConnectOptions))

err = d.Set("connection_log_options", flattenConnLoggingConfig(result.ClientVpnEndpoints[0].ConnectionLogOptions))
if err != nil {
return fmt.Errorf("error setting connection_log_options: %w", err)
Expand Down Expand Up @@ -312,6 +345,21 @@ func resourceAwsEc2ClientVpnEndpointUpdate(d *schema.ResourceData, meta interfac
req.SplitTunnel = aws.Bool(d.Get("split_tunnel").(bool))
}

if d.HasChange("client_connect_options") {
if v, ok := d.GetOk("client_connect_options"); ok {
clientConnSet := v.([]interface{})
attrs := clientConnSet[0].(map[string]interface{})
clientConnOpts := &ec2.ClientConnectOptions{
Enabled: aws.Bool(attrs["enabled"].(bool)),
}
if attrs["enabled"].(bool) && attrs["lambda_function_arn"].(string) != "" {
clientConnOpts.LambdaFunctionArn = aws.String(attrs["lambda_function_arn"].(string))
}

req.ClientConnectOptions = clientConnOpts
}
}

if d.HasChange("connection_log_options") {
if v, ok := d.GetOk("connection_log_options"); ok {
connSet := v.([]interface{})
Expand Down Expand Up @@ -347,6 +395,15 @@ func resourceAwsEc2ClientVpnEndpointUpdate(d *schema.ResourceData, meta interfac
return resourceAwsEc2ClientVpnEndpointRead(d, meta)
}

func flattenClientConnectOptions(copts *ec2.ClientConnectResponseOptions) []map[string]interface{} {
m := make(map[string]interface{})
if copts.LambdaFunctionArn != nil {
m["lambda_function_arn"] = *copts.LambdaFunctionArn
}
m["enabled"] = *copts.Enabled
return []map[string]interface{}{m}
}

func flattenConnLoggingConfig(lopts *ec2.ConnectionLogResponseOptions) []map[string]interface{} {
m := make(map[string]interface{})
if lopts.CloudwatchLogGroup != nil {
Expand Down
66 changes: 66 additions & 0 deletions aws/resource_aws_ec2_client_vpn_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,43 @@ func testAccAwsEc2ClientVpnEndpoint_federated(t *testing.T) {
})
}

func testAccAwsEc2ClientVpnEndpoint_withClientConnectOptions(t *testing.T) {
var v1, v2 ec2.ClientVpnEndpoint
rStr := acctest.RandString(5)
resourceName := "aws_ec2_client_vpn_endpoint.test"
lambdaFunctionArn := "aws_lambda_function.lg"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheckClientVPNSyncronize(t); testAccPreCheck(t) },
ErrorCheck: testAccErrorCheck(t, ec2.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsEc2ClientVpnEndpointDestroy,
Steps: []resource.TestStep{
{
Config: testAccEc2ClientVpnEndpointConfig(rStr),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsEc2ClientVpnEndpointExists(resourceName, &v1),
),
},
{
Config: testAccEc2ClientVpnEndpointConfigWithClientConfig(rStr),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsEc2ClientVpnEndpointExists(resourceName, &v2),
resource.TestCheckResourceAttr(resourceName, "client_config_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "client_config_options.0.enabled", "true"),
resource.TestCheckResourceAttrPair(resourceName, "client_config_options.0.lambda_function_arn", lambdaFunctionArn, "arn"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})

}

func testAccAwsEc2ClientVpnEndpoint_withLogGroup(t *testing.T) {
var v1, v2 ec2.ClientVpnEndpoint
rStr := acctest.RandString(5)
Expand Down Expand Up @@ -529,6 +566,35 @@ resource "aws_ec2_client_vpn_endpoint" "test" {
`, rName)
}

func testAccEc2ClientVpnEndpointConfigWithClientConfig(rName string) string {
return testAccEc2ClientVpnEndpointConfigAcmCertificateBase() + fmt.Sprintf(`
resource "aws_lambda_function" "test" {
filename = "test-fixtures/lambdatest.zip"
function_name = "AWSClientVPN-client_config_handler_%s"
publish = false
role = aws_iam_role.iam_for_lambda.arn
handler = "exports.example"
runtime = "nodejs12.x"
}
resource "aws_ec2_client_vpn_endpoint" "test" {
description = "terraform-testacc-clientvpn-%s"
server_certificate_arn = aws_acm_certificate.test.arn
client_cidr_block = "10.0.0.0/16"
authentication_options {
type = "certificate-authentication"
root_certificate_chain_arn = aws_acm_certificate.test.arn
}
client_config_options {
enabled = true
lambda_function_arn = aws_lambda_function_test.arn
}
}
`, rName, rName)
}

func testAccEc2ClientVpnEndpointConfigWithLogGroup(rName string) string {
return testAccEc2ClientVpnEndpointConfigAcmCertificateBase() + fmt.Sprintf(`
resource "aws_cloudwatch_log_group" "lg" {
Expand Down

0 comments on commit 820d192

Please sign in to comment.