Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/aws: data source for AWS Security Group #9604

Merged
merged 4 commits into from
Oct 27, 2016

Conversation

mathieuherbert
Copy link
Contributor

@mathieuherbert mathieuherbert commented Oct 25, 2016

To add Security Group data source for AWS provider.

data "aws_security_group" "by_tag" { 
  tags {
    Name = "${aws_security_group.test.tags["Name"]}"
  }
}

The acceptance test

vagrant@terraform:/opt/gopath/src/github.com/hashicorp/terraform$ TF_ACC=true go test -v github.com/hashicorp/terraform/builtin/providers/aws -run ^TestAccDataSourceAwsSecurityGroup$
=== RUN   TestAccDataSourceAwsSecurityGroup
--- PASS: TestAccDataSourceAwsSecurityGroup (25.67s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    25.687s

It's my first pull request, don't hesitate to tell me what can be improved.

return fmt.Errorf("no matching SecurityGroup found")
}
if len(resp.SecurityGroups) > 1 {
return fmt.Errorf("multiple Security Groups matched; use additional constraints to reduce matches to a single Security Groups")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably write "...matches to a single Security Group", instead of "...matches to a single Security Groups".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I correct this in f1ac11e commit

conn := meta.(*AWSClient).ec2conn
req := &ec2.DescribeSecurityGroupsInput{}

if id := d.Get("id"); id != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would GetOk be better here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I correct this in f1ac11e commit

req.Filters = nil
}

log.Printf("[DEBUG] Describe Security Groups %s\n", req)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be %v here most likely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I correct this in f1ac11e commit

@mathieuherbert
Copy link
Contributor Author

Thank you for your comments, I modified the code with these.

Read: dataSourceAwsSecurityGroupRead,

Schema: map[string]*schema.Schema{
"vpc_id": &schema.Schema{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The &schema.Schema can be removed for Go 1.7+.

@kwilczynski
Copy link
Contributor

@mathieuherbert hi there! Thank you so much!

The last comment I made is just a nit pick, it is not essential to get this merged.

Great contribution! Thank you again! ❤️

@stack72
Copy link
Contributor

stack72 commented Oct 27, 2016

Hi @mathieuherbert

this LGTM! Tests are also great - nice first PR to Terraform :)

% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccDataSourceAwsSecurityGroup'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2016/10/27 18:13:59 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccDataSourceAwsSecurityGroup -timeout 120m
=== RUN   TestAccDataSourceAwsSecurityGroup
--- PASS: TestAccDataSourceAwsSecurityGroup (21.74s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    21.765s

@stack72 stack72 merged commit 7f9baf7 into hashicorp:master Oct 27, 2016
antonbabenko pushed a commit to antonbabenko/terraform that referenced this pull request Oct 27, 2016
* provider/aws: data source for AWS Security Group

* provider/aws: add documentation  for data source for AWS Security Group

* provider/aws: data source for AWS Security Group (improve if condition and syntax)

* fix fmt
gusmat pushed a commit to gusmat/terraform that referenced this pull request Dec 6, 2016
* provider/aws: data source for AWS Security Group

* provider/aws: add documentation  for data source for AWS Security Group

* provider/aws: data source for AWS Security Group (improve if condition and syntax)

* fix fmt
@ghost
Copy link

ghost commented Apr 21, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants