/
data_source_stats_action.go
60 lines (50 loc) · 1.46 KB
/
data_source_stats_action.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
// Copyright (C) 2018-2022, Pulse Secure, LLC.
// Licensed under the terms of the MPL 2.0. See LICENSE file for details.
// Data Source Object Action
package main
import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
vtm "github.com/pulse-vadc/go-vtm/8.3"
)
func dataSourceActionStatistics() *schema.Resource {
return &schema.Resource{
Read: dataSourceActionStatisticsRead,
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.NoZeroValues,
},
// Number of times this action has been processed.
"processed": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
},
}
}
func dataSourceActionStatisticsRead(d *schema.ResourceData, tm interface{}) (readError error) {
objectName := d.Get("name").(string)
object, err := tm.(*vtm.VirtualTrafficManager).GetActionStatistics(objectName)
if err != nil {
if err.ErrorId == "resource.not_found" {
d.SetId("")
return nil
}
return fmt.Errorf("Failed to read vtm_actions '%v': %v", objectName, err.ErrorText)
}
var lastAssignedField string
defer func() {
r := recover()
if r != nil {
readError = fmt.Errorf("Field '%s' missing from vTM configuration", lastAssignedField)
}
}()
lastAssignedField = "processed"
d.Set("processed", int(*object.Statistics.Processed))
d.SetId(objectName)
return nil
}