From f7d9e0b168a51c982813df987eeaf7c364f3b29f Mon Sep 17 00:00:00 2001 From: Jake Champlin Date: Tue, 31 Jan 2017 12:19:25 -0500 Subject: [PATCH] provider/aws: Fix aws instance data source acceptance tests Fixes 2 acceptance tests for the `aws_instance` data source ``` $ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSInstanceDataSource_SecurityGroups' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2017/01/31 12:12:15 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSInstanceDataSource_SecurityGroups -timeout 120m === RUN TestAccAWSInstanceDataSource_SecurityGroups --- PASS: TestAccAWSInstanceDataSource_SecurityGroups (119.14s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 119.172s ``` ``` $ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSInstanceDataSource_tags' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2017/01/31 12:15:42 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSInstanceDataSource_tags -timeout 120m === RUN TestAccAWSInstanceDataSource_tags --- PASS: TestAccAWSInstanceDataSource_tags (118.87s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 118.900s ``` --- .../aws/data_source_aws_instance_test.go | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/builtin/providers/aws/data_source_aws_instance_test.go b/builtin/providers/aws/data_source_aws_instance_test.go index 7116c1185..1f5bb21a3 100644 --- a/builtin/providers/aws/data_source_aws_instance_test.go +++ b/builtin/providers/aws/data_source_aws_instance_test.go @@ -3,6 +3,9 @@ package aws import ( "testing" + "fmt" + + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" ) @@ -27,17 +30,18 @@ func TestAccAWSInstanceDataSource_basic(t *testing.T) { } func TestAccAWSInstanceDataSource_tags(t *testing.T) { + rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccInstanceDataSourceConfig_Tags, + Config: testAccInstanceDataSourceConfig_Tags(rInt), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "data.aws_instance.web-instance", "ami", "ami-4fccb37f"), resource.TestCheckResourceAttr( - "data.aws_instance.web-instance", "tags.#", "1"), + "data.aws_instance.web-instance", "tags.#", "2"), resource.TestCheckResourceAttr( "data.aws_instance.web-instance", "instance_type", "m1.small"), ), @@ -215,12 +219,13 @@ func TestAccAWSInstanceDataSource_VPC(t *testing.T) { } func TestAccAWSInstanceDataSource_SecurityGroups(t *testing.T) { + rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccInstanceDataSourceConfig_SecurityGroups, + Config: testAccInstanceDataSourceConfig_SecurityGroups(rInt), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "data.aws_instance.foo", "ami", "ami-408c7f28"), @@ -280,22 +285,26 @@ data "aws_instance" "web-instance" { ` // Use the tags attribute to filter -const testAccInstanceDataSourceConfig_Tags = ` +func testAccInstanceDataSourceConfig_Tags(rInt int) string { + return fmt.Sprintf(` resource "aws_instance" "web" { # us-west-2 ami = "ami-4fccb37f" instance_type = "m1.small" tags { Name = "HelloWorld" + TestSeed = "%d" } } data "aws_instance" "web-instance" { instance_tags { Name = "${aws_instance.web.tags["Name"]}" + TestSeed = "%d" } } -` +`, rInt, rInt) +} // filter on tag, populate more attributes const testAccInstanceDataSourceConfig_AzUserData = ` @@ -463,13 +472,14 @@ data "aws_instance" "foo" { } ` -const testAccInstanceDataSourceConfig_SecurityGroups = ` +func testAccInstanceDataSourceConfig_SecurityGroups(rInt int) string { + return fmt.Sprintf(` provider "aws" { region = "us-east-1" } resource "aws_security_group" "tf_test_foo" { - name = "tf_test_foo" + name = "tf_test_foo-%d" description = "foo" ingress { @@ -490,7 +500,8 @@ resource "aws_instance" "foo" { data "aws_instance" "foo" { instance_id = "${aws_instance.foo.id}" } -` +`, rInt) +} const testAccInstanceDataSourceConfig_VPCSecurityGroups = ` resource "aws_internet_gateway" "gw" {