-
Notifications
You must be signed in to change notification settings - Fork 670
/
data_source_ibm_org_quota.go
106 lines (100 loc) · 3.37 KB
/
data_source_ibm_org_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright IBM Corp. 2017, 2021 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0
package cloudfoundry
import (
"fmt"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func DataSourceIBMOrgQuota() *schema.Resource {
return &schema.Resource{
Read: dataSourceIBMOrgQuotaRead,
Schema: map[string]*schema.Schema{
"name": {
Description: "Org quota name, for example qIBM",
Type: schema.TypeString,
Required: true,
},
"non_basic_services_allowed": {
Description: "Define non basic services are allowed for organization.",
Type: schema.TypeBool,
Computed: true,
},
"total_services": {
Description: "Defines the total services for organization.",
Type: schema.TypeInt,
Computed: true,
},
"total_routes": {
Description: "Defines the total route for organization.",
Type: schema.TypeInt,
Computed: true,
},
"memory_limit": {
Description: "Defines the total memory limit for organization.",
Type: schema.TypeInt,
Computed: true,
},
"instance_memory_limit": {
Description: "Defines the total instance memory limit for organization.",
Type: schema.TypeInt,
Computed: true,
},
"trial_db_allowed": {
Description: "Defines trial db are allowed for organization.",
Type: schema.TypeBool,
Computed: true,
},
"app_instance_limit": {
Description: "Defines the total app instance limit for organization.",
Type: schema.TypeInt,
Computed: true,
},
"total_private_domains": {
Description: "Defines the total private domain limit for organization.v",
Type: schema.TypeInt,
Computed: true,
},
"app_tasks_limit": {
Description: "Defines the total app task limit for organization.",
Type: schema.TypeInt,
Computed: true,
},
"total_service_keys": {
Description: "Defines the total service keys for organization.",
Type: schema.TypeInt,
Computed: true,
},
"total_reserved_route_ports": {
Description: "Defines the number of reserved route ports for organization. ",
Type: schema.TypeInt,
Computed: true,
},
},
}
}
func dataSourceIBMOrgQuotaRead(d *schema.ResourceData, meta interface{}) error {
cfClient, err := meta.(conns.ClientSession).MccpAPI()
if err != nil {
return err
}
orgQuotaAPI := cfClient.OrgQuotas()
orgQuotaName := d.Get("name").(string)
orgQuotaFields, err := orgQuotaAPI.FindByName(orgQuotaName)
if err != nil {
return fmt.Errorf("[ERROR] Error retrieving org quota: %s", err)
}
d.SetId(orgQuotaFields.GUID)
d.Set("app_instance_limit", orgQuotaFields.AppInstanceLimit)
d.Set("app_tasks_limit", orgQuotaFields.AppTasksLimit)
d.Set("instance_memory_limit", orgQuotaFields.InstanceMemoryLimitInMB)
d.Set("memory_limit", orgQuotaFields.MemoryLimitInMB)
d.Set("non_basic_services_allowed", orgQuotaFields.NonBasicServicesAllowed)
d.Set("total_private_domains", orgQuotaFields.PrivateDomainsLimit)
d.Set("total_reserved_route_ports", orgQuotaFields.RoutePortsLimit)
d.Set("total_routes", orgQuotaFields.RoutesLimit)
d.Set("total_service_keys", orgQuotaFields.ServiceKeysLimit)
d.Set("total_services", orgQuotaFields.ServicesLimit)
d.Set("trial_db_allowed", orgQuotaFields.TrialDBAllowed)
return nil
}