-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_source_viettelidc_networking_quota_v2.go
112 lines (91 loc) · 2.36 KB
/
data_source_viettelidc_networking_quota_v2.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
package viettelidc
import (
"context"
"fmt"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/quotas"
)
func dataSourceNetworkingQuotaV2() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceNetworkingQuotaV2Read,
Schema: map[string]*schema.Schema{
"region": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"project_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"floatingip": {
Type: schema.TypeInt,
Computed: true,
},
"network": {
Type: schema.TypeInt,
Computed: true,
},
"port": {
Type: schema.TypeInt,
Computed: true,
},
"rbac_policy": {
Type: schema.TypeInt,
Computed: true,
},
"router": {
Type: schema.TypeInt,
Computed: true,
},
"security_group": {
Type: schema.TypeInt,
Computed: true,
},
"security_group_rule": {
Type: schema.TypeInt,
Computed: true,
},
"subnet": {
Type: schema.TypeInt,
Computed: true,
},
"subnetpool": {
Type: schema.TypeInt,
Computed: true,
},
},
}
}
func dataSourceNetworkingQuotaV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
config := meta.(*Config)
region := GetRegion(d, config)
networkingClient, err := config.NetworkingV2Client(region)
if err != nil {
return diag.Errorf("Error creating OpenStack networking client: %s", err)
}
projectID := d.Get("project_id").(string)
q, err := quotas.Get(networkingClient, projectID).Extract()
if err != nil {
return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_networking_quota_v2"))
}
log.Printf("[DEBUG] Retrieved openstack_networking_quota_v2 %s: %#v", d.Id(), q)
id := fmt.Sprintf("%s/%s", projectID, region)
d.SetId(id)
d.Set("project_id", projectID)
d.Set("region", GetRegion(d, config))
d.Set("floatingip", q.FloatingIP)
d.Set("network", q.Network)
d.Set("port", q.Port)
d.Set("rbac_policy", q.RBACPolicy)
d.Set("router", q.Router)
d.Set("security_group", q.SecurityGroup)
d.Set("security_group_rule", q.SecurityGroupRule)
d.Set("subnet", q.Subnet)
d.Set("subnetpool", q.SubnetPool)
return nil
}