Help us shape the future of Go! Take the 2026 Go Developer Survey

tfpath

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package tfpath holds path predicates for Terraform/OpenTofu config files.

Index

Constants

View Source
const (
	ExtTF       = ".tf"
	ExtTofu     = ".tofu"
	ExtTFJSON   = ".tf.json"
	ExtTofuJSON = ".tofu.json"
	ExtTFVars   = ".tfvars"
)

Variables

This section is empty.

Functions

func AllowSet

func AllowSet(paths []string) map[string]struct{}

AllowSet indexes inventory paths for merge filtering.

func Extension

func Extension(path string) string

Extension returns the Terraform/OpenTofu config suffix, including compound JSON suffixes that filepath.Ext would truncate to ".json".

func FilterShadowed

func FilterShadowed(paths []string) []string

FilterShadowed drops paths ShadowedByTofu reports. The input is returned unchanged when nothing is shadowed.

func IsConfig

func IsConfig(path string) bool

IsConfig reports whether path may declare Terraform/OpenTofu modules.

func IsHCLConfig

func IsHCLConfig(path string) bool

IsHCLConfig reports whether path is a native Terraform/OpenTofu HCL configuration file.

func IsJSONConfig

func IsJSONConfig(path string) bool

IsJSONConfig reports whether path uses Terraform/OpenTofu JSON configuration syntax.

func Matching

func Matching(paths []string, pred func(string) bool) []string

Matching keeps paths that satisfy pred. It does not apply OpenTofu precedence.

func Partition

func Partition[T any](items []T, path func(T) string) (kept, shadowed []T)

Partition splits items into those OpenTofu would load and those it ignores. shadowed is nil when nothing is dropped; kept is the input slice in that case.

func PartitionWithTofuPrecedence

func PartitionWithTofuPrecedence[T any](
	items []T, path func(T) string, preferTofu func(string) bool,
) (kept, shadowed []T)

PartitionWithTofuPrecedence splits twin configs according to preferTofu. A nil callback gives every .tofu path precedence.

func Select

func Select(paths []string, pred func(string) bool) []string

Select is Matching then FilterShadowed. Use it when merging a directory into one module, not when deciding which files enter inventory.

func SelectKeeping

func SelectKeeping(paths []string, pred func(string) bool, keep string) []string

SelectKeeping is Select, except keep stays in the result when it matched pred. If keep is a .tf twin of a selected .tofu file, that .tofu twin is dropped so a scanned Terraform file is not evaluated with its OpenTofu replacement.

func SelectKeepingWithTofuPrecedence

func SelectKeepingWithTofuPrecedence(
	paths []string, pred func(string) bool, keep string, preferTofu func(string) bool,
) []string

SelectKeepingWithTofuPrecedence is SelectWithTofuPrecedence, except keep stays in the result and its twin is dropped.

func SelectWithTofuPrecedence

func SelectWithTofuPrecedence(paths []string, pred, preferTofu func(string) bool) []string

SelectWithTofuPrecedence applies OpenTofu precedence only when preferTofu accepts the .tofu path. If a twin exists and preferTofu rejects it, the .tf path is kept instead.

func ShadowedByTofu

func ShadowedByTofu(paths []string) map[string]struct{}

ShadowedByTofu reports paths OpenTofu ignores: foo.tf next to foo.tofu, foo.tf.json next to foo.tofu.json. Returns nil when nothing is shadowed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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