File tree 3 files changed +18
-0
lines changed
3 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ require (
46
46
github.com/mitchellh/reflectwalk v1.0.2 // indirect
47
47
github.com/oklog/run v1.0.0 // indirect
48
48
github.com/pmezard/go-difflib v1.0.0 // indirect
49
+ github.com/robfig/cron/v3 v3.0.1 // indirect
49
50
github.com/rogpeppe/go-internal v1.8.0 // indirect
50
51
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
51
52
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
Original file line number Diff line number Diff line change @@ -143,6 +143,8 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
143
143
github.com/pkg/errors v0.9.1 /go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0 =
144
144
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM =
145
145
github.com/pmezard/go-difflib v1.0.0 /go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4 =
146
+ github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs =
147
+ github.com/robfig/cron/v3 v3.0.1 /go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro =
146
148
github.com/rogpeppe/go-internal v1.6.1 /go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc =
147
149
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8 =
148
150
github.com/rogpeppe/go-internal v1.8.0 /go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE =
Original file line number Diff line number Diff line change @@ -2,13 +2,17 @@ package provider
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
5
6
6
7
"github.com/google/uuid"
7
8
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
8
9
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9
10
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
11
+ "github.com/robfig/cron/v3"
10
12
)
11
13
14
+ var ScriptCRONParser = cron .NewParser (cron .Second | cron .Minute | cron .Hour | cron .Dom | cron .Month | cron .DowOptional | cron .Descriptor )
15
+
12
16
func scriptResource () * schema.Resource {
13
17
return & schema.Resource {
14
18
Description : "Use this resource to run a script from an agent." ,
@@ -56,6 +60,17 @@ func scriptResource() *schema.Resource {
56
60
Type : schema .TypeString ,
57
61
Optional : true ,
58
62
Description : "The cron schedule to run the script on. This is a cron expression." ,
63
+ ValidateFunc : func (i interface {}, s string ) ([]string , []error ) {
64
+ v , ok := i .(string )
65
+ if ! ok {
66
+ return []string {}, []error {fmt .Errorf ("got type %T instead of string" , i )}
67
+ }
68
+ _ , err := ScriptCRONParser .Parse (v )
69
+ if err != nil {
70
+ return []string {}, []error {fmt .Errorf ("%s is not a valid cron expression: %w" , v , err )}
71
+ }
72
+ return nil , nil
73
+ },
59
74
},
60
75
"start_blocks_login" : {
61
76
Type : schema .TypeBool ,
You can’t perform that action at this time.
0 commit comments