Skip to content

Commit

Permalink
Merge pull request #23195 from drewmullen/b-ipam-search-notfound
Browse files Browse the repository at this point in the history
data_source/aws_vpc_ipam_pool: Add filter examples to docs, add error if no pool found
  • Loading branch information
ewbankkit authored Feb 15, 2022
2 parents 46a418d + a988188 commit d176fba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/23195.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
data_source/aws_vpc_ipam_pool: error if no pool found
```
5 changes: 3 additions & 2 deletions internal/service/ec2/vpc_ipam_pool_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)

func DataSourceVPCIpamPool() *schema.Resource {
Expand Down Expand Up @@ -115,8 +116,8 @@ func dataSourceVPCIpamPoolRead(d *schema.ResourceData, meta interface{}) error {
return err
}

if output == nil || len(output.IpamPools) == 0 || output.IpamPools[0] == nil {
return nil
if len(output.IpamPools) == 0 || output.IpamPools[0] == nil {
return tfresource.SingularDataSourceFindError("EC2 VPC IPAM POOL", tfresource.NewEmptyResultError(input))
}

if len(output.IpamPools) > 1 {
Expand Down
12 changes: 11 additions & 1 deletion website/docs/d/vpc_ipam_pool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@ via RAM, and using that pool id to create a VPC with a CIDR derived from
AWS IPAM.

```terraform
data "aws_vpc_ipam_pool" "test" {}
data "aws_vpc_ipam_pool" "test" {
filter {
name = "description"
values = ["*test*"]
}
filter {
name = "address-family"
values = ["ipv4"]
}
}
resource "aws_vpc" "test" {
ipv4_ipam_pool_id = data.aws_vpc_ipam_pool.test.id
Expand Down

0 comments on commit d176fba

Please sign in to comment.