/
data_source_workspace.go
50 lines (44 loc) · 1.11 KB
/
data_source_workspace.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package powerbi
import (
"github.com/codecutout/terraform-provider-powerbi/internal/powerbiapi"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
// DataSourceWorkspace represents a Power BI workspace
func DataSourceWorkspace() *schema.Resource {
return &schema.Resource{
Read: dataSourceWorkspaceRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name of the workspace.",
},
"capacity_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Capacity ID to be assigned to workspace.",
},
},
}
}
func dataSourceWorkspaceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*powerbiapi.Client)
name := d.Get("name").(string)
workspace, err := client.GetGroupByName(name)
if err != nil {
return err
}
if workspace == nil {
d.SetId("")
} else {
d.SetId(workspace.ID)
d.Set("name", workspace.Name)
if workspace.IsOnDedicatedCapacity {
d.Set("capacity_id", workspace.CapacityID)
} else {
d.Set("capacity_id", "")
}
}
return nil
}