Merge pull request #11563 from hashicorp/b-fix-instance-data-source-acctests

provider/aws: Fix aws instance data source acceptance tests
This commit is contained in:
Jake Champlin 2017-01-31 12:25:00 -05:00 committed by GitHub
commit ab9c94e331
1 changed files with 19 additions and 8 deletions

View File

@ -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" {