Skip to content

Commit

Permalink
Rancher: reset Id for unknown resources (#11543)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
raphink authored and stack72 committed Jan 31, 2017
1 parent b68a584 commit ed69c1e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions builtin/providers/rancher/resource_rancher_environment.go
Expand Up @@ -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)
Expand Down
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions builtin/providers/rancher/resource_rancher_registry.go
Expand Up @@ -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)
Expand Down
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions builtin/providers/rancher/resource_rancher_stack.go
Expand Up @@ -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("")
Expand Down

0 comments on commit ed69c1e

Please sign in to comment.