-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec.go
196 lines (181 loc) · 5.97 KB
/
spec.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package task_run
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
tektonapiv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
)
func tektonTaskRunSpecFields() map[string]*schema.Schema {
return map[string]*schema.Schema{
"params": {
Type: schema.TypeList,
Description: "Params is a list of input parameters required to run the task. Params must be supplied as inputs in TaskRunRuns unless they declare a default value.",
Optional: true,
// MaxItems: 1,
Elem: &schema.Resource{
Schema: tektonParamSpecFields(),
},
},
"display_name": {
Type: schema.TypeString,
Description: "DisplayName is a user-facing name of the task that may be used to populate a UI.",
Optional: true,
},
"description": {
Type: schema.TypeString,
Description: "Description is a user-facing description of the task that may be used to populate a UI.",
Optional: true,
},
"steps": {
Type: schema.TypeList,
Description: "Steps are the steps of the build; each step is run sequentially with the source mounted into /workspace.",
Optional: true,
Elem: &schema.Resource{
Schema: tektonStepFields(),
},
},
// "volumes": {
// Type: schema.TypeList,
// Description: "Volumes is a collection of volumes that are available to mount into the steps of the build.",
// Optional: true,
// Elem: &schema.Resource{
// Schema: tektonVolumeFields(),
// },
// },
"step_template": {
Type: schema.TypeList,
Description: "StepTemplate can be used as the basis for all step containers within the TaskRun, so that the steps inherit settings on the base container.",
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: tektonStepTemplateFields(),
},
},
"sidecars": {
Type: schema.TypeList,
Description: "Sidecars are run alongside the TaskRun's step containers. They begin before the steps start and end after the steps complete.",
Optional: true,
Elem: &schema.Resource{
Schema: tektonSidecarFields(),
},
},
"workspaces": {
Type: schema.TypeList,
Description: "Workspaces are the volumes that this TaskRun requires.",
Optional: true,
Elem: &schema.Resource{
Schema: tektonWorkspaceDeclarationFields(),
},
},
// "results": {
// Type: schema.TypeList,
// Description: "Results are values that this TaskRun can output",
// Optional: true,
// Elem: &schema.Resource{
// Schema: tektonTaskRunResultFields(),
// },
// },
}
}
func tektonTaskRunSpecSchema() *schema.Schema {
fields := tektonTaskRunSpecFields()
return &schema.Schema{
Type: schema.TypeList,
Description: fmt.Sprintf("TektonTaskRunSpec describes how the proper TektonTaskRun should look like."),
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: fields,
},
}
}
func tektonParamSpecFields() map[string]*schema.Schema {
return map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Description: "Name declares the name by which a parameter is referenced.",
Required: true,
},
"type": {
Type: schema.TypeString,
Description: "Type is the user-specified type of the parameter. The possible types are currently string, array and object, and string is the default.",
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"string", "array", "object"}, false),
},
"description": {
Type: schema.TypeString,
Description: "Description is a user-facing description of the parameter that may be used to populate a UI.",
Optional: true,
},
"properties": {
Type: schema.TypeMap,
Description: "Properties is the JSON Schema properties to support key-value pairs parameter.",
Optional: true,
Elem: &schema.Resource{
Schema: tektonPropertySpecFields(),
},
},
"default": {
Type: schema.TypeList,
Description: "Default is the value a parameter takes if no input value is supplied. If default is set, a TaskRun may be executed without a supplied value for the parameter.",
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: tektonParamValueFields(),
},
},
}
}
func tektonPropertySpecFields() map[string]*schema.Schema {
return map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Description: "Type is the user-specified type of the parameter. The possible types are currently string, array and object, and string is the default.",
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"string", "array", "object"}, false),
},
}
}
func tektonParamValueFields() map[string]*schema.Schema {
return map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Description: "Type is the user-specified type of the parameter. The possible types are currently string, array and object, and string is the default.",
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"string", "array", "object"}, false),
},
"string_val": {
Type: schema.TypeString,
Description: "StringVal is a string value.",
Optional: true,
},
"array_val": {
Type: schema.TypeList,
Description: "ArrayVal is an array of strings.",
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"object_val": {
Type: schema.TypeMap,
Description: "ObjectVal is a map of strings to strings.",
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
}
}
func expandTektonTaskRunSpec(task []interface{}) (tektonapiv1.TaskRunSpec, error) {
result := tektonapiv1.TaskRunSpec{}
if len(task) == 0 || task[0] == nil {
return result, nil
}
_ = task[0].(map[string]interface{})
return result, nil
}
func flattenTektonTaskRunSpec(in tektonapiv1.TaskRunSpec) []interface{} {
att := make(map[string]interface{})
return []interface{}{att}
}