From d3d42eb800965670ddedcdc130dcce1901b6f874 Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Tue, 17 Dec 2024 14:14:27 +1000 Subject: [PATCH] Update validation and schema to new recurring_schedule model --- docs/resources/deployment_freeze.md | 2 +- .../datasource_deployment_freeze_test.go | 2 +- .../resource_deployment_freeze_test.go | 4 ++-- octopusdeploy_framework/schemas/deployment_freeze.go | 4 ++-- .../schemas/deployment_freeze_validation.go | 10 +++++----- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/resources/deployment_freeze.md b/docs/resources/deployment_freeze.md index a85aade5..397a2474 100644 --- a/docs/resources/deployment_freeze.md +++ b/docs/resources/deployment_freeze.md @@ -95,7 +95,7 @@ resource "octopusdeploy_deployment_freeze_tenant" "tenant_freeze" { Required: - `end_type` (String) When the recurring schedule should end (Never, OnDate, AfterOccurrences) -- `type` (String) Type of recurring schedule (OnceDaily, DaysPerWeek, DaysPerMonth, Annually) +- `type` (String) Type of recurring schedule (Daily, Weekly, Monthly, Annually) - `unit` (Number) The unit value for the schedule Optional: diff --git a/octopusdeploy_framework/datasource_deployment_freeze_test.go b/octopusdeploy_framework/datasource_deployment_freeze_test.go index d1204bf8..230a3fd5 100644 --- a/octopusdeploy_framework/datasource_deployment_freeze_test.go +++ b/octopusdeploy_framework/datasource_deployment_freeze_test.go @@ -98,7 +98,7 @@ resource "octopusdeploy_deployment_freeze" "test_freeze" { end = "%s" recurring_schedule = { - type = "DaysPerWeek" + type = "Weekly" unit = 24 end_type = "AfterOccurrences" end_after_occurrences = 5 diff --git a/octopusdeploy_framework/resource_deployment_freeze_test.go b/octopusdeploy_framework/resource_deployment_freeze_test.go index a6c72d1f..b0cb96f7 100644 --- a/octopusdeploy_framework/resource_deployment_freeze_test.go +++ b/octopusdeploy_framework/resource_deployment_freeze_test.go @@ -60,7 +60,7 @@ func TestNewDeploymentFreezeResource(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "name", name+"1"), resource.TestCheckResourceAttr(resourceName, "start", start), resource.TestCheckResourceAttr(resourceName, "end", updatedEnd), - resource.TestCheckResourceAttr(resourceName, "recurring_schedule.type", "DaysPerWeek"), + resource.TestCheckResourceAttr(resourceName, "recurring_schedule.type", "Weekly"), resource.TestCheckResourceAttr(resourceName, "recurring_schedule.unit", "24"), resource.TestCheckResourceAttr(resourceName, "recurring_schedule.end_type", "AfterOccurrences"), resource.TestCheckResourceAttr(resourceName, "recurring_schedule.end_after_occurrences", "5"), @@ -99,7 +99,7 @@ func testDeploymentFreezeBasic(localName string, freezeName string, start string if includeRecurringSchedule { freezeConfig += ` recurring_schedule = { - type = "DaysPerWeek" + type = "Weekly" unit = 24 end_type = "AfterOccurrences" end_after_occurrences = 5 diff --git a/octopusdeploy_framework/schemas/deployment_freeze.go b/octopusdeploy_framework/schemas/deployment_freeze.go index ca55db75..59bdd9ba 100644 --- a/octopusdeploy_framework/schemas/deployment_freeze.go +++ b/octopusdeploy_framework/schemas/deployment_freeze.go @@ -24,10 +24,10 @@ func (d DeploymentFreezeSchema) GetResourceSchema() resourceSchema.Schema { }, Attributes: map[string]resourceSchema.Attribute{ "type": resourceSchema.StringAttribute{ - Description: "Type of recurring schedule (OnceDaily, DaysPerWeek, DaysPerMonth, Annually)", + Description: "Type of recurring schedule (Daily, Weekly, Monthly, Annually)", Required: true, Validators: []validator.String{ - stringvalidator.OneOf("OnceDaily", "DaysPerWeek", "DaysPerMonth", "Annually"), + stringvalidator.OneOf("Daily", "Weekly", "Monthly", "Annually"), }, }, "unit": resourceSchema.Int64Attribute{ diff --git a/octopusdeploy_framework/schemas/deployment_freeze_validation.go b/octopusdeploy_framework/schemas/deployment_freeze_validation.go index 4a91e42c..6effbb39 100644 --- a/octopusdeploy_framework/schemas/deployment_freeze_validation.go +++ b/octopusdeploy_framework/schemas/deployment_freeze_validation.go @@ -115,10 +115,10 @@ func (v recurringScheduleValidator) ValidateObject(ctx context.Context, req vali scheduleType := schedule.Type.ValueString() switch scheduleType { - case "OnceDaily": - // OnceDaily only requires type and unit which are already marked as required + case "Daily": + // Daily only requires type and unit which are already marked as required - case "DaysPerWeek": + case "Weekly": if schedule.DaysOfWeek.IsNull() { resp.Diagnostics.AddAttributeError( path.Root("days_of_week"), @@ -127,7 +127,7 @@ func (v recurringScheduleValidator) ValidateObject(ctx context.Context, req vali ) } - case "DaysPerMonth": + case "Monthly": if schedule.MonthlyScheduleType.IsNull() { resp.Diagnostics.AddAttributeError( path.Root("monthly_schedule_type"), @@ -195,7 +195,7 @@ func (v recurringScheduleValidator) ValidateObject(ctx context.Context, req vali resp.Diagnostics.AddAttributeError( path.Root("type"), "Invalid Schedule Type", - fmt.Sprintf("type must be one of: OnceDaily, DaysPerWeek, DaysPerMonth, Annually, got: %s", scheduleType), + fmt.Sprintf("type must be one of: Daily, Weekly, Monthly, Annually, got: %s", scheduleType), ) } }