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
```
This commit is contained in:
Jake Champlin 2017-01-31 12:19:25 -05:00
parent 20c0668c6b
commit f7d9e0b168
No known key found for this signature in database
GPG Key ID: DC31F41958EF4AC2
1 changed files with 19 additions and 8 deletions

View File

@ -3,6 +3,9 @@ package aws
import ( import (
"testing" "testing"
"fmt"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
) )
@ -27,17 +30,18 @@ func TestAccAWSInstanceDataSource_basic(t *testing.T) {
} }
func TestAccAWSInstanceDataSource_tags(t *testing.T) { func TestAccAWSInstanceDataSource_tags(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{
{ {
Config: testAccInstanceDataSourceConfig_Tags, Config: testAccInstanceDataSourceConfig_Tags(rInt),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"data.aws_instance.web-instance", "ami", "ami-4fccb37f"), "data.aws_instance.web-instance", "ami", "ami-4fccb37f"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"data.aws_instance.web-instance", "tags.#", "1"), "data.aws_instance.web-instance", "tags.#", "2"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"data.aws_instance.web-instance", "instance_type", "m1.small"), "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) { func TestAccAWSInstanceDataSource_SecurityGroups(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{
{ {
Config: testAccInstanceDataSourceConfig_SecurityGroups, Config: testAccInstanceDataSourceConfig_SecurityGroups(rInt),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"data.aws_instance.foo", "ami", "ami-408c7f28"), "data.aws_instance.foo", "ami", "ami-408c7f28"),
@ -280,22 +285,26 @@ data "aws_instance" "web-instance" {
` `
// Use the tags attribute to filter // Use the tags attribute to filter
const testAccInstanceDataSourceConfig_Tags = ` func testAccInstanceDataSourceConfig_Tags(rInt int) string {
return fmt.Sprintf(`
resource "aws_instance" "web" { resource "aws_instance" "web" {
# us-west-2 # us-west-2
ami = "ami-4fccb37f" ami = "ami-4fccb37f"
instance_type = "m1.small" instance_type = "m1.small"
tags { tags {
Name = "HelloWorld" Name = "HelloWorld"
TestSeed = "%d"
} }
} }
data "aws_instance" "web-instance" { data "aws_instance" "web-instance" {
instance_tags { instance_tags {
Name = "${aws_instance.web.tags["Name"]}" Name = "${aws_instance.web.tags["Name"]}"
TestSeed = "%d"
} }
} }
` `, rInt, rInt)
}
// filter on tag, populate more attributes // filter on tag, populate more attributes
const testAccInstanceDataSourceConfig_AzUserData = ` 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" { provider "aws" {
region = "us-east-1" region = "us-east-1"
} }
resource "aws_security_group" "tf_test_foo" { resource "aws_security_group" "tf_test_foo" {
name = "tf_test_foo" name = "tf_test_foo-%d"
description = "foo" description = "foo"
ingress { ingress {
@ -490,7 +500,8 @@ resource "aws_instance" "foo" {
data "aws_instance" "foo" { data "aws_instance" "foo" {
instance_id = "${aws_instance.foo.id}" instance_id = "${aws_instance.foo.id}"
} }
` `, rInt)
}
const testAccInstanceDataSourceConfig_VPCSecurityGroups = ` const testAccInstanceDataSourceConfig_VPCSecurityGroups = `
resource "aws_internet_gateway" "gw" { resource "aws_internet_gateway" "gw" {