Merge pull request #11530 from hashicorp/b-aws-test-fixes

provider/aws: Handful of Acc configuration tests
This commit is contained in:
Clint 2017-01-30 16:13:24 -06:00 committed by GitHub
commit be9fc64967
4 changed files with 35 additions and 22 deletions

View File

@ -1,21 +1,24 @@
package aws
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccAWSDBSubnetGroup_importBasic(t *testing.T) {
resourceName := "aws_db_subnet_group.foo"
rName := fmt.Sprintf("tf-test-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDBSubnetGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccDBSubnetGroupConfig,
Config: testAccDBSubnetGroupConfig(rName),
},
resource.TestStep{

View File

@ -110,18 +110,20 @@ func TestAccAWSDBInstance_subnetGroup(t *testing.T) {
func TestAccAWSDBInstance_optionGroup(t *testing.T) {
var v rds.DBInstance
rName := fmt.Sprintf("tf-option-test-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSDBInstanceConfigWithOptionGroup,
Config: testAccAWSDBInstanceConfigWithOptionGroup(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
testAccCheckAWSDBInstanceAttributes(&v),
resource.TestCheckResourceAttr(
"aws_db_instance.bar", "option_group_name", "option-group-test-terraform"),
"aws_db_instance.bar", "option_group_name", rName),
),
},
},
@ -642,10 +644,10 @@ resource "aws_db_instance" "bar" {
}
`
var testAccAWSDBInstanceConfigWithOptionGroup = fmt.Sprintf(`
func testAccAWSDBInstanceConfigWithOptionGroup(rName string) string {
return fmt.Sprintf(`
resource "aws_db_option_group" "bar" {
name = "option-group-test-terraform"
name = "%s"
option_group_description = "Test option group for terraform"
engine_name = "mysql"
major_engine_version = "5.6"
@ -665,7 +667,8 @@ resource "aws_db_instance" "bar" {
parameter_group_name = "default.mysql5.6"
option_group_name = "${aws_db_option_group.bar.name}"
}`, acctest.RandInt())
}`, rName, acctest.RandInt())
}
func testAccReplicaInstanceConfig(val int) string {
return fmt.Sprintf(`

View File

@ -4,6 +4,7 @@ import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
@ -19,18 +20,20 @@ func TestAccAWSDBSubnetGroup_basic(t *testing.T) {
return nil
}
rName := fmt.Sprintf("tf-test-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDBSubnetGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccDBSubnetGroupConfig,
Config: testAccDBSubnetGroupConfig(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDBSubnetGroupExists(
"aws_db_subnet_group.foo", &v),
resource.TestCheckResourceAttr(
"aws_db_subnet_group.foo", "name", "foo"),
"aws_db_subnet_group.foo", "name", rName),
resource.TestCheckResourceAttr(
"aws_db_subnet_group.foo", "description", "Managed by Terraform"),
testCheck,
@ -73,13 +76,14 @@ func TestAccAWSDBSubnetGroup_withUndocumentedCharacters(t *testing.T) {
func TestAccAWSDBSubnetGroup_updateDescription(t *testing.T) {
var v rds.DBSubnetGroup
rName := fmt.Sprintf("tf-test-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDBSubnetGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccDBSubnetGroupConfig,
Config: testAccDBSubnetGroupConfig(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDBSubnetGroupExists(
"aws_db_subnet_group.foo", &v),
@ -89,7 +93,7 @@ func TestAccAWSDBSubnetGroup_updateDescription(t *testing.T) {
},
resource.TestStep{
Config: testAccDBSubnetGroupConfig_updatedDescription,
Config: testAccDBSubnetGroupConfig_updatedDescription(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDBSubnetGroupExists(
"aws_db_subnet_group.foo", &v),
@ -192,7 +196,8 @@ func testAccCheckDBSubnetGroupExists(n string, v *rds.DBSubnetGroup) resource.Te
}
}
const testAccDBSubnetGroupConfig = `
func testAccDBSubnetGroupConfig(rName string) string {
return fmt.Sprintf(`
resource "aws_vpc" "foo" {
cidr_block = "10.1.0.0/16"
}
@ -216,15 +221,16 @@ resource "aws_subnet" "bar" {
}
resource "aws_db_subnet_group" "foo" {
name = "foo"
name = "%s"
subnet_ids = ["${aws_subnet.foo.id}", "${aws_subnet.bar.id}"]
tags {
Name = "tf-dbsubnet-group-test"
}
}`, rName)
}
`
const testAccDBSubnetGroupConfig_updatedDescription = `
func testAccDBSubnetGroupConfig_updatedDescription(rName string) string {
return fmt.Sprintf(`
resource "aws_vpc" "foo" {
cidr_block = "10.1.0.0/16"
}
@ -248,14 +254,14 @@ resource "aws_subnet" "bar" {
}
resource "aws_db_subnet_group" "foo" {
name = "foo"
name = "%s"
description = "foo description updated"
subnet_ids = ["${aws_subnet.foo.id}", "${aws_subnet.bar.id}"]
tags {
Name = "tf-dbsubnet-group-test"
}
}`, rName)
}
`
const testAccDBSubnetGroupConfig_withUnderscoresAndPeriodsAndSpaces = `
resource "aws_vpc" "main" {

View File

@ -21,7 +21,7 @@ func TestAccAWSBeanstalkConfigurationTemplate_basic(t *testing.T) {
CheckDestroy: testAccCheckBeanstalkConfigurationTemplateDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccBeanstalkConfigurationTemplateConfig,
Config: testAccBeanstalkConfigurationTemplateConfig(acctest.RandString(5)),
Check: resource.ComposeTestCheckFunc(
testAccCheckBeanstalkConfigurationTemplateExists("aws_elastic_beanstalk_configuration_template.tf_template", &config),
),
@ -142,18 +142,19 @@ func testAccCheckBeanstalkConfigurationTemplateExists(n string, config *elasticb
}
}
const testAccBeanstalkConfigurationTemplateConfig = `
func testAccBeanstalkConfigurationTemplateConfig(r string) string {
return fmt.Sprintf(`
resource "aws_elastic_beanstalk_application" "tftest" {
name = "tf-test-name"
description = "tf-test-desc"
name = "tf-test-%s"
description = "tf-test-desc-%s"
}
resource "aws_elastic_beanstalk_configuration_template" "tf_template" {
name = "tf-test-template-config"
application = "${aws_elastic_beanstalk_application.tftest.name}"
solution_stack_name = "64bit Amazon Linux running Python"
}`, r, r)
}
`
func testAccBeanstalkConfigurationTemplateConfig_VPC(name string) string {
return fmt.Sprintf(`