Rancher: reset Id for unknown resources (#11543)

When switching from one Rancher server to another, we want Terraform
to recreate Rancher resources. This currently leads to ugly `EOF` errors.

This patch resets resource Ids when they can't be found in the Rancher API.
This commit is contained in:
Raphaël Pinson 2017-01-31 14:04:59 +01:00 committed by Paul Stack
parent 001ee8c1af
commit f56fb80c75
5 changed files with 30 additions and 0 deletions

View File

@ -94,6 +94,12 @@ func resourceRancherEnvironmentRead(d *schema.ResourceData, meta interface{}) er
return err
}
if env == nil {
log.Printf("[INFO] Environment %s not found", d.Id())
d.SetId("")
return nil
}
log.Printf("[INFO] Environment Name: %s", env.Name)
d.Set("description", env.Description)

View File

@ -108,6 +108,12 @@ func resourceRancherRegistrationTokenRead(d *schema.ResourceData, meta interface
return err
}
if regT == nil {
log.Printf("[INFO] RegistrationToken %s not found", d.Id())
d.SetId("")
return nil
}
log.Printf("[INFO] RegistrationToken Name: %s", regT.Name)
d.Set("description", regT.Description)

View File

@ -100,6 +100,12 @@ func resourceRancherRegistryRead(d *schema.ResourceData, meta interface{}) error
return err
}
if registry == nil {
log.Printf("[INFO] Registry %s not found", d.Id())
d.SetId("")
return nil
}
log.Printf("[INFO] Registry Name: %s", registry.Name)
d.Set("description", registry.Description)

View File

@ -114,6 +114,12 @@ func resourceRancherRegistryCredentialRead(d *schema.ResourceData, meta interfac
return err
}
if registryCred == nil {
log.Printf("[INFO] RegistryCredential %s not found", d.Id())
d.SetId("")
return nil
}
log.Printf("[INFO] RegistryCredential Name: %s", registryCred.Name)
d.Set("description", registryCred.Description)

View File

@ -132,6 +132,12 @@ func resourceRancherStackRead(d *schema.ResourceData, meta interface{}) error {
return err
}
if stack == nil {
log.Printf("[INFO] Stack %s not found", d.Id())
d.SetId("")
return nil
}
if stack.State == "removed" {
log.Printf("[INFO] Stack %s was removed on %v", d.Id(), stack.Removed)
d.SetId("")