Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oracle only national character set #20437

Merged
merged 5 commits into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/20437.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_db_instance: Add `nchar_character_set_name` argument
```
17 changes: 12 additions & 5 deletions aws/resource_aws_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ func resourceAwsDbInstance() *schema.Resource {
Computed: true,
ForceNew: true,
},
"nchar_character_set_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"option_group_name": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -1151,6 +1157,10 @@ func resourceAwsDbInstanceCreate(d *schema.ResourceData, meta interface{}) error
opts.CharacterSetName = aws.String(attr.(string))
}

if attr, ok := d.GetOk("nchar_character_set_name"); ok {
opts.NcharCharacterSetName = aws.String(attr.(string))
}

if attr, ok := d.GetOk("timezone"); ok {
opts.Timezone = aws.String(attr.(string))
}
Expand Down Expand Up @@ -1376,11 +1386,8 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error {
if v.DBSubnetGroup != nil {
d.Set("db_subnet_group_name", v.DBSubnetGroup.DBSubnetGroupName)
}

if v.CharacterSetName != nil {
d.Set("character_set_name", v.CharacterSetName)
}

d.Set("character_set_name", v.CharacterSetName)
d.Set("nchar_character_set_name", v.NcharCharacterSetName)
d.Set("timezone", v.Timezone)

if len(v.DBParameterGroups) > 0 {
Expand Down
126 changes: 121 additions & 5 deletions aws/resource_aws_db_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3290,6 +3290,75 @@ func TestAccAWSDBInstance_RestoreToPointInTime_SourceResourceID(t *testing.T) {
})
}

func TestAccAWSDBInstance_NationalCharacterSet_Oracle(t *testing.T) {
var dbInstance rds.DBInstance

rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_db_instance.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ErrorCheck: testAccErrorCheck(t, rds.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSDBInstanceConfig_NationalCharacterSet_Oracle(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBInstanceExists(resourceName, &dbInstance),
resource.TestCheckResourceAttr(resourceName, "nchar_character_set_name", "UTF8"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"apply_immediately",
"final_snapshot_identifier",
"password",
"skip_final_snapshot",
"delete_automated_backups",
},
},
},
})
}

func TestAccAWSDBInstance_NoNationalCharacterSet_Oracle(t *testing.T) {
var dbInstance rds.DBInstance

rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_db_instance.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ErrorCheck: testAccErrorCheck(t, rds.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSDBInstanceConfig_NoNationalCharacterSet_Oracle(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBInstanceExists(resourceName, &dbInstance),
resource.TestCheckResourceAttr(resourceName, "nchar_character_set_name", "AL16UTF16"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"apply_immediately",
"final_snapshot_identifier",
"password",
"skip_final_snapshot",
"delete_automated_backups",
},
},
},
})
}
func testAccAWSDBInstanceConfig_orderableClass(engine, version, license string) string {
return fmt.Sprintf(`
data "aws_rds_orderable_db_instance" "test" {
Expand Down Expand Up @@ -5120,10 +5189,9 @@ resource "aws_db_instance" "test" {
func testAccAWSDBInstanceConfig_EnabledCloudwatchLogsExports_Oracle(rName string) string {
return fmt.Sprintf(`
data "aws_rds_orderable_db_instance" "test" {
engine = "oracle-se"
engine_version = "11.2.0.4.v25"
license_model = "bring-your-own-license"
storage_type = "standard"
engine = "oracle-se2"
license_model = "bring-your-own-license"
storage_type = "standard"

preferred_instance_classes = ["db.m5.large", "db.m4.large", "db.r4.large"]
}
Expand All @@ -5132,15 +5200,63 @@ resource "aws_db_instance" "test" {
allocated_storage = 10
enabled_cloudwatch_logs_exports = ["alert", "listener", "trace"]
engine = data.aws_rds_orderable_db_instance.test.engine
identifier = %q
identifier = %[1]q
instance_class = data.aws_rds_orderable_db_instance.test.instance_class
license_model = "bring-your-own-license"
password = "avoid-plaintext-passwords"
username = "tfacctest"
skip_final_snapshot = true
}
`, rName)
}

func testAccAWSDBInstanceConfig_NationalCharacterSet_Oracle(rName string) string {
return fmt.Sprintf(`
data "aws_rds_orderable_db_instance" "test" {
engine = "oracle-se2"
license_model = "bring-your-own-license"
storage_type = "standard"

preferred_instance_classes = ["db.m5.large", "db.m4.large", "db.r4.large"]
}

resource "aws_db_instance" "test" {
allocated_storage = 10
engine = data.aws_rds_orderable_db_instance.test.engine
identifier = %[1]q
instance_class = data.aws_rds_orderable_db_instance.test.instance_class
license_model = "bring-your-own-license"
nchar_character_set_name = "UTF8"
password = "avoid-plaintext-passwords"
username = "tfacctest"
skip_final_snapshot = true
}
`, rName)
}

func testAccAWSDBInstanceConfig_NoNationalCharacterSet_Oracle(rName string) string {
return fmt.Sprintf(`
data "aws_rds_orderable_db_instance" "test" {
engine = "oracle-se2"
license_model = "bring-your-own-license"
storage_type = "standard"

preferred_instance_classes = ["db.m5.large", "db.m4.large", "db.r4.large"]
}

resource "aws_db_instance" "test" {
allocated_storage = 10
engine = data.aws_rds_orderable_db_instance.test.engine
identifier = %[1]q
instance_class = data.aws_rds_orderable_db_instance.test.instance_class
license_model = "bring-your-own-license"
password = "avoid-plaintext-passwords"
username = "tfacctest"
skip_final_snapshot = true
}
`, rName)
}

func testAccAWSDBInstanceConfig_EnabledCloudwatchLogsExports_MSSQL(rName string) string {
return fmt.Sprintf(`
data "aws_rds_orderable_db_instance" "test" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/db_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ Documentation](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_Monit
what IAM permissions are needed to allow Enhanced Monitoring for RDS Instances.
* `multi_az` - (Optional) Specifies if the RDS instance is multi-AZ
* `name` - (Optional) The name of the database to create when the DB instance is created. If this parameter is not specified, no database is created in the DB instance. Note that this does not apply for Oracle or SQL Server engines. See the [AWS documentation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/rds/create-db-instance.html) for more details on what applies for those engines. If you are providing an Oracle db name, it needs to be in all upper case.
* `nchar_character_set_name` - (Optional, Forces new resource) The national character set is used in the NCHAR, NVARCHAR2, and NCLOB data types for Oracle instances. This can't be changed. See [Oracle Character Sets
Supported in Amazon RDS](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.OracleCharacterSets.html).
* `option_group_name` - (Optional) Name of the DB option group to associate.
* `parameter_group_name` - (Optional) Name of the DB parameter group to
associate.
Expand Down