mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-04 17:51:11 +00:00
Remove inferred zone from region on Disk import (#2694)
<!-- This change is generated by MagicModules. --> /cc @rileykarson
This commit is contained in:
parent
f4ed0939df
commit
9582532556
@ -817,32 +817,6 @@ func resourceComputeDiskImport(d *schema.ResourceData, meta interface{}) ([]*sch
|
|||||||
return nil, fmt.Errorf("Error constructing id: %s", err)
|
return nil, fmt.Errorf("Error constructing id: %s", err)
|
||||||
}
|
}
|
||||||
d.SetId(id)
|
d.SetId(id)
|
||||||
// In the end, it's possible that someone has tried to import
|
|
||||||
// a disk using only the region. To find out what zone the
|
|
||||||
// disk is in, we need to check every zone in the region, to
|
|
||||||
// see if we can find a disk with the same name. This will
|
|
||||||
// find the first disk in the specified region with a matching
|
|
||||||
// name. There might be multiple matching disks - we're not
|
|
||||||
// considering that an error case here. We don't check for it.
|
|
||||||
if zone, err := getZone(d, config); err != nil || zone == "" {
|
|
||||||
project, err := getProject(d, config)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
region, err := getRegion(d, config)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
getDisk := func(zone string) (interface{}, error) {
|
|
||||||
return config.clientCompute.Disks.Get(project, zone, d.Id()).Do()
|
|
||||||
}
|
|
||||||
resource, err := getZonalResourceFromRegion(getDisk, region, config.clientCompute, project)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
d.Set("zone", resource.(*compute.Disk).Zone)
|
|
||||||
}
|
|
||||||
|
|
||||||
return []*schema.ResourceData{d}, nil
|
return []*schema.ResourceData{d}, nil
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/hashicorp/errwrap"
|
"github.com/hashicorp/errwrap"
|
||||||
"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/googleapi"
|
"google.golang.org/api/googleapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -62,30 +61,6 @@ func getProjectFromDiff(d *schema.ResourceDiff, config *Config) (string, error)
|
|||||||
return "", fmt.Errorf("%s: required field is not set", "project")
|
return "", fmt.Errorf("%s: required field is not set", "project")
|
||||||
}
|
}
|
||||||
|
|
||||||
func getZonalResourceFromRegion(getResource func(string) (interface{}, error), region string, compute *compute.Service, project string) (interface{}, error) {
|
|
||||||
zoneList, err := compute.Zones.List(project).Do()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var resource interface{}
|
|
||||||
for _, zone := range zoneList.Items {
|
|
||||||
if strings.Contains(zone.Name, region) {
|
|
||||||
resource, err = getResource(zone.Name)
|
|
||||||
if err != nil {
|
|
||||||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
|
|
||||||
// Resource was not found in this zone
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("Error reading Resource: %s", err)
|
|
||||||
}
|
|
||||||
// Resource was found
|
|
||||||
return resource, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Resource does not exist in this region
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getRouterLockName(region string, router string) string {
|
func getRouterLockName(region string, router string) string {
|
||||||
return fmt.Sprintf("router/%s/%s", region, router)
|
return fmt.Sprintf("router/%s/%s", region, router)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user