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

Add support for Client VPN Route resource #10508

Conversation

RickyRajinder
Copy link
Contributor

@RickyRajinder RickyRajinder commented Oct 15, 2019

Adds support for the following resource:
https://docs.aws.amazon.com/vpn/latest/clientvpn-admin/cvpn-working-routes.html

Curently a workaround is implemented to access this API:
#7831 (comment)

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

Closes #10437
Closes #7831

Release note for CHANGELOG:

New Resource: aws_ec2_client_vpn_route

Output from acceptance testing:

=== RUN   TestAccAwsEc2ClientVpnRoute_basic
=== PAUSE TestAccAwsEc2ClientVpnRoute_basic
=== CONT  TestAccAwsEc2ClientVpnRoute_basic
--- PASS: TestAccAwsEc2ClientVpnRoute_basic (587.52s)
PASS

=== RUN   TestAccAwsEc2ClientVpnRoute_disappears
=== PAUSE TestAccAwsEc2ClientVpnRoute_disappears
=== CONT  TestAccAwsEc2ClientVpnRoute_disappears
--- PASS: TestAccAwsEc2ClientVpnRoute_disappears (635.60s)
PASS


...

@RickyRajinder RickyRajinder requested a review from a team October 15, 2019 07:48
@ghost ghost added size/XL Managed by automation to categorize the size of a PR. provider Pertains to the provider itself, rather than any interaction with AWS. service/ec2 Issues and PRs that pertain to the ec2 service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Oct 15, 2019
@RickyRajinder RickyRajinder force-pushed the resource-ec2-client-vpn-route branch 2 times, most recently from 2101378 to f459858 Compare October 15, 2019 07:58
@ghost ghost added the service/apigateway Issues and PRs that pertain to the apigateway service. label Oct 15, 2019
@RickyRajinder RickyRajinder force-pushed the resource-ec2-client-vpn-route branch 2 times, most recently from ef30e87 to cbad222 Compare October 15, 2019 08:04
@RickyRajinder RickyRajinder force-pushed the resource-ec2-client-vpn-route branch 2 times, most recently from 2632d4f to b8f0856 Compare October 25, 2019 23:56
@RickyRajinder RickyRajinder changed the title [WIP] Add support for Client VPN Route resource Add support for Client VPN Route resource Oct 25, 2019
Minor fixes to schema and test config methods

Adds tests and fixes bug in schema

Change destination cidr block value in test config

Change destination cidr block to internet access

fix tab issue

fix tab issue

fix typo in Read

Revert "tests/service/apigateway: Use internal implementation for TLS key/certificate"

This reverts commit da4e688157425156683562803484924addf5e002.

Fix test setup and add missing params

Fix delete issue

Fix gomft issues
@RickyRajinder
Copy link
Contributor Author

@bflad Can you please review?

@gazoakley
Copy link
Contributor

Looks like this does the same as #10560

Copy link
Contributor

@gdavison gdavison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @RickyRajinder, thanks for the PR. It's a great start for this feature. I've indicated a number of changes that can be made.

We'd also like to see some documentation added for the resource.

"origin": {
Type: schema.TypeString,
Computed: true,
ForceNew: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ForceNew does not work with Computed fields

return fmt.Errorf("error creating client VPN route: %s", err)
}

d.SetId(resource.UniqueId())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should create a "synthetic id" which can be built out of the arguments that will uniquely identify this route. Something like < client_vpn_endpoint_id>_< target_vpc_subnet_id>_< destination_cidr_block>. This is especially important since the resource is importable. The separator can be anything, but it should exclude any symbols that could be in the values, so in this case, avoid -, ., and /.

The ID can then be unpacked to use in the Read function to specify all of the parameters.

We use these in a number of resources, such as aws_route53_record and aws_security_group_rule.

func resourceAwsEc2ClientVpnRouteRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn

resp, err := conn.DescribeClientVpnRoutes(&ec2.DescribeClientVpnRoutesInput{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add values for the Filters field, to completely specify the route.

Comment on lines +113 to +140
_, exists := d.GetOk("client_vpn_endpoint_id")
if !exists {
d.Set("client_vpn_endpoint_id", resp.Routes[0].ClientVpnEndpointId)
}
_, exists = d.GetOk("destination_cidr_block")
if !exists {
d.Set("destination_cidr_block", resp.Routes[0].DestinationCidr)
}
_, exists = d.GetOk("description")
if !exists {
d.Set("description", resp.Routes[0].Description)
}
_, exists = d.GetOk("target_vpc_subnet_id")
if !exists {
d.Set("target_vpc_subnet_id", resp.Routes[0].TargetSubnet)
}
_, exists = d.GetOk("origin")
if !exists {
d.Set("origin", resp.Routes[0].Origin)
}
_, exists = d.GetOk("status")
if !exists {
d.Set("status", resp.Routes[0].Status)
}
_, exists = d.GetOk("type")
if !exists {
d.Set("type", resp.Routes[0].Type)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should set all of the values, rather than checking for it being set. This way we ensure that the Terraform state contains the values as seen by AWS, and we can check for drift and update if needed.

}

if err != nil {
return fmt.Errorf("error reading client VPN route: %s", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're updating our error messages to use the Go 1.13 error wrapping verb %w

},
})
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some other tests that would be useful for this resource:

  1. Update the values on a route and ensure that the old one is deleted and the new one is created
  2. Have more than one route associated with the Client VPN to ensure that the Read function is getting the correct route
    • Also update one of the routes to make sure that only the correct route is updated
  3. Have a test for adding and then removing a route
    • 0 -> 1 -> 0
    • 1 -> 2 -> 1

})

for _, r := range resp.Routes {
if *r.ClientVpnEndpointId == rs.Primary.Attributes["client_vpn_endpoint_id"] && !(*r.Status.Code == ec2.ClientVpnRouteStatusCodeDeleting) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should ensure that the route has been fully deleted, so ec2.ClientVpnRouteStatusCodeDeleting should not be accepted for this check


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

resp, err := conn.DescribeClientVpnRoutes(&ec2.DescribeClientVpnRoutesInput{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need to use the three required arguments to fully specify the correct route

target_vpc_subnet_id = "${aws_ec2_client_vpn_network_association.test.subnet_id}"
description = "test client VPN route"
}
`, rName, rName, rName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since rName is repeated here, you can use argument indexes, like %[1]s

}

func testAccEc2ClientVpnRouteConfig(rName string) string {
return testAccEc2ClientVpnRouteConfigAcmCertificateBase() + fmt.Sprintf(`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've added a function composeConfig() that can be used to merge together configurations. E.g.

return composeConfig(
    testAccEc2ClientVpnRouteConfigAcmCertificateBase(),
    fmt.Sprint(`...`, rName))

As you add more tests, you can make a base configuration snippet that contains the common pieces, like the VPC and subnets

@gdavison gdavison self-assigned this Jun 12, 2020
@gdavison gdavison added new-resource Introduces a new resource. waiting-response Maintainers are waiting on response from community or contributor. labels Jun 12, 2020
@ghost
Copy link

ghost commented Aug 9, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Aug 9, 2020
@breathingdust breathingdust removed the waiting-response Maintainers are waiting on response from community or contributor. label Sep 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new-resource Introduces a new resource. provider Pertains to the provider itself, rather than any interaction with AWS. service/apigateway Issues and PRs that pertain to the apigateway service. service/ec2 Issues and PRs that pertain to the ec2 service. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Client VPN Endpoint - Create Client Route VPN Client Endpoint Route Creation
4 participants