-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Client VPN Endpoint - Add Ingress Authorisation #7494
Comments
I overlooked this when I wrote the initial resource: https://docs.aws.amazon.com/sdk-for-go/api/service/ec2/#EC2.AuthorizeClientVpnIngress I'm thinking we treat this like These are just my preliminary thoughts. I'm going to l dig into this more later today. |
I think it will only be ingress blocks, but yes, that sounds sensible. Since there would only be one |
Now that I've reviewed this some more, I see what you are saying. Unfortunately, it seems that my initial take was incorrect and that this probably won't work as a separate resource. It uses the Client VPN Endpoint ID as its key identifier so that would make it hardish to track in state. Due to that fact, the best way to manage it would be to add this to |
I have a solution for this and it should be ready in the next couple days. |
Sounds good, thanks for looking into this! |
+1 |
any movement on this one :) ? |
As we create more and more endpoint auths for various cross account VPC/networks, this is quickly becoming an important Terraform feature for us. |
Any news on this issue? |
up ! |
Any news? Need any help? |
👋 +1 |
Any update on this? |
Any update please? |
As a workaround, I solved this by using the AWS CLI command. resource "null_resource" "client_vpn_ingress" { provisioner "local-exec" { |
Hi guys, |
Regarding:
One downside of the using Assume:
The |
@dostiharise thanks for sharing. I see it. It happens because the aws CLI is execute outside from Terraform context. May be we can find a way to export the AWS credential from the running terraform environment...It would be great. |
I modified the command in the null resource to include the |
I wrote this script block to help with assuming roles:
You will need the following parameters for it to work:
|
@kevinchabreck It's not just the profile, I was referring to assume role, which is different from profile credentials. As follows:
This one is hard to solve with just |
Can't you use a profile with a https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-role.html |
Wow! This is so much simpler. How did I miss this. 🤦♂ Thanks. [Update] Now, that I think about it, my above approach keeps much of the Role related Info within the terraform code, and reuses the Terraform Variables. In a way using the terraform local variable for role name achieves "high cohesion", and avoids multiple sources of truth. |
I was using something very similar to what @jinil-kargo proposed
However, that's deprecated now.
Any other ideas? |
I think you can skip the Skip this:
The reason is when you drop/destroy the I am guessing the But do keep the Do let me know if what I propose works! Wish you luck. |
Any update on when a solution for this issue will be merged in to the main "aws_ec2_client_vpn_endpoint" resource? I see every few days someone makes a PR to address this issue. |
+1 👍 |
1 similar comment
+1 👍 |
Still no update? |
+1 👍 |
+1 |
Here's what's working for us right now with TF 12: variable subnets {
type = set(string)
}
variable ad_ingress {
type = map(object({
cidr = string
ad_group_id = string
}))
}
locals {
stack = {
Resources = merge(local.ingress_custom, local.ingress_custom_routes)
}
ingress_custom = {
for k, v in var.ad_ingress : k => {
Type = "AWS::EC2::ClientVpnAuthorizationRule"
Properties = {
ClientVpnEndpointId = aws_ec2_client_vpn_endpoint.vpn.id
AccessGroupId = v.ad_group_id
TargetNetworkCidr = v.cidr
Description = format("%s Access, (%s)", k, v.cidr)
}
}
}
ingress_custom_routes = merge(flatten([[
for subnet in var.subnets : {
for k, v in var.ad_ingress : "${k}Route${split("-",subnet)[1]}" => {
Type = "AWS::EC2::ClientVpnRoute"
Properties = {
ClientVpnEndpointId = aws_ec2_client_vpn_endpoint.vpn.id
TargetVpcSubnetId = subnet
DestinationCidrBlock = v.cidr
Description = format("%sRoute-%s", k, subnet)
}
}
}
]])...)
} with a var or local var defined like: locals {
ad_ingress = {
internet_for_users = {
cidr = "0.0.0.0/0"
ad_group_id = "asdfg-hjkl-qwert-tyuuiop"
}
}
} And then use the local.stack variable in a cloudformation stack resource: resource aws_cloudformation_stack client_vpn {
name = "ClientVPN-${var.name}"
template_body = jsonencode(local.stack)
} and it'll create the routes and auth rule, that's if you don't mind creating cloudformation stacks. |
The local-exec step does the same thing as the above and is much simpler to maintain. The day I start using CloudFormations again is the day AWS invents a CloudFormation template to stop Werner Vogels from sweating like a pig on the stage of AWS reInvent. |
@MartiUK you da real mvp |
+1 |
When? |
@slapula update please?? |
Might have to use a ec2 instance with openvpn instead... Probably be cheaper as well. |
+1 |
Hi all, I see that this issue is still interesting for many. You can use local exec blocks to bypass the missing terraform components by using aws cli commands. Here is a example for you which works actually fine for me: resource "null_resource" "client-vpn_ingress" { For more informations about this commands read the docu. |
@donsamiro The main issue I see with running Additionally, depending on how you're authenticating when running Terraform, the credentials used for the main Terraform thread might not be available on the It's a good suggestion though! It's definitely not nothing, and it will be useful for some use cases. |
I'd also point out that the local-exec workarounds will break in tf 13 due to non-self resource references in the destroy provisioner: https://github.com/hashicorp/terraform/blob/master/CHANGELOG.md |
I found @MartiUK 's solution to be the best until there's official resources. I have it working in terraform12. It allows me to use aws providers with assume-role and not have to deal with how to get the permissions set on the AWS CLI for an MFA'd assume-role. It works beautifully for create/update/destroy with clean plan output. I feel like it can easily be adapted to first-class resources using the same data structure in the future. I can't wait for first-class resources to finish out AWS VPN IaC but this pattern is beautiful and I may use it for other resources not yet available in Terraform. |
Agreed! I ended up not going in that direction though, but for unrelated reasons. I haven't seen that pattern anywhere else and it's great (although certainly with some complexity), and @MartiUK if you have any publishing outlet like Medium or a personal/company blog, I would very much encourage you to make a post about it. One thing to keep in mind though, is that it may make it harder to transition away from using Just a thought! |
This has been released in version 2.70.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks! |
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! |
Community Note
Description
This request asks for the ability to automate the set up of ingress authorisation for a Client VPN endpoint.
The recently added Client VPN support creates the endpoint but does not go so far as to allow automation of the authorisation rules to grant the client access to areas of the network. Authorisation for Client VPN is described in the AWS Client VPN Authorisation Rules documentation.
New or Affected Resource(s)
This relates to the aws_ec2_client_vpn_endpoint resource, recently added to 1.58.0 by @slapula under #7009.
References
The text was updated successfully, but these errors were encountered: