Skip to content

Commit b212e71

Browse files
AshuSoni-crestlhercot
authored andcommitted
#504 added inline block for dhcpRsProv with addr attribute inside aci_dhcp_relay_policy
1 parent cfe6602 commit b212e71

File tree

6 files changed

+78
-59
lines changed

6 files changed

+78
-59
lines changed

aci/resource_aci_dhcprelayp.go

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package aci
33
import (
44
"fmt"
55
"log"
6-
"reflect"
7-
"sort"
86

97
"github.com/ciscoecosystem/aci-go-client/client"
108
"github.com/ciscoecosystem/aci-go-client/models"
@@ -72,9 +70,19 @@ func resourceAciDHCPRelayPolicy() *schema.Resource {
7270

7371
"relation_dhcp_rs_prov": &schema.Schema{
7472
Type: schema.TypeSet,
75-
Elem: &schema.Schema{Type: schema.TypeString},
7673
Optional: true,
77-
Set: schema.HashString,
74+
Elem: &schema.Resource{
75+
Schema: map[string]*schema.Schema{
76+
"tdn": {
77+
Type: schema.TypeString,
78+
Required: true,
79+
},
80+
"addr": {
81+
Type: schema.TypeString,
82+
Required: true,
83+
},
84+
},
85+
},
7886
},
7987
}),
8088
}
@@ -171,9 +179,10 @@ func resourceAciDHCPRelayPolicyCreate(d *schema.ResourceData, m interface{}) err
171179
checkDns := make([]string, 0, 1)
172180

173181
if relationTodhcpRsProv, ok := d.GetOk("relation_dhcp_rs_prov"); ok {
174-
relationParamList := toStringList(relationTodhcpRsProv.(*schema.Set).List())
182+
relationParamList := relationTodhcpRsProv.(*schema.Set).List()
175183
for _, relationParam := range relationParamList {
176-
checkDns = append(checkDns, relationParam)
184+
paramMap := relationParam.(map[string]interface{})
185+
checkDns = append(checkDns, paramMap["tdn"].(string))
177186
}
178187
}
179188

@@ -185,9 +194,10 @@ func resourceAciDHCPRelayPolicyCreate(d *schema.ResourceData, m interface{}) err
185194
d.Partial(false)
186195

187196
if relationTodhcpRsProv, ok := d.GetOk("relation_dhcp_rs_prov"); ok {
188-
relationParamList := toStringList(relationTodhcpRsProv.(*schema.Set).List())
197+
relationParamList := relationTodhcpRsProv.(*schema.Set).List()
189198
for _, relationParam := range relationParamList {
190-
err = aciClient.CreateRelationdhcpRsProvFromDHCPRelayPolicy(dhcpRelayP.DistinguishedName, relationParam)
199+
paramMap := relationParam.(map[string]interface{})
200+
err = aciClient.CreateRelationdhcpRsProvFromDHCPRelayPolicy(dhcpRelayP.DistinguishedName, paramMap["tdn"].(string), paramMap["addr"].(string))
191201

192202
if err != nil {
193203
return err
@@ -247,13 +257,11 @@ func resourceAciDHCPRelayPolicyUpdate(d *schema.ResourceData, m interface{}) err
247257
checkDns := make([]string, 0, 1)
248258

249259
if d.HasChange("relation_dhcp_rs_prov") {
250-
oldRel, newRel := d.GetChange("relation_dhcp_rs_prov")
251-
oldRelSet := oldRel.(*schema.Set)
252-
newRelSet := newRel.(*schema.Set)
253-
relToCreate := toStringList(newRelSet.Difference(oldRelSet).List())
254-
255-
for _, relDn := range relToCreate {
256-
checkDns = append(checkDns, relDn)
260+
newRel := d.Get("relation_dhcp_rs_prov")
261+
newRelList := newRel.(*schema.Set).List()
262+
for _, relationParam := range newRelList {
263+
paramMap := relationParam.(map[string]interface{})
264+
checkDns = append(checkDns, paramMap["tdn"].(string))
257265
}
258266
}
259267

@@ -266,21 +274,21 @@ func resourceAciDHCPRelayPolicyUpdate(d *schema.ResourceData, m interface{}) err
266274

267275
if d.HasChange("relation_dhcp_rs_prov") {
268276
oldRel, newRel := d.GetChange("relation_dhcp_rs_prov")
269-
oldRelSet := oldRel.(*schema.Set)
270-
newRelSet := newRel.(*schema.Set)
271-
relToDelete := toStringList(oldRelSet.Difference(newRelSet).List())
272-
relToCreate := toStringList(newRelSet.Difference(oldRelSet).List())
277+
oldRelList := oldRel.(*schema.Set).List()
278+
newRelList := newRel.(*schema.Set).List()
273279

274-
for _, relDn := range relToDelete {
275-
err = aciClient.DeleteRelationdhcpRsProvFromDHCPRelayPolicy(dhcpRelayP.DistinguishedName, relDn)
280+
for _, relationParam := range oldRelList {
281+
paramMap := relationParam.(map[string]interface{})
282+
err = aciClient.DeleteRelationdhcpRsProvFromDHCPRelayPolicy(dhcpRelayP.DistinguishedName, paramMap["tdn"].(string))
276283
if err != nil {
277284
return err
278285
}
279286

280287
}
281288

282-
for _, relDn := range relToCreate {
283-
err = aciClient.CreateRelationdhcpRsProvFromDHCPRelayPolicy(dhcpRelayP.DistinguishedName, relDn)
289+
for _, relationParam := range newRelList {
290+
paramMap := relationParam.(map[string]interface{})
291+
err = aciClient.CreateRelationdhcpRsProvFromDHCPRelayPolicy(dhcpRelayP.DistinguishedName, paramMap["tdn"].(string), paramMap["addr"].(string))
284292
if err != nil {
285293
return err
286294
}
@@ -317,18 +325,18 @@ func resourceAciDHCPRelayPolicyRead(d *schema.ResourceData, m interface{}) error
317325

318326
if err != nil {
319327
log.Printf("[DEBUG] Error while reading relation dhcpRsProv %v", err)
320-
d.Set("relation_dhcp_rs_prov", make([]string, 0, 1))
328+
d.Set("relation_dhcp_rs_prov", make([]map[string]string, 0))
321329

322330
} else {
323-
if _, ok := d.GetOk("relation_dhcp_rs_prov"); ok {
324-
relationParamList := toStringList(d.Get("relation_dhcp_rs_prov").(*schema.Set).List())
325-
dhcpRsProvDataList := toStringList(dhcpRsProvData.(*schema.Set).List())
326-
sort.Strings(relationParamList)
327-
sort.Strings(dhcpRsProvDataList)
328-
if !reflect.DeepEqual(relationParamList, dhcpRsProvDataList) {
329-
d.Set("relation_dhcp_rs_prov", make([]string, 0, 1))
330-
}
331+
dhcpRsProvMap := dhcpRsProvData.([]map[string]string)
332+
st := make([]map[string]string, 0)
333+
for _, dhcpRsProvObj := range dhcpRsProvMap {
334+
obj := make(map[string]string, 0)
335+
obj["addr"] = dhcpRsProvObj["addr"]
336+
obj["tdn"] = dhcpRsProvObj["tDn"]
337+
st = append(st, obj)
331338
}
339+
d.Set("relation_dhcp_rs_prov", st)
332340
}
333341

334342
log.Printf("[DEBUG] %s: Read finished successfully", d.Id())

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/terraform-providers/terraform-provider-aci
33
go 1.12
44

55
require (
6-
github.com/ciscoecosystem/aci-go-client v1.11.3
6+
github.com/ciscoecosystem/aci-go-client v1.11.5
77
github.com/ghodss/yaml v1.0.0
88
github.com/hashicorp/terraform v0.12.5
99
github.com/hashicorp/terraform-plugin-sdk v1.14.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXH
7070
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
7171
github.com/chzyer/readline v0.0.0-20161106042343-c914be64f07d/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
7272
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
73-
github.com/ciscoecosystem/aci-go-client v1.11.3 h1:fYbmBY35dHz3i12R6ZRaSX1mLW5PuOBpEbPdSMWxH18=
74-
github.com/ciscoecosystem/aci-go-client v1.11.3/go.mod h1:fhY7vWysK655g3Yp5Fz4Zje/JN4+moRe8RjwiRy0amQ=
73+
github.com/ciscoecosystem/aci-go-client v1.11.5 h1:QCyNbXpdAl3uDCWu+JNOaQQxd3ZGgJZvV0gbvW5Yy4U=
74+
github.com/ciscoecosystem/aci-go-client v1.11.5/go.mod h1:fhY7vWysK655g3Yp5Fz4Zje/JN4+moRe8RjwiRy0amQ=
7575
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
7676
github.com/coreos/bbolt v1.3.0/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
7777
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=

vendor/github.com/ciscoecosystem/aci-go-client/client/dhcpRelayP_service.go

Lines changed: 15 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ github.com/bgentry/go-netrc/netrc
5858
github.com/bgentry/speakeasy
5959
# github.com/blang/semver v3.5.1+incompatible
6060
github.com/blang/semver
61-
# github.com/ciscoecosystem/aci-go-client v1.11.3
61+
# github.com/ciscoecosystem/aci-go-client v1.11.5
6262
github.com/ciscoecosystem/aci-go-client/client
6363
github.com/ciscoecosystem/aci-go-client/container
6464
github.com/ciscoecosystem/aci-go-client/models

website/docs/r/dhcp_relay_policy.html.markdown

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,51 @@ sidebar_current: "docs-aci-resource-dhcp_relay_policy"
55
description: |-
66
Manages ACI DHCP Relay Policy
77
---
8-
98
# aci_dhcp_relay_policy
10-
119
Manages ACI DHCP Relay Policy.
12-
1310
## Example Usage
14-
1511
```hcl
1612
resource "aci_dhcp_relay_policy" "example" {
1713
18-
tenant_dn = "${aci_tenant.example.id}"
19-
20-
name = "name_example"
14+
tenant_dn = aci_tenant.example.id
15+
name = "name_example"
2116
annotation = "annotation_example"
22-
mode = "visible"
17+
description = "from terraform"
18+
mode = "visible"
2319
name_alias = "alias_example"
24-
owner = "infra"
20+
owner = "infra"
21+
22+
relation_dhcp_rs_prov {
23+
addr = "10.20.30.40"
24+
tdn = aci_application_epg.example.id
25+
}
26+
27+
relation_dhcp_rs_prov {
28+
addr = "10.20.30.41"
29+
tdn = aci_l2out_extepg.example.id
30+
}
2531
}
2632
```
2733

2834
## Argument Reference
29-
3035
- `tenant_dn` - (Required) Distinguished name of parent Tenant object.
3136
- `name` - (Required) Name of Object DHCP Relay Policy.
3237
- `annotation` - (Optional) Annotation for object DHCP Relay Policy.
38+
- `description` - (Optional) Description for object DHCP Relay Policy.
3339
- `mode` - (Optional) DHCP relay policy mode. Allowed Values are "visible" and "not-visible". Default Value is "visible".
3440
- `name_alias` - (Optional) Name alias for object DHCP Relay Policy.
3541
- `owner` - (Optional) Owner of the target relay servers. Allowed values are "infra" and "tenant". Default value is "infra".
3642

3743
- `relation_dhcp_rs_prov` - (Optional) List of relation to class fvEPg. Cardinality - N_TO_M. Type - Set of String.
44+
- `relation_dhcp_rs_prov.tdn` - (Required) target Dn of the class fvEPg.
45+
- `relation_dhcp_rs_prov.addr` - (Required) IP address for relation dhcpRsProv.
3846

3947
## Attribute Reference
4048

4149
The only attribute that this resource exports is the `id`, which is set to the Dn of the DHCP Relay Policy.
42-
4350
## Importing
44-
4551
An existing DHCP Relay Policy can be [imported][docs-import] into this resource via its Dn, via the following command:
4652
[docs-import]: https://www.terraform.io/docs/import/index.html
47-
4853
```
4954
terraform import aci_dhcp_relay_policy.example <Dn>
50-
```
55+
```

0 commit comments

Comments
 (0)