@@ -51,7 +51,11 @@ func resourceComputeTargetPool() *schema.Resource {
51
51
Type : schema .TypeList ,
52
52
Optional : true ,
53
53
ForceNew : false ,
54
- Elem : & schema.Schema {Type : schema .TypeString },
54
+ MaxItems : 1 ,
55
+ Elem : & schema.Schema {
56
+ Type : schema .TypeString ,
57
+ DiffSuppressFunc : compareSelfLinkOrResourceName ,
58
+ },
55
59
},
56
60
57
61
"instances" : {
@@ -111,17 +115,17 @@ func resourceComputeTargetPool() *schema.Resource {
111
115
}
112
116
113
117
// Healthchecks need to exist before being referred to from the target pool.
114
- func convertHealthChecks (config * Config , project string , names []string ) ([]string , error ) {
115
- urls := make ([]string , len (names ))
116
- for i , name := range names {
117
- // Look up the healthcheck
118
- res , err := config .clientCompute .HttpHealthChecks .Get (project , name ).Do ()
119
- if err != nil {
120
- return nil , fmt .Errorf ("Error reading HealthCheck: %s" , err )
121
- }
122
- urls [i ] = res .SelfLink
118
+ func convertHealthChecks (healthChecks []interface {}, d * schema.ResourceData , config * Config ) ([]string , error ) {
119
+ if healthChecks == nil || len (healthChecks ) == 0 {
120
+ return []string {}, nil
123
121
}
124
- return urls , nil
122
+
123
+ hc , err := ParseHttpHealthCheckFieldValue (healthChecks [0 ].(string ), d , config )
124
+ if err != nil {
125
+ return nil , err
126
+ }
127
+
128
+ return []string {hc .RelativeLink ()}, nil
125
129
}
126
130
127
131
// Instances do not need to exist yet, so we simply generate URLs.
@@ -158,8 +162,7 @@ func resourceComputeTargetPoolCreate(d *schema.ResourceData, meta interface{}) e
158
162
return err
159
163
}
160
164
161
- hchkUrls , err := convertHealthChecks (
162
- config , project , convertStringArr (d .Get ("health_checks" ).([]interface {})))
165
+ hchkUrls , err := convertHealthChecks (d .Get ("health_checks" ).([]interface {}), d , config )
163
166
if err != nil {
164
167
return err
165
168
}
@@ -247,13 +250,11 @@ func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) e
247
250
if d .HasChange ("health_checks" ) {
248
251
249
252
from_ , to_ := d .GetChange ("health_checks" )
250
- from := convertStringArr (from_ .([]interface {}))
251
- to := convertStringArr (to_ .([]interface {}))
252
- fromUrls , err := convertHealthChecks (config , project , from )
253
+ fromUrls , err := convertHealthChecks (from_ .([]interface {}), d , config )
253
254
if err != nil {
254
255
return err
255
256
}
256
- toUrls , err := convertHealthChecks (config , project , to )
257
+ toUrls , err := convertHealthChecks (to_ .([] interface {}), d , config )
257
258
if err != nil {
258
259
return err
259
260
}
@@ -376,16 +377,6 @@ func convertInstancesFromUrls(urls []string) []string {
376
377
return result
377
378
}
378
379
379
- func convertHealthChecksFromUrls (urls []string ) []string {
380
- result := make ([]string , 0 , len (urls ))
381
- for _ , url := range urls {
382
- urlArray := strings .Split (url , "/" )
383
- healthCheck := fmt .Sprintf ("%s" , urlArray [len (urlArray )- 1 ])
384
- result = append (result , healthCheck )
385
- }
386
- return result
387
- }
388
-
389
380
func resourceComputeTargetPoolRead (d * schema.ResourceData , meta interface {}) error {
390
381
config := meta .(* Config )
391
382
@@ -410,11 +401,7 @@ func resourceComputeTargetPoolRead(d *schema.ResourceData, meta interface{}) err
410
401
d .Set ("backup_pool" , tpool .BackupPool )
411
402
d .Set ("description" , tpool .Description )
412
403
d .Set ("failover_ratio" , tpool .FailoverRatio )
413
- if tpool .HealthChecks != nil {
414
- d .Set ("health_checks" , convertHealthChecksFromUrls (tpool .HealthChecks ))
415
- } else {
416
- d .Set ("health_checks" , nil )
417
- }
404
+ d .Set ("health_checks" , tpool .HealthChecks )
418
405
if tpool .Instances != nil {
419
406
d .Set ("instances" , convertInstancesFromUrls (tpool .Instances ))
420
407
} else {
0 commit comments