2014-07-22 22:26:48 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-12-19 17:42:10 +01:00
|
|
|
"log"
|
2016-05-13 18:20:29 +02:00
|
|
|
"regexp"
|
2016-02-18 18:33:21 +01:00
|
|
|
"strings"
|
2015-12-19 17:42:10 +01:00
|
|
|
|
2015-04-01 16:13:41 +02:00
|
|
|
"math/rand"
|
2014-07-22 22:26:48 +02:00
|
|
|
"testing"
|
2015-04-01 16:13:41 +02:00
|
|
|
"time"
|
2014-07-22 22:26:48 +02:00
|
|
|
|
2016-02-12 21:17:19 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
2014-07-22 22:26:48 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
2015-02-23 22:22:52 +01:00
|
|
|
|
2015-06-03 20:36:57 +02:00
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
|
|
|
"github.com/aws/aws-sdk-go/service/rds"
|
2014-07-22 22:26:48 +02:00
|
|
|
)
|
|
|
|
|
2015-06-08 01:18:14 +02:00
|
|
|
func TestAccAWSDBInstance_basic(t *testing.T) {
|
2014-07-22 22:26:48 +02:00
|
|
|
var v rds.DBInstance
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-01-24 00:12:34 +01:00
|
|
|
{
|
2014-07-22 22:26:48 +02:00
|
|
|
Config: testAccAWSDBInstanceConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
|
|
|
testAccCheckAWSDBInstanceAttributes(&v),
|
2014-07-23 04:54:10 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-07-31 21:18:33 +02:00
|
|
|
"aws_db_instance.bar", "allocated_storage", "10"),
|
2014-07-23 04:54:10 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_db_instance.bar", "engine", "mysql"),
|
2015-05-14 16:44:22 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_db_instance.bar", "license_model", "general-public-license"),
|
2014-07-23 04:54:10 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_db_instance.bar", "instance_class", "db.t1.micro"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_db_instance.bar", "name", "baz"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_db_instance.bar", "username", "foo"),
|
2014-10-22 23:22:30 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_db_instance.bar", "parameter_group_name", "default.mysql5.6"),
|
2016-11-10 07:41:43 +01:00
|
|
|
resource.TestCheckResourceAttrSet("aws_db_instance.bar", "hosted_zone_id"),
|
2017-05-28 07:47:55 +02:00
|
|
|
resource.TestCheckResourceAttrSet(
|
|
|
|
"aws_db_instance.bar", "resource_id"),
|
2014-07-22 22:26:48 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-03-31 19:22:57 +02:00
|
|
|
func TestAccAWSDBInstance_namePrefix(t *testing.T) {
|
|
|
|
var v rds.DBInstance
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccAWSDBInstanceConfig_namePrefix,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSDBInstanceExists("aws_db_instance.test", &v),
|
|
|
|
testAccCheckAWSDBInstanceAttributes(&v),
|
|
|
|
resource.TestMatchResourceAttr(
|
|
|
|
"aws_db_instance.test", "identifier", regexp.MustCompile("^tf-test-")),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccAWSDBInstance_generatedName(t *testing.T) {
|
|
|
|
var v rds.DBInstance
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccAWSDBInstanceConfig_generatedName,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSDBInstanceExists("aws_db_instance.test", &v),
|
|
|
|
testAccCheckAWSDBInstanceAttributes(&v),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-05-13 18:20:29 +02:00
|
|
|
func TestAccAWSDBInstance_kmsKey(t *testing.T) {
|
|
|
|
var v rds.DBInstance
|
|
|
|
keyRegex := regexp.MustCompile("^arn:aws:kms:")
|
|
|
|
|
|
|
|
ri := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
|
|
|
|
config := fmt.Sprintf(testAccAWSDBInstanceConfigKmsKeyId, ri)
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-01-24 00:12:34 +01:00
|
|
|
{
|
2016-05-13 18:20:29 +02:00
|
|
|
Config: config,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
|
|
|
testAccCheckAWSDBInstanceAttributes(&v),
|
|
|
|
resource.TestMatchResourceAttr(
|
|
|
|
"aws_db_instance.bar", "kms_key_id", keyRegex),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-12-18 15:35:24 +01:00
|
|
|
func TestAccAWSDBInstance_subnetGroup(t *testing.T) {
|
|
|
|
var v rds.DBInstance
|
|
|
|
rName := acctest.RandString(10)
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccAWSDBInstanceConfigWithSubnetGroup(rName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
|
|
|
resource.TestCheckResourceAttr(
|
2017-02-03 17:22:46 +01:00
|
|
|
"aws_db_instance.bar", "db_subnet_group_name", "foo-"+rName),
|
2016-12-18 15:35:24 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: testAccAWSDBInstanceConfigWithSubnetGroupUpdated(rName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
|
|
|
resource.TestCheckResourceAttr(
|
2017-02-03 17:22:46 +01:00
|
|
|
"aws_db_instance.bar", "db_subnet_group_name", "bar-"+rName),
|
2016-12-18 15:35:24 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-12-21 10:15:52 +01:00
|
|
|
func TestAccAWSDBInstance_optionGroup(t *testing.T) {
|
|
|
|
var v rds.DBInstance
|
|
|
|
|
2017-01-30 22:48:52 +01:00
|
|
|
rName := fmt.Sprintf("tf-option-test-%d", acctest.RandInt())
|
|
|
|
|
2015-12-21 10:15:52 +01:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-01-24 00:12:34 +01:00
|
|
|
{
|
2017-01-30 22:48:52 +01:00
|
|
|
Config: testAccAWSDBInstanceConfigWithOptionGroup(rName),
|
2015-12-21 10:15:52 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
|
|
|
testAccCheckAWSDBInstanceAttributes(&v),
|
|
|
|
resource.TestCheckResourceAttr(
|
2017-01-30 22:48:52 +01:00
|
|
|
"aws_db_instance.bar", "option_group_name", rName),
|
2015-12-21 10:15:52 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-04-29 21:32:21 +02:00
|
|
|
func TestAccAWSDBInstance_iamAuth(t *testing.T) {
|
|
|
|
var v rds.DBInstance
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccCheckAWSDBIAMAuth(acctest.RandInt()),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
|
|
|
testAccCheckAWSDBInstanceAttributes(&v),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_db_instance.bar", "iam_database_authentication_enabled", "true"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-05-13 23:36:30 +02:00
|
|
|
func TestAccAWSDBInstanceReplica(t *testing.T) {
|
2015-05-20 16:28:33 +02:00
|
|
|
var s, r rds.DBInstance
|
2015-05-13 23:36:30 +02:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-01-24 00:12:34 +01:00
|
|
|
{
|
2015-05-20 16:28:33 +02:00
|
|
|
Config: testAccReplicaInstanceConfig(rand.New(rand.NewSource(time.Now().UnixNano())).Int()),
|
2015-05-13 23:36:30 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2015-05-20 16:28:33 +02:00
|
|
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &s),
|
2015-05-13 23:36:30 +02:00
|
|
|
testAccCheckAWSDBInstanceExists("aws_db_instance.replica", &r),
|
2015-05-20 16:28:33 +02:00
|
|
|
testAccCheckAWSDBInstanceReplicaAttributes(&s, &r),
|
2015-05-13 23:36:30 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-02-03 18:21:25 +01:00
|
|
|
func TestAccAWSDBInstanceNoSnapshot(t *testing.T) {
|
2015-11-11 18:24:59 +01:00
|
|
|
var snap rds.DBInstance
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
2017-02-03 18:21:25 +01:00
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSDBInstanceNoSnapshot,
|
2015-11-11 18:24:59 +01:00
|
|
|
Steps: []resource.TestStep{
|
2017-01-24 00:12:34 +01:00
|
|
|
{
|
2016-02-12 21:17:19 +01:00
|
|
|
Config: testAccSnapshotInstanceConfig(),
|
2015-11-11 18:24:59 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSDBInstanceExists("aws_db_instance.snapshot", &snap),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-02-03 18:21:25 +01:00
|
|
|
func TestAccAWSDBInstanceSnapshot(t *testing.T) {
|
|
|
|
var snap rds.DBInstance
|
2017-02-22 15:13:04 +01:00
|
|
|
rInt := acctest.RandInt()
|
2015-11-11 18:24:59 +01:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
2017-02-03 18:21:25 +01:00
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
// testAccCheckAWSDBInstanceSnapshot verifies a database snapshot is
|
|
|
|
// created, and subequently deletes it
|
2017-02-22 15:13:04 +01:00
|
|
|
CheckDestroy: testAccCheckAWSDBInstanceSnapshot(rInt),
|
2015-11-11 18:24:59 +01:00
|
|
|
Steps: []resource.TestStep{
|
2017-01-24 00:12:34 +01:00
|
|
|
{
|
2017-02-22 15:13:04 +01:00
|
|
|
Config: testAccSnapshotInstanceConfigWithSnapshot(rInt),
|
2015-11-11 18:24:59 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2017-02-03 18:21:25 +01:00
|
|
|
testAccCheckAWSDBInstanceExists("aws_db_instance.snapshot", &snap),
|
2015-11-11 18:24:59 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-02-01 23:32:38 +01:00
|
|
|
func TestAccAWSDBInstance_enhancedMonitoring(t *testing.T) {
|
|
|
|
var dbInstance rds.DBInstance
|
2016-09-04 11:50:50 +02:00
|
|
|
rName := acctest.RandString(5)
|
2016-02-01 23:32:38 +01:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSDBInstanceNoSnapshot,
|
|
|
|
Steps: []resource.TestStep{
|
2017-01-24 00:12:34 +01:00
|
|
|
{
|
2016-09-04 11:50:50 +02:00
|
|
|
Config: testAccSnapshotInstanceConfig_enhancedMonitoring(rName),
|
2016-02-01 23:32:38 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSDBInstanceExists("aws_db_instance.enhanced_monitoring", &dbInstance),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_db_instance.enhanced_monitoring", "monitoring_interval", "5"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-06-21 21:53:13 +02:00
|
|
|
// Regression test for https://github.com/hashicorp/terraform/issues/3760 .
|
|
|
|
// We apply a plan, then change just the iops. If the apply succeeds, we
|
|
|
|
// consider this a pass, as before in 3760 the request would fail
|
2016-07-28 21:30:50 +02:00
|
|
|
func TestAccAWS_separate_DBInstance_iops_update(t *testing.T) {
|
2016-06-21 21:53:13 +02:00
|
|
|
var v rds.DBInstance
|
|
|
|
|
|
|
|
rName := acctest.RandString(5)
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-01-24 00:12:34 +01:00
|
|
|
{
|
2016-06-21 21:53:13 +02:00
|
|
|
Config: testAccSnapshotInstanceConfig_iopsUpdate(rName, 1000),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
|
|
|
testAccCheckAWSDBInstanceAttributes(&v),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
2017-01-24 00:12:34 +01:00
|
|
|
{
|
2016-06-21 21:53:13 +02:00
|
|
|
Config: testAccSnapshotInstanceConfig_iopsUpdate(rName, 2000),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
|
|
|
testAccCheckAWSDBInstanceAttributes(&v),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-07-12 10:07:25 +02:00
|
|
|
func TestAccAWSDBInstance_portUpdate(t *testing.T) {
|
|
|
|
var v rds.DBInstance
|
|
|
|
|
|
|
|
rName := acctest.RandString(5)
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-01-24 00:12:34 +01:00
|
|
|
{
|
2016-07-12 10:07:25 +02:00
|
|
|
Config: testAccSnapshotInstanceConfig_mysqlPort(rName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_db_instance.bar", "port", "3306"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
2017-01-24 00:12:34 +01:00
|
|
|
{
|
2016-07-12 10:07:25 +02:00
|
|
|
Config: testAccSnapshotInstanceConfig_updateMysqlPort(rName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_db_instance.bar", "port", "3305"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-01-17 23:43:53 +01:00
|
|
|
func TestAccAWSDBInstance_MSSQL_TZ(t *testing.T) {
|
|
|
|
var v rds.DBInstance
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-01-24 00:12:34 +01:00
|
|
|
{
|
2017-01-17 23:43:53 +01:00
|
|
|
Config: testAccAWSDBMSSQL_timezone,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSDBInstanceExists("aws_db_instance.mssql", &v),
|
|
|
|
testAccCheckAWSDBInstanceAttributes_MSSQL(&v, ""),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_db_instance.mssql", "allocated_storage", "20"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_db_instance.mssql", "engine", "sqlserver-ex"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
2017-01-24 00:12:34 +01:00
|
|
|
{
|
2017-01-17 23:43:53 +01:00
|
|
|
Config: testAccAWSDBMSSQL_timezone_AKST,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSDBInstanceExists("aws_db_instance.mssql", &v),
|
|
|
|
testAccCheckAWSDBInstanceAttributes_MSSQL(&v, "Alaskan Standard Time"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_db_instance.mssql", "allocated_storage", "20"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_db_instance.mssql", "engine", "sqlserver-ex"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-01-24 00:12:34 +01:00
|
|
|
func TestAccAWSDBInstance_MinorVersion(t *testing.T) {
|
|
|
|
var v rds.DBInstance
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccAWSDBInstanceConfigAutoMinorVersion,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-02-13 18:26:06 +01:00
|
|
|
// See https://github.com/hashicorp/terraform/issues/11881
|
|
|
|
func TestAccAWSDBInstance_diffSuppressInitialState(t *testing.T) {
|
|
|
|
var v rds.DBInstance
|
|
|
|
rInt := acctest.RandInt()
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccAWSDBInstanceConfigSuppressInitialState(rInt),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-07-22 22:26:48 +02:00
|
|
|
func testAccCheckAWSDBInstanceDestroy(s *terraform.State) error {
|
2015-04-13 22:45:55 +02:00
|
|
|
conn := testAccProvider.Meta().(*AWSClient).rdsconn
|
2014-07-22 22:26:48 +02:00
|
|
|
|
2014-09-17 02:44:42 +02:00
|
|
|
for _, rs := range s.RootModule().Resources {
|
2014-07-22 22:26:48 +02:00
|
|
|
if rs.Type != "aws_db_instance" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to find the Group
|
2015-05-20 13:21:23 +02:00
|
|
|
var err error
|
2014-07-22 22:26:48 +02:00
|
|
|
resp, err := conn.DescribeDBInstances(
|
2015-04-13 22:45:55 +02:00
|
|
|
&rds.DescribeDBInstancesInput{
|
2015-02-23 22:22:52 +01:00
|
|
|
DBInstanceIdentifier: aws.String(rs.Primary.ID),
|
2014-07-22 22:26:48 +02:00
|
|
|
})
|
|
|
|
|
2015-12-22 04:43:42 +01:00
|
|
|
if ae, ok := err.(awserr.Error); ok && ae.Code() == "DBInstanceNotFound" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2014-07-22 22:26:48 +02:00
|
|
|
if err == nil {
|
|
|
|
if len(resp.DBInstances) != 0 &&
|
2015-02-23 22:22:52 +01:00
|
|
|
*resp.DBInstances[0].DBInstanceIdentifier == rs.Primary.ID {
|
2014-07-22 22:26:48 +02:00
|
|
|
return fmt.Errorf("DB Instance still exists")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify the error
|
2015-05-20 13:21:23 +02:00
|
|
|
newerr, ok := err.(awserr.Error)
|
2014-07-22 22:26:48 +02:00
|
|
|
if !ok {
|
|
|
|
return err
|
|
|
|
}
|
2015-12-21 10:15:52 +01:00
|
|
|
if newerr.Code() != "DBInstanceNotFound" {
|
2014-07-22 22:26:48 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-07-23 04:54:10 +02:00
|
|
|
func testAccCheckAWSDBInstanceAttributes(v *rds.DBInstance) resource.TestCheckFunc {
|
2014-07-22 22:26:48 +02:00
|
|
|
return func(s *terraform.State) error {
|
|
|
|
|
2015-02-23 22:22:52 +01:00
|
|
|
if *v.Engine != "mysql" {
|
2015-02-25 17:44:10 +01:00
|
|
|
return fmt.Errorf("bad engine: %#v", *v.Engine)
|
2014-07-23 04:54:10 +02:00
|
|
|
}
|
|
|
|
|
2015-11-10 18:35:12 +01:00
|
|
|
if *v.EngineVersion == "" {
|
2015-02-25 17:44:10 +01:00
|
|
|
return fmt.Errorf("bad engine_version: %#v", *v.EngineVersion)
|
|
|
|
}
|
|
|
|
|
|
|
|
if *v.BackupRetentionPeriod != 0 {
|
|
|
|
return fmt.Errorf("bad backup_retention_period: %#v", *v.BackupRetentionPeriod)
|
2014-07-23 04:54:10 +02:00
|
|
|
}
|
2014-07-22 22:26:48 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-17 23:43:53 +01:00
|
|
|
func testAccCheckAWSDBInstanceAttributes_MSSQL(v *rds.DBInstance, tz string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
|
|
|
|
if *v.Engine != "sqlserver-ex" {
|
|
|
|
return fmt.Errorf("bad engine: %#v", *v.Engine)
|
|
|
|
}
|
|
|
|
|
|
|
|
rtz := ""
|
|
|
|
if v.Timezone != nil {
|
|
|
|
rtz = *v.Timezone
|
|
|
|
}
|
|
|
|
|
|
|
|
if tz != rtz {
|
|
|
|
return fmt.Errorf("Expected (%s) Timezone for MSSQL test, got (%s)", tz, rtz)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-20 16:28:33 +02:00
|
|
|
func testAccCheckAWSDBInstanceReplicaAttributes(source, replica *rds.DBInstance) resource.TestCheckFunc {
|
2015-05-13 23:36:30 +02:00
|
|
|
return func(s *terraform.State) error {
|
|
|
|
|
2015-05-20 16:28:33 +02:00
|
|
|
if replica.ReadReplicaSourceDBInstanceIdentifier != nil && *replica.ReadReplicaSourceDBInstanceIdentifier != *source.DBInstanceIdentifier {
|
|
|
|
return fmt.Errorf("bad source identifier for replica, expected: '%s', got: '%s'", *source.DBInstanceIdentifier, *replica.ReadReplicaSourceDBInstanceIdentifier)
|
2015-05-13 23:36:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-22 15:13:04 +01:00
|
|
|
func testAccCheckAWSDBInstanceSnapshot(rInt int) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "aws_db_instance" {
|
|
|
|
continue
|
|
|
|
}
|
2015-11-11 18:24:59 +01:00
|
|
|
|
2017-02-22 15:13:04 +01:00
|
|
|
awsClient := testAccProvider.Meta().(*AWSClient)
|
|
|
|
conn := awsClient.rdsconn
|
2015-11-11 18:24:59 +01:00
|
|
|
|
2017-02-22 15:13:04 +01:00
|
|
|
var err error
|
|
|
|
log.Printf("[INFO] Trying to locate the DBInstance Final Snapshot")
|
|
|
|
snapshot_identifier := fmt.Sprintf("foobarbaz-test-terraform-final-snapshot-%d", rInt)
|
|
|
|
_, snapErr := conn.DescribeDBSnapshots(
|
|
|
|
&rds.DescribeDBSnapshotsInput{
|
|
|
|
DBSnapshotIdentifier: aws.String(snapshot_identifier),
|
|
|
|
})
|
2015-11-11 18:24:59 +01:00
|
|
|
|
2017-02-22 15:13:04 +01:00
|
|
|
if snapErr != nil {
|
|
|
|
newerr, _ := snapErr.(awserr.Error)
|
|
|
|
if newerr.Code() == "DBSnapshotNotFound" {
|
|
|
|
return fmt.Errorf("Snapshot %s not found", snapshot_identifier)
|
|
|
|
}
|
|
|
|
} else { // snapshot was found,
|
|
|
|
// verify we have the tags copied to the snapshot
|
|
|
|
instanceARN, err := buildRDSARN(snapshot_identifier, testAccProvider.Meta().(*AWSClient).partition, testAccProvider.Meta().(*AWSClient).accountid, testAccProvider.Meta().(*AWSClient).region)
|
|
|
|
// tags have a different ARN, just swapping :db: for :snapshot:
|
|
|
|
tagsARN := strings.Replace(instanceARN, ":db:", ":snapshot:", 1)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error building ARN for tags check with ARN (%s): %s", tagsARN, err)
|
|
|
|
}
|
|
|
|
resp, err := conn.ListTagsForResource(&rds.ListTagsForResourceInput{
|
|
|
|
ResourceName: aws.String(tagsARN),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error retrieving tags for ARN (%s): %s", tagsARN, err)
|
|
|
|
}
|
2015-11-11 18:24:59 +01:00
|
|
|
|
2017-02-22 15:13:04 +01:00
|
|
|
if resp.TagList == nil || len(resp.TagList) == 0 {
|
|
|
|
return fmt.Errorf("Tag list is nil or zero: %s", resp.TagList)
|
|
|
|
}
|
2015-11-11 18:24:59 +01:00
|
|
|
|
2017-02-22 15:13:04 +01:00
|
|
|
var found bool
|
|
|
|
for _, t := range resp.TagList {
|
|
|
|
if *t.Key == "Name" && *t.Value == "tf-tags-db" {
|
|
|
|
found = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
return fmt.Errorf("Expected to find tag Name (%s), but wasn't found. Tags: %s", "tf-tags-db", resp.TagList)
|
|
|
|
}
|
|
|
|
// end tag search
|
|
|
|
|
|
|
|
log.Printf("[INFO] Deleting the Snapshot %s", snapshot_identifier)
|
|
|
|
_, snapDeleteErr := conn.DeleteDBSnapshot(
|
|
|
|
&rds.DeleteDBSnapshotInput{
|
|
|
|
DBSnapshotIdentifier: aws.String(snapshot_identifier),
|
|
|
|
})
|
|
|
|
if snapDeleteErr != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} // end snapshot was found
|
2015-11-11 18:24:59 +01:00
|
|
|
|
2017-02-22 15:13:04 +01:00
|
|
|
resp, err := conn.DescribeDBInstances(
|
|
|
|
&rds.DescribeDBInstancesInput{
|
|
|
|
DBInstanceIdentifier: aws.String(rs.Primary.ID),
|
|
|
|
})
|
2016-02-18 18:33:21 +01:00
|
|
|
|
2017-02-22 15:13:04 +01:00
|
|
|
if err != nil {
|
|
|
|
newerr, _ := err.(awserr.Error)
|
|
|
|
if newerr.Code() != "DBInstanceNotFound" {
|
|
|
|
return err
|
|
|
|
}
|
2016-02-18 18:33:21 +01:00
|
|
|
|
2017-02-22 15:13:04 +01:00
|
|
|
} else {
|
|
|
|
if len(resp.DBInstances) != 0 &&
|
|
|
|
*resp.DBInstances[0].DBInstanceIdentifier == rs.Primary.ID {
|
|
|
|
return fmt.Errorf("DB Instance still exists")
|
2016-02-18 18:33:21 +01:00
|
|
|
}
|
|
|
|
}
|
2017-02-22 15:13:04 +01:00
|
|
|
}
|
2016-02-18 18:33:21 +01:00
|
|
|
|
2017-02-22 15:13:04 +01:00
|
|
|
return nil
|
2015-11-11 18:24:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckAWSDBInstanceNoSnapshot(s *terraform.State) error {
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).rdsconn
|
|
|
|
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "aws_db_instance" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
resp, err := conn.DescribeDBInstances(
|
|
|
|
&rds.DescribeDBInstancesInput{
|
|
|
|
DBInstanceIdentifier: aws.String(rs.Primary.ID),
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
newerr, _ := err.(awserr.Error)
|
|
|
|
if newerr.Code() != "DBInstanceNotFound" {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if len(resp.DBInstances) != 0 &&
|
2015-12-17 18:24:24 +01:00
|
|
|
*resp.DBInstances[0].DBInstanceIdentifier == rs.Primary.ID {
|
2015-11-11 18:24:59 +01:00
|
|
|
return fmt.Errorf("DB Instance still exists")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
snapshot_identifier := "foobarbaz-test-terraform-final-snapshot-2"
|
|
|
|
_, snapErr := conn.DescribeDBSnapshots(
|
|
|
|
&rds.DescribeDBSnapshotsInput{
|
|
|
|
DBSnapshotIdentifier: aws.String(snapshot_identifier),
|
|
|
|
})
|
|
|
|
|
|
|
|
if snapErr != nil {
|
|
|
|
newerr, _ := snapErr.(awserr.Error)
|
|
|
|
if newerr.Code() != "DBSnapshotNotFound" {
|
|
|
|
return fmt.Errorf("Snapshot %s found and it shouldn't have been", snapshot_identifier)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-07-22 22:26:48 +02:00
|
|
|
func testAccCheckAWSDBInstanceExists(n string, v *rds.DBInstance) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
2014-09-17 02:44:42 +02:00
|
|
|
rs, ok := s.RootModule().Resources[n]
|
2014-07-22 22:26:48 +02:00
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
2014-09-17 02:44:42 +02:00
|
|
|
if rs.Primary.ID == "" {
|
2014-07-22 22:26:48 +02:00
|
|
|
return fmt.Errorf("No DB Instance ID is set")
|
|
|
|
}
|
|
|
|
|
2015-04-13 22:45:55 +02:00
|
|
|
conn := testAccProvider.Meta().(*AWSClient).rdsconn
|
2014-07-22 22:26:48 +02:00
|
|
|
|
2015-04-13 22:45:55 +02:00
|
|
|
opts := rds.DescribeDBInstancesInput{
|
2015-02-23 22:22:52 +01:00
|
|
|
DBInstanceIdentifier: aws.String(rs.Primary.ID),
|
2014-07-22 22:26:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := conn.DescribeDBInstances(&opts)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(resp.DBInstances) != 1 ||
|
2015-02-23 22:22:52 +01:00
|
|
|
*resp.DBInstances[0].DBInstanceIdentifier != rs.Primary.ID {
|
2014-07-22 22:26:48 +02:00
|
|
|
return fmt.Errorf("DB Instance not found")
|
|
|
|
}
|
|
|
|
|
2015-04-13 22:45:55 +02:00
|
|
|
*v = *resp.DBInstances[0]
|
2014-07-22 22:26:48 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-01 16:13:41 +02:00
|
|
|
// Database names cannot collide, and deletion takes so long, that making the
|
|
|
|
// name a bit random helps so able we can kill a test that's just waiting for a
|
|
|
|
// delete and not be blocked on kicking off another one.
|
2016-03-18 21:15:30 +01:00
|
|
|
var testAccAWSDBInstanceConfig = `
|
2014-07-22 22:26:48 +02:00
|
|
|
resource "aws_db_instance" "bar" {
|
|
|
|
allocated_storage = 10
|
2015-07-16 07:39:23 +02:00
|
|
|
engine = "MySQL"
|
2015-01-10 22:19:24 +01:00
|
|
|
engine_version = "5.6.21"
|
2014-07-22 22:26:48 +02:00
|
|
|
instance_class = "db.t1.micro"
|
|
|
|
name = "baz"
|
|
|
|
password = "barbarbarbar"
|
|
|
|
username = "foo"
|
|
|
|
|
2015-08-24 18:08:19 +02:00
|
|
|
|
2017-03-31 19:22:57 +02:00
|
|
|
# Maintenance Window is stored in lower case in the API, though not strictly
|
|
|
|
# documented. Terraform will downcase this to match (as opposed to throw a
|
2015-08-24 18:08:19 +02:00
|
|
|
# validation error).
|
|
|
|
maintenance_window = "Fri:09:00-Fri:09:30"
|
2017-02-03 18:21:25 +01:00
|
|
|
skip_final_snapshot = true
|
2015-08-24 18:08:19 +02:00
|
|
|
|
2015-02-25 16:41:05 +01:00
|
|
|
backup_retention_period = 0
|
|
|
|
|
2014-10-22 23:22:30 +02:00
|
|
|
parameter_group_name = "default.mysql5.6"
|
2017-03-09 21:40:14 +01:00
|
|
|
|
|
|
|
timeouts {
|
|
|
|
create = "30m"
|
|
|
|
}
|
2016-03-18 21:15:30 +01:00
|
|
|
}`
|
2015-05-13 23:36:30 +02:00
|
|
|
|
2017-03-31 19:22:57 +02:00
|
|
|
const testAccAWSDBInstanceConfig_namePrefix = `
|
|
|
|
resource "aws_db_instance" "test" {
|
|
|
|
allocated_storage = 10
|
|
|
|
engine = "MySQL"
|
|
|
|
identifier_prefix = "tf-test-"
|
|
|
|
instance_class = "db.t1.micro"
|
|
|
|
password = "password"
|
|
|
|
username = "root"
|
|
|
|
publicly_accessible = true
|
|
|
|
skip_final_snapshot = true
|
|
|
|
|
|
|
|
timeouts {
|
|
|
|
create = "30m"
|
|
|
|
}
|
|
|
|
}`
|
|
|
|
|
|
|
|
const testAccAWSDBInstanceConfig_generatedName = `
|
|
|
|
resource "aws_db_instance" "test" {
|
|
|
|
allocated_storage = 10
|
|
|
|
engine = "MySQL"
|
|
|
|
instance_class = "db.t1.micro"
|
|
|
|
password = "password"
|
|
|
|
username = "root"
|
|
|
|
publicly_accessible = true
|
|
|
|
skip_final_snapshot = true
|
|
|
|
|
|
|
|
timeouts {
|
|
|
|
create = "30m"
|
|
|
|
}
|
|
|
|
}`
|
|
|
|
|
2016-05-13 18:20:29 +02:00
|
|
|
var testAccAWSDBInstanceConfigKmsKeyId = `
|
|
|
|
resource "aws_kms_key" "foo" {
|
|
|
|
description = "Terraform acc test %s"
|
|
|
|
policy = <<POLICY
|
|
|
|
{
|
|
|
|
"Version": "2012-10-17",
|
|
|
|
"Id": "kms-tf-1",
|
|
|
|
"Statement": [
|
|
|
|
{
|
|
|
|
"Sid": "Enable IAM User Permissions",
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Principal": {
|
|
|
|
"AWS": "*"
|
|
|
|
},
|
|
|
|
"Action": "kms:*",
|
|
|
|
"Resource": "*"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
POLICY
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_db_instance" "bar" {
|
|
|
|
allocated_storage = 10
|
|
|
|
engine = "MySQL"
|
|
|
|
engine_version = "5.6.21"
|
|
|
|
instance_class = "db.m3.medium"
|
|
|
|
name = "baz"
|
|
|
|
password = "barbarbarbar"
|
|
|
|
username = "foo"
|
|
|
|
|
|
|
|
|
|
|
|
# Maintenance Window is stored in lower case in the API, though not strictly
|
|
|
|
# documented. Terraform will downcase this to match (as opposed to throw a
|
|
|
|
# validation error).
|
|
|
|
maintenance_window = "Fri:09:00-Fri:09:30"
|
|
|
|
|
|
|
|
backup_retention_period = 0
|
|
|
|
storage_encrypted = true
|
|
|
|
kms_key_id = "${aws_kms_key.foo.arn}"
|
|
|
|
|
2017-02-03 18:21:25 +01:00
|
|
|
skip_final_snapshot = true
|
|
|
|
|
2016-05-13 18:20:29 +02:00
|
|
|
parameter_group_name = "default.mysql5.6"
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2017-01-30 22:48:52 +01:00
|
|
|
func testAccAWSDBInstanceConfigWithOptionGroup(rName string) string {
|
|
|
|
return fmt.Sprintf(`
|
2015-12-21 10:15:52 +01:00
|
|
|
resource "aws_db_option_group" "bar" {
|
2017-01-30 22:48:52 +01:00
|
|
|
name = "%s"
|
2015-12-21 10:15:52 +01:00
|
|
|
option_group_description = "Test option group for terraform"
|
|
|
|
engine_name = "mysql"
|
|
|
|
major_engine_version = "5.6"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_db_instance" "bar" {
|
|
|
|
identifier = "foobarbaz-test-terraform-%d"
|
|
|
|
|
|
|
|
allocated_storage = 10
|
|
|
|
engine = "MySQL"
|
|
|
|
instance_class = "db.m1.small"
|
|
|
|
name = "baz"
|
|
|
|
password = "barbarbarbar"
|
|
|
|
username = "foo"
|
|
|
|
|
|
|
|
backup_retention_period = 0
|
2017-02-03 18:21:25 +01:00
|
|
|
skip_final_snapshot = true
|
2015-12-21 10:15:52 +01:00
|
|
|
|
|
|
|
parameter_group_name = "default.mysql5.6"
|
2016-05-09 19:16:26 +02:00
|
|
|
option_group_name = "${aws_db_option_group.bar.name}"
|
2017-01-30 22:48:52 +01:00
|
|
|
}`, rName, acctest.RandInt())
|
|
|
|
}
|
2015-12-21 10:15:52 +01:00
|
|
|
|
2017-04-29 21:32:21 +02:00
|
|
|
func testAccCheckAWSDBIAMAuth(n int) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "aws_db_instance" "bar" {
|
|
|
|
identifier = "foobarbaz-test-terraform-%d"
|
|
|
|
allocated_storage = 10
|
|
|
|
engine = "mysql"
|
|
|
|
engine_version = "5.6.34"
|
|
|
|
instance_class = "db.t2.micro"
|
|
|
|
name = "baz"
|
|
|
|
password = "barbarbarbar"
|
|
|
|
username = "foo"
|
|
|
|
backup_retention_period = 0
|
|
|
|
skip_final_snapshot = true
|
|
|
|
parameter_group_name = "default.mysql5.6"
|
|
|
|
iam_database_authentication_enabled = true
|
|
|
|
}`, n)
|
|
|
|
}
|
|
|
|
|
2015-05-20 16:28:33 +02:00
|
|
|
func testAccReplicaInstanceConfig(val int) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "aws_db_instance" "bar" {
|
|
|
|
identifier = "foobarbaz-test-terraform-%d"
|
|
|
|
|
|
|
|
allocated_storage = 5
|
|
|
|
engine = "mysql"
|
|
|
|
engine_version = "5.6.21"
|
|
|
|
instance_class = "db.t1.micro"
|
|
|
|
name = "baz"
|
|
|
|
password = "barbarbarbar"
|
|
|
|
username = "foo"
|
|
|
|
|
|
|
|
backup_retention_period = 1
|
2017-02-03 18:21:25 +01:00
|
|
|
skip_final_snapshot = true
|
2015-05-20 16:28:33 +02:00
|
|
|
|
|
|
|
parameter_group_name = "default.mysql5.6"
|
|
|
|
}
|
2017-03-31 19:22:57 +02:00
|
|
|
|
2015-05-20 16:28:33 +02:00
|
|
|
resource "aws_db_instance" "replica" {
|
2016-03-07 14:18:58 +01:00
|
|
|
identifier = "tf-replica-db-%d"
|
2015-05-20 16:28:33 +02:00
|
|
|
backup_retention_period = 0
|
2015-05-21 16:49:46 +02:00
|
|
|
replicate_source_db = "${aws_db_instance.bar.identifier}"
|
2015-05-20 16:28:33 +02:00
|
|
|
allocated_storage = "${aws_db_instance.bar.allocated_storage}"
|
|
|
|
engine = "${aws_db_instance.bar.engine}"
|
|
|
|
engine_version = "${aws_db_instance.bar.engine_version}"
|
|
|
|
instance_class = "${aws_db_instance.bar.instance_class}"
|
|
|
|
password = "${aws_db_instance.bar.password}"
|
|
|
|
username = "${aws_db_instance.bar.username}"
|
2017-02-03 18:21:25 +01:00
|
|
|
skip_final_snapshot = true
|
2015-05-20 16:28:33 +02:00
|
|
|
tags {
|
|
|
|
Name = "tf-replica-db"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, val, val)
|
|
|
|
}
|
2015-11-11 18:24:59 +01:00
|
|
|
|
2016-02-12 21:17:19 +01:00
|
|
|
func testAccSnapshotInstanceConfig() string {
|
|
|
|
return fmt.Sprintf(`
|
2015-11-11 18:24:59 +01:00
|
|
|
provider "aws" {
|
|
|
|
region = "us-east-1"
|
|
|
|
}
|
|
|
|
resource "aws_db_instance" "snapshot" {
|
2017-02-03 18:21:25 +01:00
|
|
|
identifier = "tf-test-%d"
|
2015-11-11 18:24:59 +01:00
|
|
|
|
|
|
|
allocated_storage = 5
|
|
|
|
engine = "mysql"
|
|
|
|
engine_version = "5.6.21"
|
|
|
|
instance_class = "db.t1.micro"
|
|
|
|
name = "baz"
|
|
|
|
password = "barbarbarbar"
|
|
|
|
username = "foo"
|
|
|
|
security_group_names = ["default"]
|
|
|
|
backup_retention_period = 1
|
|
|
|
|
2016-06-13 17:05:01 +02:00
|
|
|
publicly_accessible = true
|
|
|
|
|
2015-11-11 18:24:59 +01:00
|
|
|
parameter_group_name = "default.mysql5.6"
|
|
|
|
|
2017-02-03 18:21:25 +01:00
|
|
|
skip_final_snapshot = true
|
2015-11-11 18:24:59 +01:00
|
|
|
final_snapshot_identifier = "foobarbaz-test-terraform-final-snapshot-1"
|
2016-02-12 21:17:19 +01:00
|
|
|
}`, acctest.RandInt())
|
2015-11-11 18:24:59 +01:00
|
|
|
}
|
|
|
|
|
2017-02-22 15:13:04 +01:00
|
|
|
func testAccSnapshotInstanceConfigWithSnapshot(rInt int) string {
|
2016-04-18 17:00:59 +02:00
|
|
|
return fmt.Sprintf(`
|
2015-11-11 18:24:59 +01:00
|
|
|
provider "aws" {
|
|
|
|
region = "us-east-1"
|
|
|
|
}
|
2017-02-03 18:21:25 +01:00
|
|
|
resource "aws_db_instance" "snapshot" {
|
|
|
|
identifier = "tf-snapshot-%d"
|
2015-11-11 18:24:59 +01:00
|
|
|
|
|
|
|
allocated_storage = 5
|
|
|
|
engine = "mysql"
|
|
|
|
engine_version = "5.6.21"
|
|
|
|
instance_class = "db.t1.micro"
|
|
|
|
name = "baz"
|
|
|
|
password = "barbarbarbar"
|
2016-06-13 17:05:01 +02:00
|
|
|
publicly_accessible = true
|
2015-11-11 18:24:59 +01:00
|
|
|
username = "foo"
|
2017-02-03 18:21:25 +01:00
|
|
|
security_group_names = ["default"]
|
2015-11-11 18:24:59 +01:00
|
|
|
backup_retention_period = 1
|
|
|
|
|
|
|
|
parameter_group_name = "default.mysql5.6"
|
|
|
|
|
2017-02-03 18:21:25 +01:00
|
|
|
copy_tags_to_snapshot = true
|
2017-02-22 15:13:04 +01:00
|
|
|
final_snapshot_identifier = "foobarbaz-test-terraform-final-snapshot-%d"
|
2017-02-03 18:21:25 +01:00
|
|
|
tags {
|
|
|
|
Name = "tf-tags-db"
|
|
|
|
}
|
2015-11-11 18:24:59 +01:00
|
|
|
}
|
2017-02-22 15:13:04 +01:00
|
|
|
`, rInt, rInt)
|
2016-04-18 17:00:59 +02:00
|
|
|
}
|
2016-02-01 23:32:38 +01:00
|
|
|
|
2016-09-04 11:50:50 +02:00
|
|
|
func testAccSnapshotInstanceConfig_enhancedMonitoring(rName string) string {
|
|
|
|
return fmt.Sprintf(`
|
2016-02-01 23:32:38 +01:00
|
|
|
resource "aws_iam_role" "enhanced_policy_role" {
|
2016-09-04 11:50:50 +02:00
|
|
|
name = "enhanced-monitoring-role-%s"
|
2016-02-01 23:32:38 +01:00
|
|
|
assume_role_policy = <<EOF
|
|
|
|
{
|
|
|
|
"Version": "2012-10-17",
|
|
|
|
"Statement": [
|
|
|
|
{
|
|
|
|
"Sid": "",
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Principal": {
|
|
|
|
"Service": "monitoring.rds.amazonaws.com"
|
|
|
|
},
|
|
|
|
"Action": "sts:AssumeRole"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_iam_policy_attachment" "test-attach" {
|
|
|
|
name = "enhanced-monitoring-attachment"
|
|
|
|
roles = [
|
|
|
|
"${aws_iam_role.enhanced_policy_role.name}",
|
|
|
|
]
|
|
|
|
|
|
|
|
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonRDSEnhancedMonitoringRole"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_db_instance" "enhanced_monitoring" {
|
2016-09-04 11:50:50 +02:00
|
|
|
identifier = "foobarbaz-enhanced-monitoring-%s"
|
2016-02-01 23:32:38 +01:00
|
|
|
depends_on = ["aws_iam_policy_attachment.test-attach"]
|
|
|
|
|
|
|
|
allocated_storage = 5
|
|
|
|
engine = "mysql"
|
|
|
|
engine_version = "5.6.21"
|
2016-03-08 21:08:20 +01:00
|
|
|
instance_class = "db.m3.medium"
|
2016-02-01 23:32:38 +01:00
|
|
|
name = "baz"
|
|
|
|
password = "barbarbarbar"
|
|
|
|
username = "foo"
|
|
|
|
backup_retention_period = 1
|
|
|
|
|
|
|
|
parameter_group_name = "default.mysql5.6"
|
|
|
|
|
|
|
|
monitoring_role_arn = "${aws_iam_role.enhanced_policy_role.arn}"
|
|
|
|
monitoring_interval = "5"
|
|
|
|
|
|
|
|
skip_final_snapshot = true
|
2016-09-04 11:50:50 +02:00
|
|
|
}`, rName, rName)
|
2016-02-01 23:32:38 +01:00
|
|
|
}
|
2016-06-21 21:53:13 +02:00
|
|
|
|
|
|
|
func testAccSnapshotInstanceConfig_iopsUpdate(rName string, iops int) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "aws_db_instance" "bar" {
|
|
|
|
identifier = "mydb-rds-%s"
|
|
|
|
engine = "mysql"
|
|
|
|
engine_version = "5.6.23"
|
|
|
|
instance_class = "db.t2.micro"
|
|
|
|
name = "mydb"
|
|
|
|
username = "foo"
|
|
|
|
password = "barbarbar"
|
|
|
|
parameter_group_name = "default.mysql5.6"
|
2017-02-03 18:21:25 +01:00
|
|
|
skip_final_snapshot = true
|
2016-06-21 21:53:13 +02:00
|
|
|
|
|
|
|
apply_immediately = true
|
|
|
|
|
|
|
|
storage_type = "io1"
|
|
|
|
allocated_storage = 200
|
|
|
|
iops = %d
|
|
|
|
}`, rName, iops)
|
|
|
|
}
|
2016-07-12 10:07:25 +02:00
|
|
|
|
|
|
|
func testAccSnapshotInstanceConfig_mysqlPort(rName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "aws_db_instance" "bar" {
|
|
|
|
identifier = "mydb-rds-%s"
|
|
|
|
engine = "mysql"
|
|
|
|
engine_version = "5.6.23"
|
|
|
|
instance_class = "db.t2.micro"
|
|
|
|
name = "mydb"
|
|
|
|
username = "foo"
|
|
|
|
password = "barbarbar"
|
|
|
|
parameter_group_name = "default.mysql5.6"
|
|
|
|
port = 3306
|
|
|
|
allocated_storage = 10
|
2017-02-03 18:21:25 +01:00
|
|
|
skip_final_snapshot = true
|
2016-07-12 10:07:25 +02:00
|
|
|
|
|
|
|
apply_immediately = true
|
|
|
|
}`, rName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccSnapshotInstanceConfig_updateMysqlPort(rName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "aws_db_instance" "bar" {
|
|
|
|
identifier = "mydb-rds-%s"
|
|
|
|
engine = "mysql"
|
|
|
|
engine_version = "5.6.23"
|
|
|
|
instance_class = "db.t2.micro"
|
|
|
|
name = "mydb"
|
|
|
|
username = "foo"
|
|
|
|
password = "barbarbar"
|
|
|
|
parameter_group_name = "default.mysql5.6"
|
|
|
|
port = 3305
|
|
|
|
allocated_storage = 10
|
2017-02-03 18:21:25 +01:00
|
|
|
skip_final_snapshot = true
|
2016-07-12 10:07:25 +02:00
|
|
|
|
|
|
|
apply_immediately = true
|
|
|
|
}`, rName)
|
|
|
|
}
|
2016-12-18 15:35:24 +01:00
|
|
|
|
|
|
|
func testAccAWSDBInstanceConfigWithSubnetGroup(rName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "aws_vpc" "foo" {
|
|
|
|
cidr_block = "10.1.0.0/16"
|
2017-05-17 23:26:40 +02:00
|
|
|
tags {
|
|
|
|
Name="testAccAWSDBInstanceConfigWithSubnetGroup"
|
|
|
|
}
|
2016-12-18 15:35:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "foo" {
|
|
|
|
cidr_block = "10.1.1.0/24"
|
|
|
|
availability_zone = "us-west-2a"
|
|
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
|
|
tags {
|
|
|
|
Name = "tf-dbsubnet-test-1"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "bar" {
|
|
|
|
cidr_block = "10.1.2.0/24"
|
|
|
|
availability_zone = "us-west-2b"
|
|
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
|
|
tags {
|
|
|
|
Name = "tf-dbsubnet-test-2"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_db_subnet_group" "foo" {
|
2017-02-03 17:22:46 +01:00
|
|
|
name = "foo-%s"
|
2016-12-18 15:35:24 +01:00
|
|
|
subnet_ids = ["${aws_subnet.foo.id}", "${aws_subnet.bar.id}"]
|
|
|
|
tags {
|
|
|
|
Name = "tf-dbsubnet-group-test"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_db_instance" "bar" {
|
|
|
|
identifier = "mydb-rds-%s"
|
|
|
|
engine = "mysql"
|
|
|
|
engine_version = "5.6.23"
|
|
|
|
instance_class = "db.t2.micro"
|
|
|
|
name = "mydb"
|
|
|
|
username = "foo"
|
|
|
|
password = "barbarbar"
|
|
|
|
parameter_group_name = "default.mysql5.6"
|
|
|
|
db_subnet_group_name = "${aws_db_subnet_group.foo.name}"
|
|
|
|
port = 3305
|
|
|
|
allocated_storage = 10
|
2017-02-03 18:21:25 +01:00
|
|
|
skip_final_snapshot = true
|
2016-12-18 15:35:24 +01:00
|
|
|
|
2017-02-03 17:22:46 +01:00
|
|
|
backup_retention_period = 0
|
2016-12-18 15:35:24 +01:00
|
|
|
apply_immediately = true
|
2017-02-03 17:22:46 +01:00
|
|
|
}`, rName, rName)
|
2016-12-18 15:35:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func testAccAWSDBInstanceConfigWithSubnetGroupUpdated(rName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "aws_vpc" "foo" {
|
|
|
|
cidr_block = "10.1.0.0/16"
|
2017-05-17 23:26:40 +02:00
|
|
|
tags {
|
|
|
|
Name="testAccAWSDBInstanceConfigWithSubnetGroupUpdated"
|
|
|
|
}
|
2016-12-18 15:35:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_vpc" "bar" {
|
|
|
|
cidr_block = "10.10.0.0/16"
|
2017-05-17 23:26:40 +02:00
|
|
|
tags {
|
|
|
|
Name="testAccAWSDBInstanceConfigWithSubnetGroupUpdated_other"
|
|
|
|
}
|
2016-12-18 15:35:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "foo" {
|
|
|
|
cidr_block = "10.1.1.0/24"
|
|
|
|
availability_zone = "us-west-2a"
|
|
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
|
|
tags {
|
|
|
|
Name = "tf-dbsubnet-test-1"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "bar" {
|
|
|
|
cidr_block = "10.1.2.0/24"
|
|
|
|
availability_zone = "us-west-2b"
|
|
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
|
|
tags {
|
|
|
|
Name = "tf-dbsubnet-test-2"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "test" {
|
|
|
|
cidr_block = "10.10.3.0/24"
|
2017-02-03 17:22:46 +01:00
|
|
|
availability_zone = "us-west-2b"
|
2016-12-18 15:35:24 +01:00
|
|
|
vpc_id = "${aws_vpc.bar.id}"
|
|
|
|
tags {
|
|
|
|
Name = "tf-dbsubnet-test-3"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "another_test" {
|
|
|
|
cidr_block = "10.10.4.0/24"
|
|
|
|
availability_zone = "us-west-2a"
|
|
|
|
vpc_id = "${aws_vpc.bar.id}"
|
|
|
|
tags {
|
|
|
|
Name = "tf-dbsubnet-test-4"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_db_subnet_group" "foo" {
|
2017-02-03 17:22:46 +01:00
|
|
|
name = "foo-%s"
|
2016-12-18 15:35:24 +01:00
|
|
|
subnet_ids = ["${aws_subnet.foo.id}", "${aws_subnet.bar.id}"]
|
|
|
|
tags {
|
|
|
|
Name = "tf-dbsubnet-group-test"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_db_subnet_group" "bar" {
|
2017-02-03 17:22:46 +01:00
|
|
|
name = "bar-%s"
|
2016-12-18 15:35:24 +01:00
|
|
|
subnet_ids = ["${aws_subnet.test.id}", "${aws_subnet.another_test.id}"]
|
|
|
|
tags {
|
|
|
|
Name = "tf-dbsubnet-group-test-updated"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_db_instance" "bar" {
|
|
|
|
identifier = "mydb-rds-%s"
|
|
|
|
engine = "mysql"
|
|
|
|
engine_version = "5.6.23"
|
|
|
|
instance_class = "db.t2.micro"
|
|
|
|
name = "mydb"
|
|
|
|
username = "foo"
|
|
|
|
password = "barbarbar"
|
|
|
|
parameter_group_name = "default.mysql5.6"
|
|
|
|
db_subnet_group_name = "${aws_db_subnet_group.bar.name}"
|
|
|
|
port = 3305
|
|
|
|
allocated_storage = 10
|
2017-02-03 18:21:25 +01:00
|
|
|
skip_final_snapshot = true
|
2016-12-18 15:35:24 +01:00
|
|
|
|
2017-02-03 17:22:46 +01:00
|
|
|
backup_retention_period = 0
|
|
|
|
|
2016-12-18 15:35:24 +01:00
|
|
|
apply_immediately = true
|
2017-02-03 17:22:46 +01:00
|
|
|
}`, rName, rName, rName)
|
2016-12-18 15:35:24 +01:00
|
|
|
}
|
2017-01-17 23:43:53 +01:00
|
|
|
|
|
|
|
const testAccAWSDBMSSQL_timezone = `
|
|
|
|
provider "aws" {
|
|
|
|
region = "us-west-2"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_vpc" "foo" {
|
|
|
|
cidr_block = "10.1.0.0/16"
|
|
|
|
enable_dns_hostnames = true
|
|
|
|
tags {
|
|
|
|
Name = "tf-rds-mssql-timezone-test"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_db_subnet_group" "rds_one" {
|
|
|
|
name = "rds_one_db"
|
|
|
|
description = "db subnets for rds_one"
|
|
|
|
|
|
|
|
subnet_ids = ["${aws_subnet.main.id}", "${aws_subnet.other.id}"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "main" {
|
|
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
|
|
availability_zone = "us-west-2a"
|
|
|
|
cidr_block = "10.1.1.0/24"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "other" {
|
|
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
|
|
availability_zone = "us-west-2b"
|
|
|
|
cidr_block = "10.1.2.0/24"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_db_instance" "mssql" {
|
|
|
|
#identifier = "tf-test-mssql"
|
|
|
|
|
|
|
|
db_subnet_group_name = "${aws_db_subnet_group.rds_one.name}"
|
|
|
|
|
|
|
|
instance_class = "db.t2.micro"
|
|
|
|
allocated_storage = 20
|
|
|
|
username = "somecrazyusername"
|
|
|
|
password = "somecrazypassword"
|
|
|
|
engine = "sqlserver-ex"
|
|
|
|
backup_retention_period = 0
|
2017-02-03 18:21:25 +01:00
|
|
|
skip_final_snapshot = true
|
2017-01-17 23:43:53 +01:00
|
|
|
|
|
|
|
#publicly_accessible = true
|
|
|
|
|
|
|
|
vpc_security_group_ids = ["${aws_security_group.rds-mssql.id}"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_security_group" "rds-mssql" {
|
|
|
|
name = "tf-rds-mssql-test"
|
|
|
|
|
|
|
|
description = "TF Testing"
|
|
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_security_group_rule" "rds-mssql-1" {
|
|
|
|
type = "egress"
|
|
|
|
from_port = 0
|
|
|
|
to_port = 0
|
|
|
|
protocol = "-1"
|
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
|
|
|
|
security_group_id = "${aws_security_group.rds-mssql.id}"
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const testAccAWSDBMSSQL_timezone_AKST = `
|
|
|
|
provider "aws" {
|
|
|
|
region = "us-west-2"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_vpc" "foo" {
|
|
|
|
cidr_block = "10.1.0.0/16"
|
|
|
|
enable_dns_hostnames = true
|
|
|
|
tags {
|
|
|
|
Name = "tf-rds-mssql-timezone-test"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_db_subnet_group" "rds_one" {
|
|
|
|
name = "rds_one_db"
|
|
|
|
description = "db subnets for rds_one"
|
|
|
|
|
|
|
|
subnet_ids = ["${aws_subnet.main.id}", "${aws_subnet.other.id}"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "main" {
|
|
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
|
|
availability_zone = "us-west-2a"
|
|
|
|
cidr_block = "10.1.1.0/24"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "other" {
|
|
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
|
|
availability_zone = "us-west-2b"
|
|
|
|
cidr_block = "10.1.2.0/24"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_db_instance" "mssql" {
|
|
|
|
#identifier = "tf-test-mssql"
|
|
|
|
|
|
|
|
db_subnet_group_name = "${aws_db_subnet_group.rds_one.name}"
|
|
|
|
|
|
|
|
instance_class = "db.t2.micro"
|
|
|
|
allocated_storage = 20
|
|
|
|
username = "somecrazyusername"
|
|
|
|
password = "somecrazypassword"
|
|
|
|
engine = "sqlserver-ex"
|
2017-01-24 00:28:16 +01:00
|
|
|
backup_retention_period = 0
|
2017-02-03 18:21:25 +01:00
|
|
|
skip_final_snapshot = true
|
2017-01-17 23:43:53 +01:00
|
|
|
|
|
|
|
#publicly_accessible = true
|
|
|
|
|
|
|
|
vpc_security_group_ids = ["${aws_security_group.rds-mssql.id}"]
|
|
|
|
timezone = "Alaskan Standard Time"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_security_group" "rds-mssql" {
|
|
|
|
name = "tf-rds-mssql-test"
|
|
|
|
|
|
|
|
description = "TF Testing"
|
|
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_security_group_rule" "rds-mssql-1" {
|
|
|
|
type = "egress"
|
|
|
|
from_port = 0
|
|
|
|
to_port = 0
|
|
|
|
protocol = "-1"
|
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
|
|
|
|
security_group_id = "${aws_security_group.rds-mssql.id}"
|
|
|
|
}
|
|
|
|
`
|
2017-01-24 00:12:34 +01:00
|
|
|
|
|
|
|
var testAccAWSDBInstanceConfigAutoMinorVersion = fmt.Sprintf(`
|
|
|
|
resource "aws_db_instance" "bar" {
|
|
|
|
identifier = "foobarbaz-test-terraform-%d"
|
|
|
|
allocated_storage = 10
|
|
|
|
engine = "MySQL"
|
|
|
|
engine_version = "5.6"
|
|
|
|
instance_class = "db.t1.micro"
|
|
|
|
name = "baz"
|
|
|
|
password = "barbarbarbar"
|
|
|
|
username = "foo"
|
2017-02-03 18:21:25 +01:00
|
|
|
skip_final_snapshot = true
|
2017-01-24 00:12:34 +01:00
|
|
|
}
|
|
|
|
`, acctest.RandInt())
|
2017-02-13 18:26:06 +01:00
|
|
|
|
|
|
|
func testAccAWSDBInstanceConfigSuppressInitialState(rInt int) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "aws_db_instance" "bar" {
|
|
|
|
identifier = "foobarbaz-test-terraform-%d"
|
|
|
|
allocated_storage = 10
|
|
|
|
engine = "MySQL"
|
|
|
|
instance_class = "db.t1.micro"
|
|
|
|
name = "baz"
|
|
|
|
password = "barbarbarbar"
|
|
|
|
username = "foo"
|
|
|
|
skip_final_snapshot = true
|
|
|
|
}
|
|
|
|
|
|
|
|
data "template_file" "test" {
|
|
|
|
template = ""
|
|
|
|
vars = {
|
|
|
|
test_var = "${aws_db_instance.bar.engine_version}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, rInt)
|
|
|
|
}
|