@@ -115,7 +115,13 @@ func resourceIpMoveSchema() map[string]*schema.Schema {
115115func resoursIpMoveCreate (d * schema.ResourceData , meta interface {}) error {
116116 // later on this ID will be replaced by the task if when we need to create it (see resourceIpMoveUpdate)
117117 d .SetId (d .Get ("ip" ).(string ))
118- return resourceIpMoveUpdate (d , meta )
118+
119+ err := resourceIpMoveUpdate (d , meta )
120+ if err != nil {
121+ d .SetId ("" )
122+ }
123+
124+ return err
119125}
120126
121127// resourceIpMoveUpdate will move an ip to a provided service name or detach (= park) it otherwise
@@ -160,19 +166,19 @@ func resourceIpMoveUpdate(d *schema.ResourceData, meta interface{}) error {
160166 } else {
161167 log .Printf ("[WARNING] - resource ID %s is not an int64/not a task ID. Cannot get last task state" , d .Id ())
162168 }
163- err = resourceIpServiceReadByServiceName (d , * serviceName , config )
169+ err = resourceIpServiceReadByServiceName (d , serviceName , config )
164170 if err != nil {
165171 return err
166172 }
167173
168174 currentlyRoutedService := GetRoutedToServiceName (d )
169175 // no need to update if ip is already routed to the appropriate service
170176 if reflect .DeepEqual (currentlyRoutedService , opts .To ) {
171- log .Printf ("[DEBUG] Won't do anything as ip %s (service name = %s) is already routed to service %v" , ip , * serviceName , currentlyRoutedService )
177+ log .Printf ("[DEBUG] Won't do anything as ip %s (service name = %s) is already routed to service %v" , ip , serviceName , currentlyRoutedService )
172178 return nil
173179 } else {
174180 if opts .To == nil {
175- log .Printf ("[DEBUG] Will move ip %s (service name = %s) from service %s to IP parking" , ip , * serviceName , * currentlyRoutedService )
181+ log .Printf ("[DEBUG] Will move ip %s (service name = %s) from service %s to IP parking" , ip , serviceName , * currentlyRoutedService )
176182 endpoint := fmt .Sprintf ("/ip/%s/park" ,
177183 url .PathEscape (ip ),
178184 )
@@ -181,7 +187,7 @@ func resourceIpMoveUpdate(d *schema.ResourceData, meta interface{}) error {
181187 return fmt .Errorf ("calling Post %s: %q" , endpoint , err )
182188 }
183189 } else {
184- log .Printf ("[DEBUG] Will move ip %s (service name = %s) from service %v to service %s" , ip , * serviceName , currentlyRoutedService , * opts .To )
190+ log .Printf ("[DEBUG] Will move ip %s (service name = %s) from service %v to service %s" , ip , serviceName , currentlyRoutedService , * opts .To )
185191 endpoint := fmt .Sprintf ("/ip/%s/move" ,
186192 url .PathEscape (ip ),
187193 )
@@ -269,7 +275,7 @@ func resourceIpRead(d *schema.ResourceData, meta interface{}) error {
269275 return err
270276 }
271277 config := meta .(* Config )
272- return resourceIpServiceReadByServiceName (d , * serviceName , config )
278+ return resourceIpServiceReadByServiceName (d , serviceName , config )
273279}
274280
275281// resourceIpMoveDelete is an empty implementation as move do not actually create API objects but rather updates the underlying ip spec (by modifying its routed_to service)
0 commit comments