generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 41
/
as_vm.go
298 lines (292 loc) · 8.51 KB
/
as_vm.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
package as_rule
import (
"context"
"github.com/harness/terraform-provider-harness/helpers"
"github.com/harness/terraform-provider-harness/internal"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func ResourceVMRule() *schema.Resource {
resource := &schema.Resource{
Description: "Resource for creating a Harness Variables.",
ReadContext: resourceASRuleRead,
UpdateContext: resourceVMRuleCreateOrUpdate,
DeleteContext: resourceASRuleDelete,
CreateContext: resourceVMRuleCreateOrUpdate,
Importer: helpers.MultiLevelResourceImporter,
Schema: map[string]*schema.Schema{
"identifier": {
Description: "Unique identifier of the resource",
Type: schema.TypeFloat,
Computed: true,
},
"name": {
Description: "Name of the rule",
Type: schema.TypeString,
Required: true,
},
"cloud_connector_id": {
Description: "Id of the cloud connector",
Type: schema.TypeString,
Required: true,
},
"idle_time_mins": {
Description: "Idle time in minutes. This is the time that the AutoStopping rule waits before stopping the idle instances.",
Type: schema.TypeInt,
Optional: true,
Default: 15,
},
"use_spot": {
Description: "Boolean that indicates whether the selected instances should be converted to spot vm",
Type: schema.TypeBool,
Default: false,
Optional: true,
},
"custom_domains": {
Description: "Custom URLs used to access the instances",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"filter": {
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"vm_ids": {
Description: "Ids of instances that needs to be managed using the AutoStopping rules",
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"tags": {
Description: "Tags of instances that needs to be managed using the AutoStopping rules",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Type: schema.TypeString,
Required: true,
},
"value": {
Type: schema.TypeString,
Required: true,
},
},
},
},
"regions": {
Description: "Regions of instances that needs to be managed using the AutoStopping rules",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"zones": {
Description: "Zones of instances that needs to be managed using the AutoStopping rules",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"http": {
Description: "Http routing configuration",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"proxy_id": {
Description: "Id of the proxy",
Type: schema.TypeString,
Required: true,
},
"routing": {
Description: "Routing configuration used to access the instances",
Type: schema.TypeList,
MinItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"source_protocol": {
Description: "Source protocol of the proxy can be http or https",
Type: schema.TypeString,
Required: true,
},
"target_protocol": {
Description: "Target protocol of the instance can be http or https",
Type: schema.TypeString,
Required: true,
},
"source_port": {
Description: "Port on the proxy",
Type: schema.TypeInt,
Optional: true,
},
"target_port": {
Description: "Port on the VM",
Type: schema.TypeInt,
Optional: true,
},
"action": {
Description: "Organization Identifier for the Entity",
Type: schema.TypeString,
Optional: true,
},
},
},
},
"health": {
Description: "Health Check Details",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"protocol": {
Description: "Protocol can be http or https",
Type: schema.TypeString,
Required: true,
},
"port": {
Description: "Health check port on the VM",
Type: schema.TypeInt,
Required: true,
},
"path": {
Description: "API path to use for health check",
Type: schema.TypeString,
Optional: true,
},
"timeout": {
Description: "Health check timeout",
Type: schema.TypeInt,
Optional: true,
},
"status_code_from": {
Description: "Lower limit for acceptable status code",
Type: schema.TypeInt,
Optional: true,
},
"status_code_to": {
Description: "Upper limit for acceptable status code",
Type: schema.TypeInt,
Optional: true,
},
},
},
},
},
},
},
"tcp": {
Description: "TCP routing configuration",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"proxy_id": {
Description: "Id of the Proxy",
Type: schema.TypeString,
Required: true,
},
"ssh": {
Description: "SSH configuration",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"connect_on": {
Description: "Port to listen on the proxy",
Type: schema.TypeInt,
Optional: true,
},
"port": {
Description: "Port to listen on the vm",
Type: schema.TypeInt,
Optional: true,
Default: 22,
},
},
},
},
"rdp": {
Description: "RDP configuration",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"connect_on": {
Description: "Port to listen on the proxy",
Type: schema.TypeInt,
Optional: true,
},
"port": {
Description: "Port to listen on the vm",
Type: schema.TypeInt,
Optional: true,
Default: 3389,
},
},
},
},
"forward_rule": {
Description: "Additional tcp forwarding rules",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"connect_on": {
Description: "Port to listen on the proxy",
Type: schema.TypeInt,
Optional: true,
},
"port": {
Description: "Port to listen on the vm",
Type: schema.TypeInt,
Required: true,
},
},
},
},
},
},
},
"depends": {
Description: "Dependent rules",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"rule_id": {
Description: "Rule id of the dependent rule",
Type: schema.TypeInt,
Required: true,
},
"delay_in_sec": {
Description: "Number of seconds the rule should wait after warming up the dependent rule",
Type: schema.TypeInt,
Optional: true,
Default: 5,
},
},
},
},
},
}
return resource
}
func resourceVMRuleCreateOrUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx)
saveServiceRequestV2 := buildASRule(d, Instance, c.AccountId)
return resourceASRuleCreateOrUpdate(ctx, d, meta, saveServiceRequestV2)
}