This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch main
in repository 
https://gitbox.apache.org/repos/asf/cloudstack-terraform-provider.git


The following commit(s) were added to refs/heads/main by this push:
     new 976e564  Support adding templates in all zones (#92)
976e564 is described below

commit 976e5647115d7dd441370c4aef028a4c00fc43ed
Author: Vishesh <[email protected]>
AuthorDate: Wed Mar 6 10:41:55 2024 +0530

    Support adding templates in all zones (#92)
---
 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 64d4600..967dcf1 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(

Reply via email to