Fix error if container_node_pool deleted out of band (#293)

Prior to this change it was possible for Terraform to error during plan / apply with the following:
Error 404: The resource "node pool \"foo\" not found"
This commit is contained in:
Matt Morrison 2017-08-05 05:24:53 +12:00 committed by Dana Hoffman
parent dd93516ce8
commit 0be42521c1

View File

@ -7,7 +7,6 @@ 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 resourceContainerNodePool() *schema.Resource { func resourceContainerNodePool() *schema.Resource {
@ -350,10 +349,8 @@ func resourceContainerNodePoolExists(d *schema.ResourceData, meta interface{}) (
_, err = config.clientContainer.Projects.Zones.Clusters.NodePools.Get( _, err = config.clientContainer.Projects.Zones.Clusters.NodePools.Get(
project, zone, cluster, name).Do() project, zone, cluster, name).Do()
if err != nil { if err != nil {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 { if err = handleNotFoundError(err, d, fmt.Sprintf("Container NodePool %s", d.Get("name").(string))); err == nil {
log.Printf("[WARN] Removing Container NodePool %q because it's gone", name) return false, nil
// The resource doesn't exist anymore
return false, err
} }
// There was some other error in reading the resource // There was some other error in reading the resource
return true, err return true, err