-
Notifications
You must be signed in to change notification settings - Fork 658
/
data_source_ibm_is_instance_group_manager_action.go
241 lines (210 loc) · 8.7 KB
/
data_source_ibm_is_instance_group_manager_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
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
// Copyright IBM Corp. 2017, 2021 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0
package vpc
import (
"fmt"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/IBM/vpc-go-sdk/vpcv1"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func DataSourceIBMISInstanceGroupManagerAction() *schema.Resource {
return &schema.Resource{
Read: dataSourceIBMISInstanceGroupManagerActionRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "instance group manager action name",
},
"action_id": {
Type: schema.TypeString,
Computed: true,
Description: "Instance group manager action ID",
},
"instance_group": {
Type: schema.TypeString,
Required: true,
Description: "instance group ID",
},
"instance_group_manager": {
Type: schema.TypeString,
Required: true,
Description: "Instance group manager ID of type scheduled",
},
"run_at": {
Type: schema.TypeString,
Computed: true,
Description: "The date and time the scheduled action will run.",
},
"membership_count": {
Type: schema.TypeInt,
Computed: true,
Description: "The number of members the instance group should have at the scheduled time.",
},
"max_membership_count": {
Type: schema.TypeInt,
Computed: true,
Description: "The maximum number of members in a managed instance group",
},
"min_membership_count": {
Type: schema.TypeInt,
Computed: true,
Description: "The minimum number of members in a managed instance group",
},
"target_manager": {
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this instance group manager of type autoscale.",
},
"target_manager_name": {
Type: schema.TypeString,
Computed: true,
Description: "Instance group manager name of type autoscale.",
},
"cron_spec": {
Type: schema.TypeString,
Computed: true,
Description: "The cron specification for a recurring scheduled action. Actions can be applied a maximum of one time within a 5 min period.",
},
"resource_type": {
Type: schema.TypeString,
Computed: true,
Description: "The resource type.",
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "The status of the instance group action- `active`: Action is ready to be run- `completed`: Action was completed successfully- `failed`: Action could not be completed successfully- `incompatible`: Action parameters are not compatible with the group or manager- `omitted`: Action was not applied because this action's manager was disabled.",
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
Description: "The date and time that the instance group manager action was modified.",
},
"action_type": {
Type: schema.TypeString,
Computed: true,
Description: "The type of action for the instance group.",
},
"last_applied_at": {
Type: schema.TypeString,
Computed: true,
Description: "The date and time the scheduled action was last applied. If empty the action has never been applied.",
},
"next_run_at": {
Type: schema.TypeString,
Computed: true,
Description: "The date and time the scheduled action will next run. If empty the system is currently calculating the next run time.",
},
"auto_delete": {
Type: schema.TypeBool,
Computed: true,
},
"auto_delete_timeout": {
Type: schema.TypeInt,
Computed: true,
},
"created_at": {
Type: schema.TypeString,
Computed: true,
Description: "The date and time that the instance group manager action was modified.",
},
},
}
}
func dataSourceIBMISInstanceGroupManagerActionRead(d *schema.ResourceData, meta interface{}) error {
sess, err := vpcClient(meta)
if err != nil {
return err
}
instanceGroupManagerID := d.Get("instance_group_manager").(string)
instanceGroupID := d.Get("instance_group").(string)
actionName := d.Get("name").(string)
// Support for pagination
start := ""
allrecs := []vpcv1.InstanceGroupManagerActionIntf{}
for {
listInstanceGroupManagerActionsOptions := vpcv1.ListInstanceGroupManagerActionsOptions{
InstanceGroupID: &instanceGroupID,
InstanceGroupManagerID: &instanceGroupManagerID,
}
if start != "" {
listInstanceGroupManagerActionsOptions.Start = &start
}
instanceGroupManagerActionsCollection, response, err := sess.ListInstanceGroupManagerActions(&listInstanceGroupManagerActionsOptions)
if err != nil {
return fmt.Errorf("[ERROR] Error Getting InstanceGroup Manager Actions %s\n%s", err, response)
}
if instanceGroupManagerActionsCollection != nil && *instanceGroupManagerActionsCollection.TotalCount == int64(0) {
break
}
start = flex.GetNext(instanceGroupManagerActionsCollection.Next)
allrecs = append(allrecs, instanceGroupManagerActionsCollection.Actions...)
if start == "" {
break
}
}
for _, data := range allrecs {
instanceGroupManagerAction := data.(*vpcv1.InstanceGroupManagerAction)
if actionName == *instanceGroupManagerAction.Name {
d.SetId(fmt.Sprintf("%s/%s/%s", instanceGroupID, instanceGroupManagerID, *instanceGroupManagerAction.ID))
if err = d.Set("auto_delete", *instanceGroupManagerAction.AutoDelete); err != nil {
return fmt.Errorf("[ERROR] Error setting auto_delete: %s", err)
}
if err = d.Set("auto_delete_timeout", flex.IntValue(instanceGroupManagerAction.AutoDeleteTimeout)); err != nil {
return fmt.Errorf("[ERROR] Error setting auto_delete_timeout: %s", err)
}
if err = d.Set("created_at", instanceGroupManagerAction.CreatedAt.String()); err != nil {
return fmt.Errorf("[ERROR] Error setting created_at: %s", err)
}
if err = d.Set("action_id", *instanceGroupManagerAction.ID); err != nil {
return fmt.Errorf("[ERROR] Error setting instance_group_manager_action : %s", err)
}
if err = d.Set("resource_type", *instanceGroupManagerAction.ResourceType); err != nil {
return fmt.Errorf("[ERROR] Error setting resource_type: %s", err)
}
if err = d.Set("status", *instanceGroupManagerAction.Status); err != nil {
return fmt.Errorf("[ERROR] Error setting status: %s", err)
}
if err = d.Set("updated_at", instanceGroupManagerAction.UpdatedAt.String()); err != nil {
return fmt.Errorf("[ERROR] Error setting updated_at: %s", err)
}
if err = d.Set("action_type", *instanceGroupManagerAction.ActionType); err != nil {
return fmt.Errorf("[ERROR] Error setting action_type: %s", err)
}
if instanceGroupManagerAction.CronSpec != nil {
if err = d.Set("cron_spec", *instanceGroupManagerAction.CronSpec); err != nil {
return fmt.Errorf("[ERROR] Error setting cron_spec: %s", err)
}
}
if instanceGroupManagerAction.LastAppliedAt != nil {
if err = d.Set("last_applied_at", instanceGroupManagerAction.LastAppliedAt.String()); err != nil {
return fmt.Errorf("[ERROR] Error setting last_applied_at: %s", err)
}
}
if instanceGroupManagerAction.NextRunAt != nil {
if err = d.Set("next_run_at", instanceGroupManagerAction.NextRunAt.String()); err != nil {
return fmt.Errorf("[ERROR] Error setting next_run_at: %s", err)
}
}
instanceGroupManagerScheduledActionGroupGroup := instanceGroupManagerAction.Group
if instanceGroupManagerScheduledActionGroupGroup != nil && instanceGroupManagerScheduledActionGroupGroup.MembershipCount != nil {
d.Set("membership_count", flex.IntValue(instanceGroupManagerScheduledActionGroupGroup.MembershipCount))
}
instanceGroupManagerScheduledActionManagerManagerInt := instanceGroupManagerAction.Manager
if instanceGroupManagerScheduledActionManagerManagerInt != nil {
instanceGroupManagerScheduledActionManagerManager := instanceGroupManagerScheduledActionManagerManagerInt.(*vpcv1.InstanceGroupManagerScheduledActionManager)
if instanceGroupManagerScheduledActionManagerManager != nil && instanceGroupManagerScheduledActionManagerManager.ID != nil {
if instanceGroupManagerScheduledActionManagerManager.MaxMembershipCount != nil {
d.Set("max_membership_count", flex.IntValue(instanceGroupManagerScheduledActionManagerManager.MaxMembershipCount))
}
d.Set("min_membership_count", flex.IntValue(instanceGroupManagerScheduledActionManagerManager.MinMembershipCount))
d.Set("target_manager_name", *instanceGroupManagerScheduledActionManagerManager.Name)
d.Set("target_manager", *instanceGroupManagerScheduledActionManagerManager.ID)
}
}
return nil
}
}
return fmt.Errorf("instance group manager action %s not found", actionName)
}