/
data_source_illumio_workload_settings.go
119 lines (107 loc) · 3.37 KB
/
data_source_illumio_workload_settings.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright 2021 Illumio, Inc. All Rights Reserved.
package illumiocore
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func datasourceIllumioWorkloadSettings() *schema.Resource {
return &schema.Resource{
ReadContext: datasourceIllumioWorkloadSettingsRead,
SchemaVersion: 1,
Description: "Represents Illumio Workload Settings",
Schema: map[string]*schema.Schema{
"href": {
Type: schema.TypeString,
Computed: true,
Description: "URI of the Workload Settings",
},
"workload_disconnected_timeout_seconds": {
Type: schema.TypeSet,
Computed: true,
Description: "Workload Disconnected Timeout Seconds for Workload Settings",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"scope": {
Type: schema.TypeSet,
Computed: true,
Description: "Assigned labels for Workload Disconnected Timeout Seconds",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"href": {
Type: schema.TypeString,
Computed: true,
Description: "Label URI",
},
},
},
},
"value": {
Type: schema.TypeInt,
Computed: true,
Description: "Property value associated with the scope",
},
"ven_type": {
Type: schema.TypeString,
Computed: true,
Description: `The VEN type that this property is applicable to. Must be "server" or "endpoint". An empty or missing value will default to "server" on the PCE`,
},
},
},
},
"workload_goodbye_timeout_seconds": {
Type: schema.TypeSet,
Computed: true,
Description: "Workload Goodbye Timeout Seconds for Workload Settings",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"scope": {
Type: schema.TypeSet,
Computed: true,
Description: "Assigned labels for Workload Goodbye Timeout Seconds",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"href": {
Type: schema.TypeString,
Computed: true,
Description: "Label URI",
},
},
},
},
"value": {
Type: schema.TypeInt,
Computed: true,
Description: "Property value associated with the scope",
},
"ven_type": {
Type: schema.TypeString,
Computed: true,
Description: `The VEN type that this property is applicable to. Must be "server" or "endpoint". An empty or missing value will default to "server" on the PCE`,
},
},
},
},
},
}
}
func datasourceIllumioWorkloadSettingsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
var diagnostics diag.Diagnostics
pConfig, _ := m.(Config)
illumioClient := pConfig.IllumioClient
orgID := illumioClient.OrgID
_, data, err := illumioClient.Get(fmt.Sprintf("/orgs/%v/settings/workloads", orgID), nil)
if err != nil {
return diag.FromErr(err)
}
d.SetId(data.S("href").Data().(string))
d.Set("href", data.S("href").Data().(string))
for _, k := range []string{
"workload_disconnected_timeout_seconds",
"workload_goodbye_timeout_seconds",
} {
d.Set(k, extractWorkloadSettingsTimeout(data, k))
}
return diagnostics
}