2015-11-12 00:37:56 +01:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
|
|
|
"github.com/aws/aws-sdk-go/service/redshift"
|
2017-02-09 16:18:31 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
2015-11-12 00:37:56 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccAWSRedshiftParameterGroup_withParameters(t *testing.T) {
|
|
|
|
var v redshift.ClusterParameterGroup
|
2017-02-09 16:18:31 +01:00
|
|
|
rInt := acctest.RandInt()
|
2015-11-12 00:37:56 +01:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSRedshiftParameterGroupDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-02-09 16:18:31 +01:00
|
|
|
{
|
|
|
|
Config: testAccAWSRedshiftParameterGroupConfig(rInt),
|
2015-11-12 00:37:56 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSRedshiftParameterGroupExists("aws_redshift_parameter_group.bar", &v),
|
|
|
|
resource.TestCheckResourceAttr(
|
2017-02-09 16:18:31 +01:00
|
|
|
"aws_redshift_parameter_group.bar", "name", fmt.Sprintf("test-terraform-%d", rInt)),
|
2015-11-12 00:37:56 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_redshift_parameter_group.bar", "family", "redshift-1.0"),
|
|
|
|
resource.TestCheckResourceAttr(
|
2016-04-18 23:06:15 +02:00
|
|
|
"aws_redshift_parameter_group.bar", "description", "Managed by Terraform"),
|
2015-11-12 00:37:56 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_redshift_parameter_group.bar", "parameter.490804664.name", "require_ssl"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_redshift_parameter_group.bar", "parameter.490804664.value", "true"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_redshift_parameter_group.bar", "parameter.2036118857.name", "query_group"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_redshift_parameter_group.bar", "parameter.2036118857.value", "example"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_redshift_parameter_group.bar", "parameter.484080973.name", "enable_user_activity_logging"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_redshift_parameter_group.bar", "parameter.484080973.value", "true"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccAWSRedshiftParameterGroup_withoutParameters(t *testing.T) {
|
|
|
|
var v redshift.ClusterParameterGroup
|
2017-02-09 16:18:31 +01:00
|
|
|
rInt := acctest.RandInt()
|
2015-11-12 00:37:56 +01:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSRedshiftParameterGroupDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-02-09 16:18:31 +01:00
|
|
|
{
|
|
|
|
Config: testAccAWSRedshiftParameterGroupOnlyConfig(rInt),
|
2015-11-12 00:37:56 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSRedshiftParameterGroupExists("aws_redshift_parameter_group.bar", &v),
|
|
|
|
resource.TestCheckResourceAttr(
|
2017-02-09 16:18:31 +01:00
|
|
|
"aws_redshift_parameter_group.bar", "name", fmt.Sprintf("test-terraform-%d", rInt)),
|
2015-11-12 00:37:56 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_redshift_parameter_group.bar", "family", "redshift-1.0"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_redshift_parameter_group.bar", "description", "Test parameter group for terraform"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-11-12 10:45:22 +01:00
|
|
|
func TestResourceAWSRedshiftParameterGroupNameValidation(t *testing.T) {
|
2015-11-12 00:37:56 +01:00
|
|
|
cases := []struct {
|
|
|
|
Value string
|
|
|
|
ErrCount int
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Value: "tEsting123",
|
|
|
|
ErrCount: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: "testing123!",
|
|
|
|
ErrCount: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: "1testing123",
|
|
|
|
ErrCount: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: "testing--123",
|
|
|
|
ErrCount: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: "testing123-",
|
|
|
|
ErrCount: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: randomString(256),
|
|
|
|
ErrCount: 1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
_, errors := validateRedshiftParamGroupName(tc.Value, "aws_redshift_parameter_group_name")
|
|
|
|
|
|
|
|
if len(errors) != tc.ErrCount {
|
|
|
|
t.Fatalf("Expected the Redshift Parameter Group Name to trigger a validation error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckAWSRedshiftParameterGroupDestroy(s *terraform.State) error {
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).redshiftconn
|
|
|
|
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "aws_redshift_parameter_group" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to find the Group
|
|
|
|
resp, err := conn.DescribeClusterParameterGroups(
|
|
|
|
&redshift.DescribeClusterParameterGroupsInput{
|
|
|
|
ParameterGroupName: aws.String(rs.Primary.ID),
|
|
|
|
})
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
if len(resp.ParameterGroups) != 0 &&
|
|
|
|
*resp.ParameterGroups[0].ParameterGroupName == rs.Primary.ID {
|
|
|
|
return fmt.Errorf("Redshift Parameter Group still exists")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify the error
|
|
|
|
newerr, ok := err.(awserr.Error)
|
|
|
|
if !ok {
|
|
|
|
return err
|
|
|
|
}
|
2016-01-13 23:58:07 +01:00
|
|
|
if newerr.Code() != "ClusterParameterGroupNotFound" {
|
2015-11-12 00:37:56 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckAWSRedshiftParameterGroupExists(n string, v *redshift.ClusterParameterGroup) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("No Redshift Parameter Group ID is set")
|
|
|
|
}
|
|
|
|
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).redshiftconn
|
|
|
|
|
|
|
|
opts := redshift.DescribeClusterParameterGroupsInput{
|
|
|
|
ParameterGroupName: aws.String(rs.Primary.ID),
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := conn.DescribeClusterParameterGroups(&opts)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(resp.ParameterGroups) != 1 ||
|
|
|
|
*resp.ParameterGroups[0].ParameterGroupName != rs.Primary.ID {
|
|
|
|
return fmt.Errorf("Redshift Parameter Group not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
*v = *resp.ParameterGroups[0]
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-09 16:18:31 +01:00
|
|
|
func testAccAWSRedshiftParameterGroupOnlyConfig(rInt int) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "aws_redshift_parameter_group" "bar" {
|
|
|
|
name = "test-terraform-%d"
|
|
|
|
family = "redshift-1.0"
|
|
|
|
description = "Test parameter group for terraform"
|
|
|
|
}`, rInt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccAWSRedshiftParameterGroupConfig(rInt int) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "aws_redshift_parameter_group" "bar" {
|
|
|
|
name = "test-terraform-%d"
|
|
|
|
family = "redshift-1.0"
|
|
|
|
parameter {
|
|
|
|
name = "require_ssl"
|
|
|
|
value = "true"
|
|
|
|
}
|
|
|
|
parameter {
|
|
|
|
name = "query_group"
|
|
|
|
value = "example"
|
|
|
|
}
|
|
|
|
parameter{
|
|
|
|
name = "enable_user_activity_logging"
|
|
|
|
value = "true"
|
|
|
|
}
|
|
|
|
}`, rInt)
|
2015-11-12 00:37:56 +01:00
|
|
|
}
|