Skip to content

Commit 6e024b1

Browse files
GilTeraSkyramya-bangera
authored andcommitted
[Feature-Inspection] Client/Models/Schema, implementation, tests & Docs
Signed-off-by: GilTS <gil@terasky.com>
1 parent 8e66181 commit 6e024b1

39 files changed

+1685
-13
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- 'v*'
77

88
env:
9-
BUILD_TAGS: 'akscluster cluster clustergroup credential ekscluster gitrepository iampolicy kustomization namespace custompolicy imagepolicy networkpolicy quotapolicy securitypolicy sourcesecret workspace tanzupackage tanzupackages packagerepository packageinstall clustersecret integration mutationpolicy backupschedule targetlocation dataprotection tanzukubernetescluster clusterclass managementcluster provisioner'
9+
BUILD_TAGS: 'akscluster cluster clustergroup credential ekscluster gitrepository iampolicy kustomization namespace custompolicy imagepolicy networkpolicy quotapolicy securitypolicy sourcesecret workspace tanzupackage tanzupackages packagerepository packageinstall clustersecret integration mutationpolicy backupschedule targetlocation dataprotection tanzukubernetescluster clusterclass managementcluster provisioner inspections'
1010

1111
jobs:
1212
goreleaser:

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Test and coverage
33
on: [pull_request, push]
44

55
env:
6-
BUILD_TAGS: 'akscluster cluster clustergroup credential ekscluster gitrepository iampolicy kustomization namespace custompolicy imagepolicy networkpolicy quotapolicy securitypolicy sourcesecret workspace tanzupackage tanzupackages packagerepository packageinstall clustersecret integration mutationpolicy backupschedule targetlocation dataprotection tanzukubernetescluster clusterclass managementcluster provisioner'
6+
BUILD_TAGS: 'akscluster cluster clustergroup credential ekscluster gitrepository iampolicy kustomization namespace custompolicy imagepolicy networkpolicy quotapolicy securitypolicy sourcesecret workspace tanzupackage tanzupackages packagerepository packageinstall clustersecret integration mutationpolicy backupschedule targetlocation dataprotection tanzukubernetescluster clusterclass managementcluster provisioner inspections'
77
jobs:
88
build:
99
name: Test and coverage
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
Title: "Inspection Results Data Source"
3+
Description: |-
4+
Get inspection results
5+
---
6+
7+
# Inspection Results Data Source
8+
9+
This data source enables users to get a specific cluster inspection results.
10+
11+
## Example Usage
12+
13+
```terraform
14+
data "tanzu-mission-control_inspection_results" "demo" {
15+
management_cluster_name = "MGMT_CLS_NAME"
16+
provisioner_name = "PROVISIONER_NAME"
17+
cluster_name = "CLS_NAME"
18+
name = "INSPECTION_NAME"
19+
}
20+
21+
output "inspection_report" {
22+
value = jsondecode(data.tanzu-mission-control_inspection_results.demo.status.report)
23+
}
24+
```
25+
26+
<!-- schema generated by tfplugindocs -->
27+
## Schema
28+
29+
### Required
30+
31+
- `cluster_name` (String) Cluster name.
32+
- `management_cluster_name` (String) Management cluster name.
33+
- `name` (String) Inspection name.
34+
- `provisioner_name` (String) Cluster provisioner name.
35+
36+
### Read-Only
37+
38+
- `id` (String) The ID of this resource.
39+
- `status` (Map of String) Status of inspection resource
40+
41+
## Status Field ##
42+
43+
Status field is a key-value pair of type string-string and it contains the following keys:
44+
* phase - The phase which the inspection is in.
45+
* phase_info - Information about the phase.
46+
* report - JSON encoded string of the report data in the inspection.

docs/data-sources/inspections.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
Title: "Inspections Data Source"
3+
Description: |-
4+
List cluster inspections
5+
---
6+
7+
# Inspections Data Source
8+
9+
This data source enables users to list cluster inspections.
10+
11+
## Example Usage
12+
13+
```terraform
14+
data "tanzu-mission-control_inspections" "demo" {
15+
management_cluster_name = "MGMT_CLS_NAME"
16+
provisioner_name = "PROVISIONER_NAME"
17+
cluster_name = "CLS_NAME"
18+
}
19+
20+
output "inspections" {
21+
value = data.tanzu-mission-control_inspections.demo.inspections
22+
}
23+
```
24+
25+
<!-- schema generated by tfplugindocs -->
26+
## Schema
27+
28+
### Required
29+
30+
- `cluster_name` (String) Cluster name.
31+
- `management_cluster_name` (String) Management cluster name.
32+
- `provisioner_name` (String) Cluster provisioner name.
33+
34+
### Optional
35+
36+
- `name` (String) Inspection name.
37+
38+
### Read-Only
39+
40+
- `id` (String) The ID of this resource.
41+
- `inspections` (List of Object) Inspection objects. (see [below for nested schema](#nestedatt--inspections))
42+
- `total_count` (String) Total count of inspections returned.
43+
44+
<a id="nestedatt--inspections"></a>
45+
### Nested Schema for `inspections`
46+
47+
Read-Only:
48+
49+
- `cluster_name` (String)
50+
- `management_cluster_name` (String)
51+
- `name` (String)
52+
- `provisioner_name` (String)
53+
- `status` (Map of String)
54+
55+
## Status Field ##
56+
57+
Status field is a key-value pair of type string-string and it contains the following keys:
58+
* phase - The phase which the inspection is in.
59+
* phase_info - Information about the phase.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
data "tanzu-mission-control_inspection_results" "demo" {
2+
management_cluster_name = "MGMT_CLS_NAME"
3+
provisioner_name = "PROVISIONER_NAME"
4+
cluster_name = "CLS_NAME"
5+
name = "INSPECTION_NAME"
6+
}
7+
8+
output "inspection_report" {
9+
value = jsondecode(data.tanzu-mission-control_inspection_results.demo.status.report)
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
data "tanzu-mission-control_inspections" "demo" {
2+
management_cluster_name = "MGMT_CLS_NAME"
3+
provisioner_name = "PROVISIONER_NAME"
4+
cluster_name = "CLS_NAME"
5+
}
6+
7+
output "inspections" {
8+
value = data.tanzu-mission-control_inspections.demo.inspections
9+
}

internal/client/http_client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
credentialclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/credential"
4141
eksclusterclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/ekscluster"
4242
eksnodepoolclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/ekscluster/nodepool"
43+
inspectionsclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/inspections"
4344
integrationclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/integration"
4445
kubeconfigclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/kubeconfig"
4546
secretclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/kubernetessecret"
@@ -137,6 +138,7 @@ func newHTTPClient(httpClient *transport.Client) *TanzuMissionControl {
137138
ClusterGroupSecretResourceService: secretclustergroupclient.New(httpClient),
138139
ClusterGroupSecretExportResourceService: secretexportclustergroupclient.New(httpClient),
139140
KubeConfigResourceService: kubeconfigclient.New(httpClient),
141+
InspectionsResourceService: inspectionsclient.New(httpClient),
140142
BackupScheduleService: backupscheduleclient.New(httpClient),
141143
DataProtectionService: dataprotectionclient.New(httpClient),
142144
TargetLocationService: targetlocationclient.New(httpClient),
@@ -202,4 +204,5 @@ type TanzuMissionControl struct {
202204
ClusterClassResourceService clusterclassclient.ClientService
203205
TanzuKubernetesClusterResourceService tanzukubernetesclusterclient.ClientService
204206
ProvisionerResourceService provisionerclient.ClientService
207+
InspectionsResourceService inspectionsclient.ClientService
205208
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
Copyright © 2023 VMware, Inc. All Rights Reserved.
3+
SPDX-License-Identifier: MPL-2.0
4+
*/
5+
6+
package inspectionsclient
7+
8+
import (
9+
"net/url"
10+
11+
"github.com/pkg/errors"
12+
13+
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/transport"
14+
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper"
15+
inspectionsmodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/inspections"
16+
)
17+
18+
const (
19+
// URL Paths.
20+
clustersAPIVersionAndGroupPath = "v1alpha1/clusters"
21+
inspectionsPath = "inspection/scans"
22+
23+
// Query Params.
24+
managementClusterNameListInspectionsParam = "searchScope.managementClusterName"
25+
provisionerNameListInspectionsParam = "searchScope.provisionerName"
26+
managementClusterNameGetInspectionParam = "fullName.managementClusterName"
27+
provisionerNameGetInspectionParam = "fullName.provisionerName"
28+
)
29+
30+
// New creates a new inspections resource service API client.
31+
func New(transport *transport.Client) ClientService {
32+
return &Client{Client: transport}
33+
}
34+
35+
/*
36+
Client for inspections resource service API.
37+
*/
38+
type Client struct {
39+
*transport.Client
40+
}
41+
42+
// ClientService is the interface for Client methods.
43+
type ClientService interface {
44+
InspectionsResourceServiceList(fn *inspectionsmodel.VmwareTanzuManageV1alpha1ClusterInspectionScanFullName) (*inspectionsmodel.VmwareTanzuManageV1alpha1ClusterInspectionScanListData, error)
45+
46+
InspectionsResourceServiceGet(fn *inspectionsmodel.VmwareTanzuManageV1alpha1ClusterInspectionScanFullName) (*inspectionsmodel.VmwareTanzuManageV1alpha1ClusterInspectionScanData, error)
47+
}
48+
49+
/*
50+
InspectionsResourceServiceList lists inspections.
51+
*/
52+
func (c *Client) InspectionsResourceServiceList(fn *inspectionsmodel.VmwareTanzuManageV1alpha1ClusterInspectionScanFullName) (*inspectionsmodel.VmwareTanzuManageV1alpha1ClusterInspectionScanListData, error) {
53+
resp := &inspectionsmodel.VmwareTanzuManageV1alpha1ClusterInspectionScanListData{}
54+
55+
if fn.ManagementClusterName == "" || fn.ProvisionerName == "" || fn.ClusterName == "" {
56+
return nil, errors.New("Management Cluster Name, Provisioner Name and Cluster Name must be provided.")
57+
}
58+
59+
requestURL := helper.ConstructRequestURL(clustersAPIVersionAndGroupPath, fn.ClusterName, inspectionsPath)
60+
queryParams := url.Values{}
61+
62+
queryParams.Add(managementClusterNameListInspectionsParam, fn.ManagementClusterName)
63+
queryParams.Add(provisionerNameListInspectionsParam, fn.ProvisionerName)
64+
65+
requestURL = requestURL.AppendQueryParams(queryParams)
66+
67+
err := c.Get(requestURL.String(), resp)
68+
69+
return resp, err
70+
}
71+
72+
/*
73+
InspectionsResourceServiceGet returns an inspection.
74+
*/
75+
func (c *Client) InspectionsResourceServiceGet(fn *inspectionsmodel.VmwareTanzuManageV1alpha1ClusterInspectionScanFullName) (*inspectionsmodel.VmwareTanzuManageV1alpha1ClusterInspectionScanData, error) {
76+
resp := &inspectionsmodel.VmwareTanzuManageV1alpha1ClusterInspectionScanData{}
77+
78+
if fn.ManagementClusterName == "" || fn.ProvisionerName == "" || fn.ClusterName == "" || fn.Name == "" {
79+
return nil, errors.New("Management Cluster Name, Provisioner Name, Cluster Name and Inspection Name must be provided.")
80+
}
81+
82+
requestURL := helper.ConstructRequestURL(clustersAPIVersionAndGroupPath, fn.ClusterName, inspectionsPath, fn.Name)
83+
queryParams := url.Values{}
84+
85+
queryParams.Add(managementClusterNameGetInspectionParam, fn.ManagementClusterName)
86+
queryParams.Add(provisionerNameGetInspectionParam, fn.ProvisionerName)
87+
88+
requestURL = requestURL.AppendQueryParams(queryParams)
89+
90+
err := c.Get(requestURL.String(), resp)
91+
92+
return resp, err
93+
}

internal/helper/converter/construct_model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (converter *TFSchemaModelConverter[T]) modelHandleBlockMap(modelJSON *Block
6565
}
6666
}
6767

68-
for key, value := range definedKeysMapValue {
68+
for key, value := range *definedKeysMapValue {
6969
converter.buildModelField(modelJSON, rootSchemaDict[key], value, arrIndexer)
7070
}
7171
}

internal/helper/converter/construct_tf_schema.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (converter *TFSchemaModelConverter[T]) tfHandleBlockMap(modelJSONData *map[
7373
}
7474
}
7575

76-
newBlock := BlockToStruct(mapValue.(*Map).Copy([]string{AllMapKeysFieldMarker}))
76+
newBlock := BlockToStruct(*(mapValue.(*Map).Copy([]string{AllMapKeysFieldMarker})))
7777
mapValue = &newBlock
7878
}
7979

0 commit comments

Comments
 (0)