|
| 1 | +/* Copyright © 2023 VMware, Inc. All Rights Reserved. |
| 2 | + SPDX-License-Identifier: MPL-2.0 */ |
| 3 | + |
| 4 | +package nsxt |
| 5 | + |
| 6 | +import ( |
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 8 | + "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/sha/runbook_invocations" |
| 9 | +) |
| 10 | + |
| 11 | +func dataSourceNsxtPolicyODSRunbookInvocationReport() *schema.Resource { |
| 12 | + return &schema.Resource{ |
| 13 | + Read: dataSourceNsxtPolicyODSPRunbookInvocationReportRead, |
| 14 | + |
| 15 | + Schema: map[string]*schema.Schema{ |
| 16 | + "invocation_id": { |
| 17 | + Type: schema.TypeString, |
| 18 | + Required: true, |
| 19 | + Description: "UUID of runbook invocation", |
| 20 | + }, |
| 21 | + "target_node": { |
| 22 | + Type: schema.TypeString, |
| 23 | + Computed: true, |
| 24 | + Optional: true, |
| 25 | + Description: "Identifier of an appliance node or transport node", |
| 26 | + }, |
| 27 | + "error_detail": { |
| 28 | + Type: schema.TypeString, |
| 29 | + Computed: true, |
| 30 | + Optional: true, |
| 31 | + Description: "The report error detail", |
| 32 | + }, |
| 33 | + "invalid_reason": { |
| 34 | + Type: schema.TypeString, |
| 35 | + Computed: true, |
| 36 | + Optional: true, |
| 37 | + Description: "Invalid report reason", |
| 38 | + }, |
| 39 | + "recommendation_code": { |
| 40 | + Type: schema.TypeInt, |
| 41 | + Computed: true, |
| 42 | + Optional: true, |
| 43 | + Description: "Online Diagnostic System recommendation code", |
| 44 | + }, |
| 45 | + "recommendation_message": { |
| 46 | + Type: schema.TypeString, |
| 47 | + Computed: true, |
| 48 | + Optional: true, |
| 49 | + Description: "Online Diagnostic System recommendation message", |
| 50 | + }, |
| 51 | + "result_code": { |
| 52 | + Type: schema.TypeInt, |
| 53 | + Computed: true, |
| 54 | + Optional: true, |
| 55 | + Description: "Online Diagnostic System result code", |
| 56 | + }, |
| 57 | + "result_message": { |
| 58 | + Type: schema.TypeString, |
| 59 | + Computed: true, |
| 60 | + Optional: true, |
| 61 | + Description: "Online Diagnostic System result message", |
| 62 | + }, |
| 63 | + "request_status": { |
| 64 | + Type: schema.TypeString, |
| 65 | + Computed: true, |
| 66 | + Optional: true, |
| 67 | + Description: "Request status of a runbook invocation", |
| 68 | + }, |
| 69 | + "operation_state": { |
| 70 | + Type: schema.TypeString, |
| 71 | + Computed: true, |
| 72 | + Optional: true, |
| 73 | + Description: "Operation state of a runbook invocation on the target node", |
| 74 | + }, |
| 75 | + }, |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +func dataSourceNsxtPolicyODSPRunbookInvocationReportRead(d *schema.ResourceData, m interface{}) error { |
| 80 | + connector := getPolicyConnector(m) |
| 81 | + invocationID := d.Get("invocation_id").(string) |
| 82 | + client := runbook_invocations.NewReportClient(connector) |
| 83 | + |
| 84 | + obj, err := client.Get(invocationID) |
| 85 | + if err != nil { |
| 86 | + return handleDataSourceReadError(d, "OdsRunbookInvocationReport", invocationID, err) |
| 87 | + } |
| 88 | + |
| 89 | + d.SetId(invocationID) |
| 90 | + d.Set("target_node", obj.TargetNode) |
| 91 | + d.Set("error_detail", obj.ErrorDetail) |
| 92 | + d.Set("invalid_reason", obj.InvalidReason) |
| 93 | + d.Set("recommendation_code", obj.RecommendationCode) |
| 94 | + d.Set("recommendation_message", obj.RecommendationMessage) |
| 95 | + d.Set("result_code", obj.ResultCode) |
| 96 | + d.Set("result_message", obj.ResultMessage) |
| 97 | + if obj.Status != nil { |
| 98 | + d.Set("request_status", obj.Status.RequestStatus) |
| 99 | + d.Set("operation_state", obj.Status.OperationState) |
| 100 | + } |
| 101 | + |
| 102 | + return nil |
| 103 | +} |
0 commit comments