Skip to content

Commit

Permalink
feat: [CCM-14715] Support for fixed schedule in Harness AutoStopping (#…
Browse files Browse the repository at this point in the history
…714)

* Resource structure added for static schedule resource of AutoStopping

* Added provision for specifying AutoStopping rule ID in schedules of AutoStopping rules

* Parsing logic for AutoStopping static schedule

* Introduced read context for schedule

* Wired read context for read of static schedule of AutoStopping

* Wired create context for static schedules of AutoStopping rules

* Wired delete context for fixed schedules of AutoStopping rules

* Update context wired for fixed schedules of AutoStopping rules

* Added resource data file for fixed schedule of AutoStopping:

* Wired resource provider and data source for schedule of Harness AutoStopping rule

* Corrections on computed attribute in schedules of AutoStopping

* Corrections - Schedules of AutoStopping

* First tested version of schedule of AutoStopping rules

* Final working version of Fixed schedule of AutoStopping rule

* Test file for resource of fixed schedule of AutoStopping feature

* made period end time to be optional in fixed schedule of AutoStopping

* Correction - simplified structure of schedule of AutoStopping rule

* Added example resource file for schedule of AutoStopping

* Partial day downtime example - schedule of AutoStopping

* Periodic schedule example - schedule of AutoStopping

* Example of periodic schedule with starting date - schedule of AutoStopping

* Example of periodic schedule with bounding date - schedule of AutoStopping

* Example of implicit end time - schedule of AutoStopping

* Example of whole day schedule - schedule of AutoStopping

* Example of one time trigger schedule- schedule of AutoStopping

* Example of overnight schedule- schedule of AutoStopping

* Modified example name for clarity

* Data source example file for schedule of AutoStopping rule

* Docs for fixed schedules

* Changelog for fixed schedule support of AutoStopping

* GoSDK version upgraded to latest release of 0.3.56

Source : https://harness.slack.com/archives/C0413DEHL1M/p1698216446558869?thread_ts=1698215288.389389&cid=C0413DEHL1M

* Subcategory correction

* Upgraded go sdk version to latest of v0.3.57

source https://harness.slack.com/archives/C0413DEHL1M/p1698222960525819

* Extracted value of time.DateTime to variable as the value is not supported in old Go version. This was causing build failure in pipeline
  • Loading branch information
shalinlk committed Oct 25, 2023
1 parent 78cb911 commit ad152c0
Show file tree
Hide file tree
Showing 11 changed files with 1,044 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/714.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
Fixed schedule support for AutoStopping
```
40 changes: 40 additions & 0 deletions docs/data-sources/autostopping_schedule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "harness_autostopping_schedule Data Source - terraform-provider-harness"
subcategory: "Next Gen"
description: |-
Data source for retrieving a fixed schedule for Harness AutoStopping rule
---

# harness_autostopping_schedule (Data Source)

Data source for retrieving a fixed schedule for Harness AutoStopping rule



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `schedule_type` (String) Type of the schedule. Valid values are `uptime` and `downtime`

### Read-Only

- `ending_on` (String) Time until which schedule will be active. Need to be in YYYY-MM-DD HH:mm:SS format. Eg 2006-01-02 15:04:05
- `id` (String) The ID of this resource.
- `identifier` (Number) Unique identifier of the schedule
- `name` (String) Name of the schedule
- `repeats` (List of Object) For defining periodic schedule. Periodic nature will be applicable from the time of creation of schedule, unless specific 'time_period' is specified (see [below for nested schema](#nestedatt--repeats))
- `rules` (List of Number) ID of AutoStopping rules on which the schedule applies
- `starting_from` (String) Time from which schedule will be active. Schedule will take immediate effect if starting_from is not specified. Need to be in YYYY-MM-DD HH:mm:SS format. Eg 2006-01-02 15:04:05
- `time_zone` (String) Time zone in which schedule needs to be executed

<a id="nestedatt--repeats"></a>
### Nested Schema for `repeats`

Read-Only:

- `days` (String)
- `end_time` (String)
- `start_time` (String)
169 changes: 169 additions & 0 deletions docs/resources/autostopping_schedule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "harness_autostopping_schedule Resource - terraform-provider-harness"
subcategory: "Next Gen"
description: |-
Resource for creating a fixed schedule for Harness AutoStopping rule
---

# harness_autostopping_schedule (Resource)

Resource for creating a fixed schedule for Harness AutoStopping rule

## Example Usage

```terraform
resource "harness_autostopping_schedule" "MondayWholeDayUp" {
name = "MondayWholeDayUp"
schedule_type = "uptime"
time_zone = "UTC"
repeats {
days = "MON"
}
rules = [123]
}
resource "harness_autostopping_schedule" "MondayUpTill4:30pm" {
name = "MondayUpTill4:30pm"
schedule_type = "uptime"
time_zone = "UTC"
repeats {
days = "MON"
end_time = "16:30"
}
rules = [123]
}
resource "harness_autostopping_schedule" "MondayThroughFridayUptimeFrom9amTo6pm" {
name = "MondayThroughFridayUptimeFrom9amTo6pm"
schedule_type = "uptime"
time_zone = "UTC"
repeats {
days = "MON, TUE, WED, THU, FRI"
start_time = "09:00"
end_time = "18:00"
}
rules = [123]
}
resource "harness_autostopping_schedule" "MondayThroughFridayUptimeFrom9amTo6pmStartingFromDate" {
name = "MondayThroughFridayUptimeFrom9amTo6pmStartingFrom"
schedule_type = "uptime"
time_zone = "UTC"
starting_from = "2023-01-02 15:04:05"
repeats {
days = "MON, TUE, WED, THU, FRI"
start_time = "09:00"
end_time = "18:00"
}
rules = [123]
}
resource "harness_autostopping_schedule" "DownTimeForISTLuchOnEveryFridayInBetweenDate" {
name = "DownTimeForISTLuchOnEveryFridayInBetweenDate"
schedule_type = "downtime"
time_zone = "Asia/Calcutta"
starting_from = "2023-01-02 15:04:05"
ending_on = "2023-02-02 15:04:05"
repeats {
days = "FRI"
start_time = "12:30"
end_time = "14:30"
}
rules = [123]
}
resource "harness_autostopping_schedule" "DowntimeEveryFridayAfterNoonTillEOD" {
name = "DowntimeEveryFridayAfterNoonTillEOD"
schedule_type = "downtime"
time_zone = "Asia/Calcutta"
repeats {
days = "FRI"
start_time = "17:30"
}
rules = [123]
}
resource "harness_autostopping_schedule" "CompleteDownTimeOnWeekEnd" {
name = "CompleteDownTimeOnWeekEnd"
schedule_type = "downtime"
time_zone = "UTC"
repeats {
days = "SUN, SAT"
}
rules = [123]
}
resource "harness_autostopping_schedule" "TriggerDowntimeOnceOnDate" {
name = "TriggerDowntimeOnceOnDate"
schedule_type = "downtime"
time_zone = "UTC"
starting_from = "2023-01-02 15:04:05"
rules = [123]
}
resource "harness_autostopping_schedule" "OverNightDowntimeOnWeekDays" {
name = "OverNightDowntimeOnWeekDays"
schedule_type = "downtime"
time_zone = "Asia/Calcutta"
repeats {
days = "MON, TUE, WED, THU, FRI"
start_time = "18:00"
end_time = "07:00"
}
rules = [123]
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) Name of the schedule
- `rules` (List of Number) ID of AutoStopping rules on which the schedule applies
- `schedule_type` (String) Type of the schedule. Valid values are `uptime` and `downtime`
- `time_zone` (String) Time zone in which schedule needs to be executed

### Optional

- `ending_on` (String) Time until which schedule will be active. Need to be in YYYY-MM-DD HH:mm:SS format. Eg 2006-01-02 15:04:05
- `repeats` (Block List) For defining periodic schedule. Periodic nature will be applicable from the time of creation of schedule, unless specific 'time_period' is specified (see [below for nested schema](#nestedblock--repeats))
- `starting_from` (String) Time from which schedule will be active. Schedule will take immediate effect if starting_from is not specified. Need to be in YYYY-MM-DD HH:mm:SS format. Eg 2006-01-02 15:04:05

### Read-Only

- `id` (String) The ID of this resource.
- `identifier` (Number) Unique identifier of the schedule

<a id="nestedblock--repeats"></a>
### Nested Schema for `repeats`

Required:

- `days` (String) Days on which schedule need to be active. Comma separated values of `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI` and `SAT`. Eg : `MON,TUE,WED,THU,FRI` for Mon through Friday

Optional:

- `end_time` (String) Ending time of schedule action on the day. Defaults to 24:00Hrs unless specified. Accepted format is HH:MM. Eg : 20:00 for 8pm
- `start_time` (String) Starting time of schedule action on the day. Defaults to 00:00Hrs unless specified. Accepted format is HH:MM. Eg : 13:15 for 01:15pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "harness_autostopping_schedule" "example" {
identifier = "identifier"
}
120 changes: 120 additions & 0 deletions examples/resources/harness_autostopping_schedule/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
resource "harness_autostopping_schedule" "MondayWholeDayUp" {
name = "MondayWholeDayUp"
schedule_type = "uptime"
time_zone = "UTC"

repeats {
days = "MON"
}

rules = [123]
}

resource "harness_autostopping_schedule" "MondayUpTill4:30pm" {
name = "MondayUpTill4:30pm"
schedule_type = "uptime"
time_zone = "UTC"

repeats {
days = "MON"
end_time = "16:30"
}

rules = [123]
}

resource "harness_autostopping_schedule" "MondayThroughFridayUptimeFrom9amTo6pm" {
name = "MondayThroughFridayUptimeFrom9amTo6pm"
schedule_type = "uptime"
time_zone = "UTC"

repeats {
days = "MON, TUE, WED, THU, FRI"
start_time = "09:00"
end_time = "18:00"
}

rules = [123]
}

resource "harness_autostopping_schedule" "MondayThroughFridayUptimeFrom9amTo6pmStartingFromDate" {
name = "MondayThroughFridayUptimeFrom9amTo6pmStartingFrom"
schedule_type = "uptime"
time_zone = "UTC"

starting_from = "2023-01-02 15:04:05"

repeats {
days = "MON, TUE, WED, THU, FRI"
start_time = "09:00"
end_time = "18:00"
}

rules = [123]
}

resource "harness_autostopping_schedule" "DownTimeForISTLuchOnEveryFridayInBetweenDate" {
name = "DownTimeForISTLuchOnEveryFridayInBetweenDate"
schedule_type = "downtime"
time_zone = "Asia/Calcutta"

starting_from = "2023-01-02 15:04:05"
ending_on = "2023-02-02 15:04:05"

repeats {
days = "FRI"
start_time = "12:30"
end_time = "14:30"
}

rules = [123]
}

resource "harness_autostopping_schedule" "DowntimeEveryFridayAfterNoonTillEOD" {
name = "DowntimeEveryFridayAfterNoonTillEOD"
schedule_type = "downtime"
time_zone = "Asia/Calcutta"

repeats {
days = "FRI"
start_time = "17:30"
}

rules = [123]
}

resource "harness_autostopping_schedule" "CompleteDownTimeOnWeekEnd" {
name = "CompleteDownTimeOnWeekEnd"
schedule_type = "downtime"
time_zone = "UTC"

repeats {
days = "SUN, SAT"
}

rules = [123]
}

resource "harness_autostopping_schedule" "TriggerDowntimeOnceOnDate" {
name = "TriggerDowntimeOnceOnDate"
schedule_type = "downtime"
time_zone = "UTC"

starting_from = "2023-01-02 15:04:05"

rules = [123]
}

resource "harness_autostopping_schedule" "OverNightDowntimeOnWeekDays" {
name = "OverNightDowntimeOnWeekDays"
schedule_type = "downtime"
time_zone = "Asia/Calcutta"

repeats {
days = "MON, TUE, WED, THU, FRI"
start_time = "18:00"
end_time = "07:00"
}

rules = [123]
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ require (
github.com/antihax/optional v1.0.0
github.com/aws/aws-sdk-go v1.45.12
github.com/docker/docker v24.0.6+incompatible
github.com/harness/harness-go-sdk v0.3.55
github.com/harness/harness-go-sdk v0.3.57
github.com/harness/harness-openapi-go-client v0.0.19
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/go-retryablehttp v0.7.4
github.com/hashicorp/terraform-plugin-sdk/v2 v2.27.0
github.com/pkg/errors v0.9.1
Expand All @@ -33,7 +34,6 @@ require (
github.com/google/go-cmp v0.5.9 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.4.10 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/harness/harness-go-sdk v0.3.55 h1:54vNEpOEVHnK6RCMs0kz86/tNMxDFDNhh5FNtDFQ/5c=
github.com/harness/harness-go-sdk v0.3.55/go.mod h1:CPXydorp4zd5Dz2u2FXiHyWL4yd5PQafOMN69cgPSvk=
github.com/harness/harness-go-sdk v0.3.57 h1:W7cIA8pZ2g/os+YaBYw2goEynUrX060Fmy30FD3LQF0=
github.com/harness/harness-go-sdk v0.3.57/go.mod h1:CPXydorp4zd5Dz2u2FXiHyWL4yd5PQafOMN69cgPSvk=
github.com/harness/harness-openapi-go-client v0.0.19 h1:8XuZvSPZrNqKRLh7Qksdz78WvRMRzRf88LgzxoT5u7k=
github.com/harness/harness-openapi-go-client v0.0.19/go.mod h1:u0vqYb994BJGotmEwJevF4L3BNAdU9i8ui2d22gmLPA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down
3 changes: 3 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
pl_apikey "github.com/harness/terraform-provider-harness/internal/service/platform/api_key"
"github.com/harness/terraform-provider-harness/internal/service/platform/autostopping/load_balancer"
as_rule "github.com/harness/terraform-provider-harness/internal/service/platform/autostopping/rule"
"github.com/harness/terraform-provider-harness/internal/service/platform/autostopping/schedule"
"github.com/harness/terraform-provider-harness/internal/service/platform/ccm_filters"
"github.com/harness/terraform-provider-harness/internal/service/platform/connector"
pl_current_user "github.com/harness/terraform-provider-harness/internal/service/platform/current_user"
Expand Down Expand Up @@ -241,6 +242,7 @@ func Provider(version string) func() *schema.Provider {
"harness_autostopping_gcp_proxy": load_balancer.DataSourceGCPProxy(),
"harness_autostopping_aws_alb": load_balancer.DataSourceAwsALB(),
"harness_autostopping_azure_gateway": load_balancer.DataSourceAzureGateway(),
"harness_autostopping_schedule": schedule.DataSourceFixedSchedule(),
},
ResourcesMap: map[string]*schema.Resource{
"harness_platform_template": pl_template.ResourceTemplate(),
Expand Down Expand Up @@ -367,6 +369,7 @@ func Provider(version string) func() *schema.Provider {
"harness_autostopping_gcp_proxy": load_balancer.ResourceGCPProxy(),
"harness_autostopping_aws_alb": load_balancer.ResourceAwsALB(),
"harness_autostopping_azure_gateway": load_balancer.ResourceAzureGateway(),
"harness_autostopping_schedule": schedule.ResourceVMRule(),
},
}

Expand Down
Loading

0 comments on commit ad152c0

Please sign in to comment.