providers/google: on refresh, treat 404 as resource gone

This commit is contained in:
Mitchell Hashimoto 2014-08-25 22:49:14 -07:00
parent 673b62db96
commit f2d7900e63
6 changed files with 48 additions and 0 deletions

View File

@ -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)
} }

View File

@ -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)
} }

View File

@ -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)
} }

View File

@ -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)
} }

View File

@ -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)
} }

View File

@ -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)
} }