Skip to content

Commit 3b2ccbf

Browse files
committed
Updated filter on comp report
1 parent ac43501 commit 3b2ccbf

File tree

7 files changed

+131
-300
lines changed

7 files changed

+131
-300
lines changed

docs/data-sources/compliance_report_resource_group.md

Lines changed: 35 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -47,86 +47,33 @@ limitations under the License.
4747
*/
4848
4949
# commands to run this tf file : terraform init && terraform apply --auto-approve
50-
51-
# To get the resource_group_id you can use the powerflex_resource_group data source as shown below:
52-
5350
# Get all Resource Group details present in the PowerFlex
54-
data "powerflex_resource_group" "example1" {
55-
}
56-
57-
# Get Resource Group details using the Name of the Resource Group
58-
data "powerflex_resource_group" "example3" {
59-
resource_group_names = ["Name_1", "Name_2"]
60-
}
61-
62-
# Get all compliance report details for the given resource group
63-
data "powerflex_compliance_report_resource_group" "complianceReport" {
64-
resource_group_id = "ID"
51+
data "powerflex_compliance_report_resource_group" "example1" {
6552
}
6653
67-
# Get compliance report details for the given resource group filtered by given ipaddresses
68-
data "powerflex_compliance_report_resource_group" "complianceReport" {
69-
resource_group_id = "ID"
70-
# this datasource supports multiple filters like ip_addresses, host_names, service_tags, resource_ids, compliant
71-
# and gives an intersection of the results
72-
filter {
73-
ip_addresses = ["10.xxx.xxx.xx", "10.xxx.xxx.xx"]
74-
}
75-
}
76-
77-
# Get compliance report details for the given resource group filtered by resource ids and compliant status
78-
data "powerflex_compliance_report_resource_group" "complianceReport" {
79-
resource_group_id = "ID"
80-
# this datasource supports multiple filters like ip_addresses, host_names, service_tags, resource_ids, compliant
81-
# and gives an intersection of the results
82-
filter {
83-
resource_ids = ["resourceid1", "resourceid2"]
84-
compliant = true
85-
}
86-
}
87-
88-
# Get compliance report details for the given resource group filtered by compliant resources
89-
data "powerflex_compliance_report_resource_group" "complianceReport" {
90-
resource_group_id = "ID"
91-
# this datasource supports multiple filters like ip_addresses, host_names, service_tags, resource_ids, compliant
92-
# and gives an intersection of the results
93-
filter {
94-
compliant = true
95-
}
96-
}
97-
98-
# Get compliance report details for the given resource group filtered by hostnames
99-
data "powerflex_compliance_report_resource_group" "complianceReport" {
100-
resource_group_id = "ID"
101-
# this datasource supports multiple filters like ip_addresses, host_names, service_tags, resource_ids, compliant
102-
# and gives an intersection of the results
103-
filter {
104-
host_names = ["hostname1", "hostname2"]
105-
}
106-
}
107-
108-
# Get compliance report details for the given resource group filtered by service tags
109-
data "powerflex_compliance_report_resource_group" "complianceReport" {
110-
resource_group_id = "ID"
111-
# this datasource supports multiple filters like ip_addresses, host_names, service_tags, resource_ids, compliant
112-
# and gives an intersection of the results
113-
filter {
114-
service_tags = ["servicetag1", "servicetag2"]
115-
}
116-
}
117-
118-
# Get compliance report details for the given resource group filtered by resource ids
119-
data "powerflex_compliance_report_resource_group" "complianceReport" {
120-
resource_group_id = "ID"
121-
# this datasource supports multiple filters like ip_addresses, host_names, service_tags, resource_ids, compliant
122-
# and gives an intersection of the results
123-
filter {
124-
resource_ids = ["resourceid1", "resourceid2"]
125-
}
126-
}
54+
# this datasource supports multiple filters like ip_address, host_name, service_tag, compliant,etc.
55+
# Note: If both filters are used simultaneously, the results will include any records that match either of the filters.
56+
# data "powerflex_compliance_report_resource_group" "complianceReport" {
57+
# filter {
58+
# firmware_repository_name = ["name1", "name2"]
59+
# device_type = ["devicetype1", "devicetype2"]
60+
# model = ["model1", "model2"]
61+
# resource_ids = ["resourceid1", "resourceid2"]
62+
# service_tag = ["servicetag1", "servicetag2"]
63+
# compliant = true
64+
# embedded_report = true
65+
# can_update = true
66+
# available = true
67+
# device_state = ["devicestate1", "devicestate2"]
68+
# managed_state = ["managedstate1", "managedstate2"]
69+
# host_name = ["hostname1", "hostname2"]
70+
# id = ["id1", "id2"]
71+
# ip_address = ["ip1", "ip2"]
72+
# }
73+
# }
12774
12875
output "result" {
129-
value = data.powerflex_compliance_report_resource_group.complianceReport
76+
value = data.powerflex_compliance_report_resource_group.example1
13077
}
13178
```
13279

@@ -135,10 +82,6 @@ After the successful execution of above said block, we can see the output by exe
13582
<!-- schema generated by tfplugindocs -->
13683
## Schema
13784

138-
### Required
139-
140-
- `resource_group_id` (String) Unique id Of resource group for which you want to get the compliance report. Conflicts with resource_group_name
141-
14285
### Optional
14386

14487
- `filter` (Block, Optional) (see [below for nested schema](#nestedblock--filter))
@@ -153,11 +96,19 @@ After the successful execution of above said block, we can see the output by exe
15396

15497
Optional:
15598

156-
- `compliant` (Boolean) Compliant status for resources.
157-
- `host_names` (Set of String) List of host names for resources.
158-
- `ip_addresses` (Set of String) List of Ip Address for resources.
159-
- `resource_ids` (Set of String) List of resource ids.
160-
- `service_tags` (Set of String) List of service tags for resources.
99+
- `available` (Boolean) Value for available
100+
- `can_update` (Boolean) Value for can_update
101+
- `compliant` (Boolean) Value for compliant
102+
- `device_state` (Set of String) List of device_state
103+
- `device_type` (Set of String) List of device_type
104+
- `embedded_report` (Boolean) Value for embedded_report
105+
- `firmware_repository_name` (Set of String) List of firmware_repository_name
106+
- `host_name` (Set of String) List of host_name
107+
- `id` (Set of String) List of id
108+
- `ip_address` (Set of String) List of ip_address
109+
- `managed_state` (Set of String) List of managed_state
110+
- `model` (Set of String) List of model
111+
- `service_tag` (Set of String) List of service_tag
161112

162113

163114
<a id="nestedatt--compliance_reports"></a>

examples/data-sources/powerflex_compliance_report_resource_group/data-source.tf

Lines changed: 24 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -16,84 +16,31 @@ limitations under the License.
1616
*/
1717

1818
# commands to run this tf file : terraform init && terraform apply --auto-approve
19-
20-
# To get the resource_group_id you can use the powerflex_resource_group data source as shown below:
21-
2219
# Get all Resource Group details present in the PowerFlex
23-
data "powerflex_resource_group" "example1" {
24-
}
25-
26-
# Get Resource Group details using the Name of the Resource Group
27-
data "powerflex_resource_group" "example3" {
28-
resource_group_names = ["Name_1", "Name_2"]
29-
}
30-
31-
# Get all compliance report details for the given resource group
32-
data "powerflex_compliance_report_resource_group" "complianceReport" {
33-
resource_group_id = "ID"
34-
}
35-
36-
# Get compliance report details for the given resource group filtered by given ipaddresses
37-
data "powerflex_compliance_report_resource_group" "complianceReport" {
38-
resource_group_id = "ID"
39-
# this datasource supports multiple filters like ip_addresses, host_names, service_tags, resource_ids, compliant
40-
# and gives an intersection of the results
41-
filter {
42-
ip_addresses = ["10.xxx.xxx.xx", "10.xxx.xxx.xx"]
43-
}
44-
}
45-
46-
# Get compliance report details for the given resource group filtered by resource ids and compliant status
47-
data "powerflex_compliance_report_resource_group" "complianceReport" {
48-
resource_group_id = "ID"
49-
# this datasource supports multiple filters like ip_addresses, host_names, service_tags, resource_ids, compliant
50-
# and gives an intersection of the results
51-
filter {
52-
resource_ids = ["resourceid1", "resourceid2"]
53-
compliant = true
54-
}
55-
}
56-
57-
# Get compliance report details for the given resource group filtered by compliant resources
58-
data "powerflex_compliance_report_resource_group" "complianceReport" {
59-
resource_group_id = "ID"
60-
# this datasource supports multiple filters like ip_addresses, host_names, service_tags, resource_ids, compliant
61-
# and gives an intersection of the results
62-
filter {
63-
compliant = true
64-
}
65-
}
66-
67-
# Get compliance report details for the given resource group filtered by hostnames
68-
data "powerflex_compliance_report_resource_group" "complianceReport" {
69-
resource_group_id = "ID"
70-
# this datasource supports multiple filters like ip_addresses, host_names, service_tags, resource_ids, compliant
71-
# and gives an intersection of the results
72-
filter {
73-
host_names = ["hostname1", "hostname2"]
74-
}
75-
}
76-
77-
# Get compliance report details for the given resource group filtered by service tags
78-
data "powerflex_compliance_report_resource_group" "complianceReport" {
79-
resource_group_id = "ID"
80-
# this datasource supports multiple filters like ip_addresses, host_names, service_tags, resource_ids, compliant
81-
# and gives an intersection of the results
82-
filter {
83-
service_tags = ["servicetag1", "servicetag2"]
84-
}
85-
}
86-
87-
# Get compliance report details for the given resource group filtered by resource ids
88-
data "powerflex_compliance_report_resource_group" "complianceReport" {
89-
resource_group_id = "ID"
90-
# this datasource supports multiple filters like ip_addresses, host_names, service_tags, resource_ids, compliant
91-
# and gives an intersection of the results
92-
filter {
93-
resource_ids = ["resourceid1", "resourceid2"]
94-
}
95-
}
20+
data "powerflex_compliance_report_resource_group" "example1" {
21+
}
22+
23+
# this datasource supports multiple filters like ip_address, host_name, service_tag, compliant,etc.
24+
# Note: If both filters are used simultaneously, the results will include any records that match either of the filters.
25+
# data "powerflex_compliance_report_resource_group" "complianceReport" {
26+
# filter {
27+
# firmware_repository_name = ["name1", "name2"]
28+
# device_type = ["devicetype1", "devicetype2"]
29+
# model = ["model1", "model2"]
30+
# resource_ids = ["resourceid1", "resourceid2"]
31+
# service_tag = ["servicetag1", "servicetag2"]
32+
# compliant = true
33+
# embedded_report = true
34+
# can_update = true
35+
# available = true
36+
# device_state = ["devicestate1", "devicestate2"]
37+
# managed_state = ["managedstate1", "managedstate2"]
38+
# host_name = ["hostname1", "hostname2"]
39+
# id = ["id1", "id2"]
40+
# ip_address = ["ip1", "ip2"]
41+
# }
42+
# }
9643

9744
output "result" {
98-
value = data.powerflex_compliance_report_resource_group.complianceReport
45+
value = data.powerflex_compliance_report_resource_group.example1
9946
}

powerflex/helper/compliance_report_resource_group_helper.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ limitations under the License.
1818
package helper
1919

2020
import (
21-
"fmt"
2221
"terraform-provider-powerflex/powerflex/models"
2322

2423
scaleiotypes "github.com/dell/goscaleio/types/v1"
@@ -81,26 +80,3 @@ func GetComplianceReportComponentVersionInfo(versionInfo scaleiotypes.Compliance
8180
FirmwareLevel: types.StringValue(versionInfo.FirmwareLevel),
8281
}
8382
}
84-
85-
// GetFilteredComplianceReports returns a list of compliance reports that match the filter
86-
func GetFilteredComplianceReports(complianceReports []scaleiotypes.ComplianceReport, filter models.ComplianceReportFilterType) ([]scaleiotypes.ComplianceReport, error) {
87-
var matchingReports []scaleiotypes.ComplianceReport
88-
89-
for _, report := range complianceReports {
90-
ipAddressesMatch := filter.IPAddresses.IsNull() || SetContains(filter.IPAddresses, report.IPAddress)
91-
serviceTagsMatch := filter.ServiceTags.IsNull() || SetContains(filter.ServiceTags, report.ServiceTag)
92-
hostNamesMatch := filter.HostNames.IsNull() || SetContains(filter.HostNames, report.HostName)
93-
resourceIDsMatch := filter.ResourceIDs.IsNull() || SetContains(filter.ResourceIDs, report.ID)
94-
compliantMatch := filter.Compliant.IsNull() || filter.Compliant.ValueBool() == report.Compliant
95-
96-
if ipAddressesMatch && serviceTagsMatch && hostNamesMatch && resourceIDsMatch && compliantMatch {
97-
matchingReports = append(matchingReports, report)
98-
}
99-
}
100-
101-
if len(matchingReports) == 0 {
102-
return nil, fmt.Errorf("no compliance reports found matching the filter: %+v", filter)
103-
}
104-
105-
return matchingReports, nil
106-
}

powerflex/models/complaince_report_resource_group.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,24 @@ import (
2525
type ComplianceReportResourceGroupDatasource struct {
2626
ComplianceReports []ComplianceReportResourceGroup `tfsdk:"compliance_reports"`
2727
ID types.String `tfsdk:"id"`
28-
ResourceGroupID types.String `tfsdk:"resource_group_id"`
2928
ComplianceReportFilter *ComplianceReportFilterType `tfsdk:"filter"`
3029
}
3130

3231
// ComplianceReportFilterType defines the filter for datasource
3332
type ComplianceReportFilterType struct {
34-
IPAddresses types.Set `tfsdk:"ip_addresses"`
35-
ServiceTags types.Set `tfsdk:"service_tags"`
36-
Compliant types.Bool `tfsdk:"compliant"`
37-
HostNames types.Set `tfsdk:"host_names"`
38-
ResourceIDs types.Set `tfsdk:"resource_ids"`
33+
ServiceTag []types.String `tfsdk:"service_tag"`
34+
IPAddress []types.String `tfsdk:"ip_address"`
35+
FirmwareRepositoryName []types.String `tfsdk:"firmware_repository_name"`
36+
Compliant types.Bool `tfsdk:"compliant"`
37+
DeviceType []types.String `tfsdk:"device_type"`
38+
Model []types.String `tfsdk:"model"`
39+
Available types.Bool `tfsdk:"available"`
40+
ManagedState []types.String `tfsdk:"managed_state"`
41+
EmbeddedReport types.Bool `tfsdk:"embedded_report"`
42+
DeviceState []types.String `tfsdk:"device_state"`
43+
ID []types.String `tfsdk:"id"`
44+
HostName []types.String `tfsdk:"host_name"`
45+
CanUpdate types.Bool `tfsdk:"can_update"`
3946
}
4047

4148
// ComplianceReportResourceGroup defines the compliance report for a service.

powerflex/provider/compliance_report_resource_group_datasource.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func (d *complianceReportResourceGroupDataSource) Configure(_ context.Context, r
7878
func (d *complianceReportResourceGroupDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
7979
tflog.Info(ctx, "Started compliance report data source read method")
8080

81+
var complianceReports, complianceReportAll []scaleiotypes.ComplianceReport
8182
var state models.ComplianceReportResourceGroupDatasource
8283

8384
diags := req.Config.Get(ctx, &state)
@@ -86,29 +87,45 @@ func (d *complianceReportResourceGroupDataSource) Read(ctx context.Context, req
8687
return
8788
}
8889

89-
// Get all Compliance Reports
90-
complianceReportList, err := d.gatewayClient.GetServiceComplianceDetails(state.ResourceGroupID.ValueString())
90+
//Get all resource groups
91+
serviceDetails, err := d.gatewayClient.GetAllServiceDetails()
9192
if err != nil {
92-
resp.Diagnostics.AddError(
93-
"Error in getting compliance report for resource group.",
94-
err.Error(),
95-
)
93+
resp.Diagnostics.AddError("Error in getting service details", err.Error())
9694
return
9795
}
98-
complianceReports := make([]scaleiotypes.ComplianceReport, 0)
96+
97+
for _, service := range serviceDetails {
98+
resourceGroupID := types.StringValue(service.ID)
99+
// Get all Compliance Reports
100+
complianceReport, err := d.gatewayClient.GetServiceComplianceDetails(resourceGroupID.ValueString())
101+
if err != nil {
102+
resp.Diagnostics.AddError(
103+
"Error in getting compliance report(s) for resource group.",
104+
err.Error(),
105+
)
106+
return
107+
}
108+
109+
complianceReportAll = append(complianceReportAll, complianceReport...)
110+
}
111+
99112
if state.ComplianceReportFilter == nil {
100113
// add all reports
101-
complianceReports = append(complianceReports, complianceReportList...)
114+
complianceReports = append(complianceReports, complianceReportAll...)
102115
} else {
103116
// Get filtered reports
104-
complianceReports, err = helper.GetFilteredComplianceReports(complianceReportList, *state.ComplianceReportFilter)
117+
complianceReportsFiltered, err := helper.GetDataSourceByValue(*state.ComplianceReportFilter, complianceReportAll)
105118
if err != nil {
106119
resp.Diagnostics.AddError(
107120
"Error in getting compliance report for resource group for given filter.",
108121
err.Error(),
109122
)
110123
return
111124
}
125+
// Convert filtered reports to compliance reports
126+
for _, val := range complianceReportsFiltered {
127+
complianceReports = append(complianceReports, val.(scaleiotypes.ComplianceReport))
128+
}
112129
}
113130

114131
state.ComplianceReports = helper.GetComplianceReportsModel(complianceReports)

0 commit comments

Comments
 (0)