mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-10 07:35:34 -06:00
Return route_table_id from aws_route_table data source. (#11703)
This commit is contained in:
parent
5bbed52e19
commit
1ab38ceae5
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
)
|
||||
@ -138,7 +139,8 @@ func dataSourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error
|
||||
|
||||
rt := resp.RouteTables[0]
|
||||
|
||||
d.SetId(*rt.RouteTableId)
|
||||
d.SetId(aws.StringValue(rt.RouteTableId))
|
||||
d.Set("route_table_id", rt.RouteTableId)
|
||||
d.Set("vpc_id", rt.VpcId)
|
||||
d.Set("tags", tagsToMap(rt.Tags))
|
||||
if err := d.Set("routes", dataSourceRoutesRead(rt.Routes)); err != nil {
|
||||
|
@ -1,3 +1,4 @@
|
||||
// make testacc TEST=./builtin/providers/aws/ TESTARGS='-run=TestAccDataSourceAwsRouteTable_'
|
||||
package aws
|
||||
|
||||
import (
|
||||
@ -8,7 +9,7 @@ import (
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
func TestAccDataSourceAwsRouteTable(t *testing.T) {
|
||||
func TestAccDataSourceAwsRouteTable_basic(t *testing.T) {
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
@ -21,6 +22,7 @@ func TestAccDataSourceAwsRouteTable(t *testing.T) {
|
||||
testAccDataSourceAwsRouteTableCheck("data.aws_route_table.by_subnet"),
|
||||
testAccDataSourceAwsRouteTableCheck("data.aws_route_table.by_id"),
|
||||
),
|
||||
ExpectNonEmptyPlan: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -71,6 +73,14 @@ func testAccDataSourceAwsRouteTableCheck(name string) resource.TestCheckFunc {
|
||||
)
|
||||
}
|
||||
|
||||
if attr["route_table_id"] != rts.Primary.Attributes["id"] {
|
||||
return fmt.Errorf(
|
||||
"route_table_id is %s; want %s",
|
||||
attr["route_table_id"],
|
||||
rts.Primary.Attributes["id"],
|
||||
)
|
||||
}
|
||||
|
||||
if attr["vpc_id"] != vpcRs.Primary.Attributes["id"] {
|
||||
return fmt.Errorf(
|
||||
"vpc_id is %s; want %s",
|
||||
@ -184,6 +194,14 @@ provider "aws" {
|
||||
region = "us-east-2"
|
||||
}
|
||||
|
||||
resource "aws_vpc" "test" {
|
||||
cidr_block = "172.16.0.0/16"
|
||||
|
||||
tags {
|
||||
Name = "terraform-testacc-data-source"
|
||||
}
|
||||
}
|
||||
|
||||
data "aws_route_table" "by_filter" {
|
||||
filter {
|
||||
name = "association.main"
|
||||
@ -191,7 +209,7 @@ data "aws_route_table" "by_filter" {
|
||||
}
|
||||
filter {
|
||||
name = "vpc-id"
|
||||
values = ["vpc-6bd70802"]
|
||||
values = ["${aws_vpc.test.id}"]
|
||||
}
|
||||
}
|
||||
`
|
||||
|
Loading…
Reference in New Issue
Block a user