Skip to content

Commit

Permalink
Implement ODS runbook report data source
Browse files Browse the repository at this point in the history
Signed-off-by: Kobi Samoray <ksamoray@vmware.com>
  • Loading branch information
ksamoray committed Jan 23, 2024
1 parent 2efb4ac commit aa24f8b
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 73 deletions.
103 changes: 103 additions & 0 deletions nsxt/data_source_nsxt_policy_ods_runbook_invocation_report.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/* Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0 */

package nsxt

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/sha/runbook_invocations"
)

func dataSourceNsxtPolicyODSRunbookInvocationReport() *schema.Resource {
return &schema.Resource{
Read: dataSourceNsxtPolicyODSPRunbookInvocationReportRead,

Schema: map[string]*schema.Schema{
"invocation_id": {
Type: schema.TypeString,
Required: true,
Description: "UUID of runbook invocation",
},
"target_node": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "Identifier of an appliance node or transport node",
},
"error_detail": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "The report error detail",
},
"invalid_reason": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "Invalid report reason",
},
"recommendation_code": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
Description: "Online Diagnostic System recommendation code",
},
"recommendation_message": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "Online Diagnostic System recommendation message",
},
"result_code": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
Description: "Online Diagnostic System result code",
},
"result_message": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "Online Diagnostic System result message",
},
"request_status": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "Request status of a runbook invocation",
},
"operation_state": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "Operation state of a runbook invocation on the target node",
},
},
}
}

func dataSourceNsxtPolicyODSPRunbookInvocationReportRead(d *schema.ResourceData, m interface{}) error {
connector := getPolicyConnector(m)
invocationID := d.Get("invocation_id").(string)
client := runbook_invocations.NewReportClient(connector)

obj, err := client.Get(invocationID)
if err != nil {
return handleDataSourceReadError(d, "OdsRunbookInvocationReport", invocationID, err)
}

d.SetId(invocationID)
d.Set("target_node", obj.TargetNode)
d.Set("error_detail", obj.ErrorDetail)
d.Set("invalid_reason", obj.InvalidReason)
d.Set("recommendation_code", obj.RecommendationCode)
d.Set("recommendation_message", obj.RecommendationMessage)
d.Set("result_code", obj.ResultCode)
d.Set("result_message", obj.ResultMessage)
if obj.Status != nil {
d.Set("request_status", obj.Status.RequestStatus)
d.Set("operation_state", obj.Status.OperationState)
}

return nil
}
43 changes: 43 additions & 0 deletions nsxt/data_source_nsxt_policy_ods_runbook_invocation_report_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* Copyright © 2023 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0 */

package nsxt

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccResourceNsxtPolicyODSRunbookInvocationReport_basic(t *testing.T) {
name := getAccTestResourceName()
testResourceName := "data.nsxt_policy_ods_runbook_invocation_report.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccOnlyLocalManager(t)
testAccPreCheck(t)
testAccNSXVersion(t, "4.1.1")
testAccEnvDefined(t, "NSXT_TEST_HOST_TRANSPORT_NODE")
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccNsxtPolicyODSRunbookInvocationReportReadTemplate(name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(testResourceName, "target_node"),
resource.TestCheckResourceAttrSet(testResourceName, "request_status"),
resource.TestCheckResourceAttrSet(testResourceName, "operation_state"),
),
},
},
})
}

func testAccNsxtPolicyODSRunbookInvocationReportReadTemplate(name string) string {
return testAccNsxtPolicyODSRunbookInvocationCreateTemplate(name, "ControllerConn", "") + fmt.Sprintf(`
data "nsxt_policy_ods_runbook_invocation_report" "test" {
invocation_id = nsxt_policy_ods_runbook_invocation.test.id
}`)
}
147 changes: 74 additions & 73 deletions nsxt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,79 +225,80 @@ func Provider() *schema.Provider {
},

DataSourcesMap: map[string]*schema.Resource{
"nsxt_provider_info": dataSourceNsxtProviderInfo(),
"nsxt_transport_zone": dataSourceNsxtTransportZone(),
"nsxt_switching_profile": dataSourceNsxtSwitchingProfile(),
"nsxt_logical_tier0_router": dataSourceNsxtLogicalTier0Router(),
"nsxt_logical_tier1_router": dataSourceNsxtLogicalTier1Router(),
"nsxt_mac_pool": dataSourceNsxtMacPool(),
"nsxt_ns_group": dataSourceNsxtNsGroup(),
"nsxt_ns_groups": dataSourceNsxtNsGroups(),
"nsxt_ns_service": dataSourceNsxtNsService(),
"nsxt_ns_services": dataSourceNsxtNsServices(),
"nsxt_edge_cluster": dataSourceNsxtEdgeCluster(),
"nsxt_certificate": dataSourceNsxtCertificate(),
"nsxt_ip_pool": dataSourceNsxtIPPool(),
"nsxt_firewall_section": dataSourceNsxtFirewallSection(),
"nsxt_management_cluster": dataSourceNsxtManagementCluster(),
"nsxt_policy_edge_cluster": dataSourceNsxtPolicyEdgeCluster(),
"nsxt_policy_edge_node": dataSourceNsxtPolicyEdgeNode(),
"nsxt_policy_tier0_gateway": dataSourceNsxtPolicyTier0Gateway(),
"nsxt_policy_tier1_gateway": dataSourceNsxtPolicyTier1Gateway(),
"nsxt_policy_service": dataSourceNsxtPolicyService(),
"nsxt_policy_realization_info": dataSourceNsxtPolicyRealizationInfo(),
"nsxt_policy_segment_realization": dataSourceNsxtPolicySegmentRealization(),
"nsxt_policy_transport_zone": dataSourceNsxtPolicyTransportZone(),
"nsxt_policy_ip_discovery_profile": dataSourceNsxtPolicyIPDiscoveryProfile(),
"nsxt_policy_spoofguard_profile": dataSourceNsxtPolicySpoofGuardProfile(),
"nsxt_policy_qos_profile": dataSourceNsxtPolicyQosProfile(),
"nsxt_policy_ipv6_ndra_profile": dataSourceNsxtPolicyIpv6NdraProfile(),
"nsxt_policy_ipv6_dad_profile": dataSourceNsxtPolicyIpv6DadProfile(),
"nsxt_policy_gateway_qos_profile": dataSourceNsxtPolicyGatewayQosProfile(),
"nsxt_policy_segment_security_profile": dataSourceNsxtPolicySegmentSecurityProfile(),
"nsxt_policy_mac_discovery_profile": dataSourceNsxtPolicyMacDiscoveryProfile(),
"nsxt_policy_vm": dataSourceNsxtPolicyVM(),
"nsxt_policy_vms": dataSourceNsxtPolicyVMs(),
"nsxt_policy_lb_app_profile": dataSourceNsxtPolicyLBAppProfile(),
"nsxt_policy_lb_client_ssl_profile": dataSourceNsxtPolicyLBClientSslProfile(),
"nsxt_policy_lb_server_ssl_profile": dataSourceNsxtPolicyLBServerSslProfile(),
"nsxt_policy_lb_monitor": dataSourceNsxtPolicyLBMonitor(),
"nsxt_policy_certificate": dataSourceNsxtPolicyCertificate(),
"nsxt_policy_lb_persistence_profile": dataSourceNsxtPolicyLbPersistenceProfile(),
"nsxt_policy_vni_pool": dataSourceNsxtPolicyVniPool(),
"nsxt_policy_ip_block": dataSourceNsxtPolicyIPBlock(),
"nsxt_policy_ip_pool": dataSourceNsxtPolicyIPPool(),
"nsxt_policy_site": dataSourceNsxtPolicySite(),
"nsxt_policy_gateway_policy": dataSourceNsxtPolicyGatewayPolicy(),
"nsxt_policy_security_policy": dataSourceNsxtPolicySecurityPolicy(),
"nsxt_policy_group": dataSourceNsxtPolicyGroup(),
"nsxt_policy_context_profile": dataSourceNsxtPolicyContextProfile(),
"nsxt_policy_dhcp_server": dataSourceNsxtPolicyDhcpServer(),
"nsxt_policy_bfd_profile": dataSourceNsxtPolicyBfdProfile(),
"nsxt_policy_intrusion_service_profile": dataSourceNsxtPolicyIntrusionServiceProfile(),
"nsxt_policy_lb_service": dataSourceNsxtPolicyLbService(),
"nsxt_policy_gateway_locale_service": dataSourceNsxtPolicyGatewayLocaleService(),
"nsxt_policy_bridge_profile": dataSourceNsxtPolicyBridgeProfile(),
"nsxt_policy_ipsec_vpn_local_endpoint": dataSourceNsxtPolicyIPSecVpnLocalEndpoint(),
"nsxt_policy_ipsec_vpn_service": dataSourceNsxtPolicyIPSecVpnService(),
"nsxt_policy_l2_vpn_service": dataSourceNsxtPolicyL2VpnService(),
"nsxt_policy_segment": dataSourceNsxtPolicySegment(),
"nsxt_policy_project": dataSourceNsxtPolicyProject(),
"nsxt_policy_gateway_dns_forwarder": dataSourceNsxtPolicyGatewayDNSForwarder(),
"nsxt_policy_gateway_prefix_list": dataSourceNsxtPolicyGatewayPrefixList(),
"nsxt_policy_gateway_route_map": dataSourceNsxtPolicyGatewayRouteMap(),
"nsxt_policy_uplink_host_switch_profile": dataSourceNsxtUplinkHostSwitchProfile(),
"nsxt_compute_manager": dataSourceNsxtComputeManager(),
"nsxt_transport_node_realization": dataSourceNsxtTransportNodeRealization(),
"nsxt_failure_domain": dataSourceNsxtFailureDomain(),
"nsxt_compute_collection": dataSourceNsxtComputeCollection(),
"nsxt_compute_manager_realization": dataSourceNsxtComputeManagerRealization(),
"nsxt_policy_host_transport_node": dataSourceNsxtPolicyHostTransportNode(),
"nsxt_manager_cluster_node": dataSourceNsxtManagerClusterNode(),
"nsxt_policy_host_transport_node_profile": dataSourceNsxtPolicyHostTransportNodeProfile(),
"nsxt_transport_node": dataSourceNsxtEdgeTransportNode(),
"nsxt_discover_node": dataSourceNsxtDiscoverNode(),
"nsxt_policy_ods_pre_defined_runbook": dataSourceNsxtPolicyODSPreDefinedRunbook(),
"nsxt_provider_info": dataSourceNsxtProviderInfo(),
"nsxt_transport_zone": dataSourceNsxtTransportZone(),
"nsxt_switching_profile": dataSourceNsxtSwitchingProfile(),
"nsxt_logical_tier0_router": dataSourceNsxtLogicalTier0Router(),
"nsxt_logical_tier1_router": dataSourceNsxtLogicalTier1Router(),
"nsxt_mac_pool": dataSourceNsxtMacPool(),
"nsxt_ns_group": dataSourceNsxtNsGroup(),
"nsxt_ns_groups": dataSourceNsxtNsGroups(),
"nsxt_ns_service": dataSourceNsxtNsService(),
"nsxt_ns_services": dataSourceNsxtNsServices(),
"nsxt_edge_cluster": dataSourceNsxtEdgeCluster(),
"nsxt_certificate": dataSourceNsxtCertificate(),
"nsxt_ip_pool": dataSourceNsxtIPPool(),
"nsxt_firewall_section": dataSourceNsxtFirewallSection(),
"nsxt_management_cluster": dataSourceNsxtManagementCluster(),
"nsxt_policy_edge_cluster": dataSourceNsxtPolicyEdgeCluster(),
"nsxt_policy_edge_node": dataSourceNsxtPolicyEdgeNode(),
"nsxt_policy_tier0_gateway": dataSourceNsxtPolicyTier0Gateway(),
"nsxt_policy_tier1_gateway": dataSourceNsxtPolicyTier1Gateway(),
"nsxt_policy_service": dataSourceNsxtPolicyService(),
"nsxt_policy_realization_info": dataSourceNsxtPolicyRealizationInfo(),
"nsxt_policy_segment_realization": dataSourceNsxtPolicySegmentRealization(),
"nsxt_policy_transport_zone": dataSourceNsxtPolicyTransportZone(),
"nsxt_policy_ip_discovery_profile": dataSourceNsxtPolicyIPDiscoveryProfile(),
"nsxt_policy_spoofguard_profile": dataSourceNsxtPolicySpoofGuardProfile(),
"nsxt_policy_qos_profile": dataSourceNsxtPolicyQosProfile(),
"nsxt_policy_ipv6_ndra_profile": dataSourceNsxtPolicyIpv6NdraProfile(),
"nsxt_policy_ipv6_dad_profile": dataSourceNsxtPolicyIpv6DadProfile(),
"nsxt_policy_gateway_qos_profile": dataSourceNsxtPolicyGatewayQosProfile(),
"nsxt_policy_segment_security_profile": dataSourceNsxtPolicySegmentSecurityProfile(),
"nsxt_policy_mac_discovery_profile": dataSourceNsxtPolicyMacDiscoveryProfile(),
"nsxt_policy_vm": dataSourceNsxtPolicyVM(),
"nsxt_policy_vms": dataSourceNsxtPolicyVMs(),
"nsxt_policy_lb_app_profile": dataSourceNsxtPolicyLBAppProfile(),
"nsxt_policy_lb_client_ssl_profile": dataSourceNsxtPolicyLBClientSslProfile(),
"nsxt_policy_lb_server_ssl_profile": dataSourceNsxtPolicyLBServerSslProfile(),
"nsxt_policy_lb_monitor": dataSourceNsxtPolicyLBMonitor(),
"nsxt_policy_certificate": dataSourceNsxtPolicyCertificate(),
"nsxt_policy_lb_persistence_profile": dataSourceNsxtPolicyLbPersistenceProfile(),
"nsxt_policy_vni_pool": dataSourceNsxtPolicyVniPool(),
"nsxt_policy_ip_block": dataSourceNsxtPolicyIPBlock(),
"nsxt_policy_ip_pool": dataSourceNsxtPolicyIPPool(),
"nsxt_policy_site": dataSourceNsxtPolicySite(),
"nsxt_policy_gateway_policy": dataSourceNsxtPolicyGatewayPolicy(),
"nsxt_policy_security_policy": dataSourceNsxtPolicySecurityPolicy(),
"nsxt_policy_group": dataSourceNsxtPolicyGroup(),
"nsxt_policy_context_profile": dataSourceNsxtPolicyContextProfile(),
"nsxt_policy_dhcp_server": dataSourceNsxtPolicyDhcpServer(),
"nsxt_policy_bfd_profile": dataSourceNsxtPolicyBfdProfile(),
"nsxt_policy_intrusion_service_profile": dataSourceNsxtPolicyIntrusionServiceProfile(),
"nsxt_policy_lb_service": dataSourceNsxtPolicyLbService(),
"nsxt_policy_gateway_locale_service": dataSourceNsxtPolicyGatewayLocaleService(),
"nsxt_policy_bridge_profile": dataSourceNsxtPolicyBridgeProfile(),
"nsxt_policy_ipsec_vpn_local_endpoint": dataSourceNsxtPolicyIPSecVpnLocalEndpoint(),
"nsxt_policy_ipsec_vpn_service": dataSourceNsxtPolicyIPSecVpnService(),
"nsxt_policy_l2_vpn_service": dataSourceNsxtPolicyL2VpnService(),
"nsxt_policy_segment": dataSourceNsxtPolicySegment(),
"nsxt_policy_project": dataSourceNsxtPolicyProject(),
"nsxt_policy_gateway_dns_forwarder": dataSourceNsxtPolicyGatewayDNSForwarder(),
"nsxt_policy_gateway_prefix_list": dataSourceNsxtPolicyGatewayPrefixList(),
"nsxt_policy_gateway_route_map": dataSourceNsxtPolicyGatewayRouteMap(),
"nsxt_policy_uplink_host_switch_profile": dataSourceNsxtUplinkHostSwitchProfile(),
"nsxt_compute_manager": dataSourceNsxtComputeManager(),
"nsxt_transport_node_realization": dataSourceNsxtTransportNodeRealization(),
"nsxt_failure_domain": dataSourceNsxtFailureDomain(),
"nsxt_compute_collection": dataSourceNsxtComputeCollection(),
"nsxt_compute_manager_realization": dataSourceNsxtComputeManagerRealization(),
"nsxt_policy_host_transport_node": dataSourceNsxtPolicyHostTransportNode(),
"nsxt_manager_cluster_node": dataSourceNsxtManagerClusterNode(),
"nsxt_policy_host_transport_node_profile": dataSourceNsxtPolicyHostTransportNodeProfile(),
"nsxt_transport_node": dataSourceNsxtEdgeTransportNode(),
"nsxt_discover_node": dataSourceNsxtDiscoverNode(),
"nsxt_policy_ods_pre_defined_runbook": dataSourceNsxtPolicyODSPreDefinedRunbook(),
"nsxt_policy_ods_runbook_invocation_report": dataSourceNsxtPolicyODSRunbookInvocationReport(),
},

ResourcesMap: map[string]*schema.Resource{
Expand Down
37 changes: 37 additions & 0 deletions website/docs/d/policy_ods_runbook_invocation_report.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
subcategory: "ODS Runbook"
layout: "nsxt"
page_title: "NSXT: nsxt_policy_ods_runbook_invocation_report"
description: Policy ODS runbook invocation report data source.
---

# nsxt_policy_ods_runbook_invocation_report

This data source provides information about policy ODS runbook invocation report on NSX.
This data source is applicable to NSX Policy Manager.

## Example Usage

```hcl
data "nsxt_policy_ods_runbook_invocation_report" "test" {
invocation_id = nsxt_policy_ods_runbook_invocation.test.id
}
```

## Argument Reference

* `invocation_id` - (Required) UUID of runbook invocation.

## Attributes Reference

In addition to arguments listed above, the following attributes are exported:

* `target_node` - Identifier of an appliance node or transport node.
* `error_detail` - The report error detail.
* `invalid_reason` - Invalid report reason.
* `recommendation_code` - Online Diagnostic System recommendation code.
* `recommendation_message` - Online Diagnostic System recommendation message.
* `result_code` - Online Diagnostic System result code.
* `result_message` - Online Diagnostic System result message.
* `request_status` - Request status of a runbook invocation.
* `operation_state` - Operation state of a runbook invocation on the target node.

0 comments on commit aa24f8b

Please sign in to comment.