provider/google: Handle all 404 checks in read functions via the new function
This commit is contained in:
parent
a6a796708e
commit
37911bcc99
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
"github.com/hashicorp/terraform/helper/validation"
|
"github.com/hashicorp/terraform/helper/validation"
|
||||||
"google.golang.org/api/bigquery/v2"
|
"google.golang.org/api/bigquery/v2"
|
||||||
"google.golang.org/api/googleapi"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceBigQueryDataset() *schema.Resource {
|
func resourceBigQueryDataset() *schema.Resource {
|
||||||
|
@ -225,15 +224,7 @@ func resourceBigQueryDatasetRead(d *schema.ResourceData, meta interface{}) error
|
||||||
|
|
||||||
res, err := config.clientBigQuery.Datasets.Get(projectID, datasetID).Do()
|
res, err := config.clientBigQuery.Datasets.Get(projectID, datasetID).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("BigQuery dataset %q", datasetID))
|
||||||
log.Printf("[WARN] Removing BigQuery dataset %q because it's gone", datasetID)
|
|
||||||
// The resource doesn't exist anymore
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("etag", res.Etag)
|
d.Set("etag", res.Etag)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"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 resourceComputeAddress() *schema.Resource {
|
func resourceComputeAddress() *schema.Resource {
|
||||||
|
@ -97,15 +96,7 @@ func resourceComputeAddressRead(d *schema.ResourceData, meta interface{}) error
|
||||||
addr, err := config.clientCompute.Addresses.Get(
|
addr, err := config.clientCompute.Addresses.Get(
|
||||||
project, region, d.Id()).Do()
|
project, region, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Address %q", d.Get("name").(string)))
|
||||||
// The resource doesn't exist anymore
|
|
||||||
log.Printf("[WARN] Removing Address %q because it's gone", d.Get("name").(string))
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading address: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("address", addr.Address)
|
d.Set("address", addr.Address)
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
|
|
||||||
"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 resourceComputeBackendBucket() *schema.Resource {
|
func resourceComputeBackendBucket() *schema.Resource {
|
||||||
|
@ -118,15 +117,7 @@ func resourceComputeBackendBucketRead(d *schema.ResourceData, meta interface{})
|
||||||
bucket, err := config.clientCompute.BackendBuckets.Get(
|
bucket, err := config.clientCompute.BackendBuckets.Get(
|
||||||
project, d.Id()).Do()
|
project, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Backend Bucket %q", d.Get("name").(string)))
|
||||||
// The resource doesn't exist anymore
|
|
||||||
log.Printf("[WARN] Removing Backend Bucket %q because it's gone", d.Get("name").(string))
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading bucket: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("bucket_name", bucket.BucketName)
|
d.Set("bucket_name", bucket.BucketName)
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/hashicorp/terraform/helper/hashcode"
|
"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"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceComputeBackendService() *schema.Resource {
|
func resourceComputeBackendService() *schema.Resource {
|
||||||
|
@ -225,15 +224,7 @@ func resourceComputeBackendServiceRead(d *schema.ResourceData, meta interface{})
|
||||||
service, err := config.clientCompute.BackendServices.Get(
|
service, err := config.clientCompute.BackendServices.Get(
|
||||||
project, d.Id()).Do()
|
project, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Backend Service %q", d.Get("name").(string)))
|
||||||
// The resource doesn't exist anymore
|
|
||||||
log.Printf("[WARN] Removing Backend Service %q because it's gone", d.Get("name").(string))
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading service: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("description", service.Description)
|
d.Set("description", service.Description)
|
||||||
|
|
|
@ -174,15 +174,7 @@ func resourceComputeDiskRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
disk, err := config.clientCompute.Disks.Get(
|
disk, err := config.clientCompute.Disks.Get(
|
||||||
project, d.Get("zone").(string), d.Id()).Do()
|
project, d.Get("zone").(string), d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Disk %q", d.Get("name").(string)))
|
||||||
log.Printf("[WARN] Removing Disk %q because it's gone", d.Get("name").(string))
|
|
||||||
// The resource doesn't exist anymore
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading disk: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("self_link", disk.SelfLink)
|
d.Set("self_link", disk.SelfLink)
|
||||||
|
|
|
@ -3,14 +3,12 @@ package google
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/hashcode"
|
"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"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceComputeFirewall() *schema.Resource {
|
func resourceComputeFirewall() *schema.Resource {
|
||||||
|
@ -171,15 +169,7 @@ func resourceComputeFirewallRead(d *schema.ResourceData, meta interface{}) error
|
||||||
firewall, err := config.clientCompute.Firewalls.Get(
|
firewall, err := config.clientCompute.Firewalls.Get(
|
||||||
project, d.Id()).Do()
|
project, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Firewall %q", d.Get("name").(string)))
|
||||||
// The resource doesn't exist anymore
|
|
||||||
log.Printf("[WARN] Removing Firewall %q because it's gone", d.Get("name").(string))
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading firewall: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
networkUrl := strings.Split(firewall.Network, "/")
|
networkUrl := strings.Split(firewall.Network, "/")
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"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 resourceComputeForwardingRule() *schema.Resource {
|
func resourceComputeForwardingRule() *schema.Resource {
|
||||||
|
@ -226,15 +225,7 @@ func resourceComputeForwardingRuleRead(d *schema.ResourceData, meta interface{})
|
||||||
frule, err := config.clientCompute.ForwardingRules.Get(
|
frule, err := config.clientCompute.ForwardingRules.Get(
|
||||||
project, region, d.Id()).Do()
|
project, region, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Forwarding Rule %q", d.Get("name").(string)))
|
||||||
log.Printf("[WARN] Removing Forwarding Rule %q because it's gone", d.Get("name").(string))
|
|
||||||
// The resource doesn't exist anymore
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading ForwardingRule: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("name", frule.Name)
|
d.Set("name", frule.Name)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"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 resourceComputeGlobalAddress() *schema.Resource {
|
func resourceComputeGlobalAddress() *schema.Resource {
|
||||||
|
@ -81,15 +80,7 @@ func resourceComputeGlobalAddressRead(d *schema.ResourceData, meta interface{})
|
||||||
addr, err := config.clientCompute.GlobalAddresses.Get(
|
addr, err := config.clientCompute.GlobalAddresses.Get(
|
||||||
project, d.Id()).Do()
|
project, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Global Address %q", d.Get("name").(string)))
|
||||||
log.Printf("[WARN] Removing Global Address %q because it's gone", d.Get("name").(string))
|
|
||||||
// The resource doesn't exist anymore
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading address: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("address", addr.Address)
|
d.Set("address", addr.Address)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"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 resourceComputeGlobalForwardingRule() *schema.Resource {
|
func resourceComputeGlobalForwardingRule() *schema.Resource {
|
||||||
|
@ -152,15 +151,7 @@ func resourceComputeGlobalForwardingRuleRead(d *schema.ResourceData, meta interf
|
||||||
frule, err := config.clientCompute.GlobalForwardingRules.Get(
|
frule, err := config.clientCompute.GlobalForwardingRules.Get(
|
||||||
project, d.Id()).Do()
|
project, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Global Forwarding Rule %q", d.Get("name").(string)))
|
||||||
log.Printf("[WARN] Removing Global Forwarding Rule %q because it's gone", d.Get("name").(string))
|
|
||||||
// The resource doesn't exist anymore
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading GlobalForwardingRule: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("ip_address", frule.IPAddress)
|
d.Set("ip_address", frule.IPAddress)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"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 resourceComputeHealthCheck() *schema.Resource {
|
func resourceComputeHealthCheck() *schema.Resource {
|
||||||
|
@ -442,15 +441,7 @@ func resourceComputeHealthCheckRead(d *schema.ResourceData, meta interface{}) er
|
||||||
hchk, err := config.clientCompute.HealthChecks.Get(
|
hchk, err := config.clientCompute.HealthChecks.Get(
|
||||||
project, d.Id()).Do()
|
project, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Health Check %q", d.Get("name").(string)))
|
||||||
// The resource doesn't exist anymore
|
|
||||||
log.Printf("[WARN] Removing Health Check %q because it's gone", d.Get("name").(string))
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading HealthCheck: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("check_interval_sec", hchk.CheckIntervalSec)
|
d.Set("check_interval_sec", hchk.CheckIntervalSec)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"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 resourceComputeHttpHealthCheck() *schema.Resource {
|
func resourceComputeHttpHealthCheck() *schema.Resource {
|
||||||
|
@ -210,15 +209,7 @@ func resourceComputeHttpHealthCheckRead(d *schema.ResourceData, meta interface{}
|
||||||
hchk, err := config.clientCompute.HttpHealthChecks.Get(
|
hchk, err := config.clientCompute.HttpHealthChecks.Get(
|
||||||
project, d.Id()).Do()
|
project, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("HTTP Health Check %q", d.Get("name").(string)))
|
||||||
// The resource doesn't exist anymore
|
|
||||||
log.Printf("[WARN] Removing HTTP Health Check %q because it's gone", d.Get("name").(string))
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading HttpHealthCheck: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("host", hchk.Host)
|
d.Set("host", hchk.Host)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"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 resourceComputeHttpsHealthCheck() *schema.Resource {
|
func resourceComputeHttpsHealthCheck() *schema.Resource {
|
||||||
|
@ -206,15 +205,7 @@ func resourceComputeHttpsHealthCheckRead(d *schema.ResourceData, meta interface{
|
||||||
hchk, err := config.clientCompute.HttpsHealthChecks.Get(
|
hchk, err := config.clientCompute.HttpsHealthChecks.Get(
|
||||||
project, d.Id()).Do()
|
project, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("HTTPS Health Check %q", d.Get("name").(string)))
|
||||||
log.Printf("[WARN] Removing HTTPS Health Check %q because it's gone", d.Get("name").(string))
|
|
||||||
// The resource doesn't exist anymore
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading HttpsHealthCheck: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("host", hchk.Host)
|
d.Set("host", hchk.Host)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"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 resourceComputeImage() *schema.Resource {
|
func resourceComputeImage() *schema.Resource {
|
||||||
|
@ -164,15 +163,7 @@ func resourceComputeImageRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
image, err := config.clientCompute.Images.Get(
|
image, err := config.clientCompute.Images.Get(
|
||||||
project, d.Id()).Do()
|
project, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Image %q", d.Get("name").(string)))
|
||||||
// The resource doesn't exist anymore
|
|
||||||
log.Printf("[WARN] Removing Image %q because it's gone", d.Get("name").(string))
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading image: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("self_link", image.SelfLink)
|
d.Set("self_link", image.SelfLink)
|
||||||
|
|
|
@ -183,14 +183,7 @@ func resourceComputeInstanceGroupRead(d *schema.ResourceData, meta interface{})
|
||||||
instanceGroup, err := config.clientCompute.InstanceGroups.Get(
|
instanceGroup, err := config.clientCompute.InstanceGroups.Get(
|
||||||
project, d.Get("zone").(string), d.Id()).Do()
|
project, d.Get("zone").(string), d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Instance Group %q", d.Get("name").(string)))
|
||||||
// The resource doesn't exist anymore
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading InstanceGroup: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// retreive instance group members
|
// retreive instance group members
|
||||||
|
|
|
@ -2,13 +2,11 @@ package google
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"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/compute/v1"
|
"google.golang.org/api/compute/v1"
|
||||||
"google.golang.org/api/googleapi"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceComputeInstanceTemplate() *schema.Resource {
|
func resourceComputeInstanceTemplate() *schema.Resource {
|
||||||
|
@ -721,14 +719,7 @@ func resourceComputeInstanceTemplateRead(d *schema.ResourceData, meta interface{
|
||||||
instanceTemplate, err := config.clientCompute.InstanceTemplates.Get(
|
instanceTemplate, err := config.clientCompute.InstanceTemplates.Get(
|
||||||
project, d.Id()).Do()
|
project, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Instance Template %q", d.Get("name").(string)))
|
||||||
log.Printf("[WARN] Removing Instance Template %q because it's gone", d.Get("name").(string))
|
|
||||||
// The resource doesn't exist anymore
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading instance template: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the metadata fingerprint if there is one.
|
// Set the metadata fingerprint if there is one.
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"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 resourceComputeNetwork() *schema.Resource {
|
func resourceComputeNetwork() *schema.Resource {
|
||||||
|
@ -132,15 +131,7 @@ func resourceComputeNetworkRead(d *schema.ResourceData, meta interface{}) error
|
||||||
network, err := config.clientCompute.Networks.Get(
|
network, err := config.clientCompute.Networks.Get(
|
||||||
project, d.Id()).Do()
|
project, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Network %q", d.Get("name").(string)))
|
||||||
log.Printf("[WARN] Removing Network %q because it's gone", d.Get("name").(string))
|
|
||||||
// The resource doesn't exist anymore
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading network: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("gateway_ipv4", network.GatewayIPv4)
|
d.Set("gateway_ipv4", network.GatewayIPv4)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"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 resourceComputeProjectMetadata() *schema.Resource {
|
func resourceComputeProjectMetadata() *schema.Resource {
|
||||||
|
@ -100,15 +99,7 @@ func resourceComputeProjectMetadataRead(d *schema.ResourceData, meta interface{}
|
||||||
log.Printf("[DEBUG] Loading project service: %s", projectID)
|
log.Printf("[DEBUG] Loading project service: %s", projectID)
|
||||||
project, err := config.clientCompute.Projects.Get(projectID).Do()
|
project, err := config.clientCompute.Projects.Get(projectID).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Project metadata for project %q", projectID))
|
||||||
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", projectID, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
md := project.CommonInstanceMetadata
|
md := project.CommonInstanceMetadata
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/hashicorp/terraform/helper/hashcode"
|
"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"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceComputeRegionBackendService() *schema.Resource {
|
func resourceComputeRegionBackendService() *schema.Resource {
|
||||||
|
@ -189,15 +188,7 @@ func resourceComputeRegionBackendServiceRead(d *schema.ResourceData, meta interf
|
||||||
service, err := config.clientCompute.RegionBackendServices.Get(
|
service, err := config.clientCompute.RegionBackendServices.Get(
|
||||||
project, region, d.Id()).Do()
|
project, region, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Region Backend Service %q", d.Get("name").(string)))
|
||||||
// The resource doesn't exist anymore
|
|
||||||
log.Printf("[WARN] Removing Backend Service %q because it's gone", d.Get("name").(string))
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading service: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("description", service.Description)
|
d.Set("description", service.Description)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"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 resourceComputeRoute() *schema.Resource {
|
func resourceComputeRoute() *schema.Resource {
|
||||||
|
@ -192,15 +191,7 @@ func resourceComputeRouteRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
route, err := config.clientCompute.Routes.Get(
|
route, err := config.clientCompute.Routes.Get(
|
||||||
project, d.Id()).Do()
|
project, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Route %q", d.Get("name").(string)))
|
||||||
log.Printf("[WARN] Removing Route %q because it's gone", d.Get("name").(string))
|
|
||||||
// The resource doesn't exist anymore
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading route: %#v", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("next_hop_network", route.NextHopNetwork)
|
d.Set("next_hop_network", route.NextHopNetwork)
|
||||||
|
|
|
@ -130,15 +130,7 @@ func resourceComputeSnapshotRead(d *schema.ResourceData, meta interface{}) error
|
||||||
snapshot, err := config.clientCompute.Snapshots.Get(
|
snapshot, err := config.clientCompute.Snapshots.Get(
|
||||||
project, d.Id()).Do()
|
project, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Snapshot %q", d.Get("name").(string)))
|
||||||
log.Printf("[WARN] Removing Snapshot %q because it's gone", d.Get("name").(string))
|
|
||||||
// The resource doesn't exist anymore
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading snapshot: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("self_link", snapshot.SelfLink)
|
d.Set("self_link", snapshot.SelfLink)
|
||||||
|
|
|
@ -2,13 +2,11 @@ package google
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"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/compute/v1"
|
"google.golang.org/api/compute/v1"
|
||||||
"google.golang.org/api/googleapi"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceComputeSslCertificate() *schema.Resource {
|
func resourceComputeSslCertificate() *schema.Resource {
|
||||||
|
@ -144,15 +142,7 @@ func resourceComputeSslCertificateRead(d *schema.ResourceData, meta interface{})
|
||||||
cert, err := config.clientCompute.SslCertificates.Get(
|
cert, err := config.clientCompute.SslCertificates.Get(
|
||||||
project, d.Id()).Do()
|
project, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("SSL Certificate %q", d.Get("name").(string)))
|
||||||
log.Printf("[WARN] Removing SSL Certificate %q because it's gone", d.Get("name").(string))
|
|
||||||
// The resource doesn't exist anymore
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading ssl certificate: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("self_link", cert.SelfLink)
|
d.Set("self_link", cert.SelfLink)
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
|
|
||||||
"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 resourceComputeSubnetwork() *schema.Resource {
|
func resourceComputeSubnetwork() *schema.Resource {
|
||||||
|
@ -146,15 +145,7 @@ func resourceComputeSubnetworkRead(d *schema.ResourceData, meta interface{}) err
|
||||||
subnetwork, err := config.clientCompute.Subnetworks.Get(
|
subnetwork, err := config.clientCompute.Subnetworks.Get(
|
||||||
project, region, name).Do()
|
project, region, name).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Subnetwork %q", name))
|
||||||
log.Printf("[WARN] Removing Subnetwork %q because it's gone", name)
|
|
||||||
// The resource doesn't exist anymore
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading subnetwork: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("gateway_address", subnetwork.GatewayAddress)
|
d.Set("gateway_address", subnetwork.GatewayAddress)
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
|
|
||||||
"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 resourceComputeTargetHttpProxy() *schema.Resource {
|
func resourceComputeTargetHttpProxy() *schema.Resource {
|
||||||
|
@ -131,15 +130,7 @@ func resourceComputeTargetHttpProxyRead(d *schema.ResourceData, meta interface{}
|
||||||
proxy, err := config.clientCompute.TargetHttpProxies.Get(
|
proxy, err := config.clientCompute.TargetHttpProxies.Get(
|
||||||
project, d.Id()).Do()
|
project, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Target HTTP Proxy %q", d.Get("name").(string)))
|
||||||
log.Printf("[WARN] Removing Target HTTP Proxy %q because it's gone", d.Get("name").(string))
|
|
||||||
// The resource doesn't exist anymore
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading TargetHttpProxy: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("self_link", proxy.SelfLink)
|
d.Set("self_link", proxy.SelfLink)
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
|
|
||||||
"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 resourceComputeTargetHttpsProxy() *schema.Resource {
|
func resourceComputeTargetHttpsProxy() *schema.Resource {
|
||||||
|
@ -206,15 +205,7 @@ func resourceComputeTargetHttpsProxyRead(d *schema.ResourceData, meta interface{
|
||||||
proxy, err := config.clientCompute.TargetHttpsProxies.Get(
|
proxy, err := config.clientCompute.TargetHttpsProxies.Get(
|
||||||
project, d.Id()).Do()
|
project, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Target HTTPS proxy %q", d.Get("name").(string)))
|
||||||
log.Printf("[WARN] Removing Target HTTPS Proxy %q because it's gone", d.Get("name").(string))
|
|
||||||
// The resource doesn't exist anymore
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading TargetHttpsProxy: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_certs := d.Get("ssl_certificates").([]interface{})
|
_certs := d.Get("ssl_certificates").([]interface{})
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
|
|
||||||
"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 resourceComputeTargetPool() *schema.Resource {
|
func resourceComputeTargetPool() *schema.Resource {
|
||||||
|
@ -391,15 +390,7 @@ func resourceComputeTargetPoolRead(d *schema.ResourceData, meta interface{}) err
|
||||||
tpool, err := config.clientCompute.TargetPools.Get(
|
tpool, err := config.clientCompute.TargetPools.Get(
|
||||||
project, region, d.Id()).Do()
|
project, region, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Target Pool %q", d.Get("name").(string)))
|
||||||
log.Printf("[WARN] Removing Target Pool %q because it's gone", d.Get("name").(string))
|
|
||||||
// The resource doesn't exist anymore
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error reading TargetPool: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
regionUrl := strings.Split(tpool.Region, "/")
|
regionUrl := strings.Split(tpool.Region, "/")
|
||||||
|
|
|
@ -2,12 +2,10 @@ 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 {
|
||||||
|
@ -312,15 +310,7 @@ func resourceComputeUrlMapRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
urlMap, err := config.clientCompute.UrlMaps.Get(project, name).Do()
|
urlMap, err := config.clientCompute.UrlMaps.Get(project, name).Do()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("URL Map %q", d.Get("name").(string)))
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.SetId(name)
|
d.SetId(name)
|
||||||
|
|
|
@ -2,12 +2,10 @@ 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 {
|
||||||
|
@ -119,15 +117,7 @@ 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 {
|
return handleNotFoundError(err, d, fmt.Sprintf("VPN Gateway %q", d.Get("name").(string)))
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("self_link", vpnGateway.SelfLink)
|
d.Set("self_link", vpnGateway.SelfLink)
|
||||||
|
|
|
@ -3,13 +3,11 @@ package google
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"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 {
|
||||||
|
@ -189,15 +187,7 @@ 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 {
|
return handleNotFoundError(err, d, fmt.Sprintf("VPN Tunnel %q", d.Get("name").(string)))
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
localTrafficSelectors := []string{}
|
localTrafficSelectors := []string{}
|
||||||
|
|
|
@ -9,7 +9,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"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -535,15 +534,7 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
|
||||||
cluster, err := config.clientContainer.Projects.Zones.Clusters.Get(
|
cluster, err := config.clientContainer.Projects.Zones.Clusters.Get(
|
||||||
project, zoneName, d.Get("name").(string)).Do()
|
project, zoneName, d.Get("name").(string)).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Container Cluster %q", d.Get("name").(string)))
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("name", cluster.Name)
|
d.Set("name", cluster.Name)
|
||||||
|
|
|
@ -6,7 +6,6 @@ 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 resourceDnsManagedZone() *schema.Resource {
|
func resourceDnsManagedZone() *schema.Resource {
|
||||||
|
@ -99,15 +98,7 @@ func resourceDnsManagedZoneRead(d *schema.ResourceData, meta interface{}) error
|
||||||
zone, err := config.clientDns.ManagedZones.Get(
|
zone, err := config.clientDns.ManagedZones.Get(
|
||||||
project, d.Id()).Do()
|
project, d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("DNS Managed Zone %q", d.Get("name").(string)))
|
||||||
log.Printf("[WARN] Removing DNS Managed Zone %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 ManagedZone: %#v", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("name_servers", zone.NameServers)
|
d.Set("name_servers", zone.NameServers)
|
||||||
|
|
|
@ -6,7 +6,6 @@ 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 {
|
||||||
|
@ -117,15 +116,7 @@ func resourceDnsRecordSetRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
resp, err := config.clientDns.ResourceRecordSets.List(
|
resp, err := config.clientDns.ResourceRecordSets.List(
|
||||||
project, zone).Name(name).Type(dnsType).Do()
|
project, zone).Name(name).Type(dnsType).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("DNS Record Set %q", d.Get("name").(string)))
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
if len(resp.Rrsets) == 0 {
|
if len(resp.Rrsets) == 0 {
|
||||||
// The resource doesn't exist anymore
|
// The resource doesn't exist anymore
|
||||||
|
|
|
@ -136,10 +136,7 @@ func resourceGoogleProjectRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
// Read the project
|
// Read the project
|
||||||
p, err := config.clientResourceManager.Projects.Get(pid).Do()
|
p, err := config.clientResourceManager.Projects.Get(pid).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if v, ok := err.(*googleapi.Error); ok && v.Code == http.StatusNotFound {
|
return handleNotFoundError(err, d, fmt.Sprintf("Project %q", pid))
|
||||||
return fmt.Errorf("Project %q does not exist.", pid)
|
|
||||||
}
|
|
||||||
return fmt.Errorf("Error checking project %q: %s", pid, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("project_id", pid)
|
d.Set("project_id", pid)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
"google.golang.org/api/googleapi"
|
|
||||||
"google.golang.org/api/iam/v1"
|
"google.golang.org/api/iam/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -116,14 +115,7 @@ func resourceGoogleServiceAccountRead(d *schema.ResourceData, meta interface{})
|
||||||
// Confirm the service account exists
|
// Confirm the service account exists
|
||||||
sa, err := config.clientIAM.Projects.ServiceAccounts.Get(d.Id()).Do()
|
sa, err := config.clientIAM.Projects.ServiceAccounts.Get(d.Id()).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Service Account %q", d.Id()))
|
||||||
log.Printf("[WARN] Removing reference to service account %q because it no longer exists", d.Id())
|
|
||||||
// The resource doesn't exist anymore
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return fmt.Errorf("Error reading service account %q: %q", d.Id(), err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("email", sa.Email)
|
d.Set("email", sa.Email)
|
||||||
|
|
|
@ -130,7 +130,7 @@ func resourcePubsubSubscriptionRead(d *schema.ResourceData, meta interface{}) er
|
||||||
call := config.clientPubsub.Projects.Subscriptions.Get(name)
|
call := config.clientPubsub.Projects.Subscriptions.Get(name)
|
||||||
_, err := call.Do()
|
_, err := call.Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return handleNotFoundError(err, d, fmt.Sprintf("Pubsub Subscription %q", name))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -58,7 +58,7 @@ func resourcePubsubTopicRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
call := config.clientPubsub.Projects.Topics.Get(name)
|
call := config.clientPubsub.Projects.Topics.Get(name)
|
||||||
_, err := call.Do()
|
_, err := call.Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return handleNotFoundError(err, d, fmt.Sprintf("Pubsub Topic %q", name))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -2,11 +2,9 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -93,17 +91,7 @@ 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 {
|
return handleNotFoundError(err, d, fmt.Sprintf("SQL Database %q in instance %q", database_name, instance_name))
|
||||||
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"+
|
|
||||||
"database %s in instance %s: %s", database_name,
|
|
||||||
instance_name, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("self_link", db.SelfLink)
|
d.Set("self_link", db.SelfLink)
|
||||||
|
|
|
@ -2,7 +2,6 @@ package google
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
@ -610,16 +609,7 @@ 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 {
|
return handleNotFoundError(err, d, fmt.Sprintf("SQL Database Instance %q", d.Get("name").(string)))
|
||||||
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",
|
|
||||||
d.Get("name").(string), err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_settingsList := d.Get("settings").([]interface{})
|
_settingsList := d.Get("settings").([]interface{})
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -102,14 +101,7 @@ func resourceSqlUserRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
users, err := config.clientSqlAdmin.Users.List(project, instance).Do()
|
users, err := config.clientSqlAdmin.Users.List(project, instance).Do()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("SQL User %q in instance %q", name, instance))
|
||||||
log.Printf("[WARN] Removing SQL User %q because it's gone", d.Get("name").(string))
|
|
||||||
d.SetId("")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("Error, failed to get user %s in instance %s: %s", name, instance, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
found := false
|
found := false
|
||||||
|
|
|
@ -215,15 +215,7 @@ 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 {
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Storage Bucket %q", d.Get("name").(string)))
|
||||||
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)
|
||||||
|
|
|
@ -7,7 +7,6 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -170,15 +169,7 @@ 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 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Storage Bucket ACL for bucket %q", d.Get("bucket").(string)))
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range res.Items {
|
for _, v := range res.Items {
|
||||||
|
|
|
@ -182,15 +182,7 @@ 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 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Storage Bucket Object %q", d.Get("name").(string)))
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Set("md5hash", res.Md5Hash)
|
d.Set("md5hash", res.Md5Hash)
|
||||||
|
|
|
@ -6,7 +6,6 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -138,15 +137,7 @@ 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 {
|
return handleNotFoundError(err, d, fmt.Sprintf("Storage Object ACL for Bucket %q", d.Get("bucket").(string)))
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range res.Items {
|
for _, v := range res.Items {
|
||||||
|
|
Loading…
Reference in New Issue