/
instance_tags.go
42 lines (34 loc) · 1.08 KB
/
instance_tags.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
package resources
import (
"context"
"github.com/cloudquery/plugin-sdk/v4/schema"
"github.com/cloudquery/plugin-sdk/v4/transformers"
"github.com/dihedron/cq-plugin-utils/transform"
"github.com/dihedron/cq-source-openstack/client"
)
func InstanceTags() *schema.Table {
return &schema.Table{
Name: "openstack_instance_tags",
Resolver: fetchInstanceTags,
Transform: transformers.TransformWithStruct(
&Tag{},
transformers.WithNameTransformer(transform.TagNameTransformer), // use cq-name tags to translate name
transformers.WithTypeTransformer(transform.TagTypeTransformer), // use cq-type tags to translate type
),
}
}
func fetchInstanceTags(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
api := meta.(*client.Client)
instance := parent.Item.(*Instance)
if instance.Tags != nil {
for _, v := range *instance.Tags {
tag := &Tag{Value: v}
api.Logger().Debug().Str("instance id", instance.ID).Msg("streaming instance tag")
res <- tag
}
}
return nil
}
type Tag struct {
Value string `cq-name:"value"`
}