Skip to content

Commit

Permalink
data-source/aws_security_groups: Implement #2947 PR feedback
Browse files Browse the repository at this point in the history
make testacc TEST=./aws TESTARGS='-run=TestAccDataSourceAwsSecurityGroups'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccDataSourceAwsSecurityGroups -timeout 120m
=== RUN   TestAccDataSourceAwsSecurityGroups_tag
--- PASS: TestAccDataSourceAwsSecurityGroups_tag (31.31s)
=== RUN   TestAccDataSourceAwsSecurityGroups_filter
--- PASS: TestAccDataSourceAwsSecurityGroups_filter (28.44s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	59.788s
  • Loading branch information
bflad committed Jun 27, 2018
1 parent c61412d commit 87215b7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
16 changes: 6 additions & 10 deletions aws/data_source_aws_security_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package aws

import (
"fmt"
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"log"
)

func dataSourceAwsSecurityGroups() *schema.Resource {
Expand Down Expand Up @@ -55,26 +56,21 @@ func dataSourceAwsSecurityGroupsRead(d *schema.ResourceData, meta interface{}) e
log.Printf("[DEBUG] Reading Security Groups with request: %s", req)

var ids, vpc_ids []string
nextToken := ""
for {
if nextToken != "" {
req.NextToken = aws.String(nextToken)
}

resp, err := conn.DescribeSecurityGroups(req)
if err != nil {
return err
return fmt.Errorf("error reading security groups: %s", err)
}

for _, sg := range resp.SecurityGroups {
ids = append(ids, *sg.GroupId)
vpc_ids = append(vpc_ids, *sg.VpcId)
ids = append(ids, aws.StringValue(sg.GroupId))
vpc_ids = append(vpc_ids, aws.StringValue(sg.VpcId))
}

if resp.NextToken == nil {
break
}
nextToken = *resp.NextToken
req.NextToken = resp.NextToken
}

if len(ids) < 1 {
Expand Down
2 changes: 1 addition & 1 deletion website/aws.erb
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
<li<%= sidebar_current("docs-aws-datasource-secretsmanager-secret-version") %>>
<a href="/docs/providers/aws/d/secretsmanager_secret_version.html">aws_secretsmanager_secret_version</a>
</li>
<li<%= sidebar_current("docs-aws-datasource-security-group") %>>
<li<%= sidebar_current("docs-aws-datasource-security-group-x") %>>
<a href="/docs/providers/aws/d/security_group.html">aws_security_group</a>
</li>
<li<%= sidebar_current("docs-aws-datasource-security-groups") %>>
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/security_group.html.markdown
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: "aws"
page_title: "AWS: aws_security_group"
sidebar_current: "docs-aws-datasource-security-group"
sidebar_current: "docs-aws-datasource-security-group-x"
description: |-
Provides details about a specific Security Group
---
Expand Down

0 comments on commit 87215b7

Please sign in to comment.