provider/aws: Fix sg data source acctests (#11994)

Fixes the `data_source_aws_security_group` acceptance tests

```
$ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccDataSourceAwsSecurityGroup'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/02/15 22:19:51 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccDataSourceAwsSecurityGroup -timeout 120m
=== RUN   TestAccDataSourceAwsSecurityGroup
--- PASS: TestAccDataSourceAwsSecurityGroup (45.67s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    45.676s
```
This commit is contained in:
Jake Champlin 2017-02-16 00:21:56 -05:00 committed by Paul Stack
parent ad69c540b8
commit 3219037359
1 changed files with 45 additions and 41 deletions

View File

@ -4,17 +4,19 @@ import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccDataSourceAwsSecurityGroup(t *testing.T) {
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccDataSourceAwsSecurityGroupConfig,
{
Config: testAccDataSourceAwsSecurityGroupConfig(rInt),
Check: resource.ComposeTestCheckFunc(
testAccDataSourceAwsSecurityGroupCheck("data.aws_security_group.by_id"),
testAccDataSourceAwsSecurityGroupCheck("data.aws_security_group.by_tag"),
@ -60,7 +62,7 @@ func testAccDataSourceAwsSecurityGroupCheck(name string) resource.TestCheckFunc
)
}
if attr["tags.Name"] != "terraform-testacc-security-group-data-source" {
if attr["tags.Name"] != "tf-acctest" {
return fmt.Errorf("bad Name tag %s", attr["tags.Name"])
}
@ -93,49 +95,51 @@ func testAccDataSourceAwsSecurityGroupCheckDefault(name string) resource.TestChe
}
}
const testAccDataSourceAwsSecurityGroupConfig = `
provider "aws" {
region = "eu-west-1"
}
resource "aws_vpc" "test" {
cidr_block = "172.16.0.0/16"
func testAccDataSourceAwsSecurityGroupConfig(rInt int) string {
return fmt.Sprintf(`
provider "aws" {
region = "eu-west-1"
}
resource "aws_vpc" "test" {
cidr_block = "172.16.0.0/16"
tags {
Name = "terraform-testacc-subnet-data-source"
}
}
tags {
Name = "terraform-testacc-subnet-data-source"
}
}
resource "aws_security_group" "test" {
vpc_id = "${aws_vpc.test.id}"
name = "security-groupe-name-test"
tags {
Name = "terraform-testacc-security-group-data-source"
}
}
resource "aws_security_group" "test" {
vpc_id = "${aws_vpc.test.id}"
name = "test-%d"
tags {
Name = "tf-acctest"
Seed = "%d"
}
}
data "aws_security_group" "by_id" {
id = "${aws_security_group.test.id}"
}
data "aws_security_group" "by_id" {
id = "${aws_security_group.test.id}"
}
data "aws_security_group" "by_name" {
name = "${aws_security_group.test.name}"
}
data "aws_security_group" "by_name" {
name = "${aws_security_group.test.name}"
}
data "aws_security_group" "default_by_name" {
vpc_id = "${aws_vpc.test.id}"
name = "default"
}
data "aws_security_group" "default_by_name" {
vpc_id = "${aws_vpc.test.id}"
name = "default"
}
data "aws_security_group" "by_tag" {
tags {
Name = "${aws_security_group.test.tags["Name"]}"
}
}
data "aws_security_group" "by_tag" {
tags {
Seed = "${aws_security_group.test.tags["Seed"]}"
}
}
data "aws_security_group" "by_filter" {
filter {
name = "group-name"
values = ["${aws_security_group.test.name}"]
}
data "aws_security_group" "by_filter" {
filter {
name = "group-name"
values = ["${aws_security_group.test.name}"]
}
}`, rInt, rInt)
}
`