-
Notifications
You must be signed in to change notification settings - Fork 649
/
data_source_ibm_scc_report_rule.go
147 lines (126 loc) · 4.33 KB
/
data_source_ibm_scc_report_rule.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
// Copyright IBM Corp. 2023 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0
package scc
import (
"context"
"fmt"
"log"
"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/scc-go-sdk/v5/securityandcompliancecenterapiv3"
)
func DataSourceIbmSccReportRule() *schema.Resource {
return AddSchemaData(&schema.Resource{
ReadContext: dataSourceIbmSccReportRuleRead,
Schema: map[string]*schema.Schema{
"report_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "The ID of the scan that is associated with a report.",
},
"rule_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "The ID of a rule in a report.",
},
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The rule ID.",
},
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The rule type.",
},
"description": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The rule description.",
},
"version": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The rule version.",
},
"account_id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The rule account ID.",
},
"created_on": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The date when the rule was created.",
},
"created_by": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The ID of the user who created the rule.",
},
"updated_on": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The date when the rule was updated.",
},
"updated_by": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The ID of the user who updated the rule.",
},
"labels": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The rule labels.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
})
}
func dataSourceIbmSccReportRuleRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
resultsClient, err := meta.(conns.ClientSession).SecurityAndComplianceCenterV3()
if err != nil {
return diag.FromErr(err)
}
getReportRuleOptions := &securityandcompliancecenterapiv3.GetReportRuleOptions{}
getReportRuleOptions.SetReportID(d.Get("report_id").(string))
getReportRuleOptions.SetRuleID(d.Get("rule_id").(string))
getReportRuleOptions.SetInstanceID(d.Get("instance_id").(string))
ruleInfo, response, err := resultsClient.GetReportRuleWithContext(context, getReportRuleOptions)
if err != nil {
log.Printf("[DEBUG] GetReportRuleWithContext failed %s\n%s", err, response)
return diag.FromErr(fmt.Errorf("GetReportRuleWithContext failed %s\n%s", err, response))
}
d.SetId(*ruleInfo.ID)
if err = d.Set("id", ruleInfo.ID); err != nil {
return diag.FromErr(fmt.Errorf("Error setting id: %s", err))
}
if err = d.Set("type", ruleInfo.Type); err != nil {
return diag.FromErr(fmt.Errorf("Error setting type: %s", err))
}
if err = d.Set("description", ruleInfo.Description); err != nil {
return diag.FromErr(fmt.Errorf("Error setting description: %s", err))
}
if err = d.Set("version", ruleInfo.Version); err != nil {
return diag.FromErr(fmt.Errorf("Error setting version: %s", err))
}
if err = d.Set("account_id", ruleInfo.AccountID); err != nil {
return diag.FromErr(fmt.Errorf("Error setting account_id: %s", err))
}
if err = d.Set("created_on", ruleInfo.CreatedOn); err != nil {
return diag.FromErr(fmt.Errorf("Error setting created_on: %s", err))
}
if err = d.Set("created_by", ruleInfo.CreatedBy); err != nil {
return diag.FromErr(fmt.Errorf("Error setting created_by: %s", err))
}
if err = d.Set("updated_on", ruleInfo.UpdatedOn); err != nil {
return diag.FromErr(fmt.Errorf("Error setting updated_on: %s", err))
}
if err = d.Set("updated_by", ruleInfo.UpdatedBy); err != nil {
return diag.FromErr(fmt.Errorf("Error setting updated_by: %s", err))
}
return nil
}