forked from hashicorp/terraform-provider-aws
/
data_source_aws_workspaces_bundle.go
126 lines (113 loc) · 2.91 KB
/
data_source_aws_workspaces_bundle.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
package aws
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/workspaces"
"github.com/hashicorp/terraform/helper/schema"
)
func dataSourceAwsWorkspaceBundle() *schema.Resource {
return &schema.Resource{
Read: dataSourceAwsWorkspaceBundleRead,
Schema: map[string]*schema.Schema{
"bundle_id": {
Type: schema.TypeString,
Required: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"owner": {
Type: schema.TypeString,
Computed: true,
},
"compute_type": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"user_storage": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"capacity": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"root_storage": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"capacity": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
}
}
func dataSourceAwsWorkspaceBundleRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).workspacesconn
bundleID := d.Get("bundle_id").(string)
input := &workspaces.DescribeWorkspaceBundlesInput{
BundleIds: []*string{aws.String(bundleID)},
}
resp, err := conn.DescribeWorkspaceBundles(input)
if err != nil {
return err
}
if len(resp.Bundles) != 1 {
return fmt.Errorf("The number of Workspace Bundle (%s) should be 1, but %d", bundleID, len(resp.Bundles))
}
bundle := resp.Bundles[0]
d.SetId(bundleID)
d.Set("description", bundle.Description)
d.Set("name", bundle.Name)
d.Set("owner", bundle.Owner)
computeType := make([]map[string]interface{}, 1)
if bundle.ComputeType != nil {
computeType[0] = map[string]interface{}{
"name": aws.StringValue(bundle.ComputeType.Name),
}
}
if err := d.Set("compute_type", computeType); err != nil {
return fmt.Errorf("error setting compute_type: %s", err)
}
rootStorage := make([]map[string]interface{}, 1)
if bundle.RootStorage != nil {
rootStorage[0] = map[string]interface{}{
"capacity": aws.StringValue(bundle.RootStorage.Capacity),
}
}
if err := d.Set("root_storage", rootStorage); err != nil {
return fmt.Errorf("error setting root_storage: %s", err)
}
userStorage := make([]map[string]interface{}, 1)
if bundle.UserStorage != nil {
userStorage[0] = map[string]interface{}{
"capacity": aws.StringValue(bundle.UserStorage.Capacity),
}
}
if err := d.Set("user_storage", userStorage); err != nil {
return fmt.Errorf("error setting user_storage: %s", err)
}
return nil
}