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

azurerm_mssql_database - support for the recovery_point_id & restore_long_term_retention_backup_id property #24904

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -538,8 +538,8 @@ func resourceLogAnalyticsWorkspaceDelete(d *pluginsdk.ResourceData, meta interfa
return err
}

PermanentlyDeleteOnDestroy := meta.(*clients.Client).Features.LogAnalyticsWorkspace.PermanentlyDeleteOnDestroy
err = client.DeleteThenPoll(ctx, sharedKeyId, sharedKeyWorkspaces.DeleteOperationOptions{Force: utils.Bool(PermanentlyDeleteOnDestroy)})
permanentlyDeleteOnDestroy := meta.(*clients.Client).Features.LogAnalyticsWorkspace.PermanentlyDeleteOnDestroy
err = client.DeleteThenPoll(ctx, sharedKeyId, sharedKeyWorkspaces.DeleteOperationOptions{Force: utils.Bool(permanentlyDeleteOnDestroy)})
if err != nil {
return fmt.Errorf("issuing AzureRM delete request for Log Analytics Workspaces '%s': %+v", id.WorkspaceName, err)
}
Expand Down
19 changes: 19 additions & 0 deletions internal/services/mssql/mssql_database_resource.go
Expand Up @@ -324,6 +324,10 @@ func resourceMsSqlDatabaseCreate(d *pluginsdk.ResourceData, meta interface{}) er
if _, dbok := d.GetOk("restore_dropped_database_id"); !dbok {
return fmt.Errorf("'restore_dropped_database_id' is required for create_mode %s", createMode)
}
case databases.CreateModeRestoreLongTermRetentionBackup:
if _, dbok := d.GetOk("recovery_point_id"); !dbok {
return fmt.Errorf("'recovery_point_id' is required for create_mode %s", createMode)
}
}

// we should not specify the value of `maintenance_configuration_name` when `elastic_pool_id` is set since its value depends on the elastic pool's `maintenance_configuration_name` value.
Expand Down Expand Up @@ -377,6 +381,10 @@ func resourceMsSqlDatabaseCreate(d *pluginsdk.ResourceData, meta interface{}) er
input.Properties.RecoverableDatabaseId = pointer.To(v.(string))
}

if v, ok := d.GetOk("recovery_point_id"); ok {
input.Properties.RecoveryServicesRecoveryPointId = pointer.To(v.(string))
}

if v, ok := d.GetOk("restore_dropped_database_id"); ok {
input.Properties.RestorableDroppedDatabaseId = pointer.To(v.(string))
}
Expand Down Expand Up @@ -1004,6 +1012,10 @@ func resourceMsSqlDatabaseUpdate(d *pluginsdk.ResourceData, meta interface{}) er
props.RecoverableDatabaseId = pointer.To(d.Get("recover_database_id").(string))
}

if d.HasChange("recovery_point_id") {
props.RecoveryServicesRecoveryPointId = pointer.To(d.Get("recover_database_id").(string))
katbyte marked this conversation as resolved.
Show resolved Hide resolved
}

if d.HasChange("restore_dropped_database_id") {
props.RestorableDroppedDatabaseId = pointer.To(d.Get("restore_dropped_database_id").(string))
}
Expand Down Expand Up @@ -1412,6 +1424,7 @@ func resourceMsSqlDatabaseSchema() map[string]*pluginsdk.Schema {
false),
ConflictsWith: []string{"import"},
},

"import": {
Type: pluginsdk.TypeList,
Optional: true,
Expand Down Expand Up @@ -1522,6 +1535,12 @@ func resourceMsSqlDatabaseSchema() map[string]*pluginsdk.Schema {
ValidateFunc: validate.RecoverableDatabaseID,
},

"recovery_point_id": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"restore_dropped_database_id": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/mssql_database.html.markdown
Expand Up @@ -220,6 +220,8 @@ The following arguments are supported:

* `recover_database_id` - (Optional) The ID of the database to be recovered. This property is only applicable when the `create_mode` is `Recovery`.

* `recovery_point_id` - (Optional) The ID of the Recovery Services Recovery Point Id to be restored. This property is only applicable when the `create_mode` is `CreateModeRestoreLongTermRetentionBackup`.

* `restore_dropped_database_id` - (Optional) The ID of the database to be restored. This property is only applicable when the `create_mode` is `Restore`.

* `read_replica_count` - (Optional) The number of readonly secondary replicas associated with the database to which readonly application intent connections may be routed. This property is only settable for Hyperscale edition databases.
Expand Down