diff --git a/aws/data_source_aws_ec2_coip_pools.go b/aws/data_source_aws_ec2_coip_pools.go index a1b8d30c02e..5bdabf1ea3e 100644 --- a/aws/data_source_aws_ec2_coip_pools.go +++ b/aws/data_source_aws_ec2_coip_pools.go @@ -2,7 +2,6 @@ package aws import ( "fmt" - "log" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" @@ -49,26 +48,40 @@ func dataSourceAwsEc2CoipPoolsRead(d *schema.ResourceData, meta interface{}) err req.Filters = nil } - log.Printf("[DEBUG] DescribeCoipPools %s\n", req) - resp, err := conn.DescribeCoipPools(req) + var coipPools []*ec2.CoipPool + + err := conn.DescribeCoipPoolsPages(req, func(page *ec2.DescribeCoipPoolsOutput, lastPage bool) bool { + if page == nil { + return !lastPage + } + + coipPools = append(coipPools, page.CoipPools...) + + return !lastPage + }) + if err != nil { return fmt.Errorf("error describing EC2 COIP Pools: %w", err) } - if resp == nil || len(resp.CoipPools) == 0 { - return fmt.Errorf("no matching Coip Pool found") + if len(coipPools) == 0 { + return fmt.Errorf("no matching EC2 COIP Pools found") } - coippools := make([]string, 0) + var poolIDs []string + + for _, coipPool := range coipPools { + if coipPool == nil { + continue + } - for _, coippool := range resp.CoipPools { - coippools = append(coippools, aws.StringValue(coippool.PoolId)) + poolIDs = append(poolIDs, aws.StringValue(coipPool.PoolId)) } d.SetId(meta.(*AWSClient).region) - if err := d.Set("pool_ids", coippools); err != nil { - return fmt.Errorf("Error setting coip pool ids: %s", err) + if err := d.Set("pool_ids", poolIDs); err != nil { + return fmt.Errorf("error setting pool_ids: %w", err) } return nil diff --git a/aws/data_source_aws_ec2_local_gateway_route_tables.go b/aws/data_source_aws_ec2_local_gateway_route_tables.go index cf86861ab1d..d2b2a873fcd 100644 --- a/aws/data_source_aws_ec2_local_gateway_route_tables.go +++ b/aws/data_source_aws_ec2_local_gateway_route_tables.go @@ -2,7 +2,6 @@ package aws import ( "fmt" - "log" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" @@ -45,26 +44,40 @@ func dataSourceAwsEc2LocalGatewayRouteTablesRead(d *schema.ResourceData, meta in req.Filters = nil } - log.Printf("[DEBUG] DescribeLocalGatewayRouteTables %s\n", req) - resp, err := conn.DescribeLocalGatewayRouteTables(req) + var localGatewayRouteTables []*ec2.LocalGatewayRouteTable + + err := conn.DescribeLocalGatewayRouteTablesPages(req, func(page *ec2.DescribeLocalGatewayRouteTablesOutput, lastPage bool) bool { + if page == nil { + return !lastPage + } + + localGatewayRouteTables = append(localGatewayRouteTables, page.LocalGatewayRouteTables...) + + return !lastPage + }) + if err != nil { return fmt.Errorf("error describing EC2 Local Gateway Route Tables: %w", err) } - if resp == nil || len(resp.LocalGatewayRouteTables) == 0 { - return fmt.Errorf("no matching Local Gateway Route Table found") + if len(localGatewayRouteTables) == 0 { + return fmt.Errorf("no matching EC2 Local Gateway Route Tables found") } - localgatewayroutetables := make([]string, 0) + var ids []string + + for _, localGatewayRouteTable := range localGatewayRouteTables { + if localGatewayRouteTable == nil { + continue + } - for _, localgatewayroutetable := range resp.LocalGatewayRouteTables { - localgatewayroutetables = append(localgatewayroutetables, aws.StringValue(localgatewayroutetable.LocalGatewayRouteTableId)) + ids = append(ids, aws.StringValue(localGatewayRouteTable.LocalGatewayRouteTableId)) } d.SetId(meta.(*AWSClient).region) - if err := d.Set("ids", localgatewayroutetables); err != nil { - return fmt.Errorf("Error setting local gateway route table ids: %s", err) + if err := d.Set("ids", ids); err != nil { + return fmt.Errorf("error setting ids: %w", err) } return nil diff --git a/aws/data_source_aws_ec2_local_gateway_virtual_interface_groups.go b/aws/data_source_aws_ec2_local_gateway_virtual_interface_groups.go index d7eecdbb3b6..abc927d14c6 100644 --- a/aws/data_source_aws_ec2_local_gateway_virtual_interface_groups.go +++ b/aws/data_source_aws_ec2_local_gateway_virtual_interface_groups.go @@ -47,19 +47,33 @@ func dataSourceAwsEc2LocalGatewayVirtualInterfaceGroupsRead(d *schema.ResourceDa input.Filters = nil } - output, err := conn.DescribeLocalGatewayVirtualInterfaceGroups(input) + var localGatewayVirtualInterfaceGroups []*ec2.LocalGatewayVirtualInterfaceGroup + + err := conn.DescribeLocalGatewayVirtualInterfaceGroupsPages(input, func(page *ec2.DescribeLocalGatewayVirtualInterfaceGroupsOutput, lastPage bool) bool { + if page == nil { + return !lastPage + } + + localGatewayVirtualInterfaceGroups = append(localGatewayVirtualInterfaceGroups, page.LocalGatewayVirtualInterfaceGroups...) + + return !lastPage + }) if err != nil { - return fmt.Errorf("error describing EC2 Virtual Interface Groups: %w", err) + return fmt.Errorf("error describing EC2 Local Gateway Virtual Interface Groups: %w", err) } - if output == nil || len(output.LocalGatewayVirtualInterfaceGroups) == 0 { - return fmt.Errorf("no matching Virtual Interface Group found") + if len(localGatewayVirtualInterfaceGroups) == 0 { + return fmt.Errorf("no matching EC2 Local Gateway Virtual Interface Groups found") } var ids, localGatewayVirtualInterfaceIds []*string - for _, group := range output.LocalGatewayVirtualInterfaceGroups { + for _, group := range localGatewayVirtualInterfaceGroups { + if group == nil { + continue + } + ids = append(ids, group.LocalGatewayVirtualInterfaceGroupId) localGatewayVirtualInterfaceIds = append(localGatewayVirtualInterfaceIds, group.LocalGatewayVirtualInterfaceIds...) } diff --git a/aws/data_source_aws_ec2_local_gateways.go b/aws/data_source_aws_ec2_local_gateways.go index ccc7a1afdc1..6e1a3d37003 100644 --- a/aws/data_source_aws_ec2_local_gateways.go +++ b/aws/data_source_aws_ec2_local_gateways.go @@ -2,7 +2,6 @@ package aws import ( "fmt" - "log" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" @@ -49,26 +48,40 @@ func dataSourceAwsEc2LocalGatewaysRead(d *schema.ResourceData, meta interface{}) req.Filters = nil } - log.Printf("[DEBUG] DescribeLocalGateways %s\n", req) - resp, err := conn.DescribeLocalGateways(req) + var localGateways []*ec2.LocalGateway + + err := conn.DescribeLocalGatewaysPages(req, func(page *ec2.DescribeLocalGatewaysOutput, lastPage bool) bool { + if page == nil { + return !lastPage + } + + localGateways = append(localGateways, page.LocalGateways...) + + return !lastPage + }) + if err != nil { return fmt.Errorf("error describing EC2 Local Gateways: %w", err) } - if resp == nil || len(resp.LocalGateways) == 0 { - return fmt.Errorf("no matching Local Gateways found") + if len(localGateways) == 0 { + return fmt.Errorf("no matching EC2 Local Gateways found") } - localgateways := make([]string, 0) + var ids []string + + for _, localGateway := range localGateways { + if localGateway == nil { + continue + } - for _, localgateway := range resp.LocalGateways { - localgateways = append(localgateways, aws.StringValue(localgateway.LocalGatewayId)) + ids = append(ids, aws.StringValue(localGateway.LocalGatewayId)) } d.SetId(meta.(*AWSClient).region) - if err := d.Set("ids", localgateways); err != nil { - return fmt.Errorf("Error setting local gateway ids: %s", err) + if err := d.Set("ids", ids); err != nil { + return fmt.Errorf("error setting ids: %w", err) } return nil