From 1b6f4b6897c7ca21c6f24d375554151ce44fc77f Mon Sep 17 00:00:00 2001 From: Vishesh Date: Tue, 5 Mar 2024 18:40:42 +0530 Subject: [PATCH] Support adding templates in all zones --- cloudstack/resource_cloudstack_template.go | 25 ++++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/cloudstack/resource_cloudstack_template.go b/cloudstack/resource_cloudstack_template.go index 64d46008..967dcf17 100644 --- a/cloudstack/resource_cloudstack_template.go +++ b/cloudstack/resource_cloudstack_template.go @@ -184,11 +184,15 @@ func resourceCloudStackTemplateCreate(d *schema.ResourceData, meta interface{}) // Retrieve the zone ID if v, ok := d.GetOk("zone"); ok { - zoneid, e := retrieveID(cs, "zone", v.(string)) - if e != nil { - return e.Error() + if v.(string) != "all" { + zoneid, e := retrieveID(cs, "zone", v.(string)) + if e != nil { + return e.Error() + } + p.SetZoneid(zoneid) + } else { + p.SetZoneid("-1") } - p.SetZoneid(zoneid) } // 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 cs := meta.(*cloudstack.CloudStackClient) // Get the template details - t, count, err := cs.Template.GetTemplateByID( - d.Id(), - "executable", - cloudstack.WithProject(d.Get("project").(string)), - ) + p := cs.Template.NewListTemplatesParams("executable") + p.SetId(d.Id()) + p.SetShowunique(true) + p.SetProjectid(d.Get("project").(string)) + + r, err := cs.Template.ListTemplates(p) + count := r.Count + t := r.Templates[0] if err != nil { if count == 0 { log.Printf(