Merge pull request #11826 from hashicorp/f-redshift-parameter-group-test-fixes

provider/aws: Fix redshift parameter group acctests
This commit is contained in:
Jake Champlin 2017-02-09 10:24:11 -05:00 committed by GitHub
commit 767764ff10
2 changed files with 41 additions and 33 deletions

View File

@ -3,22 +3,24 @@ package aws
import ( import (
"testing" "testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
) )
func TestAccAWSRedshiftParameterGroup_importBasic(t *testing.T) { func TestAccAWSRedshiftParameterGroup_importBasic(t *testing.T) {
resourceName := "aws_redshift_parameter_group.bar" resourceName := "aws_redshift_parameter_group.bar"
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,
CheckDestroy: testAccCheckAWSRedshiftParameterGroupDestroy, CheckDestroy: testAccCheckAWSRedshiftParameterGroupDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccAWSRedshiftParameterGroupConfig, Config: testAccAWSRedshiftParameterGroupConfig(rInt),
}, },
resource.TestStep{ {
ResourceName: resourceName, ResourceName: resourceName,
ImportState: true, ImportState: true,
ImportStateVerify: true, ImportStateVerify: true,

View File

@ -7,24 +7,26 @@ import (
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/redshift" "github.com/aws/aws-sdk-go/service/redshift"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
func TestAccAWSRedshiftParameterGroup_withParameters(t *testing.T) { func TestAccAWSRedshiftParameterGroup_withParameters(t *testing.T) {
var v redshift.ClusterParameterGroup var v redshift.ClusterParameterGroup
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,
CheckDestroy: testAccCheckAWSRedshiftParameterGroupDestroy, CheckDestroy: testAccCheckAWSRedshiftParameterGroupDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccAWSRedshiftParameterGroupConfig, Config: testAccAWSRedshiftParameterGroupConfig(rInt),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRedshiftParameterGroupExists("aws_redshift_parameter_group.bar", &v), testAccCheckAWSRedshiftParameterGroupExists("aws_redshift_parameter_group.bar", &v),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_redshift_parameter_group.bar", "name", "parameter-group-test-terraform"), "aws_redshift_parameter_group.bar", "name", fmt.Sprintf("test-terraform-%d", rInt)),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_redshift_parameter_group.bar", "family", "redshift-1.0"), "aws_redshift_parameter_group.bar", "family", "redshift-1.0"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -49,18 +51,19 @@ func TestAccAWSRedshiftParameterGroup_withParameters(t *testing.T) {
func TestAccAWSRedshiftParameterGroup_withoutParameters(t *testing.T) { func TestAccAWSRedshiftParameterGroup_withoutParameters(t *testing.T) {
var v redshift.ClusterParameterGroup var v redshift.ClusterParameterGroup
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,
CheckDestroy: testAccCheckAWSRedshiftParameterGroupDestroy, CheckDestroy: testAccCheckAWSRedshiftParameterGroupDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccAWSRedshiftParameterGroupOnlyConfig, Config: testAccAWSRedshiftParameterGroupOnlyConfig(rInt),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRedshiftParameterGroupExists("aws_redshift_parameter_group.bar", &v), testAccCheckAWSRedshiftParameterGroupExists("aws_redshift_parameter_group.bar", &v),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_redshift_parameter_group.bar", "name", "parameter-group-test-terraform"), "aws_redshift_parameter_group.bar", "name", fmt.Sprintf("test-terraform-%d", rInt)),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_redshift_parameter_group.bar", "family", "redshift-1.0"), "aws_redshift_parameter_group.bar", "family", "redshift-1.0"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -179,16 +182,19 @@ func testAccCheckAWSRedshiftParameterGroupExists(n string, v *redshift.ClusterPa
} }
} }
const testAccAWSRedshiftParameterGroupOnlyConfig = ` func testAccAWSRedshiftParameterGroupOnlyConfig(rInt int) string {
return fmt.Sprintf(`
resource "aws_redshift_parameter_group" "bar" { resource "aws_redshift_parameter_group" "bar" {
name = "parameter-group-test-terraform" name = "test-terraform-%d"
family = "redshift-1.0" family = "redshift-1.0"
description = "Test parameter group for terraform" description = "Test parameter group for terraform"
}` }`, rInt)
}
const testAccAWSRedshiftParameterGroupConfig = ` func testAccAWSRedshiftParameterGroupConfig(rInt int) string {
return fmt.Sprintf(`
resource "aws_redshift_parameter_group" "bar" { resource "aws_redshift_parameter_group" "bar" {
name = "parameter-group-test-terraform" name = "test-terraform-%d"
family = "redshift-1.0" family = "redshift-1.0"
parameter { parameter {
name = "require_ssl" name = "require_ssl"
@ -202,5 +208,5 @@ resource "aws_redshift_parameter_group" "bar" {
name = "enable_user_activity_logging" name = "enable_user_activity_logging"
value = "true" value = "true"
} }
}`, rInt)
} }
`