Skip to content

Commit 00c26e7

Browse files
DefCon-007fornfrey
andauthored
Add Grafana k6 schedules to the provider (#2273)
* Add Grafana k6 schedules to the provider * Remove int64 to int32 conversion * Update docs and examples * Update tests and log response on creation failure * Use schema similar to cloud api for schedules * Update internal/resources/k6/resource_schedule.go Co-authored-by: Oleksandr Kotov <[email protected]> * use load_test_id to search for a schedule * Use test id as identifier for schedules * Switch to v4 from v3 for internal/common * Fix failing tests * Fix failing tests * Update internal/resources/k6/resource_schedule.go Co-authored-by: Oleksandr Kotov <[email protected]> * Add default value for deactivated * Update docs * Make frequency optional * Add frequency validation --------- Co-authored-by: Oleksandr Kotov <[email protected]>
1 parent cb7a9f6 commit 00c26e7

File tree

19 files changed

+2120
-1
lines changed

19 files changed

+2120
-1
lines changed

docs/data-sources/k6_schedule.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "grafana_k6_schedule Data Source - terraform-provider-grafana"
4+
subcategory: "k6"
5+
description: |-
6+
Retrieves a k6 schedule.
7+
---
8+
9+
# grafana_k6_schedule (Data Source)
10+
11+
Retrieves a k6 schedule.
12+
13+
## Example Usage
14+
15+
```terraform
16+
resource "grafana_k6_project" "schedule_project" {
17+
name = "Terraform Schedule Test Project"
18+
}
19+
20+
resource "grafana_k6_load_test" "schedule_load_test" {
21+
project_id = grafana_k6_project.schedule_project.id
22+
name = "Terraform Test Load Test for Schedule"
23+
script = <<-EOT
24+
export default function() {
25+
console.log('Hello from k6 schedule test!');
26+
}
27+
EOT
28+
29+
depends_on = [
30+
grafana_k6_project.schedule_project,
31+
]
32+
}
33+
34+
resource "grafana_k6_schedule" "test_schedule" {
35+
load_test_id = grafana_k6_load_test.schedule_load_test.id
36+
starts = "2024-12-25T10:00:00Z"
37+
recurrence_rule {
38+
frequency = "MONTHLY"
39+
interval = 12
40+
count = 100
41+
}
42+
43+
depends_on = [
44+
grafana_k6_load_test.schedule_load_test,
45+
]
46+
}
47+
48+
data "grafana_k6_schedule" "from_load_test" {
49+
load_test_id = grafana_k6_load_test.schedule_load_test.id
50+
51+
depends_on = [
52+
grafana_k6_schedule.test_schedule,
53+
]
54+
}
55+
56+
output "complete_schedule_info" {
57+
description = "Complete schedule information"
58+
value = {
59+
id = data.grafana_k6_schedule.from_load_test.id
60+
load_test_id = data.grafana_k6_schedule.from_load_test.load_test_id
61+
starts = data.grafana_k6_schedule.from_load_test.starts
62+
deactivated = data.grafana_k6_schedule.from_load_test.deactivated
63+
next_run = data.grafana_k6_schedule.from_load_test.next_run
64+
created_by = data.grafana_k6_schedule.from_load_test.created_by
65+
recurrence_rule = data.grafana_k6_schedule.from_load_test.recurrence_rule
66+
}
67+
}
68+
```
69+
70+
<!-- schema generated by tfplugindocs -->
71+
## Schema
72+
73+
### Required
74+
75+
- `load_test_id` (String) The identifier of the load test to retrieve the schedule for.
76+
77+
### Read-Only
78+
79+
- `created_by` (String) The email of the user who created the schedule.
80+
- `deactivated` (Boolean) Whether the schedule is deactivated.
81+
- `id` (String) Numeric identifier of the schedule.
82+
- `next_run` (String) The next scheduled execution time.
83+
- `recurrence_rule` (Block, Read-only) The schedule recurrence settings. If null, the test will run only once on the starts date. (see [below for nested schema](#nestedblock--recurrence_rule))
84+
- `starts` (String) The start time for the schedule (RFC3339 format).
85+
86+
<a id="nestedblock--recurrence_rule"></a>
87+
### Nested Schema for `recurrence_rule`
88+
89+
Read-Only:
90+
91+
- `byday` (List of String) The weekdays when the 'WEEKLY' recurrence will be applied (e.g., ['MO', 'WE', 'FR']). Cannot be set for other frequencies.
92+
- `count` (Number) How many times the recurrence will repeat.
93+
- `frequency` (String) The frequency of the schedule (HOURLY, DAILY, WEEKLY, MONTHLY).
94+
- `interval` (Number) The interval between each frequency iteration (e.g., 2 = every 2 hours for HOURLY).
95+
- `until` (String) The end time for the recurrence (RFC3339 format).

docs/data-sources/k6_schedules.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "grafana_k6_schedules Data Source - terraform-provider-grafana"
4+
subcategory: "k6"
5+
description: |-
6+
Retrieves all k6 schedules.
7+
---
8+
9+
# grafana_k6_schedules (Data Source)
10+
11+
Retrieves all k6 schedules.
12+
13+
## Example Usage
14+
15+
```terraform
16+
resource "grafana_k6_project" "schedules_project" {
17+
name = "Terraform Schedules Test Project"
18+
}
19+
20+
resource "grafana_k6_load_test" "schedules_load_test" {
21+
project_id = grafana_k6_project.schedules_project.id
22+
name = "Terraform Test Load Test for Schedules"
23+
script = <<-EOT
24+
export default function() {
25+
console.log('Hello from k6 schedules test!');
26+
}
27+
EOT
28+
29+
depends_on = [
30+
grafana_k6_project.schedules_project,
31+
]
32+
}
33+
34+
resource "grafana_k6_load_test" "schedules_load_test_2" {
35+
project_id = grafana_k6_project.schedules_project.id
36+
name = "Terraform Test Load Test for Schedules (2)"
37+
script = <<-EOT
38+
export default function() {
39+
console.log('Hello from k6 schedules test!');
40+
}
41+
EOT
42+
43+
depends_on = [
44+
grafana_k6_project.schedules_project,
45+
]
46+
}
47+
48+
49+
resource "grafana_k6_schedule" "test_schedule_1" {
50+
load_test_id = grafana_k6_load_test.schedules_load_test.id
51+
starts = "2029-12-25T10:00:00Z"
52+
recurrence_rule {
53+
frequency = "MONTHLY"
54+
interval = 15
55+
count = 100
56+
}
57+
58+
depends_on = [
59+
grafana_k6_load_test.schedules_load_test,
60+
]
61+
}
62+
63+
resource "grafana_k6_schedule" "test_schedule_2" {
64+
load_test_id = grafana_k6_load_test.schedules_load_test_2.id
65+
starts = "2023-12-26T14:00:00Z"
66+
recurrence_rule {
67+
frequency = "WEEKLY"
68+
interval = 2
69+
until = "2047-01-31T23:59:59Z"
70+
}
71+
72+
depends_on = [
73+
grafana_k6_load_test.schedules_load_test_2,
74+
]
75+
}
76+
77+
data "grafana_k6_schedules" "from_load_test_id" {
78+
79+
depends_on = [
80+
grafana_k6_schedule.test_schedule_1,
81+
grafana_k6_schedule.test_schedule_2,
82+
]
83+
}
84+
```
85+
86+
<!-- schema generated by tfplugindocs -->
87+
## Schema
88+
89+
### Read-Only
90+
91+
- `id` (String) The identifier for this data source.
92+
- `schedules` (List of Object) List of k6 schedules. (see [below for nested schema](#nestedatt--schedules))
93+
94+
<a id="nestedatt--schedules"></a>
95+
### Nested Schema for `schedules`
96+
97+
Read-Only:
98+
99+
- `created_by` (String)
100+
- `deactivated` (Boolean)
101+
- `id` (String)
102+
- `load_test_id` (String)
103+
- `next_run` (String)
104+
- `recurrence_rule` (Object) (see [below for nested schema](#nestedobjatt--schedules--recurrence_rule))
105+
- `starts` (String)
106+
107+
<a id="nestedobjatt--schedules--recurrence_rule"></a>
108+
### Nested Schema for `schedules.recurrence_rule`
109+
110+
Read-Only:
111+
112+
- `byday` (List of String)
113+
- `count` (Number)
114+
- `frequency` (String)
115+
- `interval` (Number)
116+
- `until` (String)

docs/resources/k6_schedule.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "grafana_k6_schedule Resource - terraform-provider-grafana"
4+
subcategory: "k6"
5+
description: |-
6+
Manages a k6 schedule for automated test execution.
7+
---
8+
9+
# grafana_k6_schedule (Resource)
10+
11+
Manages a k6 schedule for automated test execution.
12+
13+
## Example Usage
14+
15+
```terraform
16+
resource "grafana_k6_project" "schedule_project" {
17+
name = "Terraform Schedule Resource Project"
18+
}
19+
20+
resource "grafana_k6_load_test" "scheduled_test" {
21+
project_id = grafana_k6_project.schedule_project.id
22+
name = "Terraform Scheduled Resource Test"
23+
script = <<-EOT
24+
export default function() {
25+
console.log('Hello from scheduled k6 test!');
26+
}
27+
EOT
28+
29+
depends_on = [
30+
grafana_k6_project.schedule_project,
31+
]
32+
}
33+
34+
resource "grafana_k6_schedule" "daily" {
35+
load_test_id = grafana_k6_load_test.scheduled_test.id
36+
starts = "2024-12-25T10:00:00Z"
37+
recurrence_rule {
38+
frequency = "DAILY"
39+
interval = 1
40+
}
41+
}
42+
43+
resource "grafana_k6_schedule" "weekly" {
44+
load_test_id = grafana_k6_load_test.scheduled_test.id
45+
starts = "2024-12-25T09:00:00Z"
46+
recurrence_rule {
47+
frequency = "WEEKLY"
48+
interval = 1
49+
byday = ["MO", "WE", "FR"]
50+
}
51+
}
52+
53+
# Example with YEARLY frequency and count
54+
resource "grafana_k6_schedule" "yearly" {
55+
load_test_id = grafana_k6_load_test.scheduled_test.id
56+
starts = "2024-01-01T12:00:00Z"
57+
recurrence_rule {
58+
frequency = "YEARLY" # Valid enum value
59+
interval = 1
60+
count = 5 # Run 5 times total
61+
}
62+
}
63+
64+
# One-time schedule without recurrence
65+
resource "grafana_k6_schedule" "one_time" {
66+
load_test_id = grafana_k6_load_test.scheduled_test.id
67+
starts = "2024-12-25T15:00:00Z"
68+
# No recurrence_rule means it runs only once
69+
}
70+
```
71+
72+
<!-- schema generated by tfplugindocs -->
73+
## Schema
74+
75+
### Required
76+
77+
- `load_test_id` (String) The identifier of the load test to schedule.
78+
- `starts` (String) The start time for the schedule (RFC3339 format).
79+
80+
### Optional
81+
82+
- `recurrence_rule` (Block, Optional) The schedule recurrence settings. If not specified, the test will run only once on the 'starts' date. (see [below for nested schema](#nestedblock--recurrence_rule))
83+
84+
### Read-Only
85+
86+
- `created_by` (String) The email of the user who created the schedule.
87+
- `deactivated` (Boolean) Whether the schedule is deactivated.
88+
- `id` (String) Numeric identifier of the schedule.
89+
- `next_run` (String) The next scheduled execution time.
90+
91+
<a id="nestedblock--recurrence_rule"></a>
92+
### Nested Schema for `recurrence_rule`
93+
94+
Optional:
95+
96+
- `byday` (List of String) The weekdays when the 'WEEKLY' recurrence will be applied (e.g., ['MO', 'WE', 'FR']). Cannot be set for other frequencies.
97+
- `count` (Number) How many times the recurrence will repeat.
98+
- `frequency` (String) The frequency of the schedule (HOURLY, DAILY, WEEKLY, MONTHLY, YEARLY).
99+
- `interval` (Number) The interval between each frequency iteration (e.g., 2 = every 2 hours for HOURLY). Defaults to 1.
100+
- `until` (String) The end time for the recurrence (RFC3339 format).
101+
102+
## Import
103+
104+
Import is supported using the following syntax:
105+
106+
```shell
107+
terraform import grafana_k6_schedule.name "{{ load_test_id }}"
108+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
resource "grafana_k6_project" "schedule_project" {
2+
name = "Terraform Schedule Test Project"
3+
}
4+
5+
resource "grafana_k6_load_test" "schedule_load_test" {
6+
project_id = grafana_k6_project.schedule_project.id
7+
name = "Terraform Test Load Test for Schedule"
8+
script = <<-EOT
9+
export default function() {
10+
console.log('Hello from k6 schedule test!');
11+
}
12+
EOT
13+
14+
depends_on = [
15+
grafana_k6_project.schedule_project,
16+
]
17+
}
18+
19+
resource "grafana_k6_schedule" "test_schedule" {
20+
load_test_id = grafana_k6_load_test.schedule_load_test.id
21+
starts = "2024-12-25T10:00:00Z"
22+
recurrence_rule {
23+
frequency = "MONTHLY"
24+
interval = 12
25+
count = 100
26+
}
27+
28+
depends_on = [
29+
grafana_k6_load_test.schedule_load_test,
30+
]
31+
}
32+
33+
data "grafana_k6_schedule" "from_load_test" {
34+
load_test_id = grafana_k6_load_test.schedule_load_test.id
35+
36+
depends_on = [
37+
grafana_k6_schedule.test_schedule,
38+
]
39+
}
40+
41+
output "complete_schedule_info" {
42+
description = "Complete schedule information"
43+
value = {
44+
id = data.grafana_k6_schedule.from_load_test.id
45+
load_test_id = data.grafana_k6_schedule.from_load_test.load_test_id
46+
starts = data.grafana_k6_schedule.from_load_test.starts
47+
deactivated = data.grafana_k6_schedule.from_load_test.deactivated
48+
next_run = data.grafana_k6_schedule.from_load_test.next_run
49+
created_by = data.grafana_k6_schedule.from_load_test.created_by
50+
recurrence_rule = data.grafana_k6_schedule.from_load_test.recurrence_rule
51+
}
52+
}

0 commit comments

Comments
 (0)