-
Notifications
You must be signed in to change notification settings - Fork 98
/
data_source_aci_fvtagselector.go
55 lines (51 loc) · 1.48 KB
/
data_source_aci_fvtagselector.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
package aci
import (
"fmt"
"github.com/ciscoecosystem/aci-go-client/v2/client"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceAciEndpointSecurityGroupTagSelector() *schema.Resource {
return &schema.Resource{
Read: dataSourceAciEndpointSecurityGroupTagSelectorRead,
SchemaVersion: 1,
Schema: AppendBaseAttrSchema(AppendNameAliasAttrSchema(map[string]*schema.Schema{
"endpoint_security_group_dn": {
Type: schema.TypeString,
Required: true,
},
"annotation": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"match_key": {
Type: schema.TypeString,
Required: true,
},
"match_value": {
Type: schema.TypeString,
Required: true,
},
"value_operator": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
})),
}
}
func dataSourceAciEndpointSecurityGroupTagSelectorRead(d *schema.ResourceData, m interface{}) error {
aciClient := m.(*client.Client)
matchKey := d.Get("match_key").(string)
matchValue := d.Get("match_value").(string)
EndpointSecurityGroupDn := d.Get("endpoint_security_group_dn").(string)
rn := fmt.Sprintf("tagselectorkey-[%s]-value-[%s]", matchKey, matchValue)
dn := fmt.Sprintf("%s/%s", EndpointSecurityGroupDn, rn)
fvTagSelector, err := getRemoteEndpointSecurityGroupTagSelector(aciClient, dn)
if err != nil {
return err
}
d.SetId(dn)
setEndpointSecurityGroupTagSelectorAttributes(fvTagSelector, d)
return nil
}