This repository has been archived by the owner on Sep 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
data_source_flexibleengine_cce_cluster_v3.go
151 lines (136 loc) · 3.82 KB
/
data_source_flexibleengine_cce_cluster_v3.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
package flexibleengine
import (
"fmt"
"log"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/huaweicloud/golangsdk/openstack/cce/v3/clusters"
)
func dataSourceCCEClusterV3() *schema.Resource {
return &schema.Resource{
Read: dataSourceCCEClusterV3Read,
Schema: map[string]*schema.Schema{
"region": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"name": {
Type: schema.TypeString,
Optional: true,
},
"id": {
Type: schema.TypeString,
Optional: true,
},
"flavor_id": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"cluster_version": {
Type: schema.TypeString,
Computed: true,
},
"cluster_type": {
Type: schema.TypeString,
Optional: true,
},
"billing_mode": {
Type: schema.TypeInt,
Computed: true,
},
"vpc_id": {
Type: schema.TypeString,
Optional: true,
},
"subnet_id": {
Type: schema.TypeString,
Computed: true,
},
"highway_subnet_id": {
Type: schema.TypeString,
Computed: true,
},
"container_network_type": {
Type: schema.TypeString,
Computed: true,
},
"container_network_cidr": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Optional: true,
},
"internal_endpoint": {
Type: schema.TypeString,
Computed: true,
},
"external_endpoint": {
Type: schema.TypeString,
Computed: true,
},
"external_apig_endpoint": {
Type: schema.TypeString,
Computed: true,
},
"security_group_id": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceCCEClusterV3Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
cceClient, err := config.cceV3Client(GetRegion(d, config))
if err != nil {
return fmt.Errorf("Unable to create flexibleengine CCE client : %s", err)
}
listOpts := clusters.ListOpts{
ID: d.Get("id").(string),
Name: d.Get("name").(string),
Type: d.Get("cluster_type").(string),
Phase: d.Get("status").(string),
VpcID: d.Get("vpc_id").(string),
}
refinedClusters, err := clusters.List(cceClient, listOpts)
log.Printf("[DEBUG] Value of allClusters: %#v", refinedClusters)
if err != nil {
return fmt.Errorf("Unable to retrieve clusters: %s", err)
}
if len(refinedClusters) < 1 {
return fmt.Errorf("Your query returned no results. " +
"Please change your search criteria and try again.")
}
if len(refinedClusters) > 1 {
return fmt.Errorf("Your query returned more than one result." +
" Please try a more specific search criteria")
}
Cluster := refinedClusters[0]
log.Printf("[DEBUG] Retrieved Clusters using given filter %s: %+v", Cluster.Metadata.Id, Cluster)
d.SetId(Cluster.Metadata.Id)
d.Set("name", Cluster.Metadata.Name)
d.Set("flavor_id", Cluster.Spec.Flavor)
d.Set("description", Cluster.Spec.Description)
d.Set("cluster_version", Cluster.Spec.Version)
d.Set("cluster_type", Cluster.Spec.Type)
d.Set("billing_mode", Cluster.Spec.BillingMode)
d.Set("vpc_id", Cluster.Spec.HostNetwork.VpcId)
d.Set("subnet_id", Cluster.Spec.HostNetwork.SubnetId)
d.Set("highway_subnet_id", Cluster.Spec.HostNetwork.HighwaySubnet)
d.Set("container_network_cidr", Cluster.Spec.ContainerNetwork.Cidr)
d.Set("container_network_type", Cluster.Spec.ContainerNetwork.Mode)
d.Set("status", Cluster.Status.Phase)
d.Set("internal_endpoint", Cluster.Status.Endpoints[0].Internal)
d.Set("external_endpoint", Cluster.Status.Endpoints[0].External)
d.Set("external_apig_endpoint", Cluster.Status.Endpoints[0].ExternalOTC)
d.Set("security_group_id", Cluster.Spec.HostNetwork.SecurityGroup)
d.Set("region", GetRegion(d, config))
return nil
}