mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-06 10:41:07 +00:00
Read from the zone set in state when possible in google_compute_autoscaler (#193)
This commit is contained in:
parent
59e139b373
commit
9f429e7ed2
@ -289,20 +289,37 @@ func resourceComputeAutoscalerRead(d *schema.ResourceData, meta interface{}) err
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var getAutoscaler = func(zone string) (interface{}, error) {
|
var getAutoscaler = func(zone string) (interface{}, error) {
|
||||||
return config.clientCompute.Autoscalers.Get(project, zone, d.Id()).Do()
|
return config.clientCompute.Autoscalers.Get(project, zone, d.Id()).Do()
|
||||||
}
|
}
|
||||||
|
|
||||||
resource, err := getZonalResourceFromRegion(getAutoscaler, region, config.clientCompute, project)
|
var scaler *compute.Autoscaler
|
||||||
if err != nil {
|
var e error
|
||||||
return err
|
if zone, ok := d.GetOk("zone"); ok {
|
||||||
|
scaler, e = config.clientCompute.Autoscalers.Get(project, zone.(string), d.Id()).Do()
|
||||||
|
if e != nil {
|
||||||
|
return handleNotFoundError(e, d, fmt.Sprintf("Autoscaler %q", d.Id()))
|
||||||
}
|
}
|
||||||
if resource == nil {
|
} else {
|
||||||
|
// If the resource was imported, the only info we have is the ID. Try to find the resource
|
||||||
|
// by searching in the region of the project.
|
||||||
|
var resource interface{}
|
||||||
|
resource, e = getZonalResourceFromRegion(getAutoscaler, region, config.clientCompute, project)
|
||||||
|
|
||||||
|
if e != nil {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
scaler = resource.(*compute.Autoscaler)
|
||||||
|
}
|
||||||
|
|
||||||
|
if scaler == nil {
|
||||||
log.Printf("[WARN] Removing Autoscaler %q because it's gone", d.Get("name").(string))
|
log.Printf("[WARN] Removing Autoscaler %q because it's gone", d.Get("name").(string))
|
||||||
d.SetId("")
|
d.SetId("")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
scaler := resource.(*compute.Autoscaler)
|
|
||||||
zoneUrl := strings.Split(scaler.Zone, "/")
|
zoneUrl := strings.Split(scaler.Zone, "/")
|
||||||
d.Set("self_link", scaler.SelfLink)
|
d.Set("self_link", scaler.SelfLink)
|
||||||
d.Set("name", scaler.Name)
|
d.Set("name", scaler.Name)
|
||||||
|
Loading…
Reference in New Issue
Block a user