mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
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:
parent
ad69c540b8
commit
3219037359
@ -4,17 +4,19 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccDataSourceAwsSecurityGroup(t *testing.T) {
|
func TestAccDataSourceAwsSecurityGroup(t *testing.T) {
|
||||||
|
rInt := acctest.RandInt()
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccDataSourceAwsSecurityGroupConfig,
|
Config: testAccDataSourceAwsSecurityGroupConfig(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccDataSourceAwsSecurityGroupCheck("data.aws_security_group.by_id"),
|
testAccDataSourceAwsSecurityGroupCheck("data.aws_security_group.by_id"),
|
||||||
testAccDataSourceAwsSecurityGroupCheck("data.aws_security_group.by_tag"),
|
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"])
|
return fmt.Errorf("bad Name tag %s", attr["tags.Name"])
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +95,8 @@ func testAccDataSourceAwsSecurityGroupCheckDefault(name string) resource.TestChe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const testAccDataSourceAwsSecurityGroupConfig = `
|
func testAccDataSourceAwsSecurityGroupConfig(rInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
provider "aws" {
|
provider "aws" {
|
||||||
region = "eu-west-1"
|
region = "eu-west-1"
|
||||||
}
|
}
|
||||||
@ -107,9 +110,10 @@ resource "aws_vpc" "test" {
|
|||||||
|
|
||||||
resource "aws_security_group" "test" {
|
resource "aws_security_group" "test" {
|
||||||
vpc_id = "${aws_vpc.test.id}"
|
vpc_id = "${aws_vpc.test.id}"
|
||||||
name = "security-groupe-name-test"
|
name = "test-%d"
|
||||||
tags {
|
tags {
|
||||||
Name = "terraform-testacc-security-group-data-source"
|
Name = "tf-acctest"
|
||||||
|
Seed = "%d"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +132,7 @@ data "aws_security_group" "default_by_name" {
|
|||||||
|
|
||||||
data "aws_security_group" "by_tag" {
|
data "aws_security_group" "by_tag" {
|
||||||
tags {
|
tags {
|
||||||
Name = "${aws_security_group.test.tags["Name"]}"
|
Seed = "${aws_security_group.test.tags["Seed"]}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,5 +141,5 @@ data "aws_security_group" "by_filter" {
|
|||||||
name = "group-name"
|
name = "group-name"
|
||||||
values = ["${aws_security_group.test.name}"]
|
values = ["${aws_security_group.test.name}"]
|
||||||
}
|
}
|
||||||
|
}`, rInt, rInt)
|
||||||
}
|
}
|
||||||
`
|
|
||||||
|
Loading…
Reference in New Issue
Block a user