-
Notifications
You must be signed in to change notification settings - Fork 91
/
config.go
44 lines (37 loc) · 1.39 KB
/
config.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
package tfsdk
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschemadata"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)
// Config represents a Terraform config.
type Config struct {
Raw tftypes.Value
Schema Schema
}
// Get populates the struct passed as `target` with the entire config.
func (c Config) Get(ctx context.Context, target interface{}) diag.Diagnostics {
return c.data().Get(ctx, target)
}
// GetAttribute retrieves the attribute found at `path` and populates the
// `target` with the value.
func (c Config) GetAttribute(ctx context.Context, path path.Path, target interface{}) diag.Diagnostics {
return c.data().GetAtPath(ctx, path, target)
}
// PathMatches returns all matching path.Paths from the given path.Expression.
//
// If a parent path is null or unknown, which would prevent a full expression
// from matching, the parent path is returned rather than no match to prevent
// false positives.
func (c Config) PathMatches(ctx context.Context, pathExpr path.Expression) (path.Paths, diag.Diagnostics) {
return c.data().PathMatches(ctx, pathExpr)
}
func (c Config) data() fwschemadata.Data {
return fwschemadata.Data{
Description: fwschemadata.DataDescriptionConfiguration,
Schema: c.Schema,
TerraformValue: c.Raw,
}
}