/
data_source_illumio_container_cluster_service_backends.go
118 lines (105 loc) · 3.21 KB
/
data_source_illumio_container_cluster_service_backends.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
// Copyright 2021 Illumio, Inc. All Rights Reserved.
package illumiocore
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func datasourceIllumioContainerClusterServiceBackends() *schema.Resource {
return &schema.Resource{
ReadContext: datasourceIllumioContainerClusterServiceBackendsRead,
SchemaVersion: 1,
Description: "Represents Illumio Container Cluster Service Backend",
Schema: map[string]*schema.Schema{
"container_cluster_href": {
Type: schema.TypeString,
Required: true,
Description: "URI of Container Cluster",
ValidateDiagFunc: isContainerClusterHref,
},
"items": {
Type: schema.TypeList,
Computed: true,
Description: "Collection of Container Cluster Service Backends",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
Description: "The name of the Container Cluster Backend",
},
"kind": {
Type: schema.TypeString,
Computed: true,
Description: "The type (or kind) of Container Cluster Backend",
},
"namespace": {
Type: schema.TypeString,
Computed: true,
Description: "The namespace of the Container Cluster Backend",
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
Description: "The time (rfc339 timestamp) at which the Container Cluster Backend was last updated",
},
"created_at": {
Type: schema.TypeString,
Computed: true,
Description: "The time (rfc339 timestamp) in which the Container Cluster Backend was created",
},
"virtual_service": {
Type: schema.TypeList,
Computed: true,
Description: "Associated virtual service. Single element list",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"href": {
Type: schema.TypeString,
Computed: true,
Description: "The URI to the associated virtual service",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "The name of virtual service",
},
},
},
},
},
},
},
},
}
}
func datasourceIllumioContainerClusterServiceBackendsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
var diagnostics diag.Diagnostics
pConfig, _ := m.(Config)
illumioClient := pConfig.IllumioClient
href := d.Get("container_cluster_href").(string) + "/service_backends"
_, data, err := illumioClient.Get(href, nil)
if err != nil {
return diag.FromErr(err)
}
d.SetId(href)
sbsKeys := []string{
"name",
"kind",
"namespace",
"updated_at",
"created_at",
}
sbs := []map[string]interface{}{}
for _, child := range data.Children() {
sb := extractMap(child, sbsKeys)
if child.Exists("virtual_service") {
sb["virtual_service"] = []interface{}{
extractMap(child.S("virtual_service"), []string{"href", "name"}),
}
}
sbs = append(sbs, sb)
}
d.Set("items", sbs)
return diagnostics
}