-
Notifications
You must be signed in to change notification settings - Fork 1
/
attribute.go
43 lines (34 loc) · 885 Bytes
/
attribute.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
package superschema
import (
"context"
schemaD "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
schemaR "github.com/hashicorp/terraform-plugin-framework/resource/schema"
)
type Attributes map[string]Attribute
func (a Attributes) process(ctx context.Context, s schemaType) any {
switch s {
case resourceT:
attributes := make(map[string]schemaR.Attribute)
for k, v := range a {
if v.IsResource() {
attributes[k] = v.GetResource(ctx)
}
}
return attributes
case dataSourceT:
attributes := make(map[string]schemaD.Attribute)
for k, v := range a {
if v.IsDataSource() {
attributes[k] = v.GetDataSource(ctx)
}
}
return attributes
}
return nil
}
type Attribute interface {
IsResource() bool
IsDataSource() bool
GetResource(ctx context.Context) schemaR.Attribute
GetDataSource(ctx context.Context) schemaD.Attribute
}