Skip to content

Commit 77125c1

Browse files
Update subnet any resource (#167)
* updated ctrl of subnet * updated any resource * updated examples
1 parent 1662413 commit 77125c1

File tree

10 files changed

+65
-27
lines changed

10 files changed

+65
-27
lines changed

aci/data_source_aci_fvsubnet.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ func dataSourceAciSubnet() *schema.Resource {
2626
},
2727

2828
"ctrl": &schema.Schema{
29-
Type: schema.TypeString,
29+
Type: schema.TypeList,
3030
Optional: true,
3131
Computed: true,
32+
Elem: &schema.Schema{
33+
Type: schema.TypeString,
34+
},
3235
},
3336

3437
"name_alias": &schema.Schema{

aci/resource_aci_fvsubnet.go

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,18 @@ func resourceAciSubnet() *schema.Resource {
4040
},
4141

4242
"ctrl": &schema.Schema{
43-
Type: schema.TypeString,
43+
Type: schema.TypeList,
4444
Optional: true,
4545
Computed: true,
46-
ValidateFunc: validation.StringInSlice([]string{
47-
"unspecified",
48-
"querier",
49-
"nd",
50-
"no-default-gateway",
51-
}, false),
46+
Elem: &schema.Schema{
47+
Type: schema.TypeString,
48+
ValidateFunc: validation.StringInSlice([]string{
49+
"unspecified",
50+
"querier",
51+
"nd",
52+
"no-default-gateway",
53+
}, false),
54+
},
5255
},
5356

5457
"name_alias": &schema.Schema{
@@ -137,10 +140,30 @@ func setSubnetAttributes(fvSubnet *models.Subnet, d *schema.ResourceData) *schem
137140
d.Set("ip", fvSubnetMap["ip"])
138141

139142
d.Set("annotation", fvSubnetMap["annotation"])
140-
d.Set("ctrl", fvSubnetMap["ctrl"])
141143
d.Set("ip", fvSubnetMap["ip"])
142144
d.Set("name_alias", fvSubnetMap["nameAlias"])
143145
d.Set("preferred", fvSubnetMap["preferred"])
146+
147+
ctrlGet := make([]string, 0, 1)
148+
for _, val := range strings.Split(fvSubnetMap["ctrl"], ",") {
149+
ctrlGet = append(ctrlGet, strings.Trim(val, " "))
150+
}
151+
sort.Strings(ctrlGet)
152+
if ctrlInp, ok := d.GetOk("ctrl"); ok {
153+
ctrlAct := make([]string, 0, 1)
154+
for _, val := range ctrlInp.([]interface{}) {
155+
ctrlAct = append(ctrlAct, val.(string))
156+
}
157+
sort.Strings(ctrlAct)
158+
if reflect.DeepEqual(ctrlAct, ctrlGet) {
159+
d.Set("ctrl", d.Get("ctrl").([]interface{}))
160+
} else {
161+
d.Set("ctrl", ctrlGet)
162+
}
163+
} else {
164+
d.Set("ctrl", ctrlGet)
165+
}
166+
144167
scopeGet := make([]string, 0, 1)
145168
for _, val := range strings.Split(fvSubnetMap["scope"], ",") {
146169
scopeGet = append(scopeGet, strings.Trim(val, " "))
@@ -274,8 +297,13 @@ func resourceAciSubnetCreate(d *schema.ResourceData, m interface{}) error {
274297
} else {
275298
fvSubnetAttr.Annotation = "{}"
276299
}
277-
if Ctrl, ok := d.GetOk("ctrl"); ok {
278-
fvSubnetAttr.Ctrl = Ctrl.(string)
300+
if ctrlInp, ok := d.GetOk("ctrl"); ok {
301+
ctrlList := make([]string, 0, 1)
302+
for _, val := range ctrlInp.([]interface{}) {
303+
ctrlList = append(ctrlList, val.(string))
304+
}
305+
ctrl := strings.Join(ctrlList, ",")
306+
fvSubnetAttr.Ctrl = ctrl
279307
}
280308
if Ip, ok := d.GetOk("ip"); ok {
281309
fvSubnetAttr.Ip = Ip.(string)
@@ -396,8 +424,13 @@ func resourceAciSubnetUpdate(d *schema.ResourceData, m interface{}) error {
396424
} else {
397425
fvSubnetAttr.Annotation = "{}"
398426
}
399-
if Ctrl, ok := d.GetOk("ctrl"); ok {
400-
fvSubnetAttr.Ctrl = Ctrl.(string)
427+
if ctrlInp, ok := d.GetOk("ctrl"); ok {
428+
ctrlList := make([]string, 0, 1)
429+
for _, val := range ctrlInp.([]interface{}) {
430+
ctrlList = append(ctrlList, val.(string))
431+
}
432+
ctrl := strings.Join(ctrlList, ",")
433+
fvSubnetAttr.Ctrl = ctrl
401434
}
402435
if Ip, ok := d.GetOk("ip"); ok {
403436
fvSubnetAttr.Ip = Ip.(string)

aci/resource_aci_fvsubnet_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func testAccCheckAciSubnetConfig_basic(description, Ctrl string) string {
7878
description = "%s"
7979
ip = "10.0.3.28/27"
8080
annotation = "tag_subnet"
81-
ctrl = "%s"
81+
ctrl = ["%s"]
8282
name_alias = "alias_subnet"
8383
preferred = "no"
8484
scope = ["private"]

examples/subnet/subnet.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ resource "aci_subnet" "demosubnet" {
1515
ip = "10.0.3.28/27"
1616
scope = ["private"]
1717
description = "This subject is created by terraform"
18-
ctrl = "unspecified"
18+
ctrl = ["unspecified"]
1919
preferred = "no"
2020
virtual = "yes"
2121
relation_fv_rs_bd_subnet_to_profile = "${aci_rest.rest_rt_ctrl_profile.id}" # Relation to rtctrlProfile class. Cardinality - N_TO_ONE.

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.3.20
6+
github.com/ciscoecosystem/aci-go-client v1.3.22
77
github.com/ghodss/yaml v1.0.0
88
github.com/hashicorp/terraform-plugin-sdk v1.14.0
99
github.com/hashicorp/terraform-plugin-test v1.4.3 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ github.com/ciscoecosystem/aci-go-client v1.3.17 h1:mCkNG8paRIA8kVAIpMw8FYpke+Chg
202202
github.com/ciscoecosystem/aci-go-client v1.3.17/go.mod h1:fhY7vWysK655g3Yp5Fz4Zje/JN4+moRe8RjwiRy0amQ=
203203
github.com/ciscoecosystem/aci-go-client v1.3.20 h1:AFd4MxZY//1wJlbAeDGf00GnHyUHuzySW65PieTCEpo=
204204
github.com/ciscoecosystem/aci-go-client v1.3.20/go.mod h1:fhY7vWysK655g3Yp5Fz4Zje/JN4+moRe8RjwiRy0amQ=
205+
github.com/ciscoecosystem/aci-go-client v1.3.22 h1:RpzWx/SvfbotuwXRpQ+q4olpzOwNFO0q0TJUduXqNDE=
206+
github.com/ciscoecosystem/aci-go-client v1.3.22/go.mod h1:fhY7vWysK655g3Yp5Fz4Zje/JN4+moRe8RjwiRy0amQ=
205207
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
206208
github.com/coreos/bbolt v1.3.0/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
207209
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=

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

Lines changed: 6 additions & 6 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
@@ -56,7 +56,7 @@ github.com/aws/aws-sdk-go/service/sts/stsiface
5656
github.com/bgentry/go-netrc/netrc
5757
# github.com/bgentry/speakeasy v0.1.0
5858
github.com/bgentry/speakeasy
59-
# github.com/ciscoecosystem/aci-go-client v1.3.20
59+
# github.com/ciscoecosystem/aci-go-client v1.3.22
6060
github.com/ciscoecosystem/aci-go-client/client
6161
github.com/ciscoecosystem/aci-go-client/container
6262
github.com/ciscoecosystem/aci-go-client/models

website/docs/d/subnet.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ data "aci_subnet" "dev_subnet" {
3131

3232
* `id` - Attribute id set to the Dn of the Subnet.
3333
* `annotation` - (Optional) annotation for object subnet.
34-
* `ctrl` - (Optional) The subnet control state. The control can be specific protocols applied to the subnet such as IGMP Snooping.
34+
* `ctrl` - (Optional) The list of subnet control state. The control can be specific protocols applied to the subnet such as IGMP Snooping.
3535
* `name_alias` - (Optional) name_alias for object subnet.
3636
* `preferred` - (Optional) Indicates if the subnet is preferred (primary) over the available alternatives. Only one preferred subnet is allowed.
3737
* `scope` - (Optional) The List of network visibility of the subnet.

website/docs/r/subnet.html.markdown

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ Manages ACI Subnet
1515
1616
resource "aci_subnet" "foosubnet" {
1717
parent_dn = "${aci_bridge_domain.bd_for_subnet.id}"
18-
description = "%s"
18+
description = "subnet"
1919
ip = "10.0.3.28/27"
2020
annotation = "tag_subnet"
21-
ctrl = "%s"
21+
ctrl = ["querier", "nd"]
2222
name_alias = "alias_subnet"
2323
preferred = "no"
2424
scope = ["private", "shared"]
@@ -32,7 +32,7 @@ Manages ACI Subnet
3232
* `parent_dn` - (Required) Distinguished name of parent object.
3333
* `ip` - (Required) The IP address and mask of the default gateway.
3434
* `annotation` - (Optional) annotation for object subnet.
35-
* `ctrl` - (Optional) The subnet control state. The control can be specific protocols applied to the subnet such as IGMP Snooping. Allowed values are "unspecified", "querier", "nd" and "no-default-gateway". Default is "nd".
35+
* `ctrl` - (Optional) The list of subnet control state. The control can be specific protocols applied to the subnet such as IGMP Snooping. Allowed values are "unspecified", "querier", "nd" and "no-default-gateway". Default is "nd".
3636
* `name_alias` - (Optional) name_alias for object subnet.
3737
* `preferred` - (Optional) Indicates if the subnet is preferred (primary) over the available alternatives. Only one preferred subnet is allowed. Allowed values are "yes" and "no". Default is "no".
3838
* `scope` - (Optional) The List of network visibility of the subnet. Allowed values are "private", "public" and "shared". Default is "private".

0 commit comments

Comments
 (0)