/
datasource_vcd_nsxt_segment_mac_discovery_profile.go
107 lines (96 loc) · 3.41 KB
/
datasource_vcd_nsxt_segment_mac_discovery_profile.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
package vcd
import (
"context"
"fmt"
"net/url"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func datasourceVcdNsxtSegmentMacDiscoveryProfile() *schema.Resource {
return &schema.Resource{
ReadContext: datasourceNsxtSegmentMacDiscoveryProfileRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name of Segment MAC Discovery Profile",
},
"nsxt_manager_id": {
Type: schema.TypeString,
Optional: true,
ExactlyOneOf: []string{"nsxt_manager_id", "vdc_id", "vdc_group_id"},
Description: "ID of NSX-T Manager",
},
"vdc_id": {
Type: schema.TypeString,
Optional: true,
ExactlyOneOf: []string{"nsxt_manager_id", "vdc_id", "vdc_group_id"},
Description: "ID of VDC",
},
"vdc_group_id": {
Type: schema.TypeString,
Optional: true,
ExactlyOneOf: []string{"nsxt_manager_id", "vdc_id", "vdc_group_id"},
Description: "ID of VDC Group",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "Description of Segment MAC Discovery Profile",
},
"is_mac_change_enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "Indcates whether source MAC address change is enabled",
},
"is_mac_learning_enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates whether source MAC address learning is enabled",
},
"is_unknown_unicast_flooding_enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates whether unknown unicast flooding rule is enabled",
},
"mac_learning_aging_time": {
Type: schema.TypeInt,
Computed: true,
Description: "Indicates aging time in seconds for learned MAC address",
},
"mac_limit": {
Type: schema.TypeInt,
Computed: true,
Description: "Indicates the maximum number of MAC addresses that can be learned on this port",
},
"mac_policy": {
Type: schema.TypeString,
Computed: true,
Description: "Defines the policy after MAC Limit is exceeded. It can be either 'ALLOW' or 'DROP'",
},
},
}
}
func datasourceNsxtSegmentMacDiscoveryProfileRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
vcdClient := meta.(*VCDClient)
profileName := d.Get("name").(string)
contextFilterField, contextUrn, err := getContextFilterField(d)
if err != nil {
return diag.FromErr(err)
}
queryFilter := url.Values{}
queryFilter.Add("filter", fmt.Sprintf("%s==%s", contextFilterField, contextUrn))
macDiscoveryProfile, err := vcdClient.GetMacDiscoveryProfileByName(profileName, queryFilter)
if err != nil {
return diag.Errorf("could not find MAC Discovery Profile by name '%s': %s", profileName, err)
}
dSet(d, "description", macDiscoveryProfile.Description)
dSet(d, "is_mac_change_enabled", macDiscoveryProfile.IsMacChangeEnabled)
dSet(d, "is_mac_learning_enabled", macDiscoveryProfile.IsMacLearningEnabled)
dSet(d, "is_unknown_unicast_flooding_enabled", macDiscoveryProfile.IsUnknownUnicastFloodingEnabled)
dSet(d, "mac_learning_aging_time", macDiscoveryProfile.MacLearningAgingTime)
dSet(d, "mac_limit", macDiscoveryProfile.MacLimit)
dSet(d, "mac_policy", macDiscoveryProfile.MacPolicy)
d.SetId(macDiscoveryProfile.ID)
return nil
}