generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 41
/
data_source_manual_freeze.go
186 lines (172 loc) · 4.89 KB
/
data_source_manual_freeze.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
package manual_freeze
import (
"context"
"github.com/harness/harness-go-sdk/harness/nextgen"
"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 DataSourceManualFreeze() *schema.Resource {
resource := &schema.Resource{
Description: "DataSource for deployment freeze in harness.",
ReadContext: dataSourceManualFreezeRead,
Schema: map[string]*schema.Schema{
"identifier": {
Description: "Identifier of the freeze",
Type: schema.TypeString,
Required: true,
},
"description": {
Description: "Description of the freeze",
Type: schema.TypeString,
Computed: true,
},
"name": {
Description: "Name of the freeze",
Type: schema.TypeString,
Computed: true,
},
"org_id": {
Description: "Organization identifier of the freeze",
Type: schema.TypeString,
Optional: true,
},
"project_id": {
Description: "Project identifier of the freeze",
Type: schema.TypeString,
Optional: true,
},
"tags": {
Description: "Tags associated with the freeze",
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"type": {
Description: "Type of freeze",
Type: schema.TypeString,
Computed: true,
},
"account_id": {
Description: "Account Identifier of the freeze",
Type: schema.TypeString,
Required: true,
},
"status": {
Description: "Status of the freeze",
Type: schema.TypeString,
Computed: true,
},
"scope": {
Description: "Scope of the freeze",
Type: schema.TypeString,
Computed: true,
},
"yaml": {
Description: "Yaml of the freeze",
Type: schema.TypeString,
Computed: true,
},
"current_or_upcoming_windows": {
Description: "Current or upcoming windows",
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"start_time": {
Description: "Start time of the freeze window",
Type: schema.TypeInt,
Computed: true,
},
"end_time": {
Description: "End time of the freeze window",
Type: schema.TypeInt,
Computed: true,
},
}},
},
"freeze_windows": {
Description: "Freeze windows in the freeze response",
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"time_zone": {
Description: "Time zone of the freeze window",
Type: schema.TypeString,
Computed: true,
},
"start_time": {
Description: "Start Time of the freeze window",
Type: schema.TypeString,
Computed: true,
},
"duration": {
Description: "Duration of the freeze window",
Type: schema.TypeString,
Computed: true,
},
"end_time": {
Description: "End Time of the freeze window",
Type: schema.TypeString,
Computed: true,
},
"recurrence": {
Description: "Recurrence of the freeze window",
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Description: "Type of the recurrence",
Type: schema.TypeString,
Computed: true,
},
"recurrence_spec": {
Description: "Used to filter resources on their attributes",
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"until": {
Description: "Time till which freeze window recurrs",
Type: schema.TypeString,
Computed: true,
},
"value": {
Description: "Every n months recurrence",
Type: schema.TypeInt,
Computed: true,
},
},
},
},
},
},
},
},
},
},
},
}
return resource
}
func dataSourceManualFreezeRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx)
id := d.Get("identifier").(string)
resp, httpResp, err := c.FreezeCRUDApi.GetFreeze(ctx, c.AccountId, id, &nextgen.FreezeCRUDApiGetFreezeOpts{
OrgIdentifier: helpers.BuildField(d, "org_id"),
ProjectIdentifier: helpers.BuildField(d, "project_id"),
})
if err != nil {
return helpers.HandleApiError(err, d, httpResp)
}
if resp.Data == nil {
return nil
}
readFreezeResponse(d, resp.Data)
return nil
}