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

Change parameter to optional and add test #27693

Merged
merged 3 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .changelog/27693.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_vpn_connection: Configuring exactly one of `transit_gateway_id` or `vpn_gateway_id` is not required
```
12 changes: 6 additions & 6 deletions internal/service/ec2/vpnsite_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ func ResourceVPNConnection() *schema.Resource {
Computed: true,
},
"transit_gateway_id": {
Type: schema.TypeString,
Optional: true,
ExactlyOneOf: []string{"transit_gateway_id", "vpn_gateway_id"},
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"vpn_gateway_id"},
},
"transport_transit_gateway_attachment_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -608,9 +608,9 @@ func ResourceVPNConnection() *schema.Resource {
},
},
"vpn_gateway_id": {
Type: schema.TypeString,
Optional: true,
ExactlyOneOf: []string{"transit_gateway_id", "vpn_gateway_id"},
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"transit_gateway_id"},
},
},

Expand Down
112 changes: 112 additions & 0 deletions internal/service/ec2/vpnsite_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,99 @@ func TestAccSiteVPNConnection_basic(t *testing.T) {
})
}

func TestAccSiteVPNConnection_withoutTGWorVGW(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
rBgpAsn := sdkacctest.RandIntRange(64512, 65534)
resourceName := "aws_vpn_connection.test"
var vpn ec2.VpnConnection

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccVPNConnectionDestroy,
Steps: []resource.TestStep{
{
Config: testAccSiteVPNConnectionConfig_withoutTGWorVGW(rName, rBgpAsn),
Check: resource.ComposeAggregateTestCheckFunc(
testAccVPNConnectionExists(resourceName, &vpn),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "ec2", regexp.MustCompile(`vpn-connection/vpn-.+`)),
resource.TestCheckResourceAttr(resourceName, "core_network_arn", ""),
resource.TestCheckResourceAttr(resourceName, "core_network_attachment_arn", ""),
resource.TestCheckResourceAttrSet(resourceName, "customer_gateway_configuration"),
resource.TestCheckResourceAttr(resourceName, "enable_acceleration", "false"),
resource.TestCheckResourceAttr(resourceName, "local_ipv4_network_cidr", "0.0.0.0/0"),
resource.TestCheckResourceAttr(resourceName, "local_ipv6_network_cidr", ""),
resource.TestCheckResourceAttr(resourceName, "outside_ip_address_type", "PublicIpv4"),
resource.TestCheckResourceAttr(resourceName, "remote_ipv4_network_cidr", "0.0.0.0/0"),
resource.TestCheckResourceAttr(resourceName, "remote_ipv6_network_cidr", ""),
resource.TestCheckResourceAttr(resourceName, "routes.#", "0"),
resource.TestCheckResourceAttr(resourceName, "static_routes_only", "false"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "transit_gateway_attachment_id", ""),
resource.TestCheckResourceAttrSet(resourceName, "tunnel1_address"),
resource.TestCheckResourceAttr(resourceName, "tunnel1_bgp_holdtime", "30"),
resource.TestCheckResourceAttrSet(resourceName, "tunnel1_cgw_inside_address"),
resource.TestCheckResourceAttr(resourceName, "tunnel1_dpd_timeout_action", ""),
resource.TestCheckResourceAttr(resourceName, "tunnel1_dpd_timeout_seconds", "0"),
resource.TestCheckNoResourceAttr(resourceName, "tunnel1_ike_versions"),
resource.TestCheckResourceAttrSet(resourceName, "tunnel1_inside_cidr"),
resource.TestCheckResourceAttr(resourceName, "tunnel1_inside_ipv6_cidr", ""),
resource.TestCheckResourceAttr(resourceName, "tunnel1_log_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "tunnel1_log_options.0.cloudwatch_log_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "tunnel1_log_options.0.cloudwatch_log_options.0.log_enabled", "false"),
resource.TestCheckNoResourceAttr(resourceName, "tunnel1_phase1_dh_group_numbers"),
resource.TestCheckNoResourceAttr(resourceName, "tunnel1_phase1_encryption_algorithms"),
resource.TestCheckNoResourceAttr(resourceName, "tunnel1_phase1_integrity_algorithms"),
resource.TestCheckResourceAttr(resourceName, "tunnel1_phase1_lifetime_seconds", "0"),
resource.TestCheckNoResourceAttr(resourceName, "tunnel1_phase2_dh_group_numbers"),
resource.TestCheckNoResourceAttr(resourceName, "tunnel1_phase2_encryption_algorithms"),
resource.TestCheckNoResourceAttr(resourceName, "tunnel1_phase2_integrity_algorithms"),
resource.TestCheckResourceAttr(resourceName, "tunnel1_phase2_lifetime_seconds", "0"),
resource.TestCheckResourceAttrSet(resourceName, "tunnel1_preshared_key"),
resource.TestCheckResourceAttr(resourceName, "tunnel1_rekey_fuzz_percentage", "0"),
resource.TestCheckResourceAttr(resourceName, "tunnel1_rekey_margin_time_seconds", "0"),
resource.TestCheckResourceAttr(resourceName, "tunnel1_replay_window_size", "0"),
resource.TestCheckResourceAttr(resourceName, "tunnel1_startup_action", ""),
resource.TestCheckResourceAttrSet(resourceName, "tunnel1_vgw_inside_address"),
resource.TestCheckResourceAttrSet(resourceName, "tunnel2_address"),
resource.TestCheckResourceAttr(resourceName, "tunnel2_bgp_holdtime", "30"),
resource.TestCheckResourceAttrSet(resourceName, "tunnel2_cgw_inside_address"),
resource.TestCheckResourceAttr(resourceName, "tunnel2_dpd_timeout_action", ""),
resource.TestCheckResourceAttr(resourceName, "tunnel2_dpd_timeout_seconds", "0"),
resource.TestCheckNoResourceAttr(resourceName, "tunnel2_ike_versions"),
resource.TestCheckResourceAttrSet(resourceName, "tunnel2_inside_cidr"),
resource.TestCheckResourceAttr(resourceName, "tunnel2_inside_ipv6_cidr", ""),
resource.TestCheckResourceAttr(resourceName, "tunnel2_log_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "tunnel2_log_options.0.cloudwatch_log_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "tunnel2_log_options.0.cloudwatch_log_options.0.log_enabled", "false"),
resource.TestCheckNoResourceAttr(resourceName, "tunnel2_phase1_dh_group_numbers"),
resource.TestCheckNoResourceAttr(resourceName, "tunnel2_phase1_encryption_algorithms"),
resource.TestCheckNoResourceAttr(resourceName, "tunnel2_phase1_integrity_algorithms"),
resource.TestCheckResourceAttr(resourceName, "tunnel2_phase1_lifetime_seconds", "0"),
resource.TestCheckNoResourceAttr(resourceName, "tunnel2_phase2_dh_group_numbers"),
resource.TestCheckNoResourceAttr(resourceName, "tunnel2_phase2_encryption_algorithms"),
resource.TestCheckNoResourceAttr(resourceName, "tunnel2_phase2_integrity_algorithms"),
resource.TestCheckResourceAttr(resourceName, "tunnel2_phase2_lifetime_seconds", "0"),
resource.TestCheckResourceAttrSet(resourceName, "tunnel2_preshared_key"),
resource.TestCheckResourceAttr(resourceName, "tunnel2_rekey_fuzz_percentage", "0"),
resource.TestCheckResourceAttr(resourceName, "tunnel2_rekey_margin_time_seconds", "0"),
resource.TestCheckResourceAttr(resourceName, "tunnel2_replay_window_size", "0"),
resource.TestCheckResourceAttr(resourceName, "tunnel2_startup_action", ""),
resource.TestCheckResourceAttrSet(resourceName, "tunnel2_vgw_inside_address"),
resource.TestCheckResourceAttr(resourceName, "tunnel_inside_ip_version", "ipv4"),
resource.TestCheckResourceAttr(resourceName, "vgw_telemetry.#", "2"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccSiteVPNConnection_cloudWatchLogOptions(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
rBgpAsn := sdkacctest.RandIntRange(64512, 65534)
Expand Down Expand Up @@ -1626,6 +1719,25 @@ resource "aws_vpn_connection" "test" {
`, rName, rBgpAsn)
}

func testAccSiteVPNConnectionConfig_withoutTGWorVGW(rName string, rBgpAsn int) string {
return fmt.Sprintf(`
resource "aws_customer_gateway" "test" {
bgp_asn = %[2]d
ip_address = "178.0.0.1"
type = "ipsec.1"

tags = {
Name = %[1]q
}
}

resource "aws_vpn_connection" "test" {
customer_gateway_id = aws_customer_gateway.test.id
type = "ipsec.1"
}
`, rName, rBgpAsn)
}

func testAccSiteVPNConnectionConfig_cloudWatchLogOptions(rName string, rBgpAsn int) string {
return fmt.Sprintf(`
resource "aws_vpn_gateway" "test" {
Expand Down
8 changes: 1 addition & 7 deletions website/docs/r/vpn_connection.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,12 @@ resource "aws_vpn_connection" "example" {

## Argument Reference

The following arguments are required:
The following arguments are supported:

* `customer_gateway_id` - (Required) The ID of the customer gateway.
* `type` - (Required) The type of VPN connection. The only type AWS supports at this time is "ipsec.1".

One of the following arguments is required:

* `transit_gateway_id` - (Optional) The ID of the EC2 Transit Gateway.
* `vpn_gateway_id` - (Optional) The ID of the Virtual Private Gateway.

Other arguments:

* `static_routes_only` - (Optional, Default `false`) Whether the VPN connection uses static routes exclusively. Static routes must be used for devices that don't support BGP.
* `enable_acceleration` - (Optional, Default `false`) Indicate whether to enable acceleration for the VPN connection. Supports only EC2 Transit Gateway.
* `tags` - (Optional) Tags to apply to the connection. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.
Expand Down