Skip to content

Commit 976e564

Browse files
authored
Support adding templates in all zones (#92)
1 parent c8279b9 commit 976e564

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

cloudstack/resource_cloudstack_template.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,15 @@ func resourceCloudStackTemplateCreate(d *schema.ResourceData, meta interface{})
184184

185185
// Retrieve the zone ID
186186
if v, ok := d.GetOk("zone"); ok {
187-
zoneid, e := retrieveID(cs, "zone", v.(string))
188-
if e != nil {
189-
return e.Error()
187+
if v.(string) != "all" {
188+
zoneid, e := retrieveID(cs, "zone", v.(string))
189+
if e != nil {
190+
return e.Error()
191+
}
192+
p.SetZoneid(zoneid)
193+
} else {
194+
p.SetZoneid("-1")
190195
}
191-
p.SetZoneid(zoneid)
192196
}
193197

194198
// If there is a project supplied, we retrieve and set the project id
@@ -236,11 +240,14 @@ func resourceCloudStackTemplateRead(d *schema.ResourceData, meta interface{}) er
236240
cs := meta.(*cloudstack.CloudStackClient)
237241

238242
// Get the template details
239-
t, count, err := cs.Template.GetTemplateByID(
240-
d.Id(),
241-
"executable",
242-
cloudstack.WithProject(d.Get("project").(string)),
243-
)
243+
p := cs.Template.NewListTemplatesParams("executable")
244+
p.SetId(d.Id())
245+
p.SetShowunique(true)
246+
p.SetProjectid(d.Get("project").(string))
247+
248+
r, err := cs.Template.ListTemplates(p)
249+
count := r.Count
250+
t := r.Templates[0]
244251
if err != nil {
245252
if count == 0 {
246253
log.Printf(

0 commit comments

Comments
 (0)