Documentation
¶
Index ¶
- Constants
- Variables
- func ExportCtyValueToJSON(v cty.Value) (json.RawMessage, bool)
- func IsValidBlockReference(name string) bool
- func IsValidType(name string) bool
- func MapNestedAttribute[T any](block *Block, path string, f func(attr *Attribute, parent *Block) T) T
- func RewriteExpr(expr hclsyntax.Expression, ...) hclsyntax.Expression
- type Attribute
- func (a *Attribute) AllReferences() []*Reference
- func (a *Attribute) AsBoolValueOrDefault(defaultValue bool, parent *Block) iacTypes.BoolValue
- func (a *Attribute) AsBytesValueOrDefault(defaultValue []byte, parent *Block) iacTypes.BytesValue
- func (a *Attribute) AsIntValueOrDefault(defaultValue int, parent *Block) iacTypes.IntValue
- func (a *Attribute) AsMapValue() iacTypes.MapValue
- func (a *Attribute) AsNumber() float64
- func (a *Attribute) AsStringValueOrDefault(defaultValue string, parent *Block) iacTypes.StringValue
- func (a *Attribute) AsStringValueSliceOrEmpty() (stringValues []iacTypes.StringValue)
- func (a *Attribute) AsStringValues() iacTypes.StringValueList
- func (a *Attribute) AsStringValuesOrDefault(parent *Block, defaults ...string) []iacTypes.StringValue
- func (a *Attribute) Contains(checkValue any, equalityOptions ...EqualityOption) bool
- func (a *Attribute) DecodeVarType() (cty.Type, *typeexpr.Defaults, error)
- func (a *Attribute) Each(f func(key cty.Value, val cty.Value)) error
- func (a *Attribute) Equals(checkValue any, equalityOptions ...EqualityOption) bool
- func (a *Attribute) GetMetadata() iacTypes.Metadata
- func (a *Attribute) GetRawValue() any
- func (a *Attribute) HCLAttribute() *hcl.Attribute
- func (a *Attribute) IsBool() bool
- func (a *Attribute) IsEmpty() bool
- func (a *Attribute) IsFalse() bool
- func (a *Attribute) IsIterable() bool
- func (a *Attribute) IsLiteral() bool
- func (a *Attribute) IsMapOrObject() bool
- func (a *Attribute) IsNil() bool
- func (a *Attribute) IsNotNil() bool
- func (a *Attribute) IsNumber() bool
- func (a *Attribute) IsResolvable() bool
- func (a *Attribute) IsResourceBlockReference(resourceType string) bool
- func (a *Attribute) IsString() bool
- func (a *Attribute) IsTrue() bool
- func (a *Attribute) MapValue(mapKey string) cty.Value
- func (a *Attribute) Name() string
- func (a *Attribute) NullableValue() (ctyVal cty.Value)
- func (a *Attribute) References(r Reference) bool
- func (a *Attribute) ReferencesBlock(b *Block) bool
- func (a *Attribute) RewriteExpr(transform func(hclsyntax.Expression) hclsyntax.Expression)
- func (a *Attribute) ToAttributeExport() AttributeExport
- func (a *Attribute) Type() cty.Type
- func (a *Attribute) Value() (ctyVal cty.Value)
- type AttributeExport
- type Block
- func (b *Block) AllBlocks() Blocks
- func (b *Block) Attributes() map[string]*Attribute
- func (b *Block) Clone(index cty.Value) *Block
- func (b *Block) Context() *context.Context
- func (b *Block) ExpandBlock() error
- func (b *Block) FullLocalName() string
- func (b *Block) FullName() string
- func (b *Block) GetAttribute(name string) *Attribute
- func (b *Block) GetAttributes() []*Attribute
- func (b *Block) GetBlock(name string) *Block
- func (b *Block) GetBlocks(name string) Blocks
- func (b *Block) GetFirstAttributeOf(names ...string) *Attribute
- func (b *Block) GetFirstMatchingBlock(names ...string) *Block
- func (b *Block) GetMetadata() iacTypes.Metadata
- func (b *Block) GetNestedAttribute(name string) (*Attribute, *Block)
- func (b *Block) GetRawValue() any
- func (b *Block) GetValueByPath(path string) cty.Value
- func (b *Block) HCLBlock() *hcl.Block
- func (b *Block) ID() string
- func (b *Block) InModule() bool
- func (b *Block) IsEmpty() bool
- func (b *Block) IsExpanded() bool
- func (b *Block) IsNil() bool
- func (b *Block) IsNotNil() bool
- func (b *Block) IsResourceType(resourceType string) bool
- func (b *Block) Label() string
- func (b *Block) Labels() []string
- func (b *Block) LocalName() string
- func (b *Block) ModuleBlock() *Block
- func (b *Block) ModuleKey() string
- func (b *Block) NameLabel() string
- func (b *Block) NullableValues() cty.Value
- func (b *Block) OverrideContext(ctx *context.Context)
- func (b *Block) Reference() Reference
- func (b *Block) ToBlockExport() BlockExport
- func (b *Block) Type() string
- func (b *Block) TypeLabel() string
- func (b *Block) UniqueName() string
- func (b *Block) Values() cty.Value
- type BlockExport
- type Blocks
- type EqualityOption
- type Module
- func (c *Module) GetBlockByID(id string) (*Block, error)
- func (c *Module) GetBlocks() Blocks
- func (c *Module) GetBlocksByTypeLabel(typeLabel string) Blocks
- func (c *Module) GetDatasByType(label string) Blocks
- func (c *Module) GetReferencedBlock(referringAttr *Attribute, parentBlock *Block) (*Block, error)
- func (c *Module) GetReferencingBlocks(originalBlock *Block, ...) Blocks
- func (c *Module) GetReferencingResources(originalBlock *Block, referencingLabel, referencingAttributeName string) Blocks
- func (c *Module) GetResourcesByIDs(ids ...string) Blocks
- func (c *Module) GetResourcesByType(labels ...string) Blocks
- func (c *Module) Ignores() ignore.Rules
- func (c *Module) ModulePath() string
- func (c *Module) Parent() *Module
- func (c *Module) RootPath() string
- func (c *Module) SetParent(parent *Module)
- func (c *Module) ToModuleExport() ModuleExport
- type ModuleExport
- type Modules
- func (m Modules) GetBlockById(id string) (*Block, error)
- func (m Modules) GetBlockByIgnoreRange(blockMetadata *types.Metadata) *Block
- func (m Modules) GetBlocks() Blocks
- func (m Modules) GetChildResourceIDMapByType(typeLabels ...string) ResourceIDResolutions
- func (m Modules) GetDatasByType(typeLabel string) Blocks
- func (m Modules) GetReferencedBlock(referringAttr *Attribute, parentBlock *Block) (*Block, error)
- func (m Modules) GetReferencingResources(originalBlock *Block, referencingLabel, referencingAttributeName string) Blocks
- func (m Modules) GetResourceByIDs(id ...string) Blocks
- func (m Modules) GetResourcesByType(typeLabel ...string) Blocks
- type PartialTemplateExpr
- type Reference
- func (r Reference) BlockType() Type
- func (r Reference) HumanReadable() string
- func (r Reference) Key() string
- func (r Reference) KeyBracketed() string
- func (r Reference) LogicalID() string
- func (r Reference) NameLabel() string
- func (r Reference) RawKey() cty.Value
- func (r Reference) RefersTo(other Reference) bool
- func (r *Reference) SetKey(key cty.Value)
- func (r Reference) String() string
- func (r Reference) TypeLabel() string
- type ResourceIDResolutions
- type TerraformConfigExport
- type Type
Constants ¶
const UnknownValuePrefix = "__UNRESOLVED__"
UnknownValuePrefix is a placeholder string used to represent parts of a template expression that cannot be fully evaluated due to unknown values.
Variables ¶
var Schema = &hcl.BodySchema{ Blocks: []hcl.BlockHeaderSchema{ { Type: "terraform", }, { Type: "required_providers", }, { Type: "provider", LabelNames: []string{"name"}, }, { Type: "variable", LabelNames: []string{"name"}, }, { Type: "locals", }, { Type: "output", LabelNames: []string{"name"}, }, { Type: "module", LabelNames: []string{"name"}, }, { Type: "check", LabelNames: []string{"name"}, }, { Type: "resource", LabelNames: []string{"type", "name"}, }, { Type: "data", LabelNames: []string{"type", "name"}, }, { Type: "ephemeral", LabelNames: []string{"type", "name"}, }, { Type: "action", LabelNames: []string{"type", "name"}, }, { Type: "moved", }, { Type: "import", }, { Type: "removed", }, }, }
Schema is regularly lifted from terraform source to ensure compatibility
var TypeCheck = Type{ // contains filtered or unexported fields }
var TypeData = Type{ // contains filtered or unexported fields }
var TypeImport = Type{ // contains filtered or unexported fields }
var TypeLocal = Type{ // contains filtered or unexported fields }
var TypeModule = Type{ // contains filtered or unexported fields }
var TypeMoved = Type{ // contains filtered or unexported fields }
var TypeOutput = Type{ // contains filtered or unexported fields }
var TypeProvider = Type{ // contains filtered or unexported fields }
var TypeResource = Type{ // contains filtered or unexported fields }
var TypeTerraform = Type{ // contains filtered or unexported fields }
var TypeVariable = Type{ // contains filtered or unexported fields }
var ValidTypes = []Type{ TypeCheck, TypeData, TypeImport, TypeLocal, TypeModule, TypeMoved, TypeOutput, TypeProvider, TypeResource, TypeTerraform, TypeVariable, }
Functions ¶
func ExportCtyValueToJSON ¶ added in v0.63.0
func ExportCtyValueToJSON(v cty.Value) (json.RawMessage, bool)
func IsValidBlockReference ¶
func IsValidType ¶
func MapNestedAttribute ¶
func RewriteExpr ¶ added in v0.64.0
func RewriteExpr( expr hclsyntax.Expression, transform func(hclsyntax.Expression) hclsyntax.Expression, ) hclsyntax.Expression
nolint: gocyclo RewriteExpr recursively rewrites an HCL expression tree in-place, applying the provided transformation function `transform` to each node.
Types ¶
type Attribute ¶
type Attribute struct {
// contains filtered or unexported fields
}
func NewAttribute ¶
func (*Attribute) AllReferences ¶
func (*Attribute) AsBoolValueOrDefault ¶
func (*Attribute) AsBytesValueOrDefault ¶
func (a *Attribute) AsBytesValueOrDefault(defaultValue []byte, parent *Block) iacTypes.BytesValue
func (*Attribute) AsIntValueOrDefault ¶
func (*Attribute) AsMapValue ¶
func (*Attribute) AsStringValueOrDefault ¶
func (a *Attribute) AsStringValueOrDefault(defaultValue string, parent *Block) iacTypes.StringValue
func (*Attribute) AsStringValueSliceOrEmpty ¶
func (a *Attribute) AsStringValueSliceOrEmpty() (stringValues []iacTypes.StringValue)
func (*Attribute) AsStringValues ¶
func (a *Attribute) AsStringValues() iacTypes.StringValueList
func (*Attribute) AsStringValuesOrDefault ¶
func (a *Attribute) AsStringValuesOrDefault(parent *Block, defaults ...string) []iacTypes.StringValue
func (*Attribute) Contains ¶
func (a *Attribute) Contains(checkValue any, equalityOptions ...EqualityOption) bool
func (*Attribute) DecodeVarType ¶
func (*Attribute) Equals ¶
func (a *Attribute) Equals(checkValue any, equalityOptions ...EqualityOption) bool
func (*Attribute) GetMetadata ¶
func (*Attribute) GetRawValue ¶
func (*Attribute) HCLAttribute ¶ added in v0.59.0
func (*Attribute) IsIterable ¶
func (*Attribute) IsMapOrObject ¶
func (*Attribute) IsResolvable ¶
func (*Attribute) IsResourceBlockReference ¶
func (*Attribute) NullableValue ¶
Allows a null value for a variable https://developer.hashicorp.com/terraform/language/expressions/types#null
func (*Attribute) References ¶
func (*Attribute) ReferencesBlock ¶
func (*Attribute) RewriteExpr ¶ added in v0.64.0
func (a *Attribute) RewriteExpr(transform func(hclsyntax.Expression) hclsyntax.Expression)
RewriteExpr applies the given function `transform` to the expression of the attribute, recursively traversing and transforming it.
func (*Attribute) ToAttributeExport ¶ added in v0.63.0
func (a *Attribute) ToAttributeExport() AttributeExport
type AttributeExport ¶ added in v0.63.0
type AttributeExport struct {
Metadata any `json:"__defsec_metadata"`
Name string `json:"name"`
Value json.RawMessage `json:"value"`
Known bool `json:"known"`
}
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
func (*Block) Attributes ¶
func (*Block) ExpandBlock ¶ added in v0.57.0
func (*Block) FullLocalName ¶ added in v0.57.0
func (*Block) GetAttribute ¶
func (*Block) GetAttributes ¶
func (*Block) GetFirstAttributeOf ¶ added in v0.68.0
func (*Block) GetFirstMatchingBlock ¶
func (*Block) GetMetadata ¶
func (*Block) GetNestedAttribute ¶
func (*Block) GetRawValue ¶
func (*Block) GetValueByPath ¶ added in v0.55.0
GetValueByPath returns the value of the attribute located at the given path. Supports special paths like "count.index," "each.key," and "each.value." The path may contain indices, keys and dots (used as separators).
func (*Block) IsExpanded ¶
func (*Block) IsResourceType ¶
func (*Block) ModuleBlock ¶ added in v0.60.0
func (*Block) NullableValues ¶ added in v0.58.2
func (*Block) OverrideContext ¶
func (*Block) ToBlockExport ¶ added in v0.63.0
func (b *Block) ToBlockExport() BlockExport
func (*Block) UniqueName ¶
type BlockExport ¶ added in v0.63.0
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
func (*Module) GetBlocksByTypeLabel ¶
func (*Module) GetDatasByType ¶
func (*Module) GetReferencedBlock ¶
func (*Module) GetReferencingBlocks ¶
func (*Module) GetReferencingResources ¶
func (*Module) GetResourcesByIDs ¶
func (*Module) GetResourcesByType ¶
func (*Module) ModulePath ¶ added in v0.60.0
func (*Module) ToModuleExport ¶ added in v0.63.0
func (c *Module) ToModuleExport() ModuleExport
type ModuleExport ¶ added in v0.63.0
type ModuleExport struct {
RootPath string `json:"root_path"`
ModulePath string `json:"module_path"`
ParentPath string `json:"parent_path"`
Blocks []BlockExport `json:"blocks"`
}
type Modules ¶
type Modules []*Module
func (Modules) GetBlockByIgnoreRange ¶
func (Modules) GetChildResourceIDMapByType ¶
func (m Modules) GetChildResourceIDMapByType(typeLabels ...string) ResourceIDResolutions
func (Modules) GetDatasByType ¶ added in v0.53.0
func (Modules) GetReferencedBlock ¶
func (Modules) GetReferencingResources ¶
func (Modules) GetResourceByIDs ¶
func (Modules) GetResourcesByType ¶
type PartialTemplateExpr ¶ added in v0.64.0
type PartialTemplateExpr struct {
*hclsyntax.TemplateExpr
}
PartialTemplateExpr is a wrapper around hclsyntax.TemplateExpr that replaces unknown or unevaluated parts with placeholder strings during evaluation.
func (*PartialTemplateExpr) Value ¶ added in v0.64.0
func (e *PartialTemplateExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics)
type Reference ¶
type Reference struct {
// contains filtered or unexported fields
}
func (Reference) HumanReadable ¶
func (Reference) KeyBracketed ¶
type ResourceIDResolutions ¶
func (ResourceIDResolutions) Orphans ¶
func (r ResourceIDResolutions) Orphans() (orphanIDs []string)
func (ResourceIDResolutions) Resolve ¶
func (r ResourceIDResolutions) Resolve(id string)
type TerraformConfigExport ¶ added in v0.63.0
type TerraformConfigExport struct {
Modules []ModuleExport `json:"modules"`
}
TODO(nikpivkin): export directly to OPA values
func ExportModules ¶ added in v0.63.0
func ExportModules(modules Modules) TerraformConfigExport