@@ -3,6 +3,9 @@ package aci
33import (
44 "fmt"
55 "log"
6+ "reflect"
7+ "sort"
8+ "strings"
69
710 "github.com/ciscoecosystem/aci-go-client/client"
811 "github.com/ciscoecosystem/aci-go-client/models"
@@ -54,16 +57,19 @@ func resourceAciL3ExtSubnet() *schema.Resource {
5457 },
5558
5659 "scope" : & schema.Schema {
57- Type : schema .TypeString ,
60+ Type : schema .TypeList ,
5861 Optional : true ,
5962 Computed : true ,
60- ValidateFunc : validation .StringInSlice ([]string {
61- "import-rtctrl" ,
62- "export-rtctrl" ,
63- "shared-rtctrl" ,
64- "import-security" ,
65- "shared-security" ,
66- }, false ),
63+ Elem : & schema.Schema {
64+ Type : schema .TypeString ,
65+ ValidateFunc : validation .StringInSlice ([]string {
66+ "import-rtctrl" ,
67+ "export-rtctrl" ,
68+ "shared-rtctrl" ,
69+ "import-security" ,
70+ "shared-security" ,
71+ }, false ),
72+ },
6773 },
6874
6975 "relation_l3ext_rs_subnet_to_profile" : & schema.Schema {
@@ -121,7 +127,27 @@ func setL3ExtSubnetAttributes(l3extSubnet *models.L3ExtSubnet, d *schema.Resourc
121127 d .Set ("annotation" , l3extSubnetMap ["annotation" ])
122128 d .Set ("ip" , l3extSubnetMap ["ip" ])
123129 d .Set ("name_alias" , l3extSubnetMap ["nameAlias" ])
124- d .Set ("scope" , l3extSubnetMap ["scope" ])
130+
131+ scpGet := make ([]string , 0 , 1 )
132+ for _ , val := range strings .Split (l3extSubnetMap ["scope" ], "," ) {
133+ scpGet = append (scpGet , strings .Trim (val , " " ))
134+ }
135+ sort .Strings (scpGet )
136+ if scpInp , ok := d .GetOk ("scope" ); ok {
137+ scpAct := make ([]string , 0 , 1 )
138+ for _ , val := range scpInp .([]interface {}) {
139+ scpAct = append (scpAct , val .(string ))
140+ }
141+ sort .Strings (scpAct )
142+ if reflect .DeepEqual (scpAct , scpGet ) {
143+ d .Set ("scope" , d .Get ("scope" ).([]interface {}))
144+ } else {
145+ d .Set ("scope" , scpGet )
146+ }
147+ } else {
148+ d .Set ("scope" , scpGet )
149+ }
150+
125151 return d
126152}
127153
@@ -172,7 +198,12 @@ func resourceAciL3ExtSubnetCreate(d *schema.ResourceData, m interface{}) error {
172198 l3extSubnetAttr .NameAlias = NameAlias .(string )
173199 }
174200 if Scope , ok := d .GetOk ("scope" ); ok {
175- l3extSubnetAttr .Scope = Scope .(string )
201+ scpList := make ([]string , 0 , 1 )
202+ for _ , val := range Scope .([]interface {}) {
203+ scpList = append (scpList , val .(string ))
204+ }
205+ scp := strings .Join (scpList , "," )
206+ l3extSubnetAttr .Scope = scp
176207 }
177208 l3extSubnet := models .NewL3ExtSubnet (fmt .Sprintf ("extsubnet-[%s]" , ip ), ExternalNetworkInstanceProfileDn , desc , l3extSubnetAttr )
178209
@@ -259,7 +290,12 @@ func resourceAciL3ExtSubnetUpdate(d *schema.ResourceData, m interface{}) error {
259290 l3extSubnetAttr .NameAlias = NameAlias .(string )
260291 }
261292 if Scope , ok := d .GetOk ("scope" ); ok {
262- l3extSubnetAttr .Scope = Scope .(string )
293+ scpList := make ([]string , 0 , 1 )
294+ for _ , val := range Scope .([]interface {}) {
295+ scpList = append (scpList , val .(string ))
296+ }
297+ scp := strings .Join (scpList , "," )
298+ l3extSubnetAttr .Scope = scp
263299 }
264300 l3extSubnet := models .NewL3ExtSubnet (fmt .Sprintf ("extsubnet-[%s]" , ip ), ExternalNetworkInstanceProfileDn , desc , l3extSubnetAttr )
265301
0 commit comments