github.com/bfallik/terraform@v0.7.1-0.20160814101525-d3a4714efbf5/builtin/providers/aws/resource_aws_redshift_cluster_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"math/rand"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/aws/aws-sdk-go/aws"
    10  	"github.com/aws/aws-sdk-go/aws/awserr"
    11  	"github.com/aws/aws-sdk-go/service/redshift"
    12  	"github.com/hashicorp/terraform/helper/resource"
    13  	"github.com/hashicorp/terraform/terraform"
    14  )
    15  
    16  func TestAccAWSRedshiftCluster_basic(t *testing.T) {
    17  	var v redshift.Cluster
    18  
    19  	ri := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
    20  	config := fmt.Sprintf(testAccAWSRedshiftClusterConfig_basic, ri)
    21  
    22  	resource.Test(t, resource.TestCase{
    23  		PreCheck:     func() { testAccPreCheck(t) },
    24  		Providers:    testAccProviders,
    25  		CheckDestroy: testAccCheckAWSRedshiftClusterDestroy,
    26  		Steps: []resource.TestStep{
    27  			resource.TestStep{
    28  				Config: config,
    29  				Check: resource.ComposeTestCheckFunc(
    30  					testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v),
    31  					resource.TestCheckResourceAttr(
    32  						"aws_redshift_cluster.default", "cluster_type", "single-node"),
    33  					resource.TestCheckResourceAttr(
    34  						"aws_redshift_cluster.default", "publicly_accessible", "true"),
    35  				),
    36  			},
    37  		},
    38  	})
    39  }
    40  
    41  func TestAccAWSRedshiftCluster_loggingEnabled(t *testing.T) {
    42  	var v redshift.Cluster
    43  
    44  	ri := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
    45  	preConfig := fmt.Sprintf(testAccAWSRedshiftClusterConfig_loggingEnabled, ri)
    46  	postConfig := fmt.Sprintf(testAccAWSRedshiftClusterConfig_loggingDisabled, ri)
    47  
    48  	resource.Test(t, resource.TestCase{
    49  		PreCheck:     func() { testAccPreCheck(t) },
    50  		Providers:    testAccProviders,
    51  		CheckDestroy: testAccCheckAWSRedshiftClusterDestroy,
    52  		Steps: []resource.TestStep{
    53  			resource.TestStep{
    54  				Config: preConfig,
    55  				Check: resource.ComposeTestCheckFunc(
    56  					testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v),
    57  					resource.TestCheckResourceAttr(
    58  						"aws_redshift_cluster.default", "enable_logging", "true"),
    59  					resource.TestCheckResourceAttr(
    60  						"aws_redshift_cluster.default", "bucket_name", "tf-redshift-logging-test-bucket"),
    61  				),
    62  			},
    63  
    64  			resource.TestStep{
    65  				Config: postConfig,
    66  				Check: resource.ComposeTestCheckFunc(
    67  					testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v),
    68  					resource.TestCheckResourceAttr(
    69  						"aws_redshift_cluster.default", "enable_logging", "false"),
    70  				),
    71  			},
    72  		},
    73  	})
    74  }
    75  
    76  func TestAccAWSRedshiftCluster_iamRoles(t *testing.T) {
    77  	var v redshift.Cluster
    78  
    79  	ri := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
    80  	preConfig := fmt.Sprintf(testAccAWSRedshiftClusterConfig_iamRoles, ri, ri, ri)
    81  	postConfig := fmt.Sprintf(testAccAWSRedshiftClusterConfig_updateIamRoles, ri, ri, ri)
    82  
    83  	resource.Test(t, resource.TestCase{
    84  		PreCheck:     func() { testAccPreCheck(t) },
    85  		Providers:    testAccProviders,
    86  		CheckDestroy: testAccCheckAWSRedshiftClusterDestroy,
    87  		Steps: []resource.TestStep{
    88  			resource.TestStep{
    89  				Config: preConfig,
    90  				Check: resource.ComposeTestCheckFunc(
    91  					testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v),
    92  					resource.TestCheckResourceAttr(
    93  						"aws_redshift_cluster.default", "iam_roles.#", "2"),
    94  				),
    95  			},
    96  
    97  			resource.TestStep{
    98  				Config: postConfig,
    99  				Check: resource.ComposeTestCheckFunc(
   100  					testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v),
   101  					resource.TestCheckResourceAttr(
   102  						"aws_redshift_cluster.default", "iam_roles.#", "1"),
   103  				),
   104  			},
   105  		},
   106  	})
   107  }
   108  
   109  func TestAccAWSRedshiftCluster_publiclyAccessible(t *testing.T) {
   110  	var v redshift.Cluster
   111  
   112  	ri := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
   113  	preConfig := fmt.Sprintf(testAccAWSRedshiftClusterConfig_notPubliclyAccessible, ri)
   114  	postConfig := fmt.Sprintf(testAccAWSRedshiftClusterConfig_updatePubliclyAccessible, ri)
   115  
   116  	resource.Test(t, resource.TestCase{
   117  		PreCheck:     func() { testAccPreCheck(t) },
   118  		Providers:    testAccProviders,
   119  		CheckDestroy: testAccCheckAWSRedshiftClusterDestroy,
   120  		Steps: []resource.TestStep{
   121  			resource.TestStep{
   122  				Config: preConfig,
   123  				Check: resource.ComposeTestCheckFunc(
   124  					testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v),
   125  					resource.TestCheckResourceAttr(
   126  						"aws_redshift_cluster.default", "publicly_accessible", "false"),
   127  				),
   128  			},
   129  
   130  			resource.TestStep{
   131  				Config: postConfig,
   132  				Check: resource.ComposeTestCheckFunc(
   133  					testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v),
   134  					resource.TestCheckResourceAttr(
   135  						"aws_redshift_cluster.default", "publicly_accessible", "true"),
   136  				),
   137  			},
   138  		},
   139  	})
   140  }
   141  
   142  func TestAccAWSRedshiftCluster_updateNodeCount(t *testing.T) {
   143  	var v redshift.Cluster
   144  
   145  	ri := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
   146  	preConfig := fmt.Sprintf(testAccAWSRedshiftClusterConfig_basic, ri)
   147  	postConfig := fmt.Sprintf(testAccAWSRedshiftClusterConfig_updateNodeCount, ri)
   148  
   149  	resource.Test(t, resource.TestCase{
   150  		PreCheck:     func() { testAccPreCheck(t) },
   151  		Providers:    testAccProviders,
   152  		CheckDestroy: testAccCheckAWSRedshiftClusterDestroy,
   153  		Steps: []resource.TestStep{
   154  			resource.TestStep{
   155  				Config: preConfig,
   156  				Check: resource.ComposeTestCheckFunc(
   157  					testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v),
   158  					resource.TestCheckResourceAttr(
   159  						"aws_redshift_cluster.default", "number_of_nodes", "1"),
   160  				),
   161  			},
   162  
   163  			resource.TestStep{
   164  				Config: postConfig,
   165  				Check: resource.ComposeTestCheckFunc(
   166  					testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v),
   167  					resource.TestCheckResourceAttr(
   168  						"aws_redshift_cluster.default", "number_of_nodes", "2"),
   169  				),
   170  			},
   171  		},
   172  	})
   173  }
   174  
   175  func TestAccAWSRedshiftCluster_tags(t *testing.T) {
   176  	var v redshift.Cluster
   177  
   178  	ri := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
   179  	preConfig := fmt.Sprintf(testAccAWSRedshiftClusterConfig_tags, ri)
   180  	postConfig := fmt.Sprintf(testAccAWSRedshiftClusterConfig_updatedTags, ri)
   181  
   182  	resource.Test(t, resource.TestCase{
   183  		PreCheck:     func() { testAccPreCheck(t) },
   184  		Providers:    testAccProviders,
   185  		CheckDestroy: testAccCheckAWSRedshiftClusterDestroy,
   186  		Steps: []resource.TestStep{
   187  			resource.TestStep{
   188  				Config: preConfig,
   189  				Check: resource.ComposeTestCheckFunc(
   190  					testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v),
   191  					resource.TestCheckResourceAttr(
   192  						"aws_redshift_cluster.default", "tags.%", "3"),
   193  					resource.TestCheckResourceAttr("aws_redshift_cluster.default", "tags.environment", "Production"),
   194  				),
   195  			},
   196  
   197  			resource.TestStep{
   198  				Config: postConfig,
   199  				Check: resource.ComposeTestCheckFunc(
   200  					testAccCheckAWSRedshiftClusterExists("aws_redshift_cluster.default", &v),
   201  					resource.TestCheckResourceAttr(
   202  						"aws_redshift_cluster.default", "tags.%", "1"),
   203  					resource.TestCheckResourceAttr("aws_redshift_cluster.default", "tags.environment", "Production"),
   204  				),
   205  			},
   206  		},
   207  	})
   208  }
   209  
   210  func testAccCheckAWSRedshiftClusterDestroy(s *terraform.State) error {
   211  	for _, rs := range s.RootModule().Resources {
   212  		if rs.Type != "aws_redshift_cluster" {
   213  			continue
   214  		}
   215  
   216  		// Try to find the Group
   217  		conn := testAccProvider.Meta().(*AWSClient).redshiftconn
   218  		var err error
   219  		resp, err := conn.DescribeClusters(
   220  			&redshift.DescribeClustersInput{
   221  				ClusterIdentifier: aws.String(rs.Primary.ID),
   222  			})
   223  
   224  		if err == nil {
   225  			if len(resp.Clusters) != 0 &&
   226  				*resp.Clusters[0].ClusterIdentifier == rs.Primary.ID {
   227  				return fmt.Errorf("Redshift Cluster %s still exists", rs.Primary.ID)
   228  			}
   229  		}
   230  
   231  		// Return nil if the cluster is already destroyed
   232  		if awsErr, ok := err.(awserr.Error); ok {
   233  			if awsErr.Code() == "ClusterNotFound" {
   234  				return nil
   235  			}
   236  		}
   237  
   238  		return err
   239  	}
   240  
   241  	return nil
   242  }
   243  
   244  func testAccCheckAWSRedshiftClusterExists(n string, v *redshift.Cluster) resource.TestCheckFunc {
   245  	return func(s *terraform.State) error {
   246  		rs, ok := s.RootModule().Resources[n]
   247  		if !ok {
   248  			return fmt.Errorf("Not found: %s", n)
   249  		}
   250  
   251  		if rs.Primary.ID == "" {
   252  			return fmt.Errorf("No Redshift Cluster Instance ID is set")
   253  		}
   254  
   255  		conn := testAccProvider.Meta().(*AWSClient).redshiftconn
   256  		resp, err := conn.DescribeClusters(&redshift.DescribeClustersInput{
   257  			ClusterIdentifier: aws.String(rs.Primary.ID),
   258  		})
   259  
   260  		if err != nil {
   261  			return err
   262  		}
   263  
   264  		for _, c := range resp.Clusters {
   265  			if *c.ClusterIdentifier == rs.Primary.ID {
   266  				*v = *c
   267  				return nil
   268  			}
   269  		}
   270  
   271  		return fmt.Errorf("Redshift Cluster (%s) not found", rs.Primary.ID)
   272  	}
   273  }
   274  
   275  func TestResourceAWSRedshiftClusterIdentifierValidation(t *testing.T) {
   276  	cases := []struct {
   277  		Value    string
   278  		ErrCount int
   279  	}{
   280  		{
   281  			Value:    "tEsting",
   282  			ErrCount: 1,
   283  		},
   284  		{
   285  			Value:    "1testing",
   286  			ErrCount: 1,
   287  		},
   288  		{
   289  			Value:    "testing--123",
   290  			ErrCount: 1,
   291  		},
   292  		{
   293  			Value:    "testing!",
   294  			ErrCount: 1,
   295  		},
   296  		{
   297  			Value:    "testing-",
   298  			ErrCount: 1,
   299  		},
   300  	}
   301  
   302  	for _, tc := range cases {
   303  		_, errors := validateRedshiftClusterIdentifier(tc.Value, "aws_redshift_cluster_identifier")
   304  
   305  		if len(errors) != tc.ErrCount {
   306  			t.Fatalf("Expected the Redshift Cluster cluster_identifier to trigger a validation error")
   307  		}
   308  	}
   309  }
   310  
   311  func TestResourceAWSRedshiftClusterDbNameValidation(t *testing.T) {
   312  	cases := []struct {
   313  		Value    string
   314  		ErrCount int
   315  	}{
   316  		{
   317  			Value:    "tEsting",
   318  			ErrCount: 1,
   319  		},
   320  		{
   321  			Value:    "testing1",
   322  			ErrCount: 1,
   323  		},
   324  		{
   325  			Value:    "testing-",
   326  			ErrCount: 1,
   327  		},
   328  		{
   329  			Value:    "",
   330  			ErrCount: 2,
   331  		},
   332  		{
   333  			Value:    randomString(65),
   334  			ErrCount: 1,
   335  		},
   336  	}
   337  
   338  	for _, tc := range cases {
   339  		_, errors := validateRedshiftClusterDbName(tc.Value, "aws_redshift_cluster_database_name")
   340  
   341  		if len(errors) != tc.ErrCount {
   342  			t.Fatalf("Expected the Redshift Cluster database_name to trigger a validation error")
   343  		}
   344  	}
   345  }
   346  
   347  func TestResourceAWSRedshiftClusterFinalSnapshotIdentifierValidation(t *testing.T) {
   348  	cases := []struct {
   349  		Value    string
   350  		ErrCount int
   351  	}{
   352  		{
   353  			Value:    "testing--123",
   354  			ErrCount: 1,
   355  		},
   356  		{
   357  			Value:    "testing-",
   358  			ErrCount: 1,
   359  		},
   360  		{
   361  			Value:    "Testingq123!",
   362  			ErrCount: 1,
   363  		},
   364  		{
   365  			Value:    randomString(256),
   366  			ErrCount: 1,
   367  		},
   368  	}
   369  
   370  	for _, tc := range cases {
   371  		_, errors := validateRedshiftClusterFinalSnapshotIdentifier(tc.Value, "aws_redshift_cluster_final_snapshot_identifier")
   372  
   373  		if len(errors) != tc.ErrCount {
   374  			t.Fatalf("Expected the Redshift Cluster final_snapshot_identifier to trigger a validation error")
   375  		}
   376  	}
   377  }
   378  
   379  func TestResourceAWSRedshiftClusterMasterUsernameValidation(t *testing.T) {
   380  	cases := []struct {
   381  		Value    string
   382  		ErrCount int
   383  	}{
   384  		{
   385  			Value:    "1Testing",
   386  			ErrCount: 1,
   387  		},
   388  		{
   389  			Value:    "Testing!!",
   390  			ErrCount: 1,
   391  		},
   392  		{
   393  			Value:    randomString(129),
   394  			ErrCount: 1,
   395  		},
   396  		{
   397  			Value:    "testing_testing123",
   398  			ErrCount: 0,
   399  		},
   400  	}
   401  
   402  	for _, tc := range cases {
   403  		_, errors := validateRedshiftClusterMasterUsername(tc.Value, "aws_redshift_cluster_master_username")
   404  
   405  		if len(errors) != tc.ErrCount {
   406  			t.Fatalf("Expected the Redshift Cluster master_username to trigger a validation error")
   407  		}
   408  	}
   409  }
   410  
   411  var testAccAWSRedshiftClusterConfig_updateNodeCount = `
   412  resource "aws_redshift_cluster" "default" {
   413    cluster_identifier = "tf-redshift-cluster-%d"
   414    availability_zone = "us-west-2a"
   415    database_name = "mydb"
   416    master_username = "foo_test"
   417    master_password = "Mustbe8characters"
   418    node_type = "dc1.large"
   419    automated_snapshot_retention_period = 0
   420    allow_version_upgrade = false
   421    number_of_nodes = 2
   422  }
   423  `
   424  
   425  var testAccAWSRedshiftClusterConfig_basic = `
   426  resource "aws_redshift_cluster" "default" {
   427    cluster_identifier = "tf-redshift-cluster-%d"
   428    availability_zone = "us-west-2a"
   429    database_name = "mydb"
   430    master_username = "foo_test"
   431    master_password = "Mustbe8characters"
   432    node_type = "dc1.large"
   433    automated_snapshot_retention_period = 0
   434    allow_version_upgrade = false
   435  }`
   436  
   437  var testAccAWSRedshiftClusterConfig_loggingDisabled = `
   438  resource "aws_redshift_cluster" "default" {
   439    cluster_identifier = "tf-redshift-cluster-%d"
   440    availability_zone = "us-west-2a"
   441    database_name = "mydb"
   442    master_username = "foo_test"
   443    master_password = "Mustbe8characters"
   444    node_type = "dc1.large"
   445    automated_snapshot_retention_period = 0
   446    allow_version_upgrade = false
   447    enable_logging = false
   448  }
   449  `
   450  
   451  var testAccAWSRedshiftClusterConfig_loggingEnabled = `
   452  resource "aws_s3_bucket" "bucket" {
   453  	bucket = "tf-redshift-logging-test-bucket"
   454  	force_destroy = true
   455  	policy = <<EOF
   456  {
   457  	"Version": "2008-10-17",
   458  	"Statement": [
   459  		{
   460  			"Sid": "Stmt1376526643067",
   461  			"Effect": "Allow",
   462  			"Principal": {
   463  				"AWS": "arn:aws:iam::902366379725:user/logs"
   464  			},
   465  			"Action": "s3:PutObject",
   466  			"Resource": "arn:aws:s3:::tf-redshift-logging-test-bucket/*"
   467  		},
   468  		{
   469  			"Sid": "Stmt137652664067",
   470  			"Effect": "Allow",
   471  			"Principal": {
   472  				"AWS": "arn:aws:iam::902366379725:user/logs"
   473  			},
   474  			"Action": "s3:GetBucketAcl",
   475  			"Resource": "arn:aws:s3:::tf-redshift-logging-test-bucket"
   476  		}
   477  	]
   478  }
   479  EOF
   480  }
   481  
   482  resource "aws_redshift_cluster" "default" {
   483    cluster_identifier = "tf-redshift-cluster-%d"
   484    availability_zone = "us-west-2a"
   485    database_name = "mydb"
   486    master_username = "foo_test"
   487    master_password = "Mustbe8characters"
   488    node_type = "dc1.large"
   489    automated_snapshot_retention_period = 0
   490    allow_version_upgrade = false
   491    enable_logging = true
   492    bucket_name = "${aws_s3_bucket.bucket.bucket}"
   493  }`
   494  
   495  var testAccAWSRedshiftClusterConfig_tags = `
   496  resource "aws_redshift_cluster" "default" {
   497    cluster_identifier = "tf-redshift-cluster-%d"
   498    availability_zone = "us-west-2a"
   499    database_name = "mydb"
   500    master_username = "foo"
   501    master_password = "Mustbe8characters"
   502    node_type = "dc1.large"
   503    automated_snapshot_retention_period = 7
   504    allow_version_upgrade = false
   505    tags {
   506      environment = "Production"
   507      cluster = "reader"
   508      Type = "master"
   509    }
   510  }`
   511  
   512  var testAccAWSRedshiftClusterConfig_updatedTags = `
   513  resource "aws_redshift_cluster" "default" {
   514    cluster_identifier = "tf-redshift-cluster-%d"
   515    availability_zone = "us-west-2a"
   516    database_name = "mydb"
   517    master_username = "foo"
   518    master_password = "Mustbe8characters"
   519    node_type = "dc1.large"
   520    automated_snapshot_retention_period = 7
   521    allow_version_upgrade = false
   522    tags {
   523      environment = "Production"
   524    }
   525  }`
   526  
   527  var testAccAWSRedshiftClusterConfig_notPubliclyAccessible = `
   528  resource "aws_vpc" "foo" {
   529  	cidr_block = "10.1.0.0/16"
   530  }
   531  resource "aws_internet_gateway" "foo" {
   532  	vpc_id = "${aws_vpc.foo.id}"
   533  	tags {
   534  		foo = "bar"
   535  	}
   536  }
   537  resource "aws_subnet" "foo" {
   538  	cidr_block = "10.1.1.0/24"
   539  	availability_zone = "us-west-2a"
   540  	vpc_id = "${aws_vpc.foo.id}"
   541  	tags {
   542  		Name = "tf-dbsubnet-test-1"
   543  	}
   544  }
   545  resource "aws_subnet" "bar" {
   546  	cidr_block = "10.1.2.0/24"
   547  	availability_zone = "us-west-2b"
   548  	vpc_id = "${aws_vpc.foo.id}"
   549  	tags {
   550  		Name = "tf-dbsubnet-test-2"
   551  	}
   552  }
   553  resource "aws_subnet" "foobar" {
   554  	cidr_block = "10.1.3.0/24"
   555  	availability_zone = "us-west-2c"
   556  	vpc_id = "${aws_vpc.foo.id}"
   557  	tags {
   558  		Name = "tf-dbsubnet-test-3"
   559  	}
   560  }
   561  resource "aws_redshift_subnet_group" "foo" {
   562  	name = "foo"
   563  	description = "foo description"
   564  	subnet_ids = ["${aws_subnet.foo.id}", "${aws_subnet.bar.id}", "${aws_subnet.foobar.id}"]
   565  }
   566  resource "aws_redshift_cluster" "default" {
   567    cluster_identifier = "tf-redshift-cluster-%d"
   568    availability_zone = "us-west-2a"
   569    database_name = "mydb"
   570    master_username = "foo"
   571    master_password = "Mustbe8characters"
   572    node_type = "dc1.large"
   573    automated_snapshot_retention_period = 0
   574    allow_version_upgrade = false
   575    cluster_subnet_group_name = "${aws_redshift_subnet_group.foo.name}"
   576    publicly_accessible = false
   577  }`
   578  
   579  var testAccAWSRedshiftClusterConfig_updatePubliclyAccessible = `
   580  resource "aws_vpc" "foo" {
   581  	cidr_block = "10.1.0.0/16"
   582  }
   583  resource "aws_internet_gateway" "foo" {
   584  	vpc_id = "${aws_vpc.foo.id}"
   585  	tags {
   586  		foo = "bar"
   587  	}
   588  }
   589  resource "aws_subnet" "foo" {
   590  	cidr_block = "10.1.1.0/24"
   591  	availability_zone = "us-west-2a"
   592  	vpc_id = "${aws_vpc.foo.id}"
   593  	tags {
   594  		Name = "tf-dbsubnet-test-1"
   595  	}
   596  }
   597  resource "aws_subnet" "bar" {
   598  	cidr_block = "10.1.2.0/24"
   599  	availability_zone = "us-west-2b"
   600  	vpc_id = "${aws_vpc.foo.id}"
   601  	tags {
   602  		Name = "tf-dbsubnet-test-2"
   603  	}
   604  }
   605  resource "aws_subnet" "foobar" {
   606  	cidr_block = "10.1.3.0/24"
   607  	availability_zone = "us-west-2c"
   608  	vpc_id = "${aws_vpc.foo.id}"
   609  	tags {
   610  		Name = "tf-dbsubnet-test-3"
   611  	}
   612  }
   613  resource "aws_redshift_subnet_group" "foo" {
   614  	name = "foo"
   615  	description = "foo description"
   616  	subnet_ids = ["${aws_subnet.foo.id}", "${aws_subnet.bar.id}", "${aws_subnet.foobar.id}"]
   617  }
   618  resource "aws_redshift_cluster" "default" {
   619    cluster_identifier = "tf-redshift-cluster-%d"
   620    availability_zone = "us-west-2a"
   621    database_name = "mydb"
   622    master_username = "foo"
   623    master_password = "Mustbe8characters"
   624    node_type = "dc1.large"
   625    automated_snapshot_retention_period = 0
   626    allow_version_upgrade = false
   627    cluster_subnet_group_name = "${aws_redshift_subnet_group.foo.name}"
   628    publicly_accessible = true
   629  }`
   630  
   631  var testAccAWSRedshiftClusterConfig_iamRoles = `
   632  resource "aws_iam_role" "ec2-role" {
   633  	name   = "test-role-ec2-%d"
   634  	path = "/"
   635   	assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":[\"ec2.amazonaws.com\"]},\"Action\":[\"sts:AssumeRole\"]}]}"
   636  }
   637  
   638  resource "aws_iam_role" "lambda-role" {
   639   	name   = "test-role-lambda-%d"
   640   	path = "/"
   641   	assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":[\"lambda.amazonaws.com\"]},\"Action\":[\"sts:AssumeRole\"]}]}"
   642  }
   643  
   644  resource "aws_redshift_cluster" "default" {
   645     cluster_identifier = "tf-redshift-cluster-%d"
   646     availability_zone = "us-west-2a"
   647     database_name = "mydb"
   648     master_username = "foo_test"
   649     master_password = "Mustbe8characters"
   650     node_type = "dc1.large"
   651     automated_snapshot_retention_period = 0
   652     allow_version_upgrade = false
   653     iam_roles = ["${aws_iam_role.ec2-role.arn}", "${aws_iam_role.lambda-role.arn}"]
   654  }`
   655  
   656  var testAccAWSRedshiftClusterConfig_updateIamRoles = `
   657  resource "aws_iam_role" "ec2-role" {
   658   	name   = "test-role-ec2-%d"
   659   	path = "/"
   660   	assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":[\"ec2.amazonaws.com\"]},\"Action\":[\"sts:AssumeRole\"]}]}"
   661   }
   662  
   663   resource "aws_iam_role" "lambda-role" {
   664   	name   = "test-role-lambda-%d"
   665   	path = "/"
   666   	assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":[\"lambda.amazonaws.com\"]},\"Action\":[\"sts:AssumeRole\"]}]}"
   667   }
   668  
   669   resource "aws_redshift_cluster" "default" {
   670     cluster_identifier = "tf-redshift-cluster-%d"
   671     availability_zone = "us-west-2a"
   672     database_name = "mydb"
   673     master_username = "foo_test"
   674     master_password = "Mustbe8characters"
   675     node_type = "dc1.large"
   676     automated_snapshot_retention_period = 0
   677     allow_version_upgrade = false
   678     iam_roles = ["${aws_iam_role.ec2-role.arn}"]
   679   }`