-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_source_openstack_containerinfra_nodegroup_v1.go
More file actions
133 lines (108 loc) · 3.19 KB
/
Copy pathdata_source_openstack_containerinfra_nodegroup_v1.go
File metadata and controls
133 lines (108 loc) · 3.19 KB
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
package openstack
import (
"context"
"log"
"time"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/gophercloud/gophercloud/openstack/containerinfra/v1/nodegroups"
)
func dataSourceContainerInfraNodeGroupV1() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceContainerInfraNodeGroupRead,
Schema: map[string]*schema.Schema{
"region": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"cluster_id": {
Type: schema.TypeString,
Required: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
Optional: true,
},
"project_id": {
Type: schema.TypeString,
Computed: true,
},
"created_at": {
Type: schema.TypeString,
Computed: true,
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
},
"docker_volume_size": {
Type: schema.TypeInt,
Computed: true,
},
"labels": {
Type: schema.TypeMap,
Computed: true,
},
"role": {
Type: schema.TypeString,
Computed: true,
},
"node_count": {
Type: schema.TypeInt,
Computed: true,
},
"min_node_count": {
Type: schema.TypeInt,
Computed: true,
},
"max_node_count": {
Type: schema.TypeInt,
Computed: true,
},
"image": {
Type: schema.TypeString,
Computed: true,
},
"flavor": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceContainerInfraNodeGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
config := meta.(*Config)
containerInfraClient, err := config.ContainerInfraV1Client(GetRegion(d, config))
if err != nil {
return diag.Errorf("Error creating OpenStack container infra client: %s", err)
}
containerInfraClient.Microversion = containerInfraV1NodeGroupMinMicroversion
clusterID := d.Get("cluster_id").(string)
name := d.Get("name").(string)
nodeGroup, err := nodegroups.Get(containerInfraClient, clusterID, name).Extract()
if err != nil {
return diag.Errorf("Error getting openstack_containerinfra_nodegroup_v1 %s: %s", name, err)
}
d.SetId(nodeGroup.UUID)
d.Set("project_id", nodeGroup.ProjectID)
d.Set("docker_volume_size", nodeGroup.DockerVolumeSize)
d.Set("role", nodeGroup.Role)
d.Set("node_count", nodeGroup.NodeCount)
d.Set("min_node_count", nodeGroup.MinNodeCount)
d.Set("max_node_count", nodeGroup.MaxNodeCount)
d.Set("image", nodeGroup.ImageID)
d.Set("flavor", nodeGroup.FlavorID)
if err := d.Set("labels", nodeGroup.Labels); err != nil {
log.Printf("[DEBUG] Unable to set labels for openstack_containerinfra_nodegroup_v1 %s: %s", nodeGroup.UUID, err)
}
if err := d.Set("created_at", nodeGroup.CreatedAt.Format(time.RFC3339)); err != nil {
log.Printf("[DEBUG] Unable to set created_at for openstack_containerinfra_nodegroup_v1 %s: %s", nodeGroup.UUID, err)
}
if err := d.Set("updated_at", nodeGroup.UpdatedAt.Format(time.RFC3339)); err != nil {
log.Printf("[DEBUG] Unable to set updated_at for openstack_containerinfra_nodegroup_v1 %s: %s", nodeGroup.UUID, err)
}
d.Set("region", GetRegion(d, config))
return nil
}