tfcode

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tfcode reads and writes the OpenTofu code of one stack for writ import: it reads the providers a stack requires and configures, and the names it declares, and it writes literals as HCL tokens. It is the one package besides internal/provider that holds cty values, which stay inside it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InNFC

func InNFC(s string) bool

InNFC reports whether s is in Unicode normal form C. OpenTofu reads each string of its code into cty, which keeps strings in NFC, so a string in another form reaches the provider changed.

func Quoted

func Quoted(s string) string

Quoted is s as a quoted HCL string, never a heredoc, with every template sequence and every character that is not printable escaped. OpenTofu reads back s exactly when s is valid UTF-8 in normal form C.

func Scalar

func Scalar(v value.Value) hclwrite.Tokens

Scalar is a string, number, or bool as an HCL literal. It panics on any other kind.

func String

func String(s string) hclwrite.Tokens

String is s as an HCL string that OpenTofu reads back exactly: a heredoc when s is lines of printable text that end in a line break and one of the markers EOT, EOT2 to EOT10 is free, else a quoted string. Every template sequence is escaped.

Types

type Provider

type Provider struct {
	Ref ProviderRef
	// contains filtered or unexported fields
}

Provider is one provider block.

func (*Provider) Config

func (p *Provider) Config(b schema.Block) (value.Value, error)

Config is the provider block as a value of the provider's configuration block. It reads literal values only: an expression that refers to a variable, a local value, or anything else is an error that names the attribute. A sensitive attribute's value is marked secret.

type ProviderRef

type ProviderRef struct{ Name, Alias string }

ProviderRef names one provider configuration: the provider's local name and its alias, "" for the configuration without one.

func (ProviderRef) String

func (r ProviderRef) String() string

String is the reference as a resource's provider argument writes it.

type Stack

type Stack struct {
	// Required maps the local name of each provider in required_providers
	// to its source.
	Required map[string]schema.Source
	// Providers holds each provider block by its reference.
	Providers map[ProviderRef]*Provider
	// Resources holds the names declared for each resource type:
	// Resources["random_uuid"]["main"].
	Resources map[string]map[string]bool
	// Variables are the names of the variable blocks.
	Variables map[string]bool
}

Stack is what an import needs to know of a stack's code: the providers it requires and configures, and the names it declares.

func Read

func Read(files map[string][]byte) (*Stack, error)

Read reads the code of one stack: files maps the name of each .tf or .tofu file in the stack's directory to its text.

func (*Stack) Source

func (st *Stack) Source(name string) schema.Source

Source is the provider source of a local name: the one required_providers gives, or hashicorp/NAME, as OpenTofu implies.

Jump to

Keyboard shortcuts

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