/
resource_ldap_server_host_ipv4.go
205 lines (193 loc) · 6.67 KB
/
resource_ldap_server_host_ipv4.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package thunder
import (
"context"
edpt "github.com/a10networks/terraform-provider-thunder/thunder/axapi/endpoint"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func resourceLdapServerHostIpv4() *schema.Resource {
return &schema.Resource{
Description: "`thunder_ldap_server_host_ipv4`: Specify the hostname of ldap server\n\n__PLACEHOLDER__",
CreateContext: resourceLdapServerHostIpv4Create,
UpdateContext: resourceLdapServerHostIpv4Update,
ReadContext: resourceLdapServerHostIpv4Read,
DeleteContext: resourceLdapServerHostIpv4Delete,
Schema: map[string]*schema.Schema{
"base": {
Type: schema.TypeString, Optional: true, Description: "Configure the group DN which user belongs to",
},
"cn_value": {
Type: schema.TypeString, Optional: true, Description: "LDAP common name identifier (i.e.: cn, uid)",
},
"dn_value": {
Type: schema.TypeString, Optional: true, Description: "LDAP distinguished name (dn)",
},
"domain": {
Type: schema.TypeString, Optional: true, Description: "Configure AD domain name",
},
"domain_cfg": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"port": {
Type: schema.TypeInt, Optional: true, Description: "Specify the LDAP server's port (default 389 without ssl or 636 with ssl)",
},
"ssl": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Use SSL",
},
"timeout": {
Type: schema.TypeInt, Optional: true, Description: "Specify the LDAP server's timeout (default 3)",
},
},
},
},
"group": {
Type: schema.TypeString, Optional: true, Description: "Configure the group DN which user belongs to",
},
"ipv4_addr": {
Type: schema.TypeString, Required: true, Description: "IPV4 address of ldap server",
},
"ipv4_addr_cfg": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"port": {
Type: schema.TypeInt, Optional: true, Description: "Specify the LDAP server's port (default 3268 without ssl or 3269 with ssl)",
},
"ssl": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Use SSL",
},
"timeout": {
Type: schema.TypeInt, Optional: true, Description: "Specify the LDAP server's timeout (default 3)",
},
},
},
},
"port_cfg": {
Type: schema.TypeList, MaxItems: 1, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"port": {
Type: schema.TypeInt, Optional: true, Description: "Specify the LDAP server's port (default 389 without ssl or 636 with ssl)",
},
"ssl": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Use SSL",
},
"timeout": {
Type: schema.TypeInt, Optional: true, Description: "Specify the LDAP server's timeout (default 3)",
},
},
},
},
"uuid": {
Type: schema.TypeString, Optional: true, Computed: true, Description: "uuid of the object",
},
},
}
}
func resourceLdapServerHostIpv4Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceLdapServerHostIpv4Create()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointLdapServerHostIpv4(d)
d.SetId(obj.GetId())
err := obj.Post(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceLdapServerHostIpv4Read(ctx, d, meta)
}
return diags
}
func resourceLdapServerHostIpv4Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceLdapServerHostIpv4Update()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointLdapServerHostIpv4(d)
err := obj.Put(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceLdapServerHostIpv4Read(ctx, d, meta)
}
return diags
}
func resourceLdapServerHostIpv4Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceLdapServerHostIpv4Delete()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointLdapServerHostIpv4(d)
err := obj.Delete(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func resourceLdapServerHostIpv4Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceLdapServerHostIpv4Read()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointLdapServerHostIpv4(d)
err := obj.Get(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func getObjectLdapServerHostIpv4DomainCfg(d []interface{}) edpt.LdapServerHostIpv4DomainCfg {
count1 := len(d)
var ret edpt.LdapServerHostIpv4DomainCfg
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.Port = in["port"].(int)
ret.Ssl = in["ssl"].(int)
ret.Timeout = in["timeout"].(int)
}
return ret
}
func getObjectLdapServerHostIpv4Ipv4AddrCfg(d []interface{}) edpt.LdapServerHostIpv4Ipv4AddrCfg {
count1 := len(d)
var ret edpt.LdapServerHostIpv4Ipv4AddrCfg
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.Port = in["port"].(int)
ret.Ssl = in["ssl"].(int)
ret.Timeout = in["timeout"].(int)
}
return ret
}
func getObjectLdapServerHostIpv4PortCfg(d []interface{}) edpt.LdapServerHostIpv4PortCfg {
count1 := len(d)
var ret edpt.LdapServerHostIpv4PortCfg
if count1 > 0 {
in := d[0].(map[string]interface{})
ret.Port = in["port"].(int)
ret.Ssl = in["ssl"].(int)
ret.Timeout = in["timeout"].(int)
}
return ret
}
func dataToEndpointLdapServerHostIpv4(d *schema.ResourceData) edpt.LdapServerHostIpv4 {
var ret edpt.LdapServerHostIpv4
ret.Inst.Base = d.Get("base").(string)
ret.Inst.CnValue = d.Get("cn_value").(string)
ret.Inst.DnValue = d.Get("dn_value").(string)
ret.Inst.Domain = d.Get("domain").(string)
ret.Inst.DomainCfg = getObjectLdapServerHostIpv4DomainCfg(d.Get("domain_cfg").([]interface{}))
ret.Inst.Group = d.Get("group").(string)
ret.Inst.Ipv4Addr = d.Get("ipv4_addr").(string)
ret.Inst.Ipv4AddrCfg = getObjectLdapServerHostIpv4Ipv4AddrCfg(d.Get("ipv4_addr_cfg").([]interface{}))
ret.Inst.PortCfg = getObjectLdapServerHostIpv4PortCfg(d.Get("port_cfg").([]interface{}))
//omit uuid
return ret
}