@@ -23,6 +23,7 @@ import (
2323 "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/opt"
2424 "github.com/dynatrace-oss/terraform-provider-dynatrace/terraform/hcl"
2525 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
26+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
2627)
2728
2829const SchemaVersion = 3
@@ -31,13 +32,20 @@ type Workflow struct {
3132 Title string `json:"title" maxlength:"200"` // The title / name of the workflow
3233 Description string `json:"description,omitempty"` // An optional description for the workflow
3334
34- Actor string `json:"actor,omitempty" maxlength:"36" format:"uuid"` // The user context the executions of the workflow will happen with
35- Owner string `json:"owner,omitempty" format:"uuid"` // The ID of the owner of this workflow
36- Private * bool `json:"isPrivate" default:"true"` // Defines whether this workflow is private to the owner or not. Default is `true`
37- SchemaVersion int `json:"schemaVersion,omitempty"` //
38- Trigger * Trigger `json:"trigger,omitempty"` // Configures how executions of the workflows are getting triggered. If no trigger is specified it means the workflow is getting manually triggered
39- Tasks Tasks `json:"tasks,omitempty"` // The tasks to run for every execution of this workflow
40- Type string `json:"type"`
35+ Actor string `json:"actor,omitempty" maxlength:"36" format:"uuid"` // The user context the executions of the workflow will happen with
36+ Owner string `json:"owner,omitempty" format:"uuid"` // The ID of the owner of this workflow
37+ OwnerType string `json:"ownerType,omitempty"` // The type of the owner. Possible values: `USER` and `GROUP`
38+ Private * bool `json:"isPrivate" default:"true"` // Defines whether this workflow is private to the owner or not. Default is `true`
39+ IsDeployed * bool `json:"isDeployed" default:"true"` // Defines whether this workflow is deployed or kept as a draft. Default is `true`
40+ SchemaVersion int `json:"schemaVersion,omitempty"` //
41+ Trigger * Trigger `json:"trigger,omitempty"` // Configures how executions of the workflows are getting triggered. If no trigger is specified it means the workflow is getting manually triggered
42+ Tasks Tasks `json:"tasks,omitempty"` // The tasks to run for every execution of this workflow
43+ Type string `json:"type"`
44+ HourlyExecutionLimit * int `json:"hourlyExecutionLimit,omitempty"` // Maximum number of executions per hour, default is 1000
45+ Input map [string ]any `json:"input,omitempty"` // Workflow-level input parameters
46+ TaskDefaults map [string ]any `json:"taskDefaults,omitempty"` // Default settings applied to all tasks
47+ Guide string `json:"guide,omitempty"` // Informational guide text for the workflow
48+ Result string `json:"result,omitempty"` // The result of the workflow
4149}
4250
4351func (me * Workflow ) Name () string {
@@ -72,12 +80,25 @@ func (me *Workflow) Schema() map[string]*schema.Schema {
7280 DiffSuppressFunc : func (k , old , new string , d * schema.ResourceData ) bool { return new == "" },
7381 ValidateDiagFunc : ValidateUUID ,
7482 },
83+ "owner_type" : {
84+ Type : schema .TypeString ,
85+ Description : "The type of the owner. Possible values are `USER` and `GROUP`" ,
86+ Optional : true ,
87+ DiffSuppressFunc : func (k , old , new string , d * schema.ResourceData ) bool { return new == "" },
88+ ValidateFunc : validation .StringInSlice ([]string {"USER" , "GROUP" }, false ),
89+ },
7590 "private" : {
7691 Type : schema .TypeBool ,
7792 Description : "Defines whether this workflow is private to the owner or not. Default is `true`" ,
7893 Optional : true ,
7994 Default : true ,
8095 },
96+ "is_deployed" : {
97+ Type : schema .TypeBool ,
98+ Description : "Defines whether this workflow is deployed and active, or kept as a draft. An undeployed workflow is not billed and its automatic trigger will not be running. Default is `true`" ,
99+ Optional : true ,
100+ Default : true ,
101+ },
81102 "trigger" : {
82103 Type : schema .TypeList ,
83104 Description : "Configures how executions of the workflows are getting triggered. If no trigger is specified it means the workflow is getting manually triggered" ,
@@ -100,13 +121,45 @@ func (me *Workflow) Schema() map[string]*schema.Schema {
100121 Optional : true ,
101122 Default : "STANDARD" ,
102123 },
124+ "hourly_execution_limit" : {
125+ Type : schema .TypeInt ,
126+ Description : "Maximum number of executions per hour. Default is `1000`" ,
127+ Optional : true ,
128+ Default : 1000 ,
129+ },
130+ "input" : {
131+ Type : schema .TypeString ,
132+ Description : "Workflow-level input parameters as JSON. These parameters are available to all tasks in the workflow" ,
133+ Optional : true ,
134+ DiffSuppressFunc : hcl .SuppressJSONorEOT ,
135+ },
136+ "task_defaults" : {
137+ Type : schema .TypeString ,
138+ Description : "Default task settings as JSON. These defaults are applied to all tasks in the workflow" ,
139+ Optional : true ,
140+ DiffSuppressFunc : hcl .SuppressJSONorEOT ,
141+ },
142+ "guide" : {
143+ Type : schema .TypeString ,
144+ Description : "Informational guide text for the workflow" ,
145+ Optional : true ,
146+ ValidateDiagFunc : ValidateMaxLength (10000 ),
147+ },
148+ "result" : {
149+ Type : schema .TypeString ,
150+ Description : "The result of the workflow" ,
151+ Optional : true ,
152+ },
103153 }
104154}
105155
106156func (me * Workflow ) MarshalHCL (properties hcl.Properties ) error {
107157 if me .Private == nil {
108158 me .Private = opt .NewBool (true )
109159 }
160+ if me .IsDeployed == nil {
161+ me .IsDeployed = opt .NewBool (true )
162+ }
110163 if len (me .Tasks ) > 0 {
111164 fixedTasks := Tasks {}
112165 for _ , task := range me .Tasks {
@@ -117,34 +170,79 @@ func (me *Workflow) MarshalHCL(properties hcl.Properties) error {
117170 }
118171 me .Tasks = fixedTasks
119172 }
173+ var inputJSON * string
174+ if len (me .Input ) > 0 {
175+ data , err := json .Marshal (me .Input )
176+ if err != nil {
177+ return err
178+ }
179+ s := string (data )
180+ inputJSON = & s
181+ }
182+ var taskDefaultsJSON * string
183+ if len (me .TaskDefaults ) > 0 {
184+ data , err := json .Marshal (me .TaskDefaults )
185+ if err != nil {
186+ return err
187+ }
188+ s := string (data )
189+ taskDefaultsJSON = & s
190+ }
120191 return properties .EncodeAll (map [string ]any {
121192 "title" : me .Title ,
122193 "description" : me .Description ,
123194
124- "actor" : me .Actor ,
125- "owner" : me .Owner ,
126- "private" : me .Private ,
127- "trigger" : me .Trigger ,
128- "tasks" : me .Tasks ,
129- "type" : me .Type ,
195+ "actor" : me .Actor ,
196+ "owner" : me .Owner ,
197+ "owner_type" : me .OwnerType ,
198+ "private" : me .Private ,
199+ "is_deployed" : me .IsDeployed ,
200+ "trigger" : me .Trigger ,
201+ "tasks" : me .Tasks ,
202+ "type" : me .Type ,
203+ "hourly_execution_limit" : me .HourlyExecutionLimit ,
204+ "input" : inputJSON ,
205+ "task_defaults" : taskDefaultsJSON ,
206+ "guide" : me .Guide ,
207+ "result" : me .Result ,
130208 })
131209}
132210
133211func (me * Workflow ) UnmarshalHCL (decoder hcl.Decoder ) error {
212+ var inputStr string
213+ var taskDefaultsStr string
134214 if err := decoder .DecodeAll (map [string ]any {
135215 "title" : & me .Title ,
136216 "description" : & me .Description ,
137217
138- "actor" : & me .Actor ,
139- "owner" : & me .Owner ,
218+ "actor" : & me .Actor ,
219+ "owner" : & me .Owner ,
220+ "owner_type" : & me .OwnerType ,
140221 // "private": &me.Private,
141- "trigger" : & me .Trigger ,
142- "tasks" : & me .Tasks ,
143- "type" : & me .Type ,
222+ // "is_deployed": &me.IsDeployed,
223+ "trigger" : & me .Trigger ,
224+ "tasks" : & me .Tasks ,
225+ "type" : & me .Type ,
226+ "hourly_execution_limit" : & me .HourlyExecutionLimit ,
227+ "input" : & inputStr ,
228+ "task_defaults" : & taskDefaultsStr ,
229+ "guide" : & me .Guide ,
230+ "result" : & me .Result ,
144231 }); err != nil {
145232 return err
146233 }
147234
235+ if len (inputStr ) > 0 {
236+ if err := json .Unmarshal ([]byte (inputStr ), & me .Input ); err != nil {
237+ return err
238+ }
239+ }
240+ if len (taskDefaultsStr ) > 0 {
241+ if err := json .Unmarshal ([]byte (taskDefaultsStr ), & me .TaskDefaults ); err != nil {
242+ return err
243+ }
244+ }
245+
148246 if len (me .Tasks ) > 0 {
149247 fixedTasks := Tasks {}
150248 for _ , task := range me .Tasks {
@@ -167,34 +265,59 @@ func (me *Workflow) UnmarshalHCL(decoder hcl.Decoder) error {
167265 } else {
168266 me .Private = opt .NewBool (isPrivate .(bool ))
169267 }
268+
269+ // Same pattern as `private` — `isDeployed` defaults to `true`
270+ isDeployed , isDeployedExists := decoder .GetOkExists ("is_deployed" )
271+ if ! isDeployedExists {
272+ me .IsDeployed = opt .NewBool (true )
273+ } else {
274+ me .IsDeployed = opt .NewBool (isDeployed .(bool ))
275+ }
170276 return nil
171277}
172278
173279func (me * Workflow ) MarshalJSON () ([]byte , error ) {
174280 if me .Private == nil {
175281 me .Private = opt .NewBool (true )
176282 }
283+ if me .IsDeployed == nil {
284+ me .IsDeployed = opt .NewBool (true )
285+ }
177286 wf := struct {
178287 Title string `json:"title"`
179288 Description string `json:"description,omitempty"`
180289
181- Actor string `json:"actor,omitempty"`
182- Owner string `json:"owner,omitempty"`
183- Private * bool `json:"isPrivate"`
184- SchemaVersion int `json:"schemaVersion,omitempty"`
185- Trigger * Trigger `json:"trigger,omitempty"`
186- Tasks Tasks `json:"tasks,omitempty"`
187- Type string `json:"type,omitempty"`
290+ Actor string `json:"actor,omitempty"`
291+ Owner string `json:"owner,omitempty"`
292+ OwnerType string `json:"ownerType,omitempty"`
293+ Private * bool `json:"isPrivate"`
294+ IsDeployed * bool `json:"isDeployed"`
295+ SchemaVersion int `json:"schemaVersion,omitempty"`
296+ Trigger * Trigger `json:"trigger,omitempty"`
297+ Tasks Tasks `json:"tasks,omitempty"`
298+ Type string `json:"type,omitempty"`
299+ HourlyExecutionLimit * int `json:"hourlyExecutionLimit,omitempty"`
300+ Input map [string ]any `json:"input,omitempty"`
301+ TaskDefaults map [string ]any `json:"taskDefaults,omitempty"`
302+ Guide string `json:"guide,omitempty"`
303+ Result string `json:"result,omitempty"`
188304 }{
189- SchemaVersion : SchemaVersion , // adding the Schema Version is the purpose of this custome `MarshalJSON` function
190- Title : me .Title ,
191- Description : me .Description ,
192- Actor : me .Actor ,
193- Owner : me .Owner ,
194- Private : me .Private ,
195- Trigger : me .Trigger ,
196- Tasks : me .Tasks ,
197- Type : me .Type ,
305+ SchemaVersion : SchemaVersion , // adding the Schema Version is the purpose of this custome `MarshalJSON` function
306+ Title : me .Title ,
307+ Description : me .Description ,
308+ Actor : me .Actor ,
309+ Owner : me .Owner ,
310+ OwnerType : me .OwnerType ,
311+ Private : me .Private ,
312+ IsDeployed : me .IsDeployed ,
313+ Trigger : me .Trigger ,
314+ Tasks : me .Tasks ,
315+ Type : me .Type ,
316+ HourlyExecutionLimit : me .HourlyExecutionLimit ,
317+ Input : me .Input ,
318+ TaskDefaults : me .TaskDefaults ,
319+ Guide : me .Guide ,
320+ Result : me .Result ,
198321 }
199322 return json .Marshal (wf )
200323}
0 commit comments