Merge pull request #3763 from sl1pm4t/b-gce-instance-no-exist
Issue #3742 - terraform destroy fails if Google Compute Instance no...
This commit is contained in:
commit
889b9fc95d
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
"google.golang.org/api/compute/v1"
|
"google.golang.org/api/compute/v1"
|
||||||
"google.golang.org/api/googleapi"
|
"google.golang.org/api/googleapi"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func stringHashcode(v interface{}) int {
|
func stringHashcode(v interface{}) int {
|
||||||
|
@ -285,9 +286,10 @@ func getInstance(config *Config, d *schema.ResourceData) (*compute.Instance, err
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
||||||
// The resource doesn't exist anymore
|
// The resource doesn't exist anymore
|
||||||
|
id := d.Id()
|
||||||
d.SetId("")
|
d.SetId("")
|
||||||
|
|
||||||
return nil, fmt.Errorf("Resource %s no longer exists", config.Project)
|
return nil, fmt.Errorf("Resource %s no longer exists", id)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("Error reading instance: %s", err)
|
return nil, fmt.Errorf("Error reading instance: %s", err)
|
||||||
|
@ -547,8 +549,13 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
|
||||||
func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error {
|
func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
config := meta.(*Config)
|
config := meta.(*Config)
|
||||||
|
|
||||||
|
id := d.Id()
|
||||||
instance, err := getInstance(config, d)
|
instance, err := getInstance(config, d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if strings.Contains(err.Error(), "no longer exists") {
|
||||||
|
log.Printf("[WARN] Google Compute Instance (%s) not found", id)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue