hclconfig

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package hclconfig reads and writes TFx profile blocks in ~/.tfx.hcl.

Profile block format:

profile "default" {
  hostname     = "app.terraform.io"
  organization = "my-org"
  token        = "abc123..."
}

The block label is the profile name (a user-editable alias — not the hostname). hostname is an optional key inside the block; it defaults to DefaultHostname ("app.terraform.io") when omitted.

Index

Constants

View Source
const (
	// DefaultProfileName is the profile name used when none is specified.
	DefaultProfileName = "default"
	// DefaultHostname is the TFE/HCP Terraform hostname used when none is specified.
	DefaultHostname = "app.terraform.io"
)

Variables

This section is empty.

Functions

func DefaultConfigPath

func DefaultConfigPath() (string, error)

DefaultConfigPath returns the canonical path to ~/.tfx.hcl.

func WriteProfile

func WriteProfile(path, name, hostname, organization, token string) error

WriteProfile adds or replaces the named profile block in the file at path. If path does not exist it is created. All other profiles and file content are preserved. The file is written with 0600 permissions because it contains an API token.

name defaults to DefaultProfileName when empty. hostname defaults to DefaultHostname when empty. organization may be empty; a commented placeholder is written instead.

Types

type Profile

type Profile struct {
	Name         string // block label — user-editable alias
	Hostname     string // hostname value; defaults to DefaultHostname if omitted
	Organization string // organization value; may be empty
	Token        string // token value
}

Profile holds configuration for one TFx profile.

func ListProfiles

func ListProfiles(path string) ([]Profile, error)

ListProfiles parses path and returns all profile blocks in file order.

  • Each profile block becomes one Profile. Name = block label; Hostname = hostname inside the block, or DefaultHostname when absent.
  • File not found: returns nil, nil.
  • Files without profile blocks: returns nil, nil.

Jump to

Keyboard shortcuts

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