-
Notifications
You must be signed in to change notification settings - Fork 649
/
data_source_ibm_container_vpc_cluster_worker.go
146 lines (134 loc) · 4.21 KB
/
data_source_ibm_container_vpc_cluster_worker.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
// Copyright IBM Corp. 2017, 2021 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0
package kubernetes
import (
"fmt"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func DataSourceIBMContainerVPCClusterWorker() *schema.Resource {
return &schema.Resource{
Read: dataSourceIBMContainerVPCClusterWorkerRead,
Schema: map[string]*schema.Schema{
"worker_id": {
Description: "ID of the worker",
Type: schema.TypeString,
Required: true,
},
"cluster_name_id": {
Description: "Name or ID of the cluster",
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.InvokeDataSourceValidator(
"ibm_container_vpc_cluster_worker",
"cluster_name_id"),
},
"flavor": {
Description: "flavor of the worker",
Type: schema.TypeString,
Computed: true,
},
"kube_version": {
Description: "kube version of the worker",
Type: schema.TypeString,
Computed: true,
},
"state": {
Description: "State of the worker",
Type: schema.TypeString,
Computed: true,
},
"pool_id": {
Description: "worker pool id",
Type: schema.TypeString,
Computed: true,
},
"pool_name": {
Description: "worker pool name",
Type: schema.TypeString,
Computed: true,
},
"network_interfaces": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cidr": {
Type: schema.TypeString,
Computed: true,
},
"ip_address": {
Type: schema.TypeString,
Computed: true,
},
"subnet_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"resource_group_id": {
Type: schema.TypeString,
Optional: true,
Description: "ID of the resource group.",
},
"host_pool_id": {
Type: schema.TypeString,
Computed: true,
Description: "ID of the dedicated host pool this worker is associated with",
},
flex.ResourceControllerURL: {
Type: schema.TypeString,
Computed: true,
Description: "The URL of the IBM Cloud dashboard that can be used to explore and view details about this cluster",
},
},
}
}
func DataSourceIBMContainerVPCClusterWorkerValidator() *validate.ResourceValidator {
validateSchema := make([]validate.ValidateSchema, 0)
validateSchema = append(validateSchema,
validate.ValidateSchema{
Identifier: "cluster_name_id",
ValidateFunctionIdentifier: validate.ValidateCloudData,
Type: validate.TypeString,
Required: true,
CloudDataType: "cluster",
CloudDataRange: []string{"resolved_to:id"}})
iBMContainerVPCClusterWorkerValidator := validate.ResourceValidator{ResourceName: "ibm_container_vpc_cluster_worker", Schema: validateSchema}
return &iBMContainerVPCClusterWorkerValidator
}
func dataSourceIBMContainerVPCClusterWorkerRead(d *schema.ResourceData, meta interface{}) error {
csClient, err := meta.(conns.ClientSession).VpcContainerAPI()
if err != nil {
return err
}
targetEnv, err := getVpcClusterTargetHeader(d, meta)
if err != nil {
return err
}
wrkAPI := csClient.Workers()
workerID := d.Get("worker_id").(string)
clusterID := d.Get("cluster_name_id").(string)
workerFields, err := wrkAPI.Get(clusterID, workerID, targetEnv)
if err != nil {
return fmt.Errorf("[ERROR] Error retrieving worker: %s", err)
}
d.SetId(workerFields.ID)
d.Set("flavor", workerFields.Flavor)
d.Set("kube_version", workerFields.KubeVersion.Actual)
d.Set("state", workerFields.Health.State)
d.Set("pool_id", workerFields.PoolID)
d.Set("pool_name", workerFields.PoolName)
d.Set("host_pool_id", workerFields.HostPoolID)
d.Set("network_interfaces", flex.FlattenNetworkInterfaces(workerFields.NetworkInterfaces))
controller, err := flex.GetBaseController(meta)
if err != nil {
return err
}
d.Set(flex.ResourceControllerURL, controller+"/kubernetes/clusters")
return nil
}