Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/ec2_client_vpn_endpoint - add arn attribute + plan time validations #13601

Merged
merged 2 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions aws/resource_aws_ec2_client_vpn_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand All @@ -27,18 +28,20 @@ func resourceAwsEc2ClientVpnEndpoint() *schema.Resource {
Optional: true,
},
"client_cidr_block": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.IsCIDR,
},
"dns_servers": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"server_certificate_arn": {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validateArn,
},
"split_tunnel": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -76,9 +79,10 @@ func resourceAwsEc2ClientVpnEndpoint() *schema.Resource {
ForceNew: true,
},
"root_certificate_chain_arn": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validateArn,
},
},
},
Expand Down Expand Up @@ -113,6 +117,10 @@ func resourceAwsEc2ClientVpnEndpoint() *schema.Resource {
Computed: true,
},
"tags": tagsSchema(),
"arn": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -239,6 +247,16 @@ func resourceAwsEc2ClientVpnEndpointRead(d *schema.ResourceData, meta interface{
return fmt.Errorf("error setting tags: %s", err)
}

arn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Service: "ec2",
Region: meta.(*AWSClient).region,
AccountID: meta.(*AWSClient).accountid,
Resource: fmt.Sprintf("client-vpn-endpoint/%s", d.Id()),
}.String()

d.Set("arn", arn)

return nil
}

Expand Down
76 changes: 35 additions & 41 deletions aws/resource_aws_ec2_client_vpn_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"fmt"
"log"
"regexp"
"testing"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -74,6 +75,7 @@ func testSweepEc2ClientVpnEndpoints(region string) error {

func TestAccAwsEc2ClientVpnEndpoint_basic(t *testing.T) {
rStr := acctest.RandString(5)
resourceName := "aws_ec2_client_vpn_endpoint.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -83,15 +85,16 @@ func TestAccAwsEc2ClientVpnEndpoint_basic(t *testing.T) {
{
Config: testAccEc2ClientVpnEndpointConfig(rStr),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsEc2ClientVpnEndpointExists("aws_ec2_client_vpn_endpoint.test"),
resource.TestCheckResourceAttr("aws_ec2_client_vpn_endpoint.test", "authentication_options.#", "1"),
resource.TestCheckResourceAttr("aws_ec2_client_vpn_endpoint.test", "authentication_options.0.type", "certificate-authentication"),
resource.TestCheckResourceAttr("aws_ec2_client_vpn_endpoint.test", "status", ec2.ClientVpnEndpointStatusCodePendingAssociate),
testAccCheckAwsEc2ClientVpnEndpointExists(resourceName),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "ec2", regexp.MustCompile(`client-vpn-endpoint/cvpn-endpoint-.+`)),
resource.TestCheckResourceAttr(resourceName, "authentication_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "authentication_options.0.type", "certificate-authentication"),
resource.TestCheckResourceAttr(resourceName, "status", ec2.ClientVpnEndpointStatusCodePendingAssociate),
),
},

{
ResourceName: "aws_ec2_client_vpn_endpoint.test",
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
Expand All @@ -101,6 +104,7 @@ func TestAccAwsEc2ClientVpnEndpoint_basic(t *testing.T) {

func TestAccAwsEc2ClientVpnEndpoint_disappears(t *testing.T) {
rStr := acctest.RandString(5)
resourceName := "aws_ec2_client_vpn_endpoint.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -110,8 +114,8 @@ func TestAccAwsEc2ClientVpnEndpoint_disappears(t *testing.T) {
{
Config: testAccEc2ClientVpnEndpointConfig(rStr),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsEc2ClientVpnEndpointExists("aws_ec2_client_vpn_endpoint.test"),
testAccCheckAwsEc2ClientVpnEndpointDisappears("aws_ec2_client_vpn_endpoint.test"),
testAccCheckAwsEc2ClientVpnEndpointExists(resourceName),
testAccCheckResourceDisappears(testAccProvider, resourceAwsEc2ClientVpnEndpoint(), resourceName),
),
ExpectNonEmptyPlan: true,
},
Expand All @@ -121,6 +125,7 @@ func TestAccAwsEc2ClientVpnEndpoint_disappears(t *testing.T) {

func TestAccAwsEc2ClientVpnEndpoint_msAD(t *testing.T) {
rStr := acctest.RandString(5)
resourceName := "aws_ec2_client_vpn_endpoint.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -130,14 +135,14 @@ func TestAccAwsEc2ClientVpnEndpoint_msAD(t *testing.T) {
{
Config: testAccEc2ClientVpnEndpointConfigWithMicrosoftAD(rStr),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsEc2ClientVpnEndpointExists("aws_ec2_client_vpn_endpoint.test"),
resource.TestCheckResourceAttr("aws_ec2_client_vpn_endpoint.test", "authentication_options.#", "1"),
resource.TestCheckResourceAttr("aws_ec2_client_vpn_endpoint.test", "authentication_options.0.type", "directory-service-authentication"),
testAccCheckAwsEc2ClientVpnEndpointExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "authentication_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "authentication_options.0.type", "directory-service-authentication"),
),
},

{
ResourceName: "aws_ec2_client_vpn_endpoint.test",
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
Expand All @@ -147,6 +152,7 @@ func TestAccAwsEc2ClientVpnEndpoint_msAD(t *testing.T) {

func TestAccAwsEc2ClientVpnEndpoint_mutualAuthAndMsAD(t *testing.T) {
rStr := acctest.RandString(5)
resourceName := "aws_ec2_client_vpn_endpoint.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -156,15 +162,15 @@ func TestAccAwsEc2ClientVpnEndpoint_mutualAuthAndMsAD(t *testing.T) {
{
Config: testAccEc2ClientVpnEndpointConfigWithMutualAuthAndMicrosoftAD(rStr),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsEc2ClientVpnEndpointExists("aws_ec2_client_vpn_endpoint.test"),
resource.TestCheckResourceAttr("aws_ec2_client_vpn_endpoint.test", "authentication_options.#", "2"),
resource.TestCheckResourceAttr("aws_ec2_client_vpn_endpoint.test", "authentication_options.0.type", "directory-service-authentication"),
resource.TestCheckResourceAttr("aws_ec2_client_vpn_endpoint.test", "authentication_options.1.type", "certificate-authentication"),
testAccCheckAwsEc2ClientVpnEndpointExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "authentication_options.#", "2"),
resource.TestCheckResourceAttr(resourceName, "authentication_options.0.type", "directory-service-authentication"),
resource.TestCheckResourceAttr(resourceName, "authentication_options.1.type", "certificate-authentication"),
),
},

{
ResourceName: "aws_ec2_client_vpn_endpoint.test",
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
Expand All @@ -174,6 +180,7 @@ func TestAccAwsEc2ClientVpnEndpoint_mutualAuthAndMsAD(t *testing.T) {

func TestAccAwsEc2ClientVpnEndpoint_withLogGroup(t *testing.T) {
rStr := acctest.RandString(5)
resourceName := "aws_ec2_client_vpn_endpoint.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -183,19 +190,19 @@ func TestAccAwsEc2ClientVpnEndpoint_withLogGroup(t *testing.T) {
{
Config: testAccEc2ClientVpnEndpointConfig(rStr),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsEc2ClientVpnEndpointExists("aws_ec2_client_vpn_endpoint.test"),
testAccCheckAwsEc2ClientVpnEndpointExists(resourceName),
),
},

{
Config: testAccEc2ClientVpnEndpointConfigWithLogGroup(rStr),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsEc2ClientVpnEndpointExists("aws_ec2_client_vpn_endpoint.test"),
testAccCheckAwsEc2ClientVpnEndpointExists(resourceName),
),
},

{
ResourceName: "aws_ec2_client_vpn_endpoint.test",
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
Expand All @@ -205,6 +212,7 @@ func TestAccAwsEc2ClientVpnEndpoint_withLogGroup(t *testing.T) {

func TestAccAwsEc2ClientVpnEndpoint_withDNSServers(t *testing.T) {
rStr := acctest.RandString(5)
resourceName := "aws_ec2_client_vpn_endpoint.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -214,19 +222,19 @@ func TestAccAwsEc2ClientVpnEndpoint_withDNSServers(t *testing.T) {
{
Config: testAccEc2ClientVpnEndpointConfig(rStr),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsEc2ClientVpnEndpointExists("aws_ec2_client_vpn_endpoint.test"),
testAccCheckAwsEc2ClientVpnEndpointExists(resourceName),
),
},

{
Config: testAccEc2ClientVpnEndpointConfigWithDNSServers(rStr),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsEc2ClientVpnEndpointExists("aws_ec2_client_vpn_endpoint.test"),
testAccCheckAwsEc2ClientVpnEndpointExists(resourceName),
),
},

{
ResourceName: "aws_ec2_client_vpn_endpoint.test",
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
Expand All @@ -251,6 +259,11 @@ func TestAccAwsEc2ClientVpnEndpoint_tags(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "tags.Usage", "original"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccEc2ClientVpnEndpointConfig_tagsChanged(rStr),
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -324,25 +337,6 @@ func testAccCheckAwsEc2ClientVpnEndpointDestroy(s *terraform.State) error {
return nil
}

func testAccCheckAwsEc2ClientVpnEndpointDisappears(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
if !ok {
return fmt.Errorf("Not found: %s", name)
}

conn := testAccProvider.Meta().(*AWSClient).ec2conn

input := &ec2.DeleteClientVpnEndpointInput{
ClientVpnEndpointId: aws.String(rs.Primary.ID),
}

_, err := conn.DeleteClientVpnEndpoint(input)

return err
}
}

func testAccCheckAwsEc2ClientVpnEndpointExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
_, ok := s.RootModule().Resources[name]
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/ec2_client_vpn_endpoint.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ One of the following arguments must be supplied:
In addition to all arguments above, the following attributes are exported:

* `id` - The ID of the Client VPN endpoint.
* `arn` - The ARN of the Client VPN endpoint.
* `dns_name` - The DNS name to be used by clients when establishing their VPN session.
* `status` - The current state of the Client VPN endpoint.

Expand Down