Skip to content

Commit

Permalink
Merge pull request #22931 from hashicorp/td-empty-valid-routes
Browse files Browse the repository at this point in the history
ec2/routes: Remove empty validation
  • Loading branch information
YakDriver authored Feb 4, 2022
2 parents 43f48aa + 8f81458 commit 366e17e
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 62 deletions.
11 changes: 11 additions & 0 deletions .changelog/22931.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:breaking-change
resource/aws_route_table: These arguments can no longer be set to `""`: `route.*.cidr_block`, `route.*.ipv6_cidr_block`
```

```release-note:breaking-change
resource/aws_default_route_table: These arguments can no longer be set to `""`: `route.*.cidr_block`, `route.*.ipv6_cidr_block`
```

```release-note:breaking-change
resource/aws_route: Exactly one of these can be set: `destination_cidr_block`, `destination_ipv6_cidr_block`, `destination_prefix_list_id`. These arguments can no longer be set to `""`: `destination_cidr_block`, `destination_ipv6_cidr_block`.
```
19 changes: 6 additions & 13 deletions internal/service/ec2/default_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
Expand Down Expand Up @@ -70,24 +69,18 @@ func ResourceDefaultRouteTable() *schema.Resource {
// Destinations.
///
"cidr_block": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.Any(
validation.StringIsEmpty,
verify.ValidIPv4CIDRNetworkAddress,
),
Type: schema.TypeString,
Optional: true,
ValidateFunc: verify.ValidIPv4CIDRNetworkAddress,
},
"destination_prefix_list_id": {
Type: schema.TypeString,
Optional: true,
},
"ipv6_cidr_block": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.Any(
validation.StringIsEmpty,
verify.ValidIPv6CIDRNetworkAddress,
),
Type: schema.TypeString,
Optional: true,
ValidateFunc: verify.ValidIPv6CIDRNetworkAddress,
},

//
Expand Down
12 changes: 10 additions & 2 deletions internal/service/ec2/default_route_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ func TestAccEC2DefaultRouteTable_swap(t *testing.T) {
}

func TestAccEC2DefaultRouteTable_ipv4ToTransitGateway(t *testing.T) {
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var routeTable ec2.RouteTable
resourceName := "aws_default_route_table.test"
tgwResourceName := "aws_ec2_transit_gateway.test"
Expand Down Expand Up @@ -256,6 +260,10 @@ func TestAccEC2DefaultRouteTable_ipv4ToTransitGateway(t *testing.T) {
}

func TestAccEC2DefaultRouteTable_ipv4ToVPCEndpoint(t *testing.T) {
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var routeTable ec2.RouteTable
resourceName := "aws_default_route_table.test"
vpceResourceName := "aws_vpc_endpoint.test"
Expand Down Expand Up @@ -1034,8 +1042,8 @@ resource "aws_default_route_table" "test" {
default_route_table_id = aws_vpc.test.default_route_table_id
route {
cidr_block = local.ipv6 ? "" : local.destination
ipv6_cidr_block = local.ipv6 ? local.destination_ipv6 : ""
cidr_block = local.ipv6 ? null : local.destination
ipv6_cidr_block = local.ipv6 ? local.destination_ipv6 : null
gateway_id = aws_internet_gateway.test.id
}
Expand Down
32 changes: 14 additions & 18 deletions internal/service/ec2/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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 Down Expand Up @@ -62,28 +61,25 @@ func ResourceRoute() *schema.Resource {
// Destinations.
///
"destination_cidr_block": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.Any(
validation.StringIsEmpty,
verify.ValidIPv4CIDRNetworkAddress,
),
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidIPv4CIDRNetworkAddress,
ExactlyOneOf: []string{"destination_cidr_block", "destination_ipv6_cidr_block", "destination_prefix_list_id"},
},
"destination_ipv6_cidr_block": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.Any(
validation.StringIsEmpty,
verify.ValidIPv6CIDRNetworkAddress,
),
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidIPv6CIDRNetworkAddress,
DiffSuppressFunc: suppressEqualCIDRBlockDiffs,
ExactlyOneOf: []string{"destination_cidr_block", "destination_ipv6_cidr_block", "destination_prefix_list_id"},
},
"destination_prefix_list_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ExactlyOneOf: []string{"destination_cidr_block", "destination_ipv6_cidr_block", "destination_prefix_list_id"},
},

//
Expand Down
4 changes: 4 additions & 0 deletions internal/service/ec2/route_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func TestAccEC2RouteDataSource_basic(t *testing.T) {
}

func TestAccEC2RouteDataSource_transitGatewayID(t *testing.T) {
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

dataSourceName := "data.aws_route.test"
resourceName := "aws_route.test"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
Expand Down
19 changes: 6 additions & 13 deletions internal/service/ec2/route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ 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/create"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
Expand Down Expand Up @@ -85,24 +84,18 @@ func ResourceRouteTable() *schema.Resource {
// Destinations.
///
"cidr_block": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.Any(
validation.StringIsEmpty,
verify.ValidIPv4CIDRNetworkAddress,
),
Type: schema.TypeString,
Optional: true,
ValidateFunc: verify.ValidIPv4CIDRNetworkAddress,
},
"destination_prefix_list_id": {
Type: schema.TypeString,
Optional: true,
},
"ipv6_cidr_block": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.Any(
validation.StringIsEmpty,
verify.ValidIPv6CIDRNetworkAddress,
),
Type: schema.TypeString,
Optional: true,
ValidateFunc: verify.ValidIPv6CIDRNetworkAddress,
},

//
Expand Down
16 changes: 14 additions & 2 deletions internal/service/ec2/route_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ func TestAccEC2RouteTable_tags(t *testing.T) {
}

func TestAccEC2RouteTable_requireRouteDestination(t *testing.T) {
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -382,6 +386,10 @@ func TestAccEC2RouteTable_Route_mode(t *testing.T) {
}

func TestAccEC2RouteTable_ipv4ToTransitGateway(t *testing.T) {
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var routeTable ec2.RouteTable
resourceName := "aws_route_table.test"
tgwResourceName := "aws_ec2_transit_gateway.test"
Expand Down Expand Up @@ -418,6 +426,10 @@ func TestAccEC2RouteTable_ipv4ToTransitGateway(t *testing.T) {
}

func TestAccEC2RouteTable_ipv4ToVPCEndpoint(t *testing.T) {
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var routeTable ec2.RouteTable
resourceName := "aws_route_table.test"
vpceResourceName := "aws_vpc_endpoint.test"
Expand Down Expand Up @@ -1842,8 +1854,8 @@ resource "aws_route_table" "test" {
vpc_id = aws_vpc.test.id
route {
cidr_block = local.ipv6 ? "" : local.destination
ipv6_cidr_block = local.ipv6 ? local.destination_ipv6 : ""
cidr_block = local.ipv6 ? null : local.destination
ipv6_cidr_block = local.ipv6 ? local.destination_ipv6 : null
gateway_id = aws_internet_gateway.test.id
}
Expand Down
28 changes: 26 additions & 2 deletions internal/service/ec2/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,10 @@ func TestAccEC2Route_doesNotCrashWithVPCEndpoint(t *testing.T) {
}

func TestAccEC2Route_ipv4ToTransitGateway(t *testing.T) {
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var route ec2.Route
resourceName := "aws_route.test"
tgwResourceName := "aws_ec2_transit_gateway.test"
Expand Down Expand Up @@ -806,6 +810,10 @@ func TestAccEC2Route_ipv4ToTransitGateway(t *testing.T) {
}

func TestAccEC2Route_ipv6ToTransitGateway(t *testing.T) {
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var route ec2.Route
resourceName := "aws_route.test"
tgwResourceName := "aws_ec2_transit_gateway.test"
Expand Down Expand Up @@ -1025,6 +1033,10 @@ func TestAccEC2Route_conditionalCIDRBlock(t *testing.T) {
}

func TestAccEC2Route_IPv4Update_target(t *testing.T) {
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var route ec2.Route
resourceName := "aws_route.test"
vgwResourceName := "aws_vpn_gateway.test"
Expand Down Expand Up @@ -1232,6 +1244,10 @@ func TestAccEC2Route_IPv4Update_target(t *testing.T) {
}

func TestAccEC2Route_IPv6Update_target(t *testing.T) {
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var route ec2.Route
resourceName := "aws_route.test"
vgwResourceName := "aws_vpn_gateway.test"
Expand Down Expand Up @@ -1392,6 +1408,10 @@ func TestAccEC2Route_IPv6Update_target(t *testing.T) {
}

func TestAccEC2Route_ipv4ToVPCEndpoint(t *testing.T) {
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var route ec2.Route
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_route.test"
Expand Down Expand Up @@ -1793,6 +1813,10 @@ func TestAccEC2Route_prefixListToNatGateway(t *testing.T) {
}

func TestAccEC2Route_prefixListToTransitGateway(t *testing.T) {
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var route ec2.Route
resourceName := "aws_route.test"
tgwResourceName := "aws_ec2_transit_gateway.test"
Expand Down Expand Up @@ -2514,8 +2538,8 @@ resource "aws_route" "test" {
route_table_id = aws_route_table.test.id
gateway_id = aws_internet_gateway.test.id
destination_cidr_block = local.ipv6 ? "" : local.destination
destination_ipv6_cidr_block = local.ipv6 ? local.destination_ipv6 : ""
destination_cidr_block = local.ipv6 ? null : local.destination
destination_ipv6_cidr_block = local.ipv6 ? local.destination_ipv6 : null
}
`, rName, destinationCidr, destinationIpv6Cidr, ipv6Route)
}
Expand Down
Loading

0 comments on commit 366e17e

Please sign in to comment.