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:
parent
20c0668c6b
commit
f7d9e0b168
|
@ -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" {
|
||||
|
|
Loading…
Reference in New Issue