-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathschema_run_script_action.go
136 lines (110 loc) · 4.53 KB
/
schema_run_script_action.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package octopusdeploy
import (
"strconv"
"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func addScriptFromPackageSchema(element *schema.Resource) {
element.Schema["script_file_name"] = &schema.Schema{
Description: "The script file name in the package",
Optional: true,
Type: schema.TypeString,
}
element.Schema["script_parameters"] = &schema.Schema{
Description: "Parameters expected by the script. Use platform specific calling convention. e.g. -Path #{VariableStoringPath} for PowerShell or -- #{VariableStoringPath} for ScriptCS",
Optional: true,
Type: schema.TypeString,
}
element.Schema["script_source"] = &schema.Schema{
Computed: true,
Optional: true,
Type: schema.TypeString,
}
}
func expandRunScriptAction(flattenedAction map[string]interface{}) octopusdeploy.DeploymentAction {
action := expandAction(flattenedAction)
action.ActionType = "Octopus.Script"
if v, ok := flattenedAction["script_body"]; ok {
if s := v.(string); len(s) > 0 {
action.Properties["Octopus.Action.Script.ScriptBody"] = octopusdeploy.NewPropertyValue(s, false)
}
}
if v, ok := flattenedAction["script_file_name"]; ok {
if s := v.(string); len(s) > 0 {
action.Properties["Octopus.Action.Script.ScriptFileName"] = octopusdeploy.NewPropertyValue(s, false)
}
}
if v, ok := flattenedAction["script_parameters"]; ok {
if s := v.(string); len(s) > 0 {
action.Properties["Octopus.Action.Script.ScriptParameters"] = octopusdeploy.NewPropertyValue(s, false)
}
}
if v, ok := flattenedAction["script_source"]; ok {
if s := v.(string); len(s) > 0 {
action.Properties["Octopus.Action.Script.ScriptSource"] = octopusdeploy.NewPropertyValue(s, false)
}
}
if v, ok := flattenedAction["script_syntax"]; ok {
if s := v.(string); len(s) > 0 {
action.Properties["Octopus.Action.Script.Syntax"] = octopusdeploy.NewPropertyValue(s, false)
}
}
if variableSubstitutionInFiles, ok := flattenedAction["variable_substitution_in_files"]; ok {
action.Properties["Octopus.Action.SubstituteInFiles.TargetFiles"] = octopusdeploy.NewPropertyValue(variableSubstitutionInFiles.(string), false)
action.Properties["Octopus.Action.SubstituteInFiles.Enabled"] = octopusdeploy.NewPropertyValue("True", false)
if len(action.Properties["Octopus.Action.EnabledFeatures"].Value) == 0 {
action.Properties["Octopus.Action.EnabledFeatures"] = octopusdeploy.NewPropertyValue("Octopus.Features.SubstituteInFiles", false)
} else {
actionProperty := action.Properties["Octopus.Action.EnabledFeatures"].Value + ",Octopus.Features.SubstituteInFiles"
action.Properties["Octopus.Action.EnabledFeatures"] = octopusdeploy.NewPropertyValue(actionProperty, false)
}
}
return action
}
func flattenRunScriptAction(action octopusdeploy.DeploymentAction) map[string]interface{} {
flattenedAction := flattenAction(action)
if v, ok := action.Properties["Octopus.Action.RunOnServer"]; ok {
runOnServer, _ := strconv.ParseBool(v.Value)
flattenedAction["run_on_server"] = runOnServer
}
if v, ok := action.Properties["Octopus.Action.Script.ScriptBody"]; ok {
flattenedAction["script_body"] = v.Value
}
if v, ok := action.Properties["Octopus.Action.Script.ScriptFileName"]; ok {
flattenedAction["script_file_name"] = v.Value
}
if v, ok := action.Properties["Octopus.Action.Script.ScriptParameters"]; ok {
flattenedAction["script_parameters"] = v.Value
}
if v, ok := action.Properties["Octopus.Action.Script.ScriptSource"]; ok {
flattenedAction["script_source"] = v.Value
}
if v, ok := action.Properties["Octopus.Action.Script.Syntax"]; ok {
flattenedAction["script_syntax"] = v.Value
}
if v, ok := action.Properties["Octopus.Action.SubstituteInFiles.TargetFiles"]; ok {
flattenedAction["variable_substitution_in_files"] = v.Value
}
return flattenedAction
}
func getRunScriptActionSchema() *schema.Schema {
actionSchema, element := getActionSchema()
addExecutionLocationSchema(element)
addScriptFromPackageSchema(element)
addPackagesSchema(element, false)
element.Schema["script_body"] = &schema.Schema{
Optional: true,
Type: schema.TypeString,
}
element.Schema["script_syntax"] = &schema.Schema{
Computed: true,
Optional: true,
Type: schema.TypeString,
}
element.Schema["variable_substitution_in_files"] = &schema.Schema{
Description: "A newline-separated list of file names to transform, relative to the package contents. Extended wildcard syntax is supported.",
Optional: true,
Type: schema.TypeString,
}
return actionSchema
}