Skip to content

Commit

Permalink
Merge pull request #17382 from borancar/main
Browse files Browse the repository at this point in the history
Fix data source aws_vpc_peering_connections
  • Loading branch information
anGie44 authored Jan 20, 2022
2 parents 576a4bf + 6974085 commit c9f17f2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/17382.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
data-source/aws_vpc_peering_connections: Return empty array instead of error when no connections found.
```
4 changes: 2 additions & 2 deletions internal/service/ec2/vpc_peering_connections_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func dataSourceVPCPeeringConnectionsRead(d *schema.ResourceData, meta interface{
if err != nil {
return err
}
if resp == nil || len(resp.VpcPeeringConnections) == 0 {
return fmt.Errorf("no matching VPC peering connections found")
if resp == nil {
return fmt.Errorf("error reading EC2 VPC Peering Connections: empty response")
}

var ids []string
Expand Down
24 changes: 24 additions & 0 deletions internal/service/ec2/vpc_peering_connections_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ func TestAccEC2VPCPeeringConnectionsDataSource_basic(t *testing.T) {
})
}

func TestAccEC2VPCPeeringConnectionsDataSource_NoMatches(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccVPCPeeringConnectionsDataSourceConfig_NoMatches,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.aws_vpc_peering_connections.test", "ids.#", "0"),
),
},
},
})
}

const testAccVPCPeeringConnectionsDataSourceConfig = `
resource "aws_vpc" "foo" {
cidr_block = "10.1.0.0/16"
Expand Down Expand Up @@ -81,3 +97,11 @@ data "aws_vpc_peering_connections" "test_by_filters" {
}
}
`

const testAccVPCPeeringConnectionsDataSourceConfig_NoMatches = `
data "aws_vpc_peering_connections" "test" {
tags = {
Name = "Non-Existent"
}
}
`

0 comments on commit c9f17f2

Please sign in to comment.