/
data_source_ibm_schematics_workspace.go
155 lines (140 loc) · 3.82 KB
/
data_source_ibm_schematics_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package ibm
import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
)
func dataSourceSchematicsWorkspace() *schema.Resource {
return &schema.Resource{
Read: resourceIBMSchematicsWorkspaceRead,
Schema: map[string]*schema.Schema{
"workspace_id": {
Type: schema.TypeString,
Required: true,
Description: "The id of workspace",
},
"template_id": {
Type: schema.TypeList,
Computed: true,
Description: "The id of templates",
Elem: &schema.Schema{Type: schema.TypeString},
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "The name of workspace",
},
"resource_group": {
Type: schema.TypeString,
Computed: true,
Description: "The resource group of workspace",
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "The status of workspace",
},
"types": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"is_frozen": {
Type: schema.TypeBool,
Computed: true,
},
"is_locked": {
Type: schema.TypeBool,
Computed: true,
},
"tags": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"location": {
Type: schema.TypeString,
Computed: true,
Description: "The location of workspace",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "The description of workspace",
},
"crn": {
Type: schema.TypeString,
Computed: true,
Description: "cloud resource name of the workspace",
},
"catalog_ref": {
Type: schema.TypeMap,
Computed: true,
Description: "Catalog references",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"item_id": {
Type: schema.TypeString,
Computed: true,
},
"item_name": {
Type: schema.TypeString,
Computed: true,
},
"offering_version": {
Type: schema.TypeString,
Computed: true,
},
"item_url": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
ResourceControllerURL: {
Type: schema.TypeString,
Computed: true,
Description: "The URL of the IBM Cloud dashboard that can be used to explore and view details about this workspace",
},
},
}
}
func resourceIBMSchematicsWorkspaceRead(d *schema.ResourceData, meta interface{}) error {
scClient, err := meta.(ClientSession).SchematicsAPI()
if err != nil {
return err
}
wrkAPI := scClient.Workspaces()
workspaceID := d.Get("workspace_id").(string)
// templateID := d.Get("template_id").(string)
WorkspaceInfo, err := wrkAPI.GetWorkspaceByID(workspaceID)
if err != nil {
return fmt.Errorf("Error retreiving Workspace details: %s", err)
}
templateID := []string{}
for _, items := range WorkspaceInfo.TemplateData {
templateID = append(templateID, items.TemplateID)
}
d.SetId(WorkspaceInfo.ID)
d.Set("name", WorkspaceInfo.Name)
d.Set("resource_group", WorkspaceInfo.ResourceGroup)
d.Set("status", WorkspaceInfo.Status)
d.Set("is_frozen", WorkspaceInfo.WorkspaceStatus.Frozen)
d.Set("is_locked", WorkspaceInfo.WorkspaceStatus.Locked)
d.Set("location", WorkspaceInfo.Location)
d.Set("description", WorkspaceInfo.Description)
d.Set("crn", WorkspaceInfo.CRN)
d.Set("template_id", templateID)
types := WorkspaceInfo.Type
d.Set("types", types)
//Update content catalog info of the workspace
d.Set("catalog_ref", flattenCatalogRef(WorkspaceInfo.CatalogRef))
tags := WorkspaceInfo.Tags
d.Set("tags", tags)
controller, err := getBaseController(meta)
if err != nil {
return err
}
d.Set(ResourceControllerURL, controller+"/schematics")
return nil
}