Skip to content

Commit

Permalink
Use engine_version and engine_version_actual.
Browse files Browse the repository at this point in the history
  • Loading branch information
bill-rich committed Jul 15, 2021
1 parent 0e98ae9 commit 7674f99
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 8 deletions.
24 changes: 19 additions & 5 deletions aws/resource_aws_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,14 @@ func resourceAwsDbInstance() *schema.Resource {
},

"engine_version": {
Type: schema.TypeString,
Optional: true,
Computed: true,
DiffSuppressFunc: suppressAwsDbEngineVersionDiffs,
Type: schema.TypeString,
Optional: true,
Computed: true,
},

"engine_version_actual": {
Type: schema.TypeString,
Computed: true,
},

"ca_cert_identifier": {
Expand Down Expand Up @@ -1407,7 +1411,6 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error {
d.Set("username", v.MasterUsername)
d.Set("deletion_protection", v.DeletionProtection)
d.Set("engine", v.Engine)
d.Set("engine_version", v.EngineVersion)
d.Set("allocated_storage", v.AllocatedStorage)
d.Set("iops", v.Iops)
d.Set("copy_tags_to_snapshot", v.CopyTagsToSnapshot)
Expand All @@ -1433,6 +1436,8 @@ func resourceAwsDbInstanceRead(d *schema.ResourceData, meta interface{}) error {
d.Set("db_subnet_group_name", v.DBSubnetGroup.DBSubnetGroupName)
}

dbSetResourceDataEngineVersionFromInstance(d, v)

if v.CharacterSetName != nil {
d.Set("character_set_name", v.CharacterSetName)
}
Expand Down Expand Up @@ -1993,3 +1998,12 @@ func expandRestoreToPointInTime(l []interface{}) *rds.RestoreDBInstanceToPointIn

return input
}

func dbSetResourceDataEngineVersionFromInstance(d *schema.ResourceData, c *rds.DBInstance) {
oldVersion := d.Get("engine_version").(string)
newVersion := aws.StringValue(c.EngineVersion)
if oldVersion != newVersion && string(append([]byte(oldVersion), []byte(".")...)) != string([]byte(newVersion)[0:len(oldVersion)+1]) {
d.Set("engine_version", newVersion)
}
d.Set("engine_version_actual", newVersion)
}
55 changes: 55 additions & 0 deletions aws/resource_aws_db_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,39 @@ func TestAccAWSDBInstance_basic(t *testing.T) {
})
}

func TestAccAWSDBInstance_OnlyMajorVersion(t *testing.T) {
var dbInstance1 rds.DBInstance
resourceName := "aws_db_instance.test"
engine := "mysql"
engineVersion1 := "5.6"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ErrorCheck: testAccErrorCheck(t, rds.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSDBInstanceConfig_MajorVersionOnly(engine, engineVersion1),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBInstanceExists(resourceName, &dbInstance1),
resource.TestCheckResourceAttr(resourceName, "engine", engine),
resource.TestCheckResourceAttr(resourceName, "engine_version", engineVersion1),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"engine_version",
"password",
},
},
},
})
}

func TestAccAWSDBInstance_namePrefix(t *testing.T) {
var v rds.DBInstance

Expand Down Expand Up @@ -3281,6 +3314,28 @@ resource "aws_db_instance" "bar" {
`)
}

func testAccAWSDBInstanceConfig_MajorVersionOnly(engine, engineVersion string) string {
return composeConfig(testAccAWSDBInstanceConfig_orderableClassMysql(), fmt.Sprintf(`
resource "aws_db_instance" "test" {
allocated_storage = 10
backup_retention_period = 0
engine = %[1]q
engine_version = %[2]q
instance_class = "db.r4.large"
name = "baz"
parameter_group_name = "default.mysql5.6"
password = "barbarbarbar"
skip_final_snapshot = true
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"
}
`, engine, engineVersion))
}

func testAccAWSDBInstanceConfig_namePrefix() string {
return composeConfig(testAccAWSDBInstanceConfig_orderableClassMysql(), `
resource "aws_db_instance" "test" {
Expand Down
6 changes: 3 additions & 3 deletions website/docs/r/db_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ For information on the difference between the available Aurora MySQL engines
see [Comparison between Aurora MySQL 1 and Aurora MySQL 2](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/AuroraMySQL.Updates.20180206.html)
in the Amazon RDS User Guide.
* `engine_version` - (Optional) The engine version to use. If `auto_minor_version_upgrade`
is enabled, you can provide a prefix of the version such as `5.7` (for `5.7.10`) and
this attribute will ignore differences in the patch version automatically (e.g. `5.7.17`).
is enabled, you can provide a prefix of the version such as `5.7` (for `5.7.10`).
The actual engine version used is returned in the attribute `engine_version_actual`, [defined below](#engine_version_actual).
For supported values, see the EngineVersion parameter in [API action CreateDBInstance](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html).
Note that for Amazon Aurora instances the engine version must match the [DB cluster](/docs/providers/aws/r/rds_cluster.html)'s engine version'.
* `final_snapshot_identifier` - (Optional) The name of your final DB snapshot
Expand Down Expand Up @@ -279,7 +279,7 @@ DB instance.
* `domain_iam_role_name` - The name of the IAM role to be used when making API calls to the Directory Service.
* `endpoint` - The connection endpoint in `address:port` format.
* `engine` - The database engine.
* `engine_version` - The database engine version.
* `engine_version_actual` - The running version of the database.
* `hosted_zone_id` - The canonical hosted zone ID of the DB instance (to be used
in a Route 53 Alias record).
* `id` - The RDS instance ID.
Expand Down

0 comments on commit 7674f99

Please sign in to comment.