Skip to content

Commit f7be625

Browse files
committed
Fix UserData not being found when added to a project
1 parent f19bffc commit f7be625

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

cloudstack/resource_cloudstack_user_data.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,19 @@ func resourceCloudStackUserDataRead(d *schema.ResourceData, meta interface{}) er
125125
p := cs.User.NewListUserDataParams()
126126
p.SetId(id)
127127

128+
if v, ok := d.GetOk("project_id"); ok {
129+
p.SetProjectid(v.(string))
130+
}
131+
128132
userdata, err := cs.User.ListUserData(p)
129133
if err != nil {
130134
return fmt.Errorf("Error retrieving user data with ID %s: %s", id, err)
131135
}
132136

137+
if len(userdata.UserData) == 0 {
138+
return fmt.Errorf("No user data found with ID %s", id)
139+
}
140+
133141
d.Set("name", userdata.UserData[0].Name)
134142
d.Set("userdata", userdata.UserData[0].Userdata)
135143
if d.Get("account").(string) != "" {

0 commit comments

Comments
 (0)