provider/google: Updated Read(..) behavior to handle deleted resources

This commit is contained in:
Lars Wander 2015-11-13 15:36:03 -05:00 committed by Lars Wander
parent 96976222bb
commit cef0589498
32 changed files with 138 additions and 4 deletions

View File

@ -82,6 +82,7 @@ func resourceComputeAddressRead(d *schema.ResourceData, meta interface{}) error
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
log.Printf("[WARN] Removing Address %q because it's gone", d.Get("name").(string))
d.SetId("") d.SetId("")
return nil return nil

View File

@ -240,6 +240,7 @@ func resourceComputeAutoscalerRead(d *schema.ResourceData, meta interface{}) 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
log.Printf("[WARN] Removing Autoscalar %q because it's gone", d.Get("name").(string))
d.SetId("") d.SetId("")
return nil return nil

View File

@ -186,6 +186,7 @@ func resourceComputeBackendServiceRead(d *schema.ResourceData, meta interface{})
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
log.Printf("[WARN] Removing Backend Service %q because it's gone", d.Get("name").(string))
d.SetId("") d.SetId("")
return nil return nil

View File

@ -141,6 +141,7 @@ func resourceComputeDiskRead(d *schema.ResourceData, meta interface{}) error {
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 { if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing Disk %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore // The resource doesn't exist anymore
d.SetId("") d.SetId("")

View File

@ -3,6 +3,7 @@ package google
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"log"
"sort" "sort"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
@ -150,6 +151,7 @@ func resourceComputeFirewallRead(d *schema.ResourceData, meta interface{}) error
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
log.Printf("[WARN] Removing Firewall %q because it's gone", d.Get("name").(string))
d.SetId("") d.SetId("")
return nil return nil

View File

@ -139,6 +139,7 @@ func resourceComputeForwardingRuleRead(d *schema.ResourceData, meta interface{})
config.Project, region, d.Id()).Do() config.Project, region, d.Id()).Do()
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 {
log.Printf("[WARN] Removing Forwarding Rule %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore // The resource doesn't exist anymore
d.SetId("") d.SetId("")

View File

@ -64,6 +64,7 @@ func resourceComputeGlobalAddressRead(d *schema.ResourceData, meta interface{})
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 { if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing Global Address %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore // The resource doesn't exist anymore
d.SetId("") d.SetId("")

View File

@ -131,6 +131,7 @@ func resourceComputeGlobalForwardingRuleRead(d *schema.ResourceData, meta interf
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 { if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing Global Forwarding Rule %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore // The resource doesn't exist anymore
d.SetId("") d.SetId("")

View File

@ -187,6 +187,7 @@ func resourceComputeHttpHealthCheckRead(d *schema.ResourceData, meta interface{}
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
log.Printf("[WARN] Removing HTTP Health Check %q because it's gone", d.Get("name").(string))
d.SetId("") d.SetId("")
return nil return nil

View File

@ -186,6 +186,7 @@ func resourceComputeHttpsHealthCheckRead(d *schema.ResourceData, meta interface{
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 { if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing HTTPS Health Check %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore // The resource doesn't exist anymore
d.SetId("") d.SetId("")

View File

@ -285,6 +285,7 @@ func getInstance(config *Config, d *schema.ResourceData) (*compute.Instance, err
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 { if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing Instance %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore // The resource doesn't exist anymore
id := d.Id() id := d.Id()
d.SetId("") d.SetId("")

View File

@ -149,6 +149,7 @@ func resourceComputeInstanceGroupManagerRead(d *schema.ResourceData, meta interf
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 { if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing Instance Group Manager %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore // The resource doesn't exist anymore
d.SetId("") d.SetId("")

View File

@ -2,6 +2,7 @@ package google
import ( import (
"fmt" "fmt"
"log"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -466,6 +467,7 @@ func resourceComputeInstanceTemplateRead(d *schema.ResourceData, meta interface{
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 { if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing Instance Template %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore // The resource doesn't exist anymore
d.SetId("") d.SetId("")

View File

@ -74,6 +74,7 @@ func resourceComputeNetworkRead(d *schema.ResourceData, meta interface{}) error
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 { if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing Network %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore // The resource doesn't exist anymore
d.SetId("") d.SetId("")

View File

@ -4,10 +4,9 @@ import (
"fmt" "fmt"
"log" "log"
// "github.com/hashicorp/terraform/helper/hashcode"
"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"
) )
func resourceComputeProjectMetadata() *schema.Resource { func resourceComputeProjectMetadata() *schema.Resource {
@ -85,6 +84,14 @@ func resourceComputeProjectMetadataRead(d *schema.ResourceData, meta interface{}
log.Printf("[DEBUG] Loading project service: %s", config.Project) log.Printf("[DEBUG] Loading project service: %s", config.Project)
project, err := config.clientCompute.Projects.Get(config.Project).Do() project, err := config.clientCompute.Projects.Get(config.Project).Do()
if err != nil { if err != nil {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing Project Metadata because it's gone")
// The resource doesn't exist anymore
d.SetId("")
return nil
}
return fmt.Errorf("Error loading project '%s': %s", config.Project, err) return fmt.Errorf("Error loading project '%s': %s", config.Project, err)
} }

View File

@ -185,6 +185,7 @@ func resourceComputeRouteRead(d *schema.ResourceData, meta interface{}) error {
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 { if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing Route %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore // The resource doesn't exist anymore
d.SetId("") d.SetId("")

View File

@ -2,6 +2,7 @@ package google
import ( import (
"fmt" "fmt"
"log"
"strconv" "strconv"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -91,6 +92,7 @@ func resourceComputeSslCertificateRead(d *schema.ResourceData, meta interface{})
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 { if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing SSL Certificate %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore // The resource doesn't exist anymore
d.SetId("") d.SetId("")

View File

@ -111,6 +111,7 @@ func resourceComputeTargetHttpProxyRead(d *schema.ResourceData, meta interface{}
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 { if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing Target HTTP Proxy %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore // The resource doesn't exist anymore
d.SetId("") d.SetId("")

View File

@ -186,6 +186,7 @@ func resourceComputeTargetHttpsProxyRead(d *schema.ResourceData, meta interface{
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 { if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing Target HTTPS Proxy %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore // The resource doesn't exist anymore
d.SetId("") d.SetId("")

View File

@ -330,6 +330,7 @@ func resourceComputeTargetPoolRead(d *schema.ResourceData, meta interface{}) err
config.Project, region, d.Id()).Do() config.Project, region, d.Id()).Do()
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 {
log.Printf("[WARN] Removing Target Pool %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore // The resource doesn't exist anymore
d.SetId("") d.SetId("")

View File

@ -2,10 +2,12 @@ package google
import ( import (
"fmt" "fmt"
"log"
"strconv" "strconv"
"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"
) )
func resourceComputeUrlMap() *schema.Resource { func resourceComputeUrlMap() *schema.Resource {
@ -292,6 +294,14 @@ func resourceComputeUrlMapRead(d *schema.ResourceData, meta interface{}) error {
urlMap, err := config.clientCompute.UrlMaps.Get(config.Project, name).Do() urlMap, err := config.clientCompute.UrlMaps.Get(config.Project, name).Do()
if err != nil { if err != nil {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing URL Map %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore
d.SetId("")
return nil
}
return fmt.Errorf("Error, failed to get Url Map %s: %s", name, err) return fmt.Errorf("Error, failed to get Url Map %s: %s", name, err)
} }

View File

@ -2,10 +2,12 @@ package google
import ( import (
"fmt" "fmt"
"log"
"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"
) )
func resourceComputeVpnGateway() *schema.Resource { func resourceComputeVpnGateway() *schema.Resource {
@ -88,6 +90,14 @@ func resourceComputeVpnGatewayRead(d *schema.ResourceData, meta interface{}) err
vpnGateway, err := vpnGatewaysService.Get(project, region, name).Do() vpnGateway, err := vpnGatewaysService.Get(project, region, name).Do()
if err != nil { if err != nil {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing VPN Gateway %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore
d.SetId("")
return nil
}
return fmt.Errorf("Error Reading VPN Gateway %s: %s", name, err) return fmt.Errorf("Error Reading VPN Gateway %s: %s", name, err)
} }

View File

@ -2,10 +2,12 @@ package google
import ( import (
"fmt" "fmt"
"log"
"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"
) )
func resourceComputeVpnTunnel() *schema.Resource { func resourceComputeVpnTunnel() *schema.Resource {
@ -118,6 +120,14 @@ func resourceComputeVpnTunnelRead(d *schema.ResourceData, meta interface{}) erro
vpnTunnel, err := vpnTunnelsService.Get(project, region, name).Do() vpnTunnel, err := vpnTunnelsService.Get(project, region, name).Do()
if err != nil { if err != nil {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing VPN Tunnel %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore
d.SetId("")
return nil
}
return fmt.Errorf("Error Reading VPN Tunnel %s: %s", name, err) return fmt.Errorf("Error Reading VPN Tunnel %s: %s", name, err)
} }

View File

@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/container/v1" "google.golang.org/api/container/v1"
"google.golang.org/api/googleapi"
) )
func resourceContainerCluster() *schema.Resource { func resourceContainerCluster() *schema.Resource {
@ -312,6 +313,14 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
cluster, err := config.clientContainer.Projects.Zones.Clusters.Get( cluster, err := config.clientContainer.Projects.Zones.Clusters.Get(
config.Project, zoneName, d.Get("name").(string)).Do() config.Project, zoneName, d.Get("name").(string)).Do()
if err != nil { if err != nil {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing Container Cluster %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore
d.SetId("")
return nil
}
return err return err
} }

View File

@ -81,6 +81,7 @@ func resourceDnsManagedZoneRead(d *schema.ResourceData, meta interface{}) error
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 { if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing DNS Managed Zone %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore // The resource doesn't exist anymore
d.SetId("") d.SetId("")

View File

@ -7,6 +7,7 @@ import (
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/dns/v1" "google.golang.org/api/dns/v1"
"google.golang.org/api/googleapi"
) )
func resourceDnsRecordSet() *schema.Resource { func resourceDnsRecordSet() *schema.Resource {
@ -114,6 +115,14 @@ func resourceDnsRecordSetRead(d *schema.ResourceData, meta interface{}) error {
resp, err := config.clientDns.ResourceRecordSets.List( resp, err := config.clientDns.ResourceRecordSets.List(
config.Project, zone).Name(name).Type(dnsType).Do() config.Project, zone).Name(name).Type(dnsType).Do()
if err != nil { if err != nil {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing DNS Record Set %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore
d.SetId("")
return nil
}
return fmt.Errorf("Error reading DNS RecordSet: %#v", err) return fmt.Errorf("Error reading DNS RecordSet: %#v", err)
} }
if len(resp.Rrsets) == 0 { if len(resp.Rrsets) == 0 {

View File

@ -2,9 +2,11 @@ package google
import ( import (
"fmt" "fmt"
"log"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/googleapi"
"google.golang.org/api/sqladmin/v1beta4" "google.golang.org/api/sqladmin/v1beta4"
) )
@ -75,6 +77,14 @@ func resourceSqlDatabaseRead(d *schema.ResourceData, meta interface{}) error {
database_name).Do() database_name).Do()
if err != nil { if err != nil {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing SQL Database %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore
d.SetId("")
return nil
}
return fmt.Errorf("Error, failed to get"+ return fmt.Errorf("Error, failed to get"+
"database %s in instance %s: %s", database_name, "database %s in instance %s: %s", database_name,
instance_name, err) instance_name, err)

View File

@ -2,9 +2,11 @@ package google
import ( import (
"fmt" "fmt"
"log"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/googleapi"
"google.golang.org/api/sqladmin/v1beta4" "google.golang.org/api/sqladmin/v1beta4"
) )
@ -462,6 +464,14 @@ func resourceSqlDatabaseInstanceRead(d *schema.ResourceData, meta interface{}) e
d.Get("name").(string)).Do() d.Get("name").(string)).Do()
if err != nil { if err != nil {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing SQL Database %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore
d.SetId("")
return nil
}
return fmt.Errorf("Error retrieving instance %s: %s", return fmt.Errorf("Error retrieving instance %s: %s",
d.Get("name").(string), err) d.Get("name").(string), err)
} }

View File

@ -7,6 +7,7 @@ import (
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/googleapi"
"google.golang.org/api/storage/v1" "google.golang.org/api/storage/v1"
) )
@ -174,8 +175,15 @@ func resourceStorageBucketRead(d *schema.ResourceData, meta interface{}) error {
res, err := config.clientStorage.Buckets.Get(bucket).Do() res, err := config.clientStorage.Buckets.Get(bucket).Do()
if err != nil { if err != nil {
fmt.Printf("Error reading bucket %s: %v", bucket, err) if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
return err log.Printf("[WARN] Removing Bucket %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore
d.SetId("")
return nil
}
return fmt.Errorf("Error reading bucket %s: %v", bucket, err)
} }
log.Printf("[DEBUG] Read bucket %v at location %v\n\n", res.Name, res.SelfLink) log.Printf("[DEBUG] Read bucket %v at location %v\n\n", res.Name, res.SelfLink)

View File

@ -7,6 +7,7 @@ import (
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/googleapi"
"google.golang.org/api/storage/v1" "google.golang.org/api/storage/v1"
) )
@ -166,6 +167,14 @@ func resourceStorageBucketAclRead(d *schema.ResourceData, meta interface{}) erro
res, err := config.clientStorage.BucketAccessControls.List(bucket).Do() res, err := config.clientStorage.BucketAccessControls.List(bucket).Do()
if err != nil { if err != nil {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing Bucket ACL for bucket %q because it's gone", d.Get("bucket").(string))
// The resource doesn't exist anymore
d.SetId("")
return nil
}
return err return err
} }

View File

@ -2,10 +2,12 @@ package google
import ( import (
"fmt" "fmt"
"log"
"os" "os"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/googleapi"
"google.golang.org/api/storage/v1" "google.golang.org/api/storage/v1"
) )
@ -96,6 +98,14 @@ func resourceStorageBucketObjectRead(d *schema.ResourceData, meta interface{}) e
res, err := getCall.Do() res, err := getCall.Do()
if err != nil { if err != nil {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing Bucket Object %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore
d.SetId("")
return nil
}
return fmt.Errorf("Error retrieving contents of object %s: %s", name, err) return fmt.Errorf("Error retrieving contents of object %s: %s", name, err)
} }

View File

@ -6,6 +6,7 @@ import (
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/googleapi"
"google.golang.org/api/storage/v1" "google.golang.org/api/storage/v1"
) )
@ -134,6 +135,14 @@ func resourceStorageObjectAclRead(d *schema.ResourceData, meta interface{}) erro
res, err := config.clientStorage.ObjectAccessControls.List(bucket, object).Do() res, err := config.clientStorage.ObjectAccessControls.List(bucket, object).Do()
if err != nil { if err != nil {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing Storage Object ACL for Bucket %q because it's gone", d.Get("bucket").(string))
// The resource doesn't exist anymore
d.SetId("")
return nil
}
return err return err
} }