mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-03 08:42:39 +00:00
Merge branch 'master' into cloud_router
This commit is contained in:
commit
ec3a2d9535
47
import_compute_route_test.go
Normal file
47
import_compute_route_test.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package google
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
)
|
||||
|
||||
func TestAccComputeRoute_importBasic(t *testing.T) {
|
||||
resourceName := "google_compute_network.foobar"
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckComputeRouteDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccComputeRoute_basic,
|
||||
},
|
||||
{
|
||||
ResourceName: resourceName,
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccComputeRoute_importDefaultInternetGateway(t *testing.T) {
|
||||
resourceName := "google_compute_network.foobar"
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckComputeRouteDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccComputeRoute_defaultInternetGateway,
|
||||
},
|
||||
{
|
||||
ResourceName: resourceName,
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
13
provider.go
13
provider.go
|
@ -3,6 +3,7 @@ package google
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/mutexkv"
|
||||
|
@ -262,3 +263,15 @@ func getNetworkNameFromSelfLink(network string) (string, error) {
|
|||
func getRouterLockName(region string, router string) string {
|
||||
return fmt.Sprintf("router/%s/%s", region, router)
|
||||
}
|
||||
|
||||
func handleNotFoundError(err error, d *schema.ResourceData, resource string) error {
|
||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
||||
log.Printf("[WARN] Removing %s because it's gone", resource)
|
||||
// The resource doesn't exist anymore
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("Error reading %s: %s", resource, err)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"google.golang.org/api/compute/v1"
|
||||
"google.golang.org/api/googleapi"
|
||||
)
|
||||
|
||||
func stringScopeHashcode(v interface{}) int {
|
||||
|
@ -361,16 +360,7 @@ func getInstance(config *Config, d *schema.ResourceData) (*compute.Instance, err
|
|||
instance, err := config.clientCompute.Instances.Get(
|
||||
project, d.Get("zone").(string), d.Id()).Do()
|
||||
if err != nil {
|
||||
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
|
||||
id := d.Id()
|
||||
d.SetId("")
|
||||
|
||||
return nil, fmt.Errorf("Resource %s no longer exists", id)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("Error reading instance: %s", err)
|
||||
return nil, handleNotFoundError(err, d, fmt.Sprintf("Instance %s", d.Get("name").(string)))
|
||||
}
|
||||
|
||||
return instance, nil
|
||||
|
@ -713,13 +703,8 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
|
|||
func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
|
||||
id := d.Id()
|
||||
instance, err := getInstance(config, d)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "no longer exists") {
|
||||
log.Printf("[WARN] Google Compute Instance (%s) not found", id)
|
||||
return nil
|
||||
}
|
||||
if err != nil || instance == nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -222,7 +222,7 @@ func resourceComputeInstanceGroupManagerRead(d *schema.ResourceData, meta interf
|
|||
manager, e = config.clientCompute.InstanceGroupManagers.Get(project, zone.(string), d.Id()).Do()
|
||||
|
||||
if e != nil {
|
||||
return e
|
||||
return handleNotFoundError(e, d, fmt.Sprintf("Instance Group Manager %q", d.Get("name").(string)))
|
||||
}
|
||||
} else {
|
||||
// If the resource was imported, the only info we have is the ID. Try to find the resource
|
||||
|
|
|
@ -14,6 +14,9 @@ func resourceComputeRoute() *schema.Resource {
|
|||
Create: resourceComputeRouteCreate,
|
||||
Read: resourceComputeRouteRead,
|
||||
Delete: resourceComputeRouteDelete,
|
||||
Importer: &schema.ResourceImporter{
|
||||
State: schema.ImportStatePassthrough,
|
||||
},
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"dest_range": &schema.Schema{
|
||||
|
|
|
@ -151,6 +151,14 @@ func resourceStorageBucketObjectDelete(d *schema.ResourceData, meta interface{})
|
|||
err := DeleteCall.Do()
|
||||
|
||||
if err != nil {
|
||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
||||
log.Printf("[WARN] Removing Bucket Object %q because it's gone", name)
|
||||
// The resource doesn't exist anymore
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("Error deleting contents of object %s: %s", name, err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user