providers/google: on refresh, treat 404 as resource gone
This commit is contained in:
parent
673b62db96
commit
f2d7900e63
|
@ -6,6 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.google.com/p/google-api-go-client/compute/v1"
|
"code.google.com/p/google-api-go-client/compute/v1"
|
||||||
|
"code.google.com/p/google-api-go-client/googleapi"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -78,6 +79,13 @@ func resourceComputeAddressRead(d *schema.ResourceData, meta interface{}) error
|
||||||
addr, err := config.clientCompute.Addresses.Get(
|
addr, err := config.clientCompute.Addresses.Get(
|
||||||
config.Project, config.Region, d.Id()).Do()
|
config.Project, config.Region, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
||||||
|
// The resource doesn't exist anymore
|
||||||
|
d.SetId("")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return fmt.Errorf("Error reading address: %s", err)
|
return fmt.Errorf("Error reading address: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.google.com/p/google-api-go-client/compute/v1"
|
"code.google.com/p/google-api-go-client/compute/v1"
|
||||||
|
"code.google.com/p/google-api-go-client/googleapi"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -107,6 +108,13 @@ func resourceComputeDiskRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
_, err := config.clientCompute.Disks.Get(
|
_, err := config.clientCompute.Disks.Get(
|
||||||
config.Project, d.Get("zone").(string), d.Id()).Do()
|
config.Project, d.Get("zone").(string), d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
||||||
|
// The resource doesn't exist anymore
|
||||||
|
d.SetId("")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return fmt.Errorf("Error reading disk: %s", err)
|
return fmt.Errorf("Error reading disk: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.google.com/p/google-api-go-client/compute/v1"
|
"code.google.com/p/google-api-go-client/compute/v1"
|
||||||
|
"code.google.com/p/google-api-go-client/googleapi"
|
||||||
"github.com/hashicorp/terraform/helper/hashcode"
|
"github.com/hashicorp/terraform/helper/hashcode"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
@ -193,6 +194,13 @@ func resourceComputeFirewallRead(d *schema.ResourceData, meta interface{}) error
|
||||||
_, err := config.clientCompute.Firewalls.Get(
|
_, err := config.clientCompute.Firewalls.Get(
|
||||||
config.Project, d.Id()).Do()
|
config.Project, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
||||||
|
// The resource doesn't exist anymore
|
||||||
|
d.SetId("")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return fmt.Errorf("Error reading firewall: %s", err)
|
return fmt.Errorf("Error reading firewall: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.google.com/p/google-api-go-client/compute/v1"
|
"code.google.com/p/google-api-go-client/compute/v1"
|
||||||
|
"code.google.com/p/google-api-go-client/googleapi"
|
||||||
"github.com/hashicorp/terraform/helper/hashcode"
|
"github.com/hashicorp/terraform/helper/hashcode"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
@ -304,6 +305,13 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error
|
||||||
instance, err := config.clientCompute.Instances.Get(
|
instance, err := config.clientCompute.Instances.Get(
|
||||||
config.Project, d.Get("zone").(string), d.Id()).Do()
|
config.Project, d.Get("zone").(string), d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
||||||
|
// The resource doesn't exist anymore
|
||||||
|
d.SetId("")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return fmt.Errorf("Error reading instance: %s", err)
|
return fmt.Errorf("Error reading instance: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.google.com/p/google-api-go-client/compute/v1"
|
"code.google.com/p/google-api-go-client/compute/v1"
|
||||||
|
"code.google.com/p/google-api-go-client/googleapi"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -86,6 +87,13 @@ func resourceComputeNetworkRead(d *schema.ResourceData, meta interface{}) error
|
||||||
network, err := config.clientCompute.Networks.Get(
|
network, err := config.clientCompute.Networks.Get(
|
||||||
config.Project, d.Id()).Do()
|
config.Project, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
||||||
|
// The resource doesn't exist anymore
|
||||||
|
d.SetId("")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return fmt.Errorf("Error reading network: %s", err)
|
return fmt.Errorf("Error reading network: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.google.com/p/google-api-go-client/compute/v1"
|
"code.google.com/p/google-api-go-client/compute/v1"
|
||||||
|
"code.google.com/p/google-api-go-client/googleapi"
|
||||||
"github.com/hashicorp/terraform/helper/hashcode"
|
"github.com/hashicorp/terraform/helper/hashcode"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
@ -185,6 +186,13 @@ func resourceComputeRouteRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
_, err := config.clientCompute.Routes.Get(
|
_, err := config.clientCompute.Routes.Get(
|
||||||
config.Project, d.Id()).Do()
|
config.Project, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
||||||
|
// The resource doesn't exist anymore
|
||||||
|
d.SetId("")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return fmt.Errorf("Error reading route: %#v", err)
|
return fmt.Errorf("Error reading route: %#v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue