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

sureshanaparti 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 1d703a9  Fix userdata not being found when added to a project (#293)
1d703a9 is described below

commit 1d703a91aa7bca0a9c3495f39192d3aa21fd1988
Author: bddvlpr <[email protected]>
AuthorDate: Mon Aug 17 11:14:17 2026 +0200

    Fix userdata not being found when added to a project (#293)
---
 cloudstack/resource_cloudstack_user_data.go | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/cloudstack/resource_cloudstack_user_data.go 
b/cloudstack/resource_cloudstack_user_data.go
index 65a3d2c..1197e8f 100644
--- a/cloudstack/resource_cloudstack_user_data.go
+++ b/cloudstack/resource_cloudstack_user_data.go
@@ -21,6 +21,7 @@ package cloudstack
 
 import (
        "fmt"
+       "log"
        "strings"
 
        "github.com/apache/cloudstack-go/v2/cloudstack"
@@ -125,11 +126,21 @@ func resourceCloudStackUserDataRead(d 
*schema.ResourceData, meta interface{}) er
        p := cs.User.NewListUserDataParams()
        p.SetId(id)
 
+       if v, ok := d.GetOk("project_id"); ok {
+               p.SetProjectid(v.(string))
+       }
+
        userdata, err := cs.User.ListUserData(p)
        if err != nil {
                return fmt.Errorf("Error retrieving user data with ID %s: %s", 
id, err)
        }
 
+       if len(userdata.UserData) == 0 {
+               log.Printf("[DEBUG] User data %s no longer exists", id)
+               d.SetId("")
+               return nil
+       }
+
        d.Set("name", userdata.UserData[0].Name)
        d.Set("userdata", userdata.UserData[0].Userdata)
        if d.Get("account").(string) != "" {

Reply via email to