/
resource_ibm_iam_trusted_profile_template_assignment.go
748 lines (693 loc) · 26.2 KB
/
resource_ibm_iam_trusted_profile_template_assignment.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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
// Copyright IBM Corp. 2023 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0
package iamidentity
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"log"
"time"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate"
"github.com/IBM/go-sdk-core/v5/core"
"github.com/IBM/platform-services-go-sdk/iamidentityv1"
)
const (
InProgress = "in_progress"
complete = "complete"
failed = "failed"
)
func ResourceIBMTrustedProfileTemplateAssignment() *schema.Resource {
return &schema.Resource{
CreateContext: resourceIBMTrustedProfileTemplateAssignmentCreate,
ReadContext: resourceIBMTrustedProfileTemplateAssignmentRead,
UpdateContext: resourceIBMTrustedProfileTemplateAssignmentUpdate,
DeleteContext: resourceIBMTrustedProfileTemplateAssignmentDelete,
Importer: &schema.ResourceImporter{},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Update: schema.DefaultTimeout(30 * time.Minute),
Delete: schema.DefaultTimeout(30 * time.Minute),
},
Schema: map[string]*schema.Schema{
"template_id": {
Type: schema.TypeString,
Required: true,
Description: "Template Id.",
},
"template_version": {
Type: schema.TypeInt,
Required: true,
Description: "Template version.",
},
"target_type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.InvokeValidator("ibm_iam_trusted_profile_template_assignment", "target_type"),
Description: "Assignment target type.",
},
"target": {
Type: schema.TypeString,
Required: true,
Description: "Assignment target.",
},
"context": {
Type: schema.TypeList,
Computed: true,
Description: "Context with key properties for problem determination.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"transaction_id": {
Type: schema.TypeString,
Computed: true,
Description: "The transaction ID of the inbound REST request.",
},
"operation": {
Type: schema.TypeString,
Computed: true,
Description: "The operation of the inbound REST request.",
},
"user_agent": {
Type: schema.TypeString,
Computed: true,
Description: "The user agent of the inbound REST request.",
},
"url": {
Type: schema.TypeString,
Computed: true,
Description: "The URL of that cluster.",
},
"instance_id": {
Type: schema.TypeString,
Computed: true,
Description: "The instance ID of the server instance processing the request.",
},
"thread_id": {
Type: schema.TypeString,
Computed: true,
Description: "The thread ID of the server instance processing the request.",
},
"host": {
Type: schema.TypeString,
Computed: true,
Description: "The host of the server instance processing the request.",
},
"start_time": {
Type: schema.TypeString,
Computed: true,
Description: "The start time of the request.",
},
"end_time": {
Type: schema.TypeString,
Computed: true,
Description: "The finish time of the request.",
},
"elapsed_time": {
Type: schema.TypeString,
Computed: true,
Description: "The elapsed time in msec.",
},
"cluster_name": {
Type: schema.TypeString,
Computed: true,
Description: "The cluster name.",
},
},
},
},
"account_id": {
Type: schema.TypeString,
Computed: true,
Description: "Enterprise account Id.",
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Assignment status.",
},
"resources": {
Type: schema.TypeList,
Computed: true,
Description: "Status breakdown per target account of IAM resources created or errors encountered in attempting to create those IAM resources. IAM resources are only included in the response providing the assignment is not in progress. IAM resources are also only included when getting a single assignment, and excluded by list APIs.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"target": {
Type: schema.TypeString,
Required: true,
Description: "Target account where the IAM resource is created.",
},
"profile": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "Policy Template Id, only returned for a profile assignment with policy references.",
},
"version": {
Type: schema.TypeString,
Computed: true,
Description: "Policy version, only returned for a profile assignment with policy references.",
},
"resource_created": {
Type: schema.TypeList,
Computed: true,
Description: "Body parameters for created resource.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "Id of the created resource.",
},
},
},
},
"error_message": {
Type: schema.TypeList,
Computed: true,
Description: "Body parameters for assignment error.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the error.",
},
"error_code": {
Type: schema.TypeString,
Computed: true,
Description: "Internal error code.",
},
"message": {
Type: schema.TypeString,
Computed: true,
Description: "Error message detailing the nature of the error.",
},
"status_code": {
Type: schema.TypeString,
Computed: true,
Description: "Internal status code for the error.",
},
},
},
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Status for the target account's assignment.",
},
},
},
},
"policy_template_refs": {
Type: schema.TypeList,
Computed: true,
Description: "Policy resource(s) included only for trusted profile assignments with policy references.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "Policy Template Id, only returned for a profile assignment with policy references.",
},
"version": {
Type: schema.TypeString,
Computed: true,
Description: "Policy version, only returned for a profile assignment with policy references.",
},
"resource_created": {
Type: schema.TypeList,
Computed: true,
Description: "Body parameters for created resource.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "Id of the created resource.",
},
},
},
},
"error_message": {
Type: schema.TypeList,
Computed: true,
Description: "Body parameters for assignment error.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the error.",
},
"error_code": {
Type: schema.TypeString,
Computed: true,
Description: "Internal error code.",
},
"message": {
Type: schema.TypeString,
Computed: true,
Description: "Error message detailing the nature of the error.",
},
"status_code": {
Type: schema.TypeString,
Computed: true,
Description: "Internal status code for the error.",
},
},
},
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Status for the target account's assignment.",
},
},
},
},
},
},
},
"history": {
Type: schema.TypeList,
Computed: true,
Description: "Assignment history.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"timestamp": {
Type: schema.TypeString,
Computed: true,
Description: "Timestamp when the action was triggered.",
},
"iam_id": {
Type: schema.TypeString,
Computed: true,
Description: "IAM ID of the identity which triggered the action.",
},
"iam_id_account": {
Type: schema.TypeString,
Computed: true,
Description: "Account of the identity which triggered the action.",
},
"action": {
Type: schema.TypeString,
Computed: true,
Description: "Action of the history entry.",
},
"params": {
Type: schema.TypeList,
Computed: true,
Description: "Params of the history entry.",
Elem: &schema.Schema{Type: schema.TypeString},
},
"message": {
Type: schema.TypeString,
Computed: true,
Description: "Message which summarizes the executed action.",
},
},
},
},
"href": {
Type: schema.TypeString,
Computed: true,
Description: "Href.",
},
"created_at": {
Type: schema.TypeString,
Computed: true,
Description: "Assignment created at.",
},
"created_by_id": {
Type: schema.TypeString,
Computed: true,
Description: "IAMid of the identity that created the assignment.",
},
"last_modified_at": {
Type: schema.TypeString,
Computed: true,
Description: "Assignment modified at.",
},
"last_modified_by_id": {
Type: schema.TypeString,
Computed: true,
Description: "IAMid of the identity that last modified the assignment.",
},
"entity_tag": {
Type: schema.TypeString,
Computed: true,
Description: "Entity tag for this assignment record.",
},
},
}
}
func ResourceIBMTrustedProfileTemplateAssignmentValidator() *validate.ResourceValidator {
validateSchema := make([]validate.ValidateSchema, 0)
validateSchema = append(validateSchema,
validate.ValidateSchema{
Identifier: "target_type",
ValidateFunctionIdentifier: validate.ValidateAllowedStringValue,
Type: validate.TypeString,
Required: true,
AllowedValues: "Account, AccountGroup",
},
)
resourceValidator := validate.ResourceValidator{ResourceName: "ibm_iam_trusted_profile_template_assignment", Schema: validateSchema}
return &resourceValidator
}
func resourceIBMTrustedProfileTemplateAssignmentCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
iamIdentityClient, err := meta.(conns.ClientSession).IAMIdentityV1API()
if err != nil {
return diag.FromErr(err)
}
createTrustedProfileAssignmentOptions := &iamidentityv1.CreateTrustedProfileAssignmentOptions{}
createTrustedProfileAssignmentOptions.SetTemplateID(d.Get("template_id").(string))
createTrustedProfileAssignmentOptions.SetTemplateVersion(int64(d.Get("template_version").(int)))
createTrustedProfileAssignmentOptions.SetTargetType(d.Get("target_type").(string))
createTrustedProfileAssignmentOptions.SetTarget(d.Get("target").(string))
templateAssignmentResponse, response, err := iamIdentityClient.CreateTrustedProfileAssignmentWithContext(context, createTrustedProfileAssignmentOptions)
if err != nil {
log.Printf("[DEBUG] CreateTrustedProfileAssignmentWithContext failed %s\n%s", err, response)
return diag.FromErr(fmt.Errorf("CreateTrustedProfileAssignmentWithContext failed %s\n%s", err, response))
}
d.SetId(*templateAssignmentResponse.ID)
_, err = waitForAssignment(d.Timeout(schema.TimeoutCreate), meta, d, isTrustedProfileTemplateAssigned)
if err != nil {
return diag.FromErr(fmt.Errorf("error assigning %s", err))
}
return resourceIBMTrustedProfileTemplateAssignmentRead(context, d, meta)
}
func resourceIBMTrustedProfileTemplateAssignmentRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
iamIdentityClient, err := meta.(conns.ClientSession).IAMIdentityV1API()
if err != nil {
return diag.FromErr(err)
}
getTrustedProfileAssignmentOptions := &iamidentityv1.GetTrustedProfileAssignmentOptions{}
getTrustedProfileAssignmentOptions.SetAssignmentID(d.Id())
templateAssignmentResponse, response, err := iamIdentityClient.GetTrustedProfileAssignmentWithContext(context, getTrustedProfileAssignmentOptions)
if err != nil {
if response != nil && response.StatusCode == 404 {
d.SetId("")
return nil
}
log.Printf("[DEBUG] GetTrustedProfileAssignmentWithContext failed %s\n%s", err, response)
return diag.FromErr(fmt.Errorf("GetTrustedProfileAssignmentWithContext failed %s\n%s", err, response))
}
if err = d.Set("template_id", templateAssignmentResponse.TemplateID); err != nil {
return diag.FromErr(fmt.Errorf("error setting template_id: %s", err))
}
if err = d.Set("template_version", flex.IntValue(templateAssignmentResponse.TemplateVersion)); err != nil {
return diag.FromErr(fmt.Errorf("error setting template_version: %s", err))
}
if err = d.Set("target_type", templateAssignmentResponse.TargetType); err != nil {
return diag.FromErr(fmt.Errorf("error setting target_type: %s", err))
}
if err = d.Set("target", templateAssignmentResponse.Target); err != nil {
return diag.FromErr(fmt.Errorf("error setting target: %s", err))
}
if !core.IsNil(templateAssignmentResponse.Context) {
contextMap, err := resourceIBMTrustedProfileTemplateAssignmentResponseContextToMap(templateAssignmentResponse.Context)
if err != nil {
return diag.FromErr(err)
}
if err = d.Set("context", []map[string]interface{}{contextMap}); err != nil {
return diag.FromErr(fmt.Errorf("error setting context: %s", err))
}
}
if err = d.Set("account_id", templateAssignmentResponse.AccountID); err != nil {
return diag.FromErr(fmt.Errorf("error setting account_id: %s", err))
}
if err = d.Set("status", templateAssignmentResponse.Status); err != nil {
return diag.FromErr(fmt.Errorf("error setting status: %s", err))
}
if !core.IsNil(templateAssignmentResponse.Resources) {
resources := []map[string]interface{}{}
for _, resourcesItem := range templateAssignmentResponse.Resources {
resourcesItemMap, err := resourceIBMTrustedProfileTemplateAssignmentTemplateAssignmentResponseResourceToMap(&resourcesItem)
if err != nil {
return diag.FromErr(err)
}
resources = append(resources, resourcesItemMap)
}
if err = d.Set("resources", resources); err != nil {
return diag.FromErr(fmt.Errorf("error setting resources: %s", err))
}
}
if !core.IsNil(templateAssignmentResponse.History) {
history := []map[string]interface{}{}
for _, historyItem := range templateAssignmentResponse.History {
historyItemMap, err := resourceIBMTrustedProfileTemplateAssignmentEnityHistoryRecordToMap(&historyItem)
if err != nil {
return diag.FromErr(err)
}
history = append(history, historyItemMap)
}
if err = d.Set("history", history); err != nil {
return diag.FromErr(fmt.Errorf("error setting history: %s", err))
}
}
if !core.IsNil(templateAssignmentResponse.Href) {
if err = d.Set("href", templateAssignmentResponse.Href); err != nil {
return diag.FromErr(fmt.Errorf("error setting href: %s", err))
}
}
if err = d.Set("created_at", templateAssignmentResponse.CreatedAt); err != nil {
return diag.FromErr(fmt.Errorf("error setting created_at: %s", err))
}
if err = d.Set("created_by_id", templateAssignmentResponse.CreatedByID); err != nil {
return diag.FromErr(fmt.Errorf("error setting created_by_id: %s", err))
}
if err = d.Set("last_modified_at", templateAssignmentResponse.LastModifiedAt); err != nil {
return diag.FromErr(fmt.Errorf("error setting last_modified_at: %s", err))
}
if err = d.Set("last_modified_by_id", templateAssignmentResponse.LastModifiedByID); err != nil {
return diag.FromErr(fmt.Errorf("error setting last_modified_by_id: %s", err))
}
if err = d.Set("entity_tag", templateAssignmentResponse.EntityTag); err != nil {
return diag.FromErr(fmt.Errorf("error setting entity_tag: %s", err))
}
return nil
}
func resourceIBMTrustedProfileTemplateAssignmentUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
iamIdentityClient, err := meta.(conns.ClientSession).IAMIdentityV1API()
if err != nil {
return diag.FromErr(err)
}
updateTrustedProfileAssignmentOptions := &iamidentityv1.UpdateTrustedProfileAssignmentOptions{}
updateTrustedProfileAssignmentOptions.SetAssignmentID(d.Id())
updateTrustedProfileAssignmentOptions.SetIfMatch(d.Get("entity_tag").(string))
hasChange := false
if d.HasChange("template_version") {
updateTrustedProfileAssignmentOptions.SetTemplateVersion(int64(d.Get("template_version").(int)))
hasChange = true
}
if hasChange || d.Get("status") == "failed" { // allow the same version to retry failed assignments
_, response, err := iamIdentityClient.UpdateTrustedProfileAssignmentWithContext(context, updateTrustedProfileAssignmentOptions)
if err != nil {
log.Printf("[DEBUG] UpdateTrustedProfileAssignmentWithContext failed %s\n%s", err, response)
return diag.FromErr(fmt.Errorf("UpdateTrustedProfileAssignmentWithContext failed %s\n%s", err, response))
}
_, err = waitForAssignment(d.Timeout(schema.TimeoutUpdate), meta, d, isTrustedProfileTemplateAssigned)
if err != nil {
return diag.FromErr(fmt.Errorf("error assigning %s", err))
}
}
return resourceIBMTrustedProfileTemplateAssignmentRead(context, d, meta)
}
func resourceIBMTrustedProfileTemplateAssignmentDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
iamIdentityClient, err := meta.(conns.ClientSession).IAMIdentityV1API()
if err != nil {
return diag.FromErr(err)
}
deleteTrustedProfileAssignmentOptions := &iamidentityv1.DeleteTrustedProfileAssignmentOptions{}
deleteTrustedProfileAssignmentOptions.SetAssignmentID(d.Id())
_, response, err := iamIdentityClient.DeleteTrustedProfileAssignmentWithContext(context, deleteTrustedProfileAssignmentOptions)
if err != nil {
return diag.FromErr(fmt.Errorf("[DEBUG] DeleteTrustedProfileAssignmentWithContext failed %s\n%s", err, response))
}
_, err = waitForAssignment(d.Timeout(schema.TimeoutDelete), meta, d, isTrustedProfileAssignmentRemoved)
if err != nil {
return diag.FromErr(fmt.Errorf("error removing assignment %s", err))
}
d.SetId("")
return nil
}
func waitForAssignment(timeout time.Duration, meta interface{}, d *schema.ResourceData, refreshFn func(string, interface{}) resource.StateRefreshFunc) (interface{}, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{InProgress},
Target: []string{complete},
Refresh: refreshFn(d.Id(), meta),
Delay: 30 * time.Second,
PollInterval: time.Minute,
Timeout: timeout,
}
return stateConf.WaitForState()
}
func isTrustedProfileAssignmentRemoved(id string, meta interface{}) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
iamIdentityClient, err := meta.(conns.ClientSession).IAMIdentityV1API()
getOptions := &iamidentityv1.GetTrustedProfileAssignmentOptions{
AssignmentID: &id,
}
assignment, response, err := iamIdentityClient.GetTrustedProfileAssignment(getOptions)
if err != nil {
if response != nil && response.StatusCode == 404 {
return assignment, complete, nil
}
return nil, failed, fmt.Errorf("[ERROR] The assignment %s failed to delete or deletion was not completed within specific timeout period: %s\n%s", id, err, response)
} else {
log.Printf("Assignment removal still in progress\n")
}
return assignment, InProgress, nil
}
}
func isTrustedProfileTemplateAssigned(id string, meta interface{}) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
iamIdentityClient, err := meta.(conns.ClientSession).IAMIdentityV1API()
getOptions := &iamidentityv1.GetTrustedProfileAssignmentOptions{
AssignmentID: &id,
}
assignment, response, err := iamIdentityClient.GetTrustedProfileAssignment(getOptions)
if err != nil {
return nil, failed, fmt.Errorf("[ERROR] The assignment %s failed or did not complete within specific timeout period: %s\n%s", id, err, response)
}
if assignment != nil {
if *assignment.Status == "accepted" || *assignment.Status == "in_progress" {
log.Printf("Assignment still in progress\n")
return assignment, InProgress, nil
}
if *assignment.Status == "succeeded" {
return assignment, complete, nil
}
if *assignment.Status == "failed" {
return assignment, failed, fmt.Errorf("[ERROR] The assignment %s did complete but with a 'failed' status. Please check assignment resource for detailed errors: %s\n", id, response)
}
}
return assignment, failed, fmt.Errorf("[ERROR] Unexpected status reached for assignment %s.: %s\n", id, response)
}
}
func resourceIBMTrustedProfileTemplateAssignmentResponseContextToMap(model *iamidentityv1.ResponseContext) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.TransactionID != nil {
modelMap["transaction_id"] = model.TransactionID
}
if model.Operation != nil {
modelMap["operation"] = model.Operation
}
if model.UserAgent != nil {
modelMap["user_agent"] = model.UserAgent
}
if model.URL != nil {
modelMap["url"] = model.URL
}
if model.InstanceID != nil {
modelMap["instance_id"] = model.InstanceID
}
if model.ThreadID != nil {
modelMap["thread_id"] = model.ThreadID
}
if model.Host != nil {
modelMap["host"] = model.Host
}
if model.StartTime != nil {
modelMap["start_time"] = model.StartTime
}
if model.EndTime != nil {
modelMap["end_time"] = model.EndTime
}
if model.ElapsedTime != nil {
modelMap["elapsed_time"] = model.ElapsedTime
}
if model.ClusterName != nil {
modelMap["cluster_name"] = model.ClusterName
}
return modelMap, nil
}
func resourceIBMTrustedProfileTemplateAssignmentTemplateAssignmentResponseResourceToMap(model *iamidentityv1.TemplateAssignmentResponseResource) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["target"] = model.Target
if model.Profile != nil {
profileMap, err := resourceIBMTrustedProfileTemplateAssignmentTemplateAssignmentResponseResourceDetailToMap(model.Profile)
if err != nil {
return modelMap, err
}
modelMap["profile"] = []map[string]interface{}{profileMap}
}
if model.PolicyTemplateRefs != nil {
policyTemplateRefs := []map[string]interface{}{}
for _, policyTemplateRefsItem := range model.PolicyTemplateRefs {
policyTemplateRefsItemMap, err := resourceIBMTrustedProfileTemplateAssignmentTemplateAssignmentResponseResourceDetailToMap(&policyTemplateRefsItem)
if err != nil {
return modelMap, err
}
policyTemplateRefs = append(policyTemplateRefs, policyTemplateRefsItemMap)
}
modelMap["policy_template_refs"] = policyTemplateRefs
}
return modelMap, nil
}
func resourceIBMTrustedProfileTemplateAssignmentTemplateAssignmentResponseResourceDetailToMap(model *iamidentityv1.TemplateAssignmentResponseResourceDetail) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.ID != nil {
modelMap["id"] = model.ID
}
if model.Version != nil {
modelMap["version"] = model.Version
}
if model.ResourceCreated != nil {
resourceCreatedMap, err := resourceIBMTrustedProfileTemplateAssignmentTemplateAssignmentResourceToMap(model.ResourceCreated)
if err != nil {
return modelMap, err
}
modelMap["resource_created"] = []map[string]interface{}{resourceCreatedMap}
}
if model.ErrorMessage != nil {
errorMessageMap, err := resourceIBMTrustedProfileTemplateAssignmentTemplateAssignmentResourceErrorToMap(model.ErrorMessage)
if err != nil {
return modelMap, err
}
modelMap["error_message"] = []map[string]interface{}{errorMessageMap}
}
modelMap["status"] = model.Status
return modelMap, nil
}
func resourceIBMTrustedProfileTemplateAssignmentTemplateAssignmentResourceToMap(model *iamidentityv1.TemplateAssignmentResource) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.ID != nil {
modelMap["id"] = model.ID
}
return modelMap, nil
}
func resourceIBMTrustedProfileTemplateAssignmentTemplateAssignmentResourceErrorToMap(model *iamidentityv1.TemplateAssignmentResourceError) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.Name != nil {
modelMap["name"] = model.Name
}
if model.ErrorCode != nil {
modelMap["error_code"] = model.ErrorCode
}
if model.Message != nil {
modelMap["message"] = model.Message
}
if model.StatusCode != nil {
modelMap["status_code"] = model.StatusCode
}
return modelMap, nil
}
func resourceIBMTrustedProfileTemplateAssignmentEnityHistoryRecordToMap(model *iamidentityv1.EnityHistoryRecord) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["timestamp"] = model.Timestamp
modelMap["iam_id"] = model.IamID
modelMap["iam_id_account"] = model.IamIDAccount
modelMap["action"] = model.Action
modelMap["params"] = model.Params
modelMap["message"] = model.Message
return modelMap, nil
}