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/aws_ec2_client_vpn_network_association: Deprecate security_groups; r/aws_ec2_client_vpn_endpoint: Add security_group_ids and vpc_id #22911

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5c8cba5
Add 'testAccClientVPNNetworkAssociation_multipleSubnetsWithSecurityGr…
ewbankkit Feb 2, 2022
282918e
Correct test for 'ErrCodeInvalidClientVpnAssociationIdNotFound'.
ewbankkit Feb 2, 2022
1a551b8
r/aws_ec2_client_vpn_network_association: Deprecate the 'security_gro…
ewbankkit Feb 2, 2022
7dbca77
Revert "Add 'testAccClientVPNNetworkAssociation_multipleSubnetsWithSe…
ewbankkit Feb 2, 2022
9eed22b
Standardize resource names in acceptance test case.
ewbankkit Feb 2, 2022
64db47a
r/aws_ec2_client_vpn_security_groups_association: New resource.
ewbankkit Feb 2, 2022
d38242a
Correct new resource name.
ewbankkit Feb 2, 2022
699d84b
r/aws_ec2_client_vpn_security_groups_association: Implementation.
ewbankkit Feb 2, 2022
f4b0ec3
Revert "r/aws_ec2_client_vpn_security_groups_association: Implementat…
ewbankkit Feb 2, 2022
43f4584
Revert "Correct new resource name."
ewbankkit Feb 2, 2022
6a4e0ff
Revert "r/aws_ec2_client_vpn_security_groups_association: New resource."
ewbankkit Feb 2, 2022
31f1aca
r/aws_ec2_client_vpn_network_association: Use new 'security_group_ids…
ewbankkit Feb 2, 2022
35e8f70
r/aws_ec2_client_vpn_endpoint: Add 'security_group_ids' and 'vpc_id' …
ewbankkit Feb 2, 2022
4b89496
d/aws_ec2_client_vpn_endpoint: Add 'security_group_ids' and 'vpc_id' …
ewbankkit Feb 2, 2022
54fa458
'testAccEc2ClientVpnEndpointMsADBase' -> 'testAccEc2ClientVpnEndpoint…
ewbankkit Feb 2, 2022
539f328
Add 'testAccClientVPNEndpoint_vpcNoSecurityGroups'.
ewbankkit Feb 2, 2022
7123c34
Correct CHANGELOG file name.
ewbankkit Feb 2, 2022
5b90500
Add 'testAccClientVPNEndpoint_vpcSecurityGroups'.
ewbankkit Feb 2, 2022
8c8fa95
Fix terrafmt error.
ewbankkit Feb 2, 2022
4365e8a
Standardize configuration generation function names in acceptance tests.
ewbankkit Feb 3, 2022
cd8ed96
Add 'testAccClientVPNNetworkAssociation_securityGroupsOnEndpoint'.
ewbankkit Feb 3, 2022
734ff73
r/aws_ec2_client_vpn_route: Alphabetize attributes.
ewbankkit Feb 3, 2022
c5c42e2
Rename client VPN route resource ID generate and parse functions.
ewbankkit Feb 3, 2022
78ec2d6
r/aws_ec2_client_vpn_route: Tidy up resource Create and Delete.
ewbankkit Feb 3, 2022
ecdd813
r/aws_ec2_client_vpn_route: Tidy up resource Read.
ewbankkit Feb 3, 2022
f7a0837
r/aws_ec2_client_vpn_route: Tidy up acceptance tests.
ewbankkit Feb 3, 2022
30367c8
r/aws_ec2_client_vpn_route: Add custom 'timeouts' block.
ewbankkit Feb 3, 2022
23d18cf
r/aws_ec2_client_vpn_route: Retry route creation when 'InvalidClientV…
ewbankkit Feb 3, 2022
9150caa
r/aws_ec2_client_vpn_route: Retry route creation and deletion when 'C…
ewbankkit Feb 3, 2022
c5d156f
Acceptance test output:
ewbankkit Feb 3, 2022
5685620
r/aws_ec2_client_vpn_authorization_rule: No ','s allowed in 'access_g…
ewbankkit Feb 3, 2022
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
15 changes: 15 additions & 0 deletions .changelog/22911.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```release-note:note
resource/aws_ec2_client_vpn_network_association: The `security_groups` argument has been deprecated. Use the `security_group_ids` argument of the `aws_ec2_client_vpn_endpoint` resource instead
```

```release-note:enhancement
resource/aws_ec2_client_vpn_endpoint: Add `security_group_ids` and `vpc_id` arguments
```

```release-note:enhancement
data-source/aws_ec2_client_vpn_endpoint: Add `security_group_ids` and `vpc_id` attributes
```

```release-note:note
resource/aws_ec2_client_vpn_route: Add [custom `timeouts`](https://www.terraform.io/docs/language/resources/syntax.html#operation-timeouts) block
```
25 changes: 14 additions & 11 deletions internal/conns/conns.go
Original file line number Diff line number Diff line change
Expand Up @@ -1718,26 +1718,29 @@ func (c *Config) Client() (interface{}, error) {
})

client.EC2Conn.Handlers.Retry.PushBack(func(r *request.Request) {
if r.Operation.Name == "CreateClientVpnEndpoint" {
if tfawserr.ErrMessageContains(r.Error, "OperationNotPermitted", "Endpoint cannot be created while another endpoint is being created") {
switch err := r.Error; r.Operation.Name {
case "AttachVpnGateway", "DetachVpnGateway":
if tfawserr.ErrMessageContains(err, "InvalidParameterValue", "This call cannot be completed because there are pending VPNs or Virtual Interfaces") {
r.Retryable = aws.Bool(true)
}
}

if r.Operation.Name == "CreateVpnConnection" {
if tfawserr.ErrMessageContains(r.Error, "VpnConnectionLimitExceeded", "maximum number of mutating objects has been reached") {
case "CreateClientVpnEndpoint":
if tfawserr.ErrMessageContains(err, "OperationNotPermitted", "Endpoint cannot be created while another endpoint is being created") {
r.Retryable = aws.Bool(true)
}
}

if r.Operation.Name == "CreateVpnGateway" {
if tfawserr.ErrMessageContains(r.Error, "VpnGatewayLimitExceeded", "maximum number of mutating objects has been reached") {
case "CreateClientVpnRoute", "DeleteClientVpnRoute":
if tfawserr.ErrMessageContains(err, "ConcurrentMutationLimitExceeded", "Cannot initiate another change for this endpoint at this time") {
r.Retryable = aws.Bool(true)
}

case "CreateVpnConnection":
if tfawserr.ErrMessageContains(err, "VpnConnectionLimitExceeded", "maximum number of mutating objects has been reached") {
r.Retryable = aws.Bool(true)
}
}

if r.Operation.Name == "AttachVpnGateway" || r.Operation.Name == "DetachVpnGateway" {
if tfawserr.ErrMessageContains(r.Error, "InvalidParameterValue", "This call cannot be completed because there are pending VPNs or Virtual Interfaces") {
case "CreateVpnGateway":
if tfawserr.ErrMessageContains(err, "VpnGatewayLimitExceeded", "maximum number of mutating objects has been reached") {
r.Retryable = aws.Bool(true)
}
}
Expand Down
2 changes: 2 additions & 0 deletions internal/service/ec2/client_vpn_authorization_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
Expand All @@ -33,6 +34,7 @@ func ResourceClientVPNAuthorizationRule() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringDoesNotContainAny(","),
ExactlyOneOf: []string{"access_group_id", "authorize_all_groups"},
},
"authorize_all_groups": {
Expand Down
33 changes: 33 additions & 0 deletions internal/service/ec2/client_vpn_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ func ResourceClientVPNEndpoint() *schema.Resource {
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"security_group_ids": {
Type: schema.TypeSet,
MinItems: 1,
MaxItems: 5,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"self_service_portal": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -192,6 +200,11 @@ func ResourceClientVPNEndpoint() *schema.Resource {
Default: ec2.TransportProtocolUdp,
ValidateFunc: validation.StringInSlice(ec2.TransportProtocol_Values(), false),
},
"vpc_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"vpn_port": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -243,6 +256,10 @@ func resourceClientVPNEndpointCreate(d *schema.ResourceData, meta interface{}) e
input.DnsServers = flex.ExpandStringList(v.([]interface{}))
}

if v, ok := d.GetOk("security_group_ids"); ok {
input.SecurityGroupIds = flex.ExpandStringSet(v.(*schema.Set))
}

if v, ok := d.GetOk("self_service_portal"); ok {
input.SelfServicePortal = aws.String(v.(string))
}
Expand All @@ -251,6 +268,10 @@ func resourceClientVPNEndpointCreate(d *schema.ResourceData, meta interface{}) e
input.SessionTimeoutHours = aws.Int64(int64(v.(int)))
}

if v, ok := d.GetOk("vpc_id"); ok {
input.VpcId = aws.String(v.(string))
}

log.Printf("[DEBUG] Creating EC2 Client VPN Endpoint: %s", input)
output, err := conn.CreateClientVpnEndpoint(input)

Expand Down Expand Up @@ -316,6 +337,7 @@ func resourceClientVPNEndpointRead(d *schema.ResourceData, meta interface{}) err
d.Set("description", ep.Description)
d.Set("dns_name", ep.DnsName)
d.Set("dns_servers", aws.StringValueSlice(ep.DnsServers))
d.Set("security_group_ids", aws.StringValueSlice(ep.SecurityGroupIds))
if aws.StringValue(ep.SelfServicePortalUrl) != "" {
d.Set("self_service_portal", ec2.SelfServicePortalEnabled)
} else {
Expand All @@ -326,6 +348,7 @@ func resourceClientVPNEndpointRead(d *schema.ResourceData, meta interface{}) err
d.Set("split_tunnel", ep.SplitTunnel)
d.Set("status", ep.Status.Code)
d.Set("transport_protocol", ep.TransportProtocol)
d.Set("vpc_id", ep.VpcId)
d.Set("vpn_port", ep.VpnPort)

tags := KeyValueTags(ep.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig)
Expand Down Expand Up @@ -387,6 +410,12 @@ func resourceClientVPNEndpointUpdate(d *schema.ResourceData, meta interface{}) e
}
}

if d.HasChange("security_group_ids") {
input.SecurityGroupIds = flex.ExpandStringSet(d.Get("security_group_ids").(*schema.Set))
// "InvalidParameterValue: Security Groups cannot be modified without specifying Vpc Id"
input.VpcId = aws.String(d.Get("vpc_id").(string))
}

if d.HasChange("self_service_portal") {
input.SelfServicePortal = aws.String(d.Get("self_service_portal").(string))
}
Expand All @@ -407,6 +436,10 @@ func resourceClientVPNEndpointUpdate(d *schema.ResourceData, meta interface{}) e
input.VpnPort = aws.Int64(int64(d.Get("vpn_port").(int)))
}

if d.HasChange("vpc_id") {
input.VpcId = aws.String(d.Get("vpc_id").(string))
}

if _, err := conn.ModifyClientVpnEndpoint(input); err != nil {
return fmt.Errorf("error modifying EC2 Client VPN Endpoint (%s): %w", d.Id(), err)
}
Expand Down
13 changes: 12 additions & 1 deletion internal/service/ec2/client_vpn_endpoint_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,16 @@ func DataSourceClientVPNEndpoint() *schema.Resource {
Computed: true,
},
"dns_servers": {
Type: schema.TypeSet,
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"filter": DataSourceFiltersSchema(),
"security_group_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"self_service_portal": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -145,6 +150,10 @@ func DataSourceClientVPNEndpoint() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"vpc_id": {
Type: schema.TypeString,
Computed: true,
},
"vpn_port": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -219,6 +228,7 @@ func dataSourceClientVPNEndpointRead(d *schema.ResourceData, meta interface{}) e
d.Set("description", ep.Description)
d.Set("dns_name", ep.DnsName)
d.Set("dns_servers", aws.StringValueSlice(ep.DnsServers))
d.Set("security_group_ids", aws.StringValueSlice(ep.SecurityGroupIds))
if aws.StringValue(ep.SelfServicePortalUrl) != "" {
d.Set("self_service_portal", ec2.SelfServicePortalEnabled)
} else {
Expand All @@ -228,6 +238,7 @@ func dataSourceClientVPNEndpointRead(d *schema.ResourceData, meta interface{}) e
d.Set("session_timeout_hours", ep.SessionTimeoutHours)
d.Set("split_tunnel", ep.SplitTunnel)
d.Set("transport_protocol", ep.TransportProtocol)
d.Set("vpc_id", ep.VpcId)
d.Set("vpn_port", ep.VpnPort)

if err := d.Set("tags", KeyValueTags(ep.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ func testAccClientVPNEndpointDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttrPair(datasource1Name, "description", resourceName, "description"),
resource.TestCheckResourceAttrPair(datasource1Name, "dns_name", resourceName, "dns_name"),
resource.TestCheckResourceAttrPair(datasource1Name, "dns_servers.#", resourceName, "dns_servers.#"),
resource.TestCheckResourceAttrPair(datasource1Name, "security_group_ids.#", resourceName, "security_group_ids.#"),
resource.TestCheckResourceAttrPair(datasource1Name, "self_service_portal", resourceName, "self_service_portal"),
resource.TestCheckResourceAttrPair(datasource1Name, "server_certificate_arn", resourceName, "server_certificate_arn"),
resource.TestCheckResourceAttrPair(datasource1Name, "session_timeout_hours", resourceName, "session_timeout_hours"),
resource.TestCheckResourceAttrPair(datasource1Name, "split_tunnel", resourceName, "split_tunnel"),
resource.TestCheckResourceAttrPair(datasource1Name, "tags.%", resourceName, "tags.%"),
resource.TestCheckResourceAttrPair(datasource1Name, "transport_protocol", resourceName, "transport_protocol"),
resource.TestCheckResourceAttrPair(datasource1Name, "vpc_id", resourceName, "vpc_id"),
resource.TestCheckResourceAttrPair(datasource1Name, "vpn_port", resourceName, "vpn_port"),

resource.TestCheckResourceAttrPair(datasource2Name, "arn", resourceName, "arn"),
Expand All @@ -53,12 +55,14 @@ func testAccClientVPNEndpointDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttrPair(datasource2Name, "description", resourceName, "description"),
resource.TestCheckResourceAttrPair(datasource2Name, "dns_name", resourceName, "dns_name"),
resource.TestCheckResourceAttrPair(datasource2Name, "dns_servers.#", resourceName, "dns_servers.#"),
resource.TestCheckResourceAttrPair(datasource2Name, "security_group_ids.#", resourceName, "security_group_ids.#"),
resource.TestCheckResourceAttrPair(datasource2Name, "self_service_portal", resourceName, "self_service_portal"),
resource.TestCheckResourceAttrPair(datasource2Name, "server_certificate_arn", resourceName, "server_certificate_arn"),
resource.TestCheckResourceAttrPair(datasource2Name, "session_timeout_hours", resourceName, "session_timeout_hours"),
resource.TestCheckResourceAttrPair(datasource2Name, "split_tunnel", resourceName, "split_tunnel"),
resource.TestCheckResourceAttrPair(datasource2Name, "tags.%", resourceName, "tags.%"),
resource.TestCheckResourceAttrPair(datasource2Name, "transport_protocol", resourceName, "transport_protocol"),
resource.TestCheckResourceAttrPair(datasource2Name, "vpc_id", resourceName, "vpc_id"),
resource.TestCheckResourceAttrPair(datasource2Name, "vpn_port", resourceName, "vpn_port"),

resource.TestCheckResourceAttrPair(datasource3Name, "arn", resourceName, "arn"),
Expand All @@ -71,12 +75,14 @@ func testAccClientVPNEndpointDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttrPair(datasource3Name, "description", resourceName, "description"),
resource.TestCheckResourceAttrPair(datasource3Name, "dns_name", resourceName, "dns_name"),
resource.TestCheckResourceAttrPair(datasource3Name, "dns_servers.#", resourceName, "dns_servers.#"),
resource.TestCheckResourceAttrPair(datasource3Name, "security_group_ids.#", resourceName, "security_group_ids.#"),
resource.TestCheckResourceAttrPair(datasource3Name, "self_service_portal", resourceName, "self_service_portal"),
resource.TestCheckResourceAttrPair(datasource3Name, "server_certificate_arn", resourceName, "server_certificate_arn"),
resource.TestCheckResourceAttrPair(datasource3Name, "session_timeout_hours", resourceName, "session_timeout_hours"),
resource.TestCheckResourceAttrPair(datasource3Name, "split_tunnel", resourceName, "split_tunnel"),
resource.TestCheckResourceAttrPair(datasource3Name, "tags.%", resourceName, "tags.%"),
resource.TestCheckResourceAttrPair(datasource3Name, "transport_protocol", resourceName, "transport_protocol"),
resource.TestCheckResourceAttrPair(datasource3Name, "vpc_id", resourceName, "vpc_id"),
resource.TestCheckResourceAttrPair(datasource3Name, "vpn_port", resourceName, "vpn_port"),
),
},
Expand Down
Loading