-
Notifications
You must be signed in to change notification settings - Fork 645
/
data_source_ibm_resource_quota.go
88 lines (80 loc) · 2.51 KB
/
data_source_ibm_resource_quota.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
// Copyright IBM Corp. 2017, 2021 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0
package resourcecontroller
import (
"fmt"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func DataSourceIBMResourceQuota() *schema.Resource {
return &schema.Resource{
Read: dataSourceIBMResourceQuotaRead,
Schema: map[string]*schema.Schema{
"name": {
Description: "Resource quota name, for example Trial Quota",
Type: schema.TypeString,
Required: true,
},
"type": {
Description: "Type of the quota.",
Type: schema.TypeString,
Computed: true,
},
"max_apps": {
Description: "Defines the total app limit.",
Type: schema.TypeInt,
Computed: true,
},
"max_instances_per_app": {
Description: "Defines the total instances limit per app.",
Type: schema.TypeInt,
Computed: true,
},
"max_app_instance_memory": {
Description: "Defines the total memory of app instance.",
Type: schema.TypeString,
Computed: true,
},
"total_app_memory": {
Description: "Defines the total memory for app.",
Type: schema.TypeString,
Computed: true,
},
"max_service_instances": {
Description: "Defines the total service instances limit.",
Type: schema.TypeInt,
Computed: true,
},
"vsi_limit": {
Description: "Defines the VSI limit.",
Type: schema.TypeInt,
Computed: true,
},
},
}
}
func dataSourceIBMResourceQuotaRead(d *schema.ResourceData, meta interface{}) error {
rsManagementAPI, err := meta.(conns.ClientSession).ResourceManagementAPIv2()
if err != nil {
return err
}
rsQuota := rsManagementAPI.ResourceQuota()
rsQuotaName := d.Get("name").(string)
rsQuotas, err := rsQuota.FindByName(rsQuotaName)
if err != nil {
return fmt.Errorf("[ERROR] Error retrieving resource quota: %s", err)
}
if len(rsQuotas) == 0 {
return fmt.Errorf("[ERROR] Error retrieving resource quota: %s", err)
}
rsQuotaFields := rsQuotas[0]
d.SetId(rsQuotaFields.ID)
d.Set("type", rsQuotaFields.Type)
d.Set("max_apps", rsQuotaFields.AppCountLimit)
d.Set("max_instances_per_app", rsQuotaFields.AppInstanceCountLimit)
d.Set("max_app_instance_memory", rsQuotaFields.AppInstanceMemoryLimit)
d.Set("total_app_memory", rsQuotaFields.TotalAppMemoryLimit)
d.Set("max_service_instances", rsQuotaFields.ServiceInstanceCountLimit)
d.Set("vsi_limit", rsQuotaFields.VSICountLimit)
return nil
}