@@ -16,6 +16,9 @@ func resourceComputeTargetPool() *schema.Resource {
1616 Read : resourceComputeTargetPoolRead ,
1717 Delete : resourceComputeTargetPoolDelete ,
1818 Update : resourceComputeTargetPoolUpdate ,
19+ Importer : & schema.ResourceImporter {
20+ State : schema .ImportStatePassthrough ,
21+ },
1922
2023 Schema : map [string ]* schema.Schema {
2124 "name" : & schema.Schema {
@@ -60,12 +63,14 @@ func resourceComputeTargetPool() *schema.Resource {
6063 Type : schema .TypeString ,
6164 Optional : true ,
6265 ForceNew : true ,
66+ Computed : true ,
6367 },
6468
6569 "region" : & schema.Schema {
6670 Type : schema .TypeString ,
6771 Optional : true ,
6872 ForceNew : true ,
73+ Computed : true ,
6974 },
7075
7176 "self_link" : & schema.Schema {
@@ -106,7 +111,7 @@ func convertHealthChecks(config *Config, project string, names []string) ([]stri
106111
107112// Instances do not need to exist yet, so we simply generate URLs.
108113// Instances can be full URLS or zone/name
109- func convertInstances (config * Config , project string , names []string ) ([]string , error ) {
114+ func convertInstancesToUrls (config * Config , project string , names []string ) ([]string , error ) {
110115 urls := make ([]string , len (names ))
111116 for i , name := range names {
112117 if strings .HasPrefix (name , "https://www.googleapis.com/compute/v1/" ) {
@@ -144,7 +149,7 @@ func resourceComputeTargetPoolCreate(d *schema.ResourceData, meta interface{}) e
144149 return err
145150 }
146151
147- instanceUrls , err := convertInstances (
152+ instanceUrls , err := convertInstancesToUrls (
148153 config , project , convertStringArr (d .Get ("instances" ).([]interface {})))
149154 if err != nil {
150155 return err
@@ -279,11 +284,11 @@ func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) e
279284 from_ , to_ := d .GetChange ("instances" )
280285 from := convertStringArr (from_ .([]interface {}))
281286 to := convertStringArr (to_ .([]interface {}))
282- fromUrls , err := convertInstances (config , project , from )
287+ fromUrls , err := convertInstancesToUrls (config , project , from )
283288 if err != nil {
284289 return err
285290 }
286- toUrls , err := convertInstances (config , project , to )
291+ toUrls , err := convertInstancesToUrls (config , project , to )
287292 if err != nil {
288293 return err
289294 }
@@ -346,6 +351,16 @@ func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) e
346351 return resourceComputeTargetPoolRead (d , meta )
347352}
348353
354+ func convertInstancesFromUrls (urls []string ) []string {
355+ result := make ([]string , 0 , len (urls ))
356+ for _ , url := range urls {
357+ urlArray := strings .Split (url , "/" )
358+ instance := fmt .Sprintf ("%s/%s" , urlArray [len (urlArray )- 3 ], urlArray [len (urlArray )- 1 ])
359+ result = append (result , instance )
360+ }
361+ return result
362+ }
363+
349364func resourceComputeTargetPoolRead (d * schema.ResourceData , meta interface {}) error {
350365 config := meta .(* Config )
351366
@@ -373,8 +388,19 @@ func resourceComputeTargetPoolRead(d *schema.ResourceData, meta interface{}) err
373388 return fmt .Errorf ("Error reading TargetPool: %s" , err )
374389 }
375390
391+ regionUrl := strings .Split (tpool .Region , "/" )
376392 d .Set ("self_link" , tpool .SelfLink )
377-
393+ d .Set ("backup_pool" , tpool .BackupPool )
394+ d .Set ("description" , tpool .Description )
395+ d .Set ("failover_ratio" , tpool .FailoverRatio )
396+ d .Set ("health_checks" , tpool .HealthChecks )
397+ if tpool .Instances != nil {
398+ d .Set ("instances" , convertInstancesFromUrls (tpool .Instances ))
399+ }
400+ d .Set ("name" , tpool .Name )
401+ d .Set ("region" , regionUrl [len (regionUrl )- 1 ])
402+ d .Set ("session_affinity" , tpool .SessionAffinity )
403+ d .Set ("project" , project )
378404 return nil
379405}
380406
0 commit comments