parser

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package parser loads Terraform plan JSON into a normalized resource list.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProviderForType

func ProviderForType(tfType string) string

ProviderForType maps a Terraform resource type to the pricing provider that serves it, based on the type's provider prefix.

Types

type Plan

type Plan struct {
	FormatVersion string            `json:"format_version"`
	Resources     []PlannedResource `json:"-"`
}

func LoadPlanInventoryJSON added in v0.3.20

func LoadPlanInventoryJSON(path string) (*Plan, error)

LoadPlanInventoryJSON parses the final managed-resource inventory from planned_values.root_module. Older plan JSON without that root falls back to LoadPlanJSON's create/update resource_changes behavior.

func LoadPlanJSON

func LoadPlanJSON(path string) (*Plan, error)

LoadPlanJSON parses `terraform show -json <plan>` output. Only "create" and "update" actions contribute to cost; "delete" resources are handled in diff mode.

type PlannedResource

type PlannedResource struct {
	Address string                 `json:"address"`
	Type    string                 `json:"type"` // e.g. "tencentcloud_instance"
	Name    string                 `json:"name"`
	After   map[string]interface{} `json:"after"` // resource_changes[].change.after
	Region  string                 `json:"region,omitempty"`
}

PlannedResource is one row we hand to the pricing engine. It intentionally keeps the raw attribute map so per-type mappers can pull what they need (instance_type, data_disks, charge_type, etc.).

type UsageData added in v0.4.0

type UsageData struct {
	Version   int
	Legacy    UsageOverrides
	Resources map[string]UsageResource
}

UsageData contains either legacy overrides or typed versioned usage.

func LoadUsageFile added in v0.4.0

func LoadUsageFile(path string) (UsageData, error)

LoadUsageFile reads either legacy unversioned overrides or strict version 1 usage.

func (UsageData) IsVersioned added in v0.4.0

func (u UsageData) IsVersioned() bool

type UsageItem added in v0.4.0

type UsageItem struct {
	Quantity float64
	Unit     string
	Pricing  string
	Rate     UsageRate
}

type UsageOverrides

type UsageOverrides map[string]map[string]interface{}

UsageOverrides maps resource address -> arbitrary usage key/value pairs. Unknown fields are preserved and consumed by mapper-specific Extract logic.

func LoadUsageYAML

func LoadUsageYAML(path string) (UsageOverrides, error)

LoadUsageYAML retains the legacy unversioned API.

type UsageRate added in v0.4.0

type UsageRate struct {
	Amount   float64
	Per      float64
	Currency string
	Source   UsageSource
}

type UsageResource added in v0.4.0

type UsageResource struct {
	Items map[string]UsageItem
}

type UsageSource added in v0.4.0

type UsageSource struct {
	Kind       string
	Reference  string
	AsOf       string
	Confidence string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL