Documentation
¶
Index ¶
Constants ¶
const ( KindResource = "resource" KindDataSource = "data_source" KindEphemeral = "ephemeral" KindListResource = "list_resource" KindAction = "action" KindFunction = "function" KindNone = "none" // content-only categories (guides, index) )
Schema-kind identifiers used to select the right target map on ProviderSchema. They match the schema_kind values declared in internal/config/defaults.hcl.
Variables ¶
var BlockKinds = []string{ KindResource, KindDataSource, KindEphemeral, KindListResource, KindAction, }
BlockKinds are the schema kinds whose targets carry a SchemaBlock and can therefore be represented as *ResourceSchema. KindFunction is intentionally excluded — functions have signatures, not blocks.
Functions ¶
func ExpandObjectAttributes ¶ added in v0.19.0
func ExpandObjectAttributes(ps *ProviderSchema)
ExpandObjectAttributes models object-typed attributes — list(object({...})), set(object({...})), or a bare object({...}), whether SDK cty types or Framework nested types — as nested blocks. For every attribute that carries Children, it adds a Block keyed by the attribute's dot-path with those children as the block's attributes, recursing to any depth. Without this, object-typed attribute fields live only on Attribute.Children and are never reached by the block-oriented checks (coverage, ordering, descriptions, labels, headings). Existing block paths are never overwritten, and the transform is idempotent.
Types ¶
type Attribute ¶
type Attribute struct {
Name string
Required bool
Optional bool
Computed bool
Deprecated bool
Sensitive bool
Children []Attribute // nested object attributes (from cty type or nested_type)
}
Attribute represents a single schema attribute with its properties.
type Block ¶
type Block struct {
Path string
Attributes []Attribute
ChildBlocks []string // names of immediate child blocks
// ConfigUnknown is set on blocks synthesized by ExpandObjectAttributes
// from an object-typed attribute (list/set/map(object({...})), object)
// whose parent is configurable (Optional and/or Required). The cty type
// encoding of an object carries no per-field Required/Optional/Computed
// metadata, so for a configurable parent we cannot know whether each
// field is a user-supplied argument or a provider-computed value. Checks
// that enforce Argument-vs-Attribute-Reference placement must not do so
// for these blocks. It stays false for objects whose parent is
// Computed-only (their fields are necessarily read-only).
//
// For the full rationale (the proto5 mux constraint that forces the lossy
// ElementType: types.ObjectType shape, and the proto6 migration that
// resolves it) see docs/rules/object-typed-attributes.md.
ConfigUnknown bool
}
Block represents a flattened schema block with its attributes and child block names.
type FunctionSchema ¶
type FunctionSchema struct {
Name string
Description string
ParameterNames []string
VariadicParameter string // empty when none
}
FunctionSchema holds the minimal representation of a provider function. Full signature data (return type, variadic parameters) is captured on demand; we record only what rules consume today — the function's positional parameter names and descriptions. Expand when a function-aware rule needs more.
type IdentityAttribute ¶
IdentityAttribute describes a single attribute in a resource identity schema.
type IdentitySchema ¶
type IdentitySchema struct {
Attributes []IdentityAttribute
}
IdentitySchema holds the identity attributes for a resource that supports import-by-identity (Terraform v1.12+).
type ProviderSchema ¶
type ProviderSchema struct {
Resources map[string]*ResourceSchema
DataSources map[string]*ResourceSchema
Ephemerals map[string]*ResourceSchema
ListResources map[string]*ResourceSchema
Actions map[string]*ResourceSchema
Functions map[string]*FunctionSchema
IdentitySchemas map[string]*IdentitySchema
}
ProviderSchema holds every target the provider exposes, grouped by schema kind. Kinds with no entries in the provider have empty (but non-nil) maps so callers can iterate safely.
func LoadFile ¶
func LoadFile(path string, providerSource string) (*ProviderSchema, error)
LoadFile reads a `terraform providers schema -json` file and returns the parsed schemas for every target category Terraform currently exposes.
func (*ProviderSchema) Function ¶
func (ps *ProviderSchema) Function(name string) *FunctionSchema
Function returns the function with the given name, or nil when absent.
func (*ProviderSchema) ResourceSchemaFor ¶
func (ps *ProviderSchema) ResourceSchemaFor(kind, name string) *ResourceSchema
ResourceSchemaFor returns the flattened block schema for a named target of a block-kind category, or nil when: the kind is unknown, the kind is KindFunction or KindNone (no block schema to return), or the target name does not exist in that kind.
func (*ProviderSchema) TargetNames ¶
func (ps *ProviderSchema) TargetNames(kind string) []string
TargetNames returns the sorted set of target names for the given schema kind. Unknown kinds (including KindNone) yield an empty slice. Output is sorted so test assertions and log output are stable.
type ResourceSchema ¶
type ResourceSchema struct {
Name string
Blocks map[string]*Block // keyed by dot-path (e.g., "", "rule", "rule.action")
}
ResourceSchema holds the flattened block map for a single block-based target (resource, data source, ephemeral, list resource, or action).