bugfix(serverbackup): state drift in volume-id because of changed order (#979)
* fix: state drift in backup-properties.volume-id because of changed order in API response --------- Signed-off-by: Mauritz Uphoff <mauritz.uphoff@stackit.cloud> Co-authored-by: Marcel Jacek <Marcel.Jacek@stackit.cloud>
This commit is contained in:
parent
7c1920f55e
commit
822b9fc6b4
4 changed files with 32 additions and 8 deletions
|
|
@ -7,6 +7,8 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
|
||||||
|
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||||
serverbackupUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/serverbackup/utils"
|
serverbackupUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/serverbackup/utils"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
|
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
|
||||||
|
|
@ -206,6 +208,9 @@ func (r *scheduleResource) Schema(_ context.Context, _ resource.SchemaRequest, r
|
||||||
"volume_ids": schema.ListAttribute{
|
"volume_ids": schema.ListAttribute{
|
||||||
ElementType: types.StringType,
|
ElementType: types.StringType,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
Validators: []validator.List{
|
||||||
|
listvalidator.SizeAtLeast(1),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"name": schema.StringAttribute{
|
"name": schema.StringAttribute{
|
||||||
Required: true,
|
Required: true,
|
||||||
|
|
@ -455,14 +460,31 @@ func mapFields(ctx context.Context, schedule *serverbackup.BackupSchedule, model
|
||||||
model.BackupProperties = nil
|
model.BackupProperties = nil
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ids, diags := types.ListValueFrom(ctx, types.StringType, schedule.BackupProperties.VolumeIds)
|
|
||||||
if diags.HasError() {
|
volIds := types.ListNull(types.StringType)
|
||||||
return fmt.Errorf("failed to map hosts: %w", core.DiagsToError(diags))
|
if schedule.BackupProperties.VolumeIds != nil {
|
||||||
|
var modelVolIds []string
|
||||||
|
if model.BackupProperties != nil {
|
||||||
|
var err error
|
||||||
|
modelVolIds, err = utils.ListValuetoStringSlice(model.BackupProperties.VolumeIds)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
respVolIds := *schedule.BackupProperties.VolumeIds
|
||||||
|
reconciledVolIds := utils.ReconcileStringSlices(modelVolIds, respVolIds)
|
||||||
|
|
||||||
|
var diags diag.Diagnostics
|
||||||
|
volIds, diags = types.ListValueFrom(ctx, types.StringType, reconciledVolIds)
|
||||||
|
if diags.HasError() {
|
||||||
|
return fmt.Errorf("failed to map volumeIds: %w", core.DiagsToError(diags))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
model.BackupProperties = &scheduleBackupPropertiesModel{
|
model.BackupProperties = &scheduleBackupPropertiesModel{
|
||||||
BackupName: types.StringValue(*schedule.BackupProperties.Name),
|
BackupName: types.StringValue(*schedule.BackupProperties.Name),
|
||||||
RetentionPeriod: types.Int64Value(*schedule.BackupProperties.RetentionPeriod),
|
RetentionPeriod: types.Int64Value(*schedule.BackupProperties.RetentionPeriod),
|
||||||
VolumeIds: ids,
|
VolumeIds: volIds,
|
||||||
}
|
}
|
||||||
model.Region = types.StringValue(region)
|
model.Region = types.StringValue(region)
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ func TestAccServerBackupScheduleMinResource(t *testing.T) {
|
||||||
},
|
},
|
||||||
// Creation
|
// Creation
|
||||||
{
|
{
|
||||||
Config: resourceMinConfig,
|
Config: testutil.ServerBackupProviderConfig() + "\n" + resourceMinConfig,
|
||||||
ConfigVariables: testConfigVarsMin,
|
ConfigVariables: testConfigVarsMin,
|
||||||
Check: resource.ComposeAggregateTestCheckFunc(
|
Check: resource.ComposeAggregateTestCheckFunc(
|
||||||
// Backup schedule data
|
// Backup schedule data
|
||||||
|
|
@ -180,7 +180,7 @@ func TestAccServerBackupScheduleMaxResource(t *testing.T) {
|
||||||
},
|
},
|
||||||
// Creation
|
// Creation
|
||||||
{
|
{
|
||||||
Config: resourceMaxConfig,
|
Config: testutil.ServerBackupProviderConfig() + "\n" + resourceMaxConfig,
|
||||||
ConfigVariables: testConfigVarsMax,
|
ConfigVariables: testConfigVarsMax,
|
||||||
Check: resource.ComposeAggregateTestCheckFunc(
|
Check: resource.ComposeAggregateTestCheckFunc(
|
||||||
// Backup schedule data
|
// Backup schedule data
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ func TestAccServerUpdateScheduleMinResource(t *testing.T) {
|
||||||
// Creation
|
// Creation
|
||||||
{
|
{
|
||||||
ConfigVariables: testConfigVarsMin,
|
ConfigVariables: testConfigVarsMin,
|
||||||
Config: resourceMinConfig,
|
Config: testutil.ServerUpdateProviderConfig() + "\n" + resourceMinConfig,
|
||||||
Check: resource.ComposeAggregateTestCheckFunc(
|
Check: resource.ComposeAggregateTestCheckFunc(
|
||||||
// Update schedule data
|
// Update schedule data
|
||||||
resource.TestCheckResourceAttr("stackit_server_update_schedule.test_schedule", "project_id", testutil.ConvertConfigVariable(testConfigVarsMin["project_id"])),
|
resource.TestCheckResourceAttr("stackit_server_update_schedule.test_schedule", "project_id", testutil.ConvertConfigVariable(testConfigVarsMin["project_id"])),
|
||||||
|
|
@ -177,7 +177,7 @@ func TestAccServerUpdateScheduleMaxResource(t *testing.T) {
|
||||||
// Creation
|
// Creation
|
||||||
{
|
{
|
||||||
ConfigVariables: testConfigVarsMax,
|
ConfigVariables: testConfigVarsMax,
|
||||||
Config: resourceMaxConfig,
|
Config: testutil.ServerUpdateProviderConfig() + "\n" + resourceMaxConfig,
|
||||||
Check: resource.ComposeAggregateTestCheckFunc(
|
Check: resource.ComposeAggregateTestCheckFunc(
|
||||||
// Update schedule data
|
// Update schedule data
|
||||||
resource.TestCheckResourceAttr("stackit_server_update_schedule.test_schedule", "project_id", testutil.ConvertConfigVariable(testConfigVarsMax["project_id"])),
|
resource.TestCheckResourceAttr("stackit_server_update_schedule.test_schedule", "project_id", testutil.ConvertConfigVariable(testConfigVarsMax["project_id"])),
|
||||||
|
|
|
||||||
|
|
@ -379,11 +379,13 @@ func ServerBackupProviderConfig() string {
|
||||||
return `
|
return `
|
||||||
provider "stackit" {
|
provider "stackit" {
|
||||||
default_region = "eu01"
|
default_region = "eu01"
|
||||||
|
enable_beta_resources = true
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
provider "stackit" {
|
provider "stackit" {
|
||||||
server_backup_custom_endpoint = "%s"
|
server_backup_custom_endpoint = "%s"
|
||||||
|
enable_beta_resources = true
|
||||||
}`,
|
}`,
|
||||||
ServerBackupCustomEndpoint,
|
ServerBackupCustomEndpoint,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue