-
Notifications
You must be signed in to change notification settings - Fork 26
/
data_worker_pool.go
94 lines (80 loc) · 2.54 KB
/
data_worker_pool.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
package spacelift
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/spacelift-io/terraform-provider-spacelift/spacelift/internal"
"github.com/spacelift-io/terraform-provider-spacelift/spacelift/internal/structs"
"github.com/spacelift-io/terraform-provider-spacelift/spacelift/internal/validations"
)
func dataWorkerPool() *schema.Resource {
return &schema.Resource{
Description: "" +
"`spacelift_worker_pool` represents a worker pool assigned to the " +
"Spacelift account.",
ReadContext: dataWorkerPoolRead,
Schema: map[string]*schema.Schema{
"config": {
Type: schema.TypeString,
Description: "credentials necessary to connect WorkerPool's workers to the control plane",
Computed: true,
Sensitive: true,
},
"name": {
Type: schema.TypeString,
Description: "name of the worker pool",
Computed: true,
},
"description": {
Type: schema.TypeString,
Description: "description of the worker pool",
Computed: true,
},
"worker_pool_id": {
Type: schema.TypeString,
Description: "ID of the worker pool",
Required: true,
ValidateDiagFunc: validations.DisallowEmptyString,
},
"labels": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
},
"space_id": {
Type: schema.TypeString,
Description: "ID (slug) of the space the worker pool is in",
Computed: true,
},
},
}
}
func dataWorkerPoolRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var query struct {
WorkerPool *structs.WorkerPool `graphql:"workerPool(id: $id)"`
}
workerPoolID := d.Get("worker_pool_id").(string)
variables := map[string]interface{}{"id": toID(workerPoolID)}
if err := meta.(*internal.Client).Query(ctx, "WorkerPoolRead", &query, variables); err != nil {
return diag.Errorf("could not query for worker pool: %v", err)
}
workerPool := query.WorkerPool
if workerPool == nil {
return diag.Errorf("worker pool not found")
}
d.SetId(workerPoolID)
d.Set("name", workerPool.Name)
d.Set("config", workerPool.Config)
d.Set("space_id", workerPool.Space)
if workerPool.Description != nil {
d.Set("description", *workerPool.Description)
} else {
d.Set("description", nil)
}
labels := schema.NewSet(schema.HashString, []interface{}{})
for _, label := range workerPool.Labels {
labels.Add(label)
}
d.Set("labels", labels)
return nil
}