Skip to content

Commit

Permalink
Merge pull request #37708 from nikhil-goenka/f/EngineLifecycleSupport
Browse files Browse the repository at this point in the history
EngineLifecycleSupport
  • Loading branch information
ewbankkit authored Jul 16, 2024
2 parents 337163a + 4bb5881 commit 1200b46
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 25 deletions.
11 changes: 11 additions & 0 deletions .changelog/37708.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:enhancement
resource/aws_db_instance: Add `engine_lifecycle_support` argument
```

```release-note:enhancement
resource/aws_rds_cluster: Add `engine_lifecycle_support` argument
```

```release-note:enhancement
resource/aws_rds_global_cluster: Add `engine_lifecycle_support` argument
```
25 changes: 22 additions & 3 deletions internal/service/rds/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,18 @@ func ResourceCluster() *schema.Resource {
validation.StringInSlice(ClusterEngine_Values(), false),
),
},
"engine_lifecycle_support": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice(engineLifecycleSupport_Values(), false),
},
"engine_mode": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: EngineModeProvisioned,
ValidateFunc: validation.StringInSlice(EngineMode_Values(), false),
Default: engineModeProvisioned,
ValidateFunc: validation.StringInSlice(engineMode_Values(), false),
},
names.AttrEngineVersion: {
Type: schema.TypeString,
Expand Down Expand Up @@ -648,6 +654,10 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int
input.EnableCloudwatchLogsExports = flex.ExpandStringSet(v.(*schema.Set))
}

if v, ok := d.GetOk("engine_lifecycle_support"); ok {
input.EngineLifecycleSupport = aws.String(v.(string))
}

if v, ok := d.GetOk(names.AttrEngineVersion); ok {
input.EngineVersion = aws.String(v.(string))
}
Expand Down Expand Up @@ -774,6 +784,10 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int
input.EnableCloudwatchLogsExports = flex.ExpandStringSet(v.(*schema.Set))
}

if v, ok := d.GetOk("engine_lifecycle_support"); ok {
input.EngineLifecycleSupport = aws.String(v.(string))
}

if v, ok := d.GetOk(names.AttrEngineVersion); ok {
input.EngineVersion = aws.String(v.(string))
}
Expand Down Expand Up @@ -1040,6 +1054,10 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int
input.EnableCloudwatchLogsExports = flex.ExpandStringSet(v.(*schema.Set))
}

if v, ok := d.GetOk("engine_lifecycle_support"); ok {
input.EngineLifecycleSupport = aws.String(v.(string))
}

if v, ok := d.GetOk(names.AttrEngineVersion); ok {
input.EngineVersion = aws.String(v.(string))
}
Expand Down Expand Up @@ -1222,6 +1240,7 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter
d.Set("enable_http_endpoint", dbc.HttpEndpointEnabled)
d.Set(names.AttrEndpoint, dbc.Endpoint)
d.Set(names.AttrEngine, dbc.Engine)
d.Set("engine_lifecycle_support", dbc.EngineLifecycleSupport)
d.Set("engine_mode", dbc.EngineMode)
clusterSetResourceDataEngineVersionFromCluster(d, dbc)
d.Set(names.AttrHostedZoneID, dbc.HostedZoneId)
Expand Down Expand Up @@ -1284,7 +1303,7 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter
// Fetch and save Global Cluster if engine mode global
d.Set("global_cluster_identifier", "")

if aws.StringValue(dbc.EngineMode) == EngineModeGlobal || aws.StringValue(dbc.EngineMode) == EngineModeProvisioned {
if aws.StringValue(dbc.EngineMode) == engineModeGlobal || aws.StringValue(dbc.EngineMode) == engineModeProvisioned {
globalCluster, err := FindGlobalClusterByDBClusterARN(ctx, conn, aws.StringValue(dbc.DBClusterArn))

if err == nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/service/rds/cluster_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func resourceClusterResourceV0() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: EngineModeProvisioned,
Default: engineModeProvisioned,
},
names.AttrEngineVersion: {
Type: schema.TypeString,
Expand Down
43 changes: 43 additions & 0 deletions internal/service/rds/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,7 @@ func TestAccRDSCluster_engineVersion(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckClusterExists(ctx, resourceName, &dbCluster),
resource.TestCheckResourceAttr(resourceName, names.AttrEngine, tfrds.ClusterEngineAuroraPostgreSQL),
resource.TestCheckResourceAttr(resourceName, "engine_lifecycle_support", "open-source-rds-extended-support"),
resource.TestCheckResourceAttrPair(resourceName, names.AttrEngineVersion, dataSourceName, names.AttrVersion),
),
},
Expand Down Expand Up @@ -2609,6 +2610,34 @@ func TestAccRDSCluster_NoDeleteAutomatedBackups(t *testing.T) {
})
}

func TestAccRDSCluster_engineLifecycleSupport_disabled(t *testing.T) {
ctx := acctest.Context(t)
var dbCluster rds.DBCluster
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_rds_cluster.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.RDSServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckClusterDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccClusterConfig_engineLifecycleSupport_disabled(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckClusterExists(ctx, resourceName, &dbCluster),
acctest.CheckResourceAttrRegionalARN(resourceName, names.AttrARN, "rds", fmt.Sprintf("cluster:%s", rName)),
resource.TestCheckResourceAttr(resourceName, "backtrack_window", acctest.Ct0),
resource.TestCheckResourceAttr(resourceName, names.AttrClusterIdentifier, rName),
resource.TestCheckResourceAttr(resourceName, names.AttrEngine, tfrds.ClusterEngineAuroraPostgreSQL),
resource.TestCheckResourceAttr(resourceName, "engine_lifecycle_support", "open-source-rds-extended-support-disabled"),
),
},
testAccClusterImportStep(resourceName),
},
})
}

func testAccCheckClusterDestroy(ctx context.Context) resource.TestCheckFunc {
return func(s *terraform.State) error {
return testAccCheckClusterDestroyWithProvider(ctx)(s, acctest.Provider)
Expand Down Expand Up @@ -5223,3 +5252,17 @@ resource "aws_rds_cluster" "test" {
}
`, rName)
}

func testAccClusterConfig_engineLifecycleSupport_disabled(rName string) string {
return fmt.Sprintf(`
resource "aws_rds_cluster" "test" {
cluster_identifier = %[1]q
database_name = "test"
engine = %[2]q
master_username = "tfacctest"
master_password = "avoid-plaintext-passwords"
skip_final_snapshot = true
engine_lifecycle_support = "open-source-rds-extended-support-disabled"
}
`, rName, tfrds.ClusterEngineAuroraPostgreSQL)
}
48 changes: 30 additions & 18 deletions internal/service/rds/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,34 +158,46 @@ func ClusterInstanceEngine_Values() []string {
}

const (
GlobalClusterEngineAurora = "aurora"
GlobalClusterEngineAuroraMySQL = "aurora-mysql"
GlobalClusterEngineAuroraPostgreSQL = "aurora-postgresql"
globalClusterEngineAurora = "aurora"
globalClusterEngineAuroraMySQL = "aurora-mysql"
globalClusterEngineAuroraPostgreSQL = "aurora-postgresql"
)

func GlobalClusterEngine_Values() []string {
func globalClusterEngine_Values() []string {
return []string{
GlobalClusterEngineAurora,
GlobalClusterEngineAuroraMySQL,
GlobalClusterEngineAuroraPostgreSQL,
globalClusterEngineAurora,
globalClusterEngineAuroraMySQL,
globalClusterEngineAuroraPostgreSQL,
}
}

const (
EngineModeGlobal = "global"
EngineModeMultiMaster = "multimaster"
EngineModeParallelQuery = "parallelquery"
EngineModeProvisioned = "provisioned"
EngineModeServerless = "serverless"
engineModeGlobal = "global"
engineModeMultiMaster = "multimaster"
engineModeParallelQuery = "parallelquery"
engineModeProvisioned = "provisioned"
engineModeServerless = "serverless"
)

func EngineMode_Values() []string {
func engineMode_Values() []string {
return []string{
EngineModeGlobal,
EngineModeMultiMaster,
EngineModeParallelQuery,
EngineModeProvisioned,
EngineModeServerless,
engineModeGlobal,
engineModeMultiMaster,
engineModeParallelQuery,
engineModeProvisioned,
engineModeServerless,
}
}

const (
engineLifecycleSupport = "open-source-rds-extended-support"
engineLifecycleSupportDisabled = "open-source-rds-extended-support-disabled"
)

func engineLifecycleSupport_Values() []string {
return []string{
engineLifecycleSupport,
engineLifecycleSupportDisabled,
}
}

Expand Down
15 changes: 13 additions & 2 deletions internal/service/rds/global_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ func ResourceGlobalCluster() *schema.Resource {
Computed: true,
ForceNew: true,
ConflictsWith: []string{"source_db_cluster_identifier"},
ValidateFunc: validation.StringInSlice(GlobalClusterEngine_Values(), false),
ValidateFunc: validation.StringInSlice(globalClusterEngine_Values(), false),
},
"engine_lifecycle_support": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice(engineLifecycleSupport_Values(), false),
},
names.AttrEngineVersion: {
Type: schema.TypeString,
Expand Down Expand Up @@ -144,6 +150,10 @@ func resourceGlobalClusterCreate(ctx context.Context, d *schema.ResourceData, me
input.Engine = aws.String(v.(string))
}

if v, ok := d.GetOk("engine_lifecycle_support"); ok {
input.EngineLifecycleSupport = aws.String(v.(string))
}

if v, ok := d.GetOk(names.AttrEngineVersion); ok {
input.EngineVersion = aws.String(v.(string))
}
Expand All @@ -160,7 +170,7 @@ func resourceGlobalClusterCreate(ctx context.Context, d *schema.ResourceData, me
// since we cannot have Engine default after adding SourceDBClusterIdentifier:
// InvalidParameterValue: When creating standalone global cluster, value for engineName should be specified
if input.Engine == nil && input.SourceDBClusterIdentifier == nil {
input.Engine = aws.String(GlobalClusterEngineAurora)
input.Engine = aws.String(globalClusterEngineAurora)
}

output, err := conn.CreateGlobalClusterWithContext(ctx, input)
Expand Down Expand Up @@ -198,6 +208,7 @@ func resourceGlobalClusterRead(ctx context.Context, d *schema.ResourceData, meta
d.Set(names.AttrDatabaseName, globalCluster.DatabaseName)
d.Set(names.AttrDeletionProtection, globalCluster.DeletionProtection)
d.Set(names.AttrEngine, globalCluster.Engine)
d.Set("engine_lifecycle_support", globalCluster.EngineLifecycleSupport)
d.Set("global_cluster_identifier", globalCluster.GlobalClusterIdentifier)
if err := d.Set("global_cluster_members", flattenGlobalClusterMembers(globalCluster.GlobalClusterMembers)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting global_cluster_members: %s", err)
Expand Down
43 changes: 43 additions & 0 deletions internal/service/rds/global_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func TestAccRDSGlobalCluster_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, names.AttrDatabaseName, ""),
resource.TestCheckResourceAttr(resourceName, names.AttrDeletionProtection, acctest.CtFalse),
resource.TestCheckResourceAttr(resourceName, names.AttrEngine, "aurora-postgresql"),
resource.TestCheckResourceAttr(resourceName, "engine_lifecycle_support", "open-source-rds-extended-support"),
resource.TestCheckResourceAttrSet(resourceName, names.AttrEngineVersion),
resource.TestCheckResourceAttr(resourceName, "global_cluster_identifier", rName),
resource.TestMatchResourceAttr(resourceName, "global_cluster_resource_id", regexache.MustCompile(`cluster-.+`)),
Expand Down Expand Up @@ -230,6 +231,38 @@ func TestAccRDSGlobalCluster_deletionProtection(t *testing.T) {
})
}

func TestAccRDSGlobalCluster_engineLifecycleSupport_disabled(t *testing.T) {
ctx := acctest.Context(t)
var globalCluster1 rds.GlobalCluster
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_rds_global_cluster.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckGlobalCluster(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.RDSServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckGlobalClusterDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccGlobalClusterConfig_engineLifecycleSupport_disabled(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckGlobalClusterExists(ctx, resourceName, &globalCluster1),
acctest.CheckResourceAttrGlobalARN(resourceName, names.AttrARN, "rds", fmt.Sprintf("global-cluster:%s", rName)),
resource.TestCheckResourceAttr(resourceName, names.AttrDatabaseName, ""),
resource.TestCheckResourceAttr(resourceName, names.AttrEngine, "aurora-postgresql"),
resource.TestCheckResourceAttr(resourceName, "engine_lifecycle_support", "open-source-rds-extended-support-disabled"),
resource.TestCheckResourceAttrSet(resourceName, names.AttrEngineVersion),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccRDSGlobalCluster_EngineVersion_updateMinor(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
Expand Down Expand Up @@ -675,6 +708,16 @@ resource "aws_rds_global_cluster" "test" {
`, deletionProtection, rName)
}

func testAccGlobalClusterConfig_engineLifecycleSupport_disabled(rName string) string {
return fmt.Sprintf(`
resource "aws_rds_global_cluster" "test" {
global_cluster_identifier = %[1]q
engine = "aurora-postgresql"
engine_lifecycle_support = "open-source-rds-extended-support-disabled"
}
`, rName)
}

func testAccGlobalClusterConfig_engineVersion(rName, engine string) string {
return fmt.Sprintf(`
data "aws_rds_engine_version" "default" {
Expand Down
23 changes: 23 additions & 0 deletions internal/service/rds/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ func ResourceInstance() *schema.Resource {
return strings.ToLower(value)
},
},
"engine_lifecycle_support": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice(engineLifecycleSupport_Values(), false),
},
names.AttrEngineVersion: {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -1000,6 +1006,10 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in
input.DedicatedLogVolume = aws.Bool(v.(bool))
}

if v, ok := d.GetOk("engine_lifecycle_support"); ok {
input.EngineLifecycleSupport = aws.String(v.(string))
}

if v, ok := d.GetOk("iam_database_authentication_enabled"); ok {
input.EnableIAMDatabaseAuthentication = aws.Bool(v.(bool))
}
Expand Down Expand Up @@ -1215,6 +1225,10 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in
input.Engine = aws.String(engine)
}

if v, ok := d.GetOk("engine_lifecycle_support"); ok {
input.EngineLifecycleSupport = aws.String(v.(string))
}

if v, ok := d.GetOk(names.AttrEngineVersion); ok {
modifyDbInstanceInput.EngineVersion = aws.String(v.(string))
requiresModifyDbInstance = true
Expand Down Expand Up @@ -1464,6 +1478,10 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in
input.Engine = aws.String(v.(string))
}

if v, ok := d.GetOk("engine_lifecycle_support"); ok {
input.EngineLifecycleSupport = aws.String(v.(string))
}

if v, ok := d.GetOk("iam_database_authentication_enabled"); ok {
input.EnableIAMDatabaseAuthentication = aws.Bool(v.(bool))
}
Expand Down Expand Up @@ -1649,6 +1667,10 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in
input.EnableCloudwatchLogsExports = flex.ExpandStringSet(v.(*schema.Set))
}

if v, ok := d.GetOk("engine_lifecycle_support"); ok {
input.EngineLifecycleSupport = aws.String(v.(string))
}

if v, ok := d.GetOk("iam_database_authentication_enabled"); ok {
input.EnableIAMDatabaseAuthentication = aws.Bool(v.(bool))
}
Expand Down Expand Up @@ -1886,6 +1908,7 @@ func resourceInstanceRead(ctx context.Context, d *schema.ResourceData, meta inte
}
d.Set("enabled_cloudwatch_logs_exports", aws.StringValueSlice(v.EnabledCloudwatchLogsExports))
d.Set(names.AttrEngine, v.Engine)
d.Set("engine_lifecycle_support", v.EngineLifecycleSupport)
d.Set("iam_database_authentication_enabled", v.IAMDatabaseAuthenticationEnabled)
d.Set(names.AttrIdentifier, v.DBInstanceIdentifier)
d.Set("identifier_prefix", create.NamePrefixFromName(aws.StringValue(v.DBInstanceIdentifier)))
Expand Down
Loading

0 comments on commit 1200b46

Please sign in to comment.