@@ -104,18 +104,29 @@ func resourceMSOSchemaSiteAnpEpgSelector() *schema.Resource {
104104 }
105105}
106106
107+ var importReadSchemaID , importReadSiteID , importReadTemplate , importReadANP , importReadEPG string
108+
107109func resourceSchemaSiteApnEpgSelectorImport (d * schema.ResourceData , m interface {}) ([]* schema.ResourceData , error ) {
108110 log .Printf ("[DEBUG] %s: Beginning Import" , d .Id ())
109111 found := false
110112 msoClient := m .(* client.Client )
111- get_attribute := strings .Split (d .Id (), "/" )
112- schemaID := get_attribute [0 ]
113- siteID := get_attribute [2 ]
114- template := get_attribute [4 ]
115- anpName := get_attribute [6 ]
116- epgName := get_attribute [8 ]
117- name := get_attribute [10 ]
118-
113+ var schemaID , siteID , template , anpName , epgName , name string
114+ if ! strings .Contains (d .Id (), "/" ) {
115+ name = d .Id ()
116+ schemaID = importReadSchemaID
117+ siteID = importReadSiteID
118+ template = importReadTemplate
119+ anpName = importReadANP
120+ epgName = importReadEPG
121+ } else {
122+ get_attribute := strings .Split (d .Id (), "/" )
123+ schemaID = get_attribute [0 ]
124+ siteID = get_attribute [2 ]
125+ template = get_attribute [4 ]
126+ anpName = get_attribute [6 ]
127+ epgName = get_attribute [8 ]
128+ name = get_attribute [10 ]
129+ }
119130 cont , err := msoClient .GetViaURL (fmt .Sprintf ("api/v1/schemas/%s" , schemaID ))
120131 if err != nil {
121132 return nil , err
@@ -180,7 +191,7 @@ func resourceSchemaSiteApnEpgSelectorImport(d *schema.ResourceData, m interface{
180191 currentName := models .StripQuotes (selectorCont .S ("name" ).String ())
181192 if currentName == name {
182193 found = true
183- d .SetId (name )
194+ d .SetId (currentName )
184195 d .Set ("name" , currentName )
185196 exps := selectorCont .S ("expressions" ).Data ().([]interface {})
186197
@@ -357,14 +368,17 @@ func resourceSchemaSiteApnEpgSelectorUpdate(d *schema.ResourceData, m interface{
357368func resourceSchemaSiteApnEpgSelectorRead (d * schema.ResourceData , m interface {}) error {
358369 found := false
359370 msoClient := m .(* client.Client )
360-
361371 dn := d .Id ()
362372 schemaID := d .Get ("schema_id" ).(string )
363373 siteID := d .Get ("site_id" ).(string )
364374 template := d .Get ("template_name" ).(string )
365375 anpName := d .Get ("anp_name" ).(string )
366376 epgName := d .Get ("epg_name" ).(string )
367-
377+ importReadSchemaID = schemaID
378+ importReadSiteID = siteID
379+ importReadTemplate = template
380+ importReadANP = anpName
381+ importReadEPG = epgName
368382 cont , err := msoClient .GetViaURL (fmt .Sprintf ("api/v1/schemas/%s" , schemaID ))
369383 if err != nil {
370384 return err
@@ -429,7 +443,6 @@ func resourceSchemaSiteApnEpgSelectorRead(d *schema.ResourceData, m interface{})
429443 currentName := models .StripQuotes (selectorCont .S ("name" ).String ())
430444 if currentName == dn {
431445 found = true
432- d .SetId (dn )
433446 d .Set ("name" , currentName )
434447 exps := selectorCont .S ("expressions" ).Data ().([]interface {})
435448
0 commit comments