diff --git a/go.mod b/go.mod index f5a145f5..cbfd298d 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.22 toolchain go1.22.3 require ( - github.com/OctopusDeploy/go-octopusdeploy/v2 v2.63.1 + github.com/OctopusDeploy/go-octopusdeploy/v2 v2.64.0 github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20241206032352-dbc62b2d16cf github.com/google/uuid v1.6.0 github.com/hashicorp/go-cty v1.4.1-0.20200723130312-85980079f637 diff --git a/go.sum b/go.sum index 0a7a2e40..df4a0452 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERo github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/OctopusDeploy/go-octodiff v1.0.0 h1:U+ORg6azniwwYo+O44giOw6TiD5USk8S4VDhOQ0Ven0= github.com/OctopusDeploy/go-octodiff v1.0.0/go.mod h1:Mze0+EkOWTgTmi8++fyUc6r0aLZT7qD9gX+31t8MmIU= -github.com/OctopusDeploy/go-octopusdeploy/v2 v2.63.1 h1:ShfJ3VZqNblU5V0UnA/UNjQuUrgkljZdDp9Vxh8rhcI= -github.com/OctopusDeploy/go-octopusdeploy/v2 v2.63.1/go.mod h1:ggvOXzMnq+w0pLg6C9zdjz6YBaHfO3B3tqmmB7JQdaw= +github.com/OctopusDeploy/go-octopusdeploy/v2 v2.64.0 h1:NWqQ/7JLUfEJQ8QHrkek7AfePuN121+f6+tUi3xP6vE= +github.com/OctopusDeploy/go-octopusdeploy/v2 v2.64.0/go.mod h1:ggvOXzMnq+w0pLg6C9zdjz6YBaHfO3B3tqmmB7JQdaw= github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20241206032352-dbc62b2d16cf h1:wuUJ6DbSZEHE4a3SfSJIcoeTQCSI6lbQ+i46ibY14+Q= github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20241206032352-dbc62b2d16cf/go.mod h1:xVv8DvYhhwxtQUQQDfOYA6CY8KTkHXccxQ2RfRj6IJ0= github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg= diff --git a/octopusdeploy_framework/datasource_deployment_freeze.go b/octopusdeploy_framework/datasource_deployment_freeze.go index 70b802aa..5db7bfff 100644 --- a/octopusdeploy_framework/datasource_deployment_freeze.go +++ b/octopusdeploy_framework/datasource_deployment_freeze.go @@ -151,30 +151,18 @@ func mapFreezeToAttribute(ctx context.Context, freeze deploymentfreezes.Deployme endOnDate = types.StringValue(freeze.RecurringSchedule.EndOnDate.Format(time.RFC3339)) } - endAfterOccurrences := types.Int64Null() - if freeze.RecurringSchedule.EndAfterOccurrences != nil { - endAfterOccurrences = types.Int64Value(int64(*freeze.RecurringSchedule.EndAfterOccurrences)) - } + endAfterOccurrences := types.Int64Value(int64(freeze.RecurringSchedule.EndAfterOccurrences)) monthlyScheduleType := types.StringNull() if freeze.RecurringSchedule.MonthlyScheduleType != "" { monthlyScheduleType = types.StringValue(freeze.RecurringSchedule.MonthlyScheduleType) } - dateOfMonth := types.StringNull() - if freeze.RecurringSchedule.DateOfMonth != nil { - dateOfMonth = types.StringValue(*freeze.RecurringSchedule.DateOfMonth) - } + dateOfMonth := types.StringValue(freeze.RecurringSchedule.DateOfMonth) - dayNumberOfMonth := types.StringNull() - if freeze.RecurringSchedule.DayNumberOfMonth != nil { - dayNumberOfMonth = types.StringValue(*freeze.RecurringSchedule.DayNumberOfMonth) - } + dayNumberOfMonth := types.StringValue(freeze.RecurringSchedule.DayNumberOfMonth) - dayOfWeek := types.StringNull() - if freeze.RecurringSchedule.DayOfWeek != nil { - dayOfWeek = types.StringValue(*freeze.RecurringSchedule.DayOfWeek) - } + dayOfWeek := types.StringValue(freeze.RecurringSchedule.DayOfWeek) scheduleAttrs := map[string]attr.Value{ "type": types.StringValue(string(freeze.RecurringSchedule.Type)), diff --git a/octopusdeploy_framework/resource_deployment_freeze.go b/octopusdeploy_framework/resource_deployment_freeze.go index 3b6e1510..ad204b44 100644 --- a/octopusdeploy_framework/resource_deployment_freeze.go +++ b/octopusdeploy_framework/resource_deployment_freeze.go @@ -192,7 +192,6 @@ func (f *deploymentFreezeResource) Delete(ctx context.Context, req resource.Dele resp.State.RemoveResource(ctx) } - func mapFromState(state *deploymentFreezeModel) (*deploymentfreezes.DeploymentFreeze, diag.Diagnostics) { start, diags := state.Start.ValueRFC3339Time() if diags.HasError() { @@ -213,24 +212,8 @@ func mapFromState(state *deploymentFreezeModel) (*deploymentfreezes.DeploymentFr } if state.RecurringSchedule != nil { - var endOnDate *time.Time - var endAfterOccurrences *int var daysOfWeek []string - if !state.RecurringSchedule.EndOnDate.IsNull() { - date, diagsDate := state.RecurringSchedule.EndOnDate.ValueRFC3339Time() - if diagsDate.HasError() { - diags.Append(diagsDate...) - return nil, diags - } - endOnDate = &date - } - - if !state.RecurringSchedule.EndAfterOccurrences.IsNull() { - occurrences := int(state.RecurringSchedule.EndAfterOccurrences.ValueInt64()) - endAfterOccurrences = &occurrences - } - if !state.RecurringSchedule.DaysOfWeek.IsNull() { diags.Append(state.RecurringSchedule.DaysOfWeek.ElementsAs(context.TODO(), &daysOfWeek, false)...) if diags.HasError() { @@ -242,20 +225,27 @@ func mapFromState(state *deploymentFreezeModel) (*deploymentfreezes.DeploymentFr Type: deploymentfreezes.RecurringScheduleType(state.RecurringSchedule.Type.ValueString()), Unit: int(state.RecurringSchedule.Unit.ValueInt64()), EndType: deploymentfreezes.RecurringScheduleEndType(state.RecurringSchedule.EndType.ValueString()), - EndOnDate: endOnDate, - EndAfterOccurrences: endAfterOccurrences, + EndAfterOccurrences: getOptionalIntValue(state.RecurringSchedule.EndAfterOccurrences), MonthlyScheduleType: getOptionalString(state.RecurringSchedule.MonthlyScheduleType), - DateOfMonth: getOptionalStringPointer(state.RecurringSchedule.DateOfMonth), - DayNumberOfMonth: getOptionalStringPointer(state.RecurringSchedule.DayNumberOfMonth), + DateOfMonth: getOptionalString(state.RecurringSchedule.DateOfMonth), + DayNumberOfMonth: getOptionalString(state.RecurringSchedule.DayNumberOfMonth), DaysOfWeek: daysOfWeek, - DayOfWeek: getOptionalStringPointer(state.RecurringSchedule.DayOfWeek), + DayOfWeek: getOptionalString(state.RecurringSchedule.DayOfWeek), + } + + if !state.RecurringSchedule.EndOnDate.IsNull() { + date, diagsDate := state.RecurringSchedule.EndOnDate.ValueRFC3339Time() + if diagsDate.HasError() { + diags.Append(diagsDate...) + return nil, diags + } + freeze.RecurringSchedule.EndOnDate = &date } } freeze.ID = state.ID.String() return &freeze, nil } - func mapToState(ctx context.Context, state *deploymentFreezeModel, deploymentFreeze *deploymentfreezes.DeploymentFreeze) diag.Diagnostics { state.ID = types.StringValue(deploymentFreeze.ID) state.Name = types.StringValue(deploymentFreeze.Name) @@ -304,15 +294,10 @@ func mapToState(ctx context.Context, state *deploymentFreezeModel, deploymentFre state.RecurringSchedule.EndOnDate = timetypes.NewRFC3339Null() } - if deploymentFreeze.RecurringSchedule.EndAfterOccurrences != nil { - state.RecurringSchedule.EndAfterOccurrences = types.Int64Value(int64(*deploymentFreeze.RecurringSchedule.EndAfterOccurrences)) - } else { - state.RecurringSchedule.EndAfterOccurrences = types.Int64Null() - } - - state.RecurringSchedule.DateOfMonth = mapOptionalStringPointer(deploymentFreeze.RecurringSchedule.DateOfMonth) - state.RecurringSchedule.DayNumberOfMonth = mapOptionalStringPointer(deploymentFreeze.RecurringSchedule.DayNumberOfMonth) - state.RecurringSchedule.DayOfWeek = mapOptionalStringPointer(deploymentFreeze.RecurringSchedule.DayOfWeek) + state.RecurringSchedule.EndAfterOccurrences = mapOptionalIntValue(deploymentFreeze.RecurringSchedule.EndAfterOccurrences) + state.RecurringSchedule.DateOfMonth = mapOptionalStringValue(deploymentFreeze.RecurringSchedule.DateOfMonth) + state.RecurringSchedule.DayNumberOfMonth = mapOptionalStringValue(deploymentFreeze.RecurringSchedule.DayNumberOfMonth) + state.RecurringSchedule.DayOfWeek = mapOptionalStringValue(deploymentFreeze.RecurringSchedule.DayOfWeek) } return nil @@ -352,12 +337,18 @@ func mapOptionalStringValue(value string) types.String { } return types.StringValue(value) } +func getOptionalIntValue(value types.Int64) int { + if value.IsNull() { + return 0 + } + return int(value.ValueInt64()) +} -func mapOptionalStringPointer(value *string) types.String { - if value == nil { - return types.StringNull() +func mapOptionalIntValue(value int) types.Int64 { + if value == 0 { + return types.Int64Null() } - return types.StringValue(*value) + return types.Int64Value(int64(value)) } func getOptionalString(value types.String) string {