@@ -245,6 +245,7 @@ func ResourceSqlDatabaseInstance() *schema.Resource {
245245 privateNetworkCustomizeDiff ,
246246 pitrSupportDbCustomizeDiff ,
247247 nodeCountCustomDiff ,
248+ autoUpgradeEnabledCustomizeDiff ,
248249 ),
249250
250251 Schema : map [string ]* schema.Schema {
@@ -530,6 +531,11 @@ API (for read pools, effective_availability_type may differ from availability_ty
530531 Optional : true ,
531532 Description : `Enables Vertex AI Integration.` ,
532533 },
534+ "auto_upgrade_enabled" : {
535+ Type : schema .TypeBool ,
536+ Optional : true ,
537+ Description : `Enables Automatic Version Upgrade feature. Can be used with MySQL only.` ,
538+ },
533539 "enable_dataplex_integration" : {
534540 Type : schema .TypeBool ,
535541 Optional : true ,
@@ -1462,6 +1468,24 @@ func privateNetworkCustomizeDiff(_ context.Context, d *schema.ResourceDiff, meta
14621468 return nil
14631469}
14641470
1471+ // Ensures auto_upgrade_enabled is never unset (in-place) if already set to true.
1472+ func autoUpgradeEnabledCustomizeDiff (_ context.Context , d * schema.ResourceDiff , _ interface {}) error {
1473+ if ! d .HasChange ("settings.0.auto_upgrade_enabled" ) {
1474+ return nil
1475+ }
1476+ oldValueI , newValueI := d .GetChange ("settings.0.auto_upgrade_enabled" )
1477+ if oldValueI == nil && ! (newValueI .(bool )) {
1478+ if err := d .SetNew ("settings.0.auto_upgrade_enabled" , nil ); err != nil {
1479+ return err
1480+ }
1481+ } else if oldValueI != nil && oldValueI .(bool ) && (newValueI == nil || ! (newValueI .(bool ))) {
1482+ if err := d .ForceNew ("settings.0.auto_upgrade_enabled" ); err != nil {
1483+ return fmt .Errorf ("The setting auto_upgrade_enabled cannot be set to false after being set true: %s" , err )
1484+ }
1485+ }
1486+ return nil
1487+ }
1488+
14651489// helper function to see if string within list contains a particular substring
14661490func stringContainsSlice (arr []string , str string ) bool {
14671491 for _ , i := range arr {
@@ -1537,6 +1561,12 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{})
15371561 cloneContext , cloneSource := expandCloneContext (d .Get ("clone" ).([]interface {}))
15381562 pointInTimeRestoreContext := expandPointInTimeRestoreContext (d .Get ("point_in_time_restore_context" ).([]interface {}))
15391563
1564+ if valueI , ok := d .GetOk ("settings.0.auto_upgrade_enabled" ); ok && ! (valueI .(bool )) {
1565+ if err := d .Set ("settings.0.auto_upgrade_enabled" , nil ); err != nil {
1566+ return err
1567+ }
1568+ }
1569+
15401570 s , ok := d .GetOk ("settings" )
15411571 desiredSettings := expandSqlDatabaseInstanceSettings (s .([]interface {}), databaseVersion )
15421572 if ok {
@@ -1780,6 +1810,10 @@ func expandSqlDatabaseInstanceSettings(configured []interface{}, databaseVersion
17801810 settings .StorageAutoResize = & resize
17811811 settings .StorageAutoResizeLimit = int64 (_settings ["disk_autoresize_limit" ].(int ))
17821812
1813+ if _settings ["auto_upgrade_enabled" ] != nil {
1814+ settings .AutoUpgradeEnabled = _settings ["auto_upgrade_enabled" ].(bool )
1815+ }
1816+
17831817 return settings
17841818}
17851819
@@ -2600,8 +2634,11 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{})
26002634 instance .PscServiceAttachmentLink = d .Get ("psc_service_attachment_link" ).(string )
26012635 }
26022636
2603- // Database Version is required for all calls with Google ML integration enabled or it will be rejected by the API.
2604- if d .Get ("settings.0.enable_google_ml_integration" ).(bool ) || len (_settings ["connection_pool_config" ].(* schema.Set ).List ()) > 0 {
2637+ // Database Version is required for all calls with Google ML Integration, Auto Upgrade,
2638+ // and Connection Pool enabled, or it will be rejected by the API.
2639+ if d .Get ("settings.0.enable_google_ml_integration" ).(bool ) ||
2640+ d .Get ("settings.0.auto_upgrade_enabled" ).(bool ) ||
2641+ len (_settings ["connection_pool_config" ].(* schema.Set ).List ()) > 0 {
26052642 instance .DatabaseVersion = databaseVersion
26062643 }
26072644
@@ -2900,6 +2937,10 @@ func flattenSettings(settings *sqladmin.Settings, iType string, d *schema.Resour
29002937 data ["enable_google_ml_integration" ] = settings .EnableGoogleMlIntegration
29012938 data ["enable_dataplex_integration" ] = settings .EnableDataplexIntegration
29022939
2940+ if settings .AutoUpgradeEnabled {
2941+ data ["auto_upgrade_enabled" ] = settings .AutoUpgradeEnabled
2942+ }
2943+
29032944 if settings .UserLabels != nil {
29042945 data ["user_labels" ] = settings .UserLabels
29052946 }
0 commit comments