diff --git a/.changelog/16961.txt b/.changelog/16961.txt new file mode 100644 index 00000000000..0d8a128b921 --- /dev/null +++ b/.changelog/16961.txt @@ -0,0 +1,3 @@ +```release-notes:enhancement +resource/aws_route: Add `carrier_gateway_id` attribute +``` diff --git a/aws/internal/service/ec2/finder/finder.go b/aws/internal/service/ec2/finder/finder.go index c1a9fcde62a..168bffab51c 100644 --- a/aws/internal/service/ec2/finder/finder.go +++ b/aws/internal/service/ec2/finder/finder.go @@ -140,6 +140,7 @@ type RouteFinder func(*ec2.EC2, string, string) (*ec2.Route, error) // Returns NotFoundError if no route is found. func RouteByIPv4Destination(conn *ec2.EC2, routeTableID, destinationCidr string) (*ec2.Route, error) { routeTable, err := RouteTableByID(conn, routeTableID) + if err != nil { return nil, err } @@ -157,6 +158,7 @@ func RouteByIPv4Destination(conn *ec2.EC2, routeTableID, destinationCidr string) // Returns NotFoundError if no route is found. func RouteByIPv6Destination(conn *ec2.EC2, routeTableID, destinationIpv6Cidr string) (*ec2.Route, error) { routeTable, err := RouteTableByID(conn, routeTableID) + if err != nil { return nil, err } diff --git a/aws/resource_aws_route.go b/aws/resource_aws_route.go index f319ce3a125..b5eaaecde79 100644 --- a/aws/resource_aws_route.go +++ b/aws/resource_aws_route.go @@ -23,6 +23,7 @@ var routeValidDestinations = []string{ } var routeValidTargets = []string{ + "carrier_gateway_id", "egress_only_gateway_id", "gateway_id", "instance_id", @@ -89,6 +90,13 @@ func resourceAwsRoute() *schema.Resource { // // Targets. // + "carrier_gateway_id": { + Type: schema.TypeString, + Optional: true, + ExactlyOneOf: routeValidTargets, + ConflictsWith: []string{"destination_ipv6_cidr_block"}, // IPv4 destinations only. + }, + "egress_only_gateway_id": { Type: schema.TypeString, Optional: true, @@ -203,6 +211,8 @@ func resourceAwsRouteCreate(d *schema.ResourceData, meta interface{}) error { } switch target := aws.String(target); targetAttributeKey { + case "carrier_gateway_id": + input.CarrierGatewayId = target case "egress_only_gateway_id": input.EgressOnlyInternetGatewayId = target case "gateway_id": @@ -317,6 +327,7 @@ func resourceAwsRouteRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("error reading Route for Route Table (%s) with destination (%s): %w", routeTableID, destination, err) } + d.Set("carrier_gateway_id", route.CarrierGatewayId) d.Set("destination_cidr_block", route.DestinationCidrBlock) d.Set("destination_ipv6_cidr_block", route.DestinationIpv6CidrBlock) d.Set("destination_prefix_list_id", route.DestinationPrefixListId) @@ -372,6 +383,8 @@ func resourceAwsRouteUpdate(d *schema.ResourceData, meta interface{}) error { } switch target := aws.String(target); targetAttributeKey { + case "carrier_gateway_id": + input.CarrierGatewayId = target case "egress_only_gateway_id": input.EgressOnlyInternetGatewayId = target case "gateway_id": diff --git a/aws/resource_aws_route_test.go b/aws/resource_aws_route_test.go index f9bd8d57937..ae7025293bb 100644 --- a/aws/resource_aws_route_test.go +++ b/aws/resource_aws_route_test.go @@ -35,6 +35,7 @@ func TestAccAWSRoute_basic(t *testing.T) { testAccCheckRouteTableExists(rtResourceName, &routeTable), testAccCheckAWSRouteTableNumberOfRoutes(&routeTable, 2), testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -128,6 +129,7 @@ func TestAccAWSRoute_IPv6_To_EgressOnlyInternetGateway(t *testing.T) { Config: testAccAWSRouteConfigIpv6EgressOnlyInternetGateway(rName, destinationCidr), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -177,6 +179,7 @@ func TestAccAWSRoute_IPv6_To_InternetGateway(t *testing.T) { Config: testAccAWSRouteConfigIpv6InternetGateway(rName, destinationCidr), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -221,6 +224,7 @@ func TestAccAWSRoute_IPv6_To_Instance(t *testing.T) { Config: testAccAWSRouteConfigIpv6Instance(rName, destinationCidr), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -265,6 +269,7 @@ func TestAccAWSRoute_IPv6_To_NetworkInterface_Unattached(t *testing.T) { Config: testAccAWSRouteConfigIpv6NetworkInterfaceUnattached(rName, destinationCidr), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -309,6 +314,7 @@ func TestAccAWSRoute_IPv6_To_VpcPeeringConnection(t *testing.T) { Config: testAccAWSRouteConfigIpv6VpcPeeringConnection(rName, destinationCidr), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -353,6 +359,7 @@ func TestAccAWSRoute_IPv6_To_VpnGateway(t *testing.T) { Config: testAccAWSRouteConfigIpv6VpnGateway(rName, destinationCidr), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -397,6 +404,7 @@ func TestAccAWSRoute_IPv4_To_VpnGateway(t *testing.T) { Config: testAccAWSRouteConfigIpv4VpnGateway(rName, destinationCidr), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -441,6 +449,7 @@ func TestAccAWSRoute_IPv4_To_Instance(t *testing.T) { Config: testAccAWSRouteConfigIpv4Instance(rName, destinationCidr), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -485,6 +494,7 @@ func TestAccAWSRoute_IPv4_To_NetworkInterface_Unattached(t *testing.T) { Config: testAccAWSRouteConfigIpv4NetworkInterfaceUnattached(rName, destinationCidr), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -530,6 +540,7 @@ func TestAccAWSRoute_IPv4_To_NetworkInterface_Attached(t *testing.T) { Config: testAccAWSRouteConfigIpv4NetworkInterfaceAttached(rName, destinationCidr), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -576,6 +587,7 @@ func TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments(t *testing.T) { Config: testAccAWSRouteConfigIpv4NetworkInterfaceTwoAttachments(rName, destinationCidr, eni1ResourceName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -597,6 +609,7 @@ func TestAccAWSRoute_IPv4_To_NetworkInterface_TwoAttachments(t *testing.T) { Config: testAccAWSRouteConfigIpv4NetworkInterfaceTwoAttachments(rName, destinationCidr, eni2ResourceName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -641,6 +654,7 @@ func TestAccAWSRoute_IPv4_To_VpcPeeringConnection(t *testing.T) { Config: testAccAWSRouteConfigIpv4VpcPeeringConnection(rName, destinationCidr), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -685,6 +699,7 @@ func TestAccAWSRoute_IPv4_To_NatGateway(t *testing.T) { Config: testAccAWSRouteConfigIpv4NatGateway(rName, destinationCidr), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -760,6 +775,7 @@ func TestAccAWSRoute_IPv4_To_TransitGateway(t *testing.T) { Config: testAccAWSRouteConfigIpv4TransitGateway(rName, destinationCidr), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -804,6 +820,7 @@ func TestAccAWSRoute_IPv6_To_TransitGateway(t *testing.T) { Config: testAccAWSRouteConfigIpv6TransitGateway(rName, destinationCidr), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -830,6 +847,50 @@ func TestAccAWSRoute_IPv6_To_TransitGateway(t *testing.T) { }, }) } +func TestAccAWSRoute_IPv4_To_CarrierGateway(t *testing.T) { + var route ec2.Route + resourceName := "aws_route.test" + cgwResourceName := "aws_ec2_carrier_gateway.test" + rName := acctest.RandomWithPrefix("tf-acc-test") + destinationCidr := "172.16.1.0/24" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSWavelengthZoneAvailable(t) }, + ErrorCheck: testAccErrorCheck(t, ec2.EndpointsID), + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSRouteDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSRouteConfigIpv4CarrierGateway(rName, destinationCidr), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttrPair(resourceName, "carrier_gateway_id", cgwResourceName, "id"), + resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr), + resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""), + resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), + resource.TestCheckResourceAttr(resourceName, "egress_only_gateway_id", ""), + resource.TestCheckResourceAttr(resourceName, "gateway_id", ""), + resource.TestCheckResourceAttr(resourceName, "instance_id", ""), + resource.TestCheckResourceAttr(resourceName, "instance_owner_id", ""), + resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""), + resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""), + resource.TestCheckResourceAttr(resourceName, "network_interface_id", ""), + resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute), + resource.TestCheckResourceAttr(resourceName, "state", ec2.RouteStateActive), + resource.TestCheckResourceAttr(resourceName, "transit_gateway_id", ""), + resource.TestCheckResourceAttr(resourceName, "vpc_endpoint_id", ""), + resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccAWSRouteImportStateIdFunc(resourceName), + ImportStateVerify: true, + }, + }, + }) +} func TestAccAWSRoute_IPv4_To_LocalGateway(t *testing.T) { var route ec2.Route @@ -848,6 +909,7 @@ func TestAccAWSRoute_IPv4_To_LocalGateway(t *testing.T) { Config: testAccAWSRouteResourceConfigIpv4LocalGateway(rName, destinationCidr), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -892,6 +954,7 @@ func TestAccAWSRoute_IPv6_To_LocalGateway(t *testing.T) { Config: testAccAWSRouteResourceConfigIpv6LocalGateway(rName, destinationCidr), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -982,6 +1045,7 @@ func TestAccAWSRoute_IPv4_Update_Target(t *testing.T) { Config: testAccAWSRouteConfigIpv4FlexiTarget(rName, destinationCidr, "instance_id", instanceResourceName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -1003,6 +1067,7 @@ func TestAccAWSRoute_IPv4_Update_Target(t *testing.T) { Config: testAccAWSRouteConfigIpv4FlexiTarget(rName, destinationCidr, "gateway_id", vgwResourceName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -1024,6 +1089,7 @@ func TestAccAWSRoute_IPv4_Update_Target(t *testing.T) { Config: testAccAWSRouteConfigIpv4FlexiTarget(rName, destinationCidr, "gateway_id", igwResourceName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -1045,6 +1111,7 @@ func TestAccAWSRoute_IPv4_Update_Target(t *testing.T) { Config: testAccAWSRouteConfigIpv4FlexiTarget(rName, destinationCidr, "nat_gateway_id", ngwResourceName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -1066,6 +1133,7 @@ func TestAccAWSRoute_IPv4_Update_Target(t *testing.T) { Config: testAccAWSRouteConfigIpv4FlexiTarget(rName, destinationCidr, "network_interface_id", eniResourceName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -1088,6 +1156,7 @@ func TestAccAWSRoute_IPv4_Update_Target(t *testing.T) { Config: testAccAWSRouteConfigIpv4FlexiTarget(rName, destinationCidr, "transit_gateway_id", tgwResourceName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -1109,6 +1178,7 @@ func TestAccAWSRoute_IPv4_Update_Target(t *testing.T) { Config: testAccAWSRouteConfigIpv4FlexiTarget(rName, destinationCidr, "vpc_endpoint_id", vpcEndpointResourceName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -1130,6 +1200,7 @@ func TestAccAWSRoute_IPv4_Update_Target(t *testing.T) { Config: testAccAWSRouteConfigIpv4FlexiTarget(rName, destinationCidr, "vpc_peering_connection_id", pcxResourceName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -1179,6 +1250,7 @@ func TestAccAWSRoute_IPv6_Update_Target(t *testing.T) { Config: testAccAWSRouteConfigIpv6FlexiTarget(rName, destinationCidr, "instance_id", instanceResourceName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -1200,6 +1272,7 @@ func TestAccAWSRoute_IPv6_Update_Target(t *testing.T) { Config: testAccAWSRouteConfigIpv6FlexiTarget(rName, destinationCidr, "gateway_id", vgwResourceName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -1221,6 +1294,7 @@ func TestAccAWSRoute_IPv6_Update_Target(t *testing.T) { Config: testAccAWSRouteConfigIpv6FlexiTarget(rName, destinationCidr, "gateway_id", igwResourceName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -1242,6 +1316,7 @@ func TestAccAWSRoute_IPv6_Update_Target(t *testing.T) { Config: testAccAWSRouteConfigIpv6FlexiTarget(rName, destinationCidr, "egress_only_gateway_id", eoigwResourceName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -1263,6 +1338,7 @@ func TestAccAWSRoute_IPv6_Update_Target(t *testing.T) { Config: testAccAWSRouteConfigIpv6FlexiTarget(rName, destinationCidr, "network_interface_id", eniResourceName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -1284,6 +1360,7 @@ func TestAccAWSRoute_IPv6_Update_Target(t *testing.T) { Config: testAccAWSRouteConfigIpv6FlexiTarget(rName, destinationCidr, "vpc_peering_connection_id", pcxResourceName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -1328,6 +1405,7 @@ func TestAccAWSRoute_IPv4_To_VpcEndpoint(t *testing.T) { Config: testAccAWSRouteResourceConfigIpv4VpcEndpoint(rName, destinationCidr), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRouteExists(resourceName, &route), + resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""), resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr), resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""), resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""), @@ -2675,6 +2753,7 @@ resource "aws_route" "test" { route_table_id = aws_route_table.test.id destination_cidr_block = %[2]q + carrier_gateway_id = (local.target_attr == "carrier_gateway_id") ? local.target_value : null egress_only_gateway_id = (local.target_attr == "egress_only_gateway_id") ? local.target_value : null gateway_id = (local.target_attr == "gateway_id") ? local.target_value : null instance_id = (local.target_attr == "instance_id") ? local.target_value : null @@ -2796,6 +2875,7 @@ resource "aws_route" "test" { route_table_id = aws_route_table.test.id destination_ipv6_cidr_block = %[2]q + carrier_gateway_id = (local.target_attr == "carrier_gateway_id") ? local.target_value : null egress_only_gateway_id = (local.target_attr == "egress_only_gateway_id") ? local.target_value : null gateway_id = (local.target_attr == "gateway_id") ? local.target_value : null instance_id = (local.target_attr == "instance_id") ? local.target_value : null @@ -2840,3 +2920,37 @@ resource "aws_route" "test" { } `) } + +func testAccAWSRouteConfigIpv4CarrierGateway(rName, destinationCidr string) string { + return fmt.Sprintf(` +resource "aws_vpc" "test" { + cidr_block = "10.1.0.0/16" + + tags = { + Name = %[1]q + } +} + +resource "aws_ec2_carrier_gateway" "test" { + vpc_id = aws_vpc.test.id + + tags = { + Name = %[1]q + } +} + +resource "aws_route_table" "test" { + vpc_id = aws_vpc.test.id + + tags = { + Name = %[1]q + } +} + +resource "aws_route" "test" { + destination_cidr_block = %[2]q + route_table_id = aws_route_table.test.id + carrier_gateway_id = aws_ec2_carrier_gateway.test.id +} +`, rName, destinationCidr) +} diff --git a/website/docs/r/route.html.markdown b/website/docs/r/route.html.markdown index 8d517a674ab..a3fab4fd1a9 100644 --- a/website/docs/r/route.html.markdown +++ b/website/docs/r/route.html.markdown @@ -61,6 +61,7 @@ One of the following destination arguments must be supplied: One of the following target arguments must be supplied: +* `carrier_gateway_id` - (Optional) Identifier of a carrier gateway. This attribute can only be used when the VPC contains a subnet which is associated with a Wavelength Zone. * `egress_only_gateway_id` - (Optional) Identifier of a VPC Egress Only Internet Gateway. * `gateway_id` - (Optional) Identifier of a VPC internet gateway or a virtual private gateway. * `instance_id` - (Optional) Identifier of an EC2 instance.