-
Notifications
You must be signed in to change notification settings - Fork 65
/
schema_action_template_parameter.go
81 lines (73 loc) · 3.33 KB
/
schema_action_template_parameter.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
package octopusdeploy
import (
"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func expandActionTemplateParameter(tfTemplate map[string]interface{}) octopusdeploy.ActionTemplateParameter {
actionTemplateParameter := octopusdeploy.NewActionTemplateParameter()
propertyValue := octopusdeploy.NewPropertyValue(tfTemplate["default_value"].(string), false)
actionTemplateParameter.DefaultValue = &propertyValue
actionTemplateParameter.DisplaySettings = flattenDisplaySettings(tfTemplate["display_settings"].(map[string]interface{}))
actionTemplateParameter.HelpText = tfTemplate["help_text"].(string)
actionTemplateParameter.ID = tfTemplate["id"].(string)
actionTemplateParameter.Label = tfTemplate["label"].(string)
actionTemplateParameter.Name = tfTemplate["name"].(string)
return *actionTemplateParameter
}
func expandActionTemplateParameters(actionTemplateParameters []interface{}) []octopusdeploy.ActionTemplateParameter {
if len(actionTemplateParameters) == 0 {
return nil
}
expandedActionTemplateParameters := []octopusdeploy.ActionTemplateParameter{}
for _, actionTemplateParameter := range actionTemplateParameters {
actionTemplateParameterMap := actionTemplateParameter.(map[string]interface{})
expandedActionTemplateParameters = append(expandedActionTemplateParameters, expandActionTemplateParameter(actionTemplateParameterMap))
}
return expandedActionTemplateParameters
}
func flattenActionTemplateParameters(actionTemplateParameters []octopusdeploy.ActionTemplateParameter) []interface{} {
flattenedActionTemplateParameters := make([]interface{}, 0)
for _, actionTemplateParameter := range actionTemplateParameters {
a := make(map[string]interface{})
a["default_value"] = actionTemplateParameter.DefaultValue.Value
a["display_settings"] = actionTemplateParameter.DisplaySettings
a["help_text"] = actionTemplateParameter.HelpText
a["id"] = actionTemplateParameter.ID
a["label"] = actionTemplateParameter.Label
a["name"] = actionTemplateParameter.Name
flattenedActionTemplateParameters = append(flattenedActionTemplateParameters, a)
}
return flattenedActionTemplateParameters
}
func getActionTemplateParameterSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"default_value": {
Description: "A default value for the parameter, if applicable. This can be a hard-coded value or a variable reference.",
Optional: true,
Type: schema.TypeString,
},
"display_settings": {
Description: "The display settings for the parameter.",
Optional: true,
Type: schema.TypeMap,
},
"help_text": {
Description: "The help presented alongside the parameter input.",
Optional: true,
Type: schema.TypeString,
},
"id": getIDSchema(),
"label": {
Description: "The label shown beside the parameter when presented in the deployment process. Example: `Server name`.",
Optional: true,
Type: schema.TypeString,
},
"name": {
Description: "The name of the variable set by the parameter. The name can contain letters, digits, dashes and periods. Example: `ServerName`.",
Required: true,
Type: schema.TypeString,
ValidateDiagFunc: validation.ToDiagFunc(validation.StringIsNotEmpty),
},
}
}