Skip to content

Commit

Permalink
Update validation and schema to new recurring_schedule model
Browse files Browse the repository at this point in the history
  • Loading branch information
HuyPhanNguyen committed Dec 17, 2024
1 parent b71b2af commit d3d42eb
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/resources/deployment_freeze.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions octopusdeploy_framework/resource_deployment_freeze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions octopusdeploy_framework/schemas/deployment_freeze.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
10 changes: 5 additions & 5 deletions octopusdeploy_framework/schemas/deployment_freeze_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down Expand Up @@ -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),
)
}
}

0 comments on commit d3d42eb

Please sign in to comment.