variable

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package variable manages terraform workspace variables

Index

Constants

View Source
const (
	// https://developer.hashicorp.com/terraform/cloud-docs/workspaces/variables/managing-variables#character-limits
	VariableDescriptionMaxChars = 512
	VariableKeyMaxChars         = 128
	VariableValueMaxKB          = 256 // 256*1024 bytes
)

Variables

View Source
var (
	ErrVariableDescriptionMaxExceeded = fmt.Errorf("maximum variable description size (%d chars) exceeded", VariableDescriptionMaxChars)
	ErrVariableKeyMaxExceeded         = fmt.Errorf("maximum variable key size (%d chars) exceeded", VariableKeyMaxChars)
	ErrVariableValueMaxExceeded       = fmt.Errorf("maximum variable value size of %d KB exceeded", VariableValueMaxKB)
	ErrVariableConflict               = errors.New("variable conflicts with another variable with the same name and type")
)

Functions

func WriteTerraformVars

func WriteTerraformVars(dir string, vars []*Variable) error

WriteTerraformVars writes workspace variables to a file named terraform.tfvars located in the given path. If the file already exists it'll be appended to.

Types

type CreateVariableOptions

type CreateVariableOptions struct {
	Key         *string
	Value       *string
	Description *string
	Category    *VariableCategory
	Sensitive   *bool
	HCL         *bool
	// contains filtered or unexported fields
}

type CreateVariableSetOptions added in v0.1.9

type CreateVariableSetOptions struct {
	Name        string
	Description string
	Global      bool
	Workspaces  []resource.TfeID
}

type ListOptions added in v0.3.17

type ListOptions struct {
	resource.PageOptions
	Organization organization.Name `schema:"organization_name"`
}

type Options

type Options struct {
	WorkspaceService *workspace.Service
	RunClient        runClient
	Authorizer       *authz.Authorizer
	DB               *sql.DB
	Logger           logr.Logger
}

type Service

type Service struct {
	logr.Logger
	*authz.Authorizer
	// contains filtered or unexported fields
}

func NewService

func NewService(opts Options) *Service

func (*Service) ApplySetToWorkspaces added in v0.5.19

func (s *Service) ApplySetToWorkspaces(ctx context.Context, setID resource.TfeID, workspaceIDs []resource.TfeID) error

func (*Service) CreateVariable

func (s *Service) CreateVariable(ctx context.Context, parentID resource.TfeID, opts CreateVariableOptions) (*Variable, error)

func (*Service) CreateVariableSet added in v0.3.27

func (s *Service) CreateVariableSet(ctx context.Context, organization organization.Name, opts CreateVariableSetOptions) (*VariableSet, error)

func (*Service) DeleteSetFromWorkspaces added in v0.5.19

func (s *Service) DeleteSetFromWorkspaces(ctx context.Context, setID resource.TfeID, workspaceIDs []resource.TfeID) error

func (*Service) DeleteVariable

func (s *Service) DeleteVariable(ctx context.Context, variableID resource.TfeID) (*Variable, error)

func (*Service) DeleteVariableSet added in v0.4.8

func (s *Service) DeleteVariableSet(ctx context.Context, setID resource.TfeID) (*VariableSet, error)

func (*Service) GetVariable

func (s *Service) GetVariable(ctx context.Context, variableID resource.TfeID) (*Variable, error)

func (*Service) GetVariableSet added in v0.4.8

func (s *Service) GetVariableSet(ctx context.Context, setID resource.TfeID) (*VariableSet, error)

func (*Service) ListEffectiveVariables added in v0.1.9

func (s *Service) ListEffectiveVariables(ctx context.Context, runID resource.TfeID) ([]*Variable, error)

func (*Service) ListVariableSets added in v0.4.8

func (s *Service) ListVariableSets(ctx context.Context, organization organization.Name) ([]*VariableSet, error)

func (*Service) ListVariables

func (s *Service) ListVariables(ctx context.Context, parentID resource.TfeID) ([]*Variable, error)

func (*Service) ListWorkspaceVariableSets added in v0.4.8

func (s *Service) ListWorkspaceVariableSets(ctx context.Context, workspaceID resource.TfeID) ([]*VariableSet, error)

func (*Service) UpdateVariable

func (s *Service) UpdateVariable(ctx context.Context, variableID resource.TfeID, opts UpdateVariableOptions) (*Variable, error)

func (*Service) UpdateVariableSet added in v0.4.8

func (s *Service) UpdateVariableSet(ctx context.Context, setID resource.TfeID, opts UpdateVariableSetOptions) (*VariableSet, error)

type TFEVariable added in v0.3.17

type TFEVariable struct {
	ID          resource.TfeID `jsonapi:"primary,vars"`
	Key         string         `jsonapi:"attribute" json:"key"`
	Value       string         `jsonapi:"attribute" json:"value"`
	Description string         `jsonapi:"attribute" json:"description"`
	Category    string         `jsonapi:"attribute" json:"category"`
	HCL         bool           `jsonapi:"attribute" json:"hcl"`
	Sensitive   bool           `jsonapi:"attribute" json:"sensitive"`
	VersionID   string         `jsonapi:"attribute" json:"version-id"`

	// Relations
	Workspace   *workspace.TFEWorkspace `jsonapi:"relationship" json:"configurable,omitempty"`
	VariableSet *TFEVariableSet         `jsonapi:"relationship" json:"varset,omitempty"`
}

TFEVariable is a terraform enterprise variable.

type TFEVariableCreateOptions added in v0.3.17

type TFEVariableCreateOptions struct {
	// Type is a public field utilized by JSON:API to
	// set the resource type via the field tag.
	// It is not a user-defined value and does not need to be set.
	// https://jsonapi.org/format/#crud-creating
	Type string `jsonapi:"primary,vars"`

	// The name of the variable.
	Key *string `jsonapi:"attribute" json:"key"`

	// The value of the variable.
	Value *string `jsonapi:"attribute" json:"value,omitempty"`

	// The description of the variable.
	Description *string `jsonapi:"attribute" json:"description,omitempty"`

	// Whether this is a Terraform or environment variable.
	Category *string `jsonapi:"attribute" json:"category"`

	// Whether to evaluate the value of the variable as a string of HCL code.
	HCL *bool `jsonapi:"attribute" json:"hcl,omitempty"`

	// Whether the value is sensitive.
	Sensitive *bool `jsonapi:"attribute" json:"sensitive,omitempty"`
}

TFEVariableCreateOptions represents the options for creating a new variable.

type TFEVariableList added in v0.3.17

type TFEVariableList struct {
	*types.Pagination
	Items []*Variable
}

TFEVariableList is a list of workspace variables

type TFEVariableSet added in v0.3.17

type TFEVariableSet struct {
	ID          resource.TfeID `jsonapi:"primary,varsets"`
	Name        string         `jsonapi:"attribute" json:"name"`
	Description string         `jsonapi:"attribute" json:"description"`
	Global      bool           `jsonapi:"attribute" json:"global"`
	Priority    bool           `jsonapi:"attribute" json:"priority"`

	// Relations
	Organization *organization.TFEOrganization `jsonapi:"relationship" json:"organization"`
	Workspaces   []*workspace.TFEWorkspace     `jsonapi:"relationship" json:"workspaces,omitempty"`
	Variables    []*TFEVariable                `jsonapi:"relationship" json:"vars,omitempty"`
}

TFEVariableSet represents a Terraform Enterprise variable set.

type TFEVariableSetCreateOptions added in v0.3.17

type TFEVariableSetCreateOptions struct {
	// Type is a public field utilized by JSON:API to
	// set the resource type via the field tag.
	// It is not a user-defined value and does not need to be set.
	// https://jsonapi.org/format/#crud-creating
	Type string `jsonapi:"primary,varsets"`

	// The name of the variable set.
	// Affects variable precedence when there are conflicts between Variable Sets
	// https://developer.hashicorp.com/terraform/cloud-docs/api-docs/variable-sets#apply-variable-set-to-workspaces
	Name string `jsonapi:"attribute" json:"name"`

	// A description to provide context for the variable set.
	Description string `jsonapi:"attribute" json:"description,omitempty"`

	// If true the variable set is considered in all runs in the organization.
	Global bool `jsonapi:"attribute" json:"global,omitempty"`
}

TFEVariableSetCreateOptions represents the options for creating a new variable set within in a organization.

type TFEVariableSetUpdateOptions added in v0.3.17

type TFEVariableSetUpdateOptions struct {
	// Type is a public field utilized by JSON:API to
	// set the resource type via the field tag.
	// It is not a user-defined value and does not need to be set.
	// https://jsonapi.org/format/#crud-creating
	Type string `jsonapi:"primary,varsets"`

	// The name of the variable set.
	// Affects variable precedence when there are conflicts between Variable Sets
	// https://developer.hashicorp.com/terraform/cloud-docs/api-docs/variable-sets#apply-variable-set-to-workspaces
	Name *string `jsonapi:"attribute" json:"name,omitempty"`

	// A description to provide context for the variable set.
	Description *string `jsonapi:"attribute" json:"description,omitempty"`

	// If true the variable set is considered in all runs in the organization.
	Global *bool `jsonapi:"attribute" json:"global,omitempty"`

	// If true the variables in the set override any other variable values set
	// in a more specific scope including values set on the command line.
	Priority *bool `jsonapi:"attribute" json:"priority,omitempty"`
}

TFEVariableSetUpdateOptions represents the options for updating a variable set.

type TFEVariableSetVariableCreateOptions added in v0.3.17

type TFEVariableSetVariableCreateOptions struct {
	// Type is a public field utilized by JSON:API to
	// set the resource type via the field tag.
	// It is not a user-defined value and does not need to be set.
	// https://jsonapi.org/format/#crud-creating
	Type string `jsonapi:"primary,vars"`

	// The name of the variable.
	Key *string `jsonapi:"attribute" json:"key"`

	// The value of the variable.
	Value *string `jsonapi:"attribute" json:"value,omitempty"`

	// The description of the variable.
	Description *string `jsonapi:"attribute" json:"description,omitempty"`

	// Whether this is a Terraform or environment variable.
	Category *string `jsonapi:"attribute" json:"category"`

	// Whether to evaluate the value of the variable as a string of HCL code.
	HCL *bool `jsonapi:"attribute" json:"hcl,omitempty"`

	// Whether the value is sensitive.
	Sensitive *bool `jsonapi:"attribute" json:"sensitive,omitempty"`
}

TFEVariableSetVariableCreatOptions represents the options for creating a new variable within a variable set

type TFEVariableSetVariableUpdateOptions added in v0.3.17

type TFEVariableSetVariableUpdateOptions struct {
	// Type is a public field utilized by JSON:API to
	// set the resource type via the field tag.
	// It is not a user-defined value and does not need to be set.
	// https://jsonapi.org/format/#crud-creating
	Type string `jsonapi:"primary,vars"`

	// The name of the variable.
	Key *string `jsonapi:"attribute" json:"key,omitempty"`

	// The value of the variable.
	Value *string `jsonapi:"attribute" json:"value,omitempty"`

	// The description of the variable.
	Description *string `jsonapi:"attribute" json:"description,omitempty"`

	// Whether to evaluate the value of the variable as a string of HCL code.
	HCL *bool `jsonapi:"attribute" json:"hcl,omitempty"`

	// Whether the value is sensitive.
	Sensitive *bool `jsonapi:"attribute" json:"sensitive,omitempty"`
}

TFEVariableSetVariableUpdateOptions represents the options for updating a variable.

type TFEVariableUpdateOptions added in v0.3.17

type TFEVariableUpdateOptions struct {
	// Type is a public field utilized by JSON:API to
	// set the resource type via the field tag.
	// It is not a user-defined value and does not need to be set.
	// https://jsonapi.org/format/#crud-creating
	Type string `jsonapi:"primary,vars"`

	// The name of the variable.
	Key *string `jsonapi:"attribute" json:"key,omitempty"`

	// The value of the variable.
	Value *string `jsonapi:"attribute" json:"value,omitempty"`

	// The description of the variable.
	Description *string `jsonapi:"attribute" json:"description,omitempty"`

	// Whether this is a Terraform or environment variable.
	Category *string `jsonapi:"attribute" json:"category"`

	// Whether to evaluate the value of the variable as a string of HCL code.
	HCL *bool `jsonapi:"attribute" json:"hcl,omitempty"`

	// Whether the value is sensitive.
	Sensitive *bool `jsonapi:"attribute" json:"sensitive,omitempty"`
}

TFEVariableUpdateOptions represents the options for updating a variable.

type TFEWorkspace added in v0.3.21

type TFEWorkspace struct {
	ID resource.TfeID `jsonapi:"primary,workspaces"`
}

type UpdateVariableOptions

type UpdateVariableOptions struct {
	Key         *string
	Value       *string
	Description *string
	Category    *VariableCategory
	Sensitive   *bool
	HCL         *bool
	// contains filtered or unexported fields
}

type UpdateVariableSetOptions added in v0.1.9

type UpdateVariableSetOptions struct {
	Name        *string
	Description *string
	Global      *bool
	Workspaces  []resource.TfeID
}

type Variable

type Variable struct {
	ID          resource.TfeID   `jsonapi:"primary,variables" db:"variable_id"`
	Key         string           `jsonapi:"attribute" json:"key"`
	Value       string           `jsonapi:"attribute" json:"value"`
	Description string           `jsonapi:"attribute" json:"description"`
	Category    VariableCategory `jsonapi:"attribute" json:"category"`
	Sensitive   bool             `jsonapi:"attribute" json:"sensitive"`
	HCL         bool             `jsonapi:"attribute" json:"hcl"`

	// ParentID is the ID of the variable's parent resource. Must be either
	// a workspace ID if a workspace variable, or a variable set ID if a
	// variable set variable.
	ParentID resource.TfeID `jsonapi:"attribute" json:"parent_id" db:"parent_id"`

	// OTF doesn't use this internally but the go-tfe integration tests
	// expect it to be a random value that changes on every update.
	VersionID string
}

func Merge added in v0.4.8

func Merge(workspaceSets []*VariableSet, workspaceVariables []*Variable, run *run.Run) []*Variable

Merge merges variables for a run according to the precedence rules documented here:

https://developer.hashicorp.com/terraform/cloud-docs/workspaces/variables#precedence

Note: If run is nil then it is ignored.

func (*Variable) LogValue

func (v *Variable) LogValue() slog.Value

func (*Variable) Matches added in v0.1.9

func (v *Variable) Matches(vars []*Variable) bool

Matches determines whether variable is contained in vars, i.e. shares the same ID.

type VariableCategory

type VariableCategory string

VariableCategory is the category of variable

const (
	CategoryTerraform VariableCategory = "terraform"
	CategoryEnv       VariableCategory = "env"
)

type VariableService

type VariableService = Service

Alias service to permit embedding it with other services in a struct without a name clash.

type VariableSet added in v0.1.9

type VariableSet struct {
	ID           resource.TfeID
	Name         string
	Description  string
	Global       bool
	Workspaces   []resource.TfeID
	Organization organization.Name
	Variables    []*Variable
}

VariableSet is a set of variables

func (*VariableSet) LogValue added in v0.1.9

func (s *VariableSet) LogValue() slog.Value

Directories

Path Synopsis
templ: version: v0.3.1001
templ: version: v0.3.1001

Jump to

Keyboard shortcuts

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