Documentation
¶
Overview ¶
Package variable manages terraform workspace variables
Index ¶
- Constants
- Variables
- func WriteTerraformVars(dir string, vars []*Variable) error
- type Client
- type CreateVariableOptions
- type CreateVariableSetOptions
- type ListOptions
- type Options
- type Service
- func (s *Service) AddHandlers(r *mux.Router)
- func (s *Service) CreateVariableSet(ctx context.Context, organization organization.Name, ...) (*VariableSet, error)
- func (s *Service) CreateVariableSetVariable(ctx context.Context, setID resource.TfeID, opts CreateVariableOptions) (*Variable, error)
- func (s *Service) CreateWorkspaceVariable(ctx context.Context, workspaceID resource.TfeID, opts CreateVariableOptions) (*Variable, error)
- func (s *Service) DeleteVariableSet(ctx context.Context, setID resource.TfeID) (*VariableSet, error)
- func (s *Service) DeleteVariableSetVariable(ctx context.Context, variableID resource.TfeID) (*VariableSet, error)
- func (s *Service) DeleteWorkspaceVariable(ctx context.Context, variableID resource.TfeID) (*WorkspaceVariable, error)
- func (s *Service) GetVariableSet(ctx context.Context, setID resource.TfeID) (*VariableSet, error)
- func (s *Service) GetVariableSetByVariableID(ctx context.Context, variableID resource.TfeID) (*VariableSet, error)
- func (s *Service) GetWorkspaceVariable(ctx context.Context, variableID resource.TfeID) (*WorkspaceVariable, error)
- func (s *Service) ListEffectiveVariables(ctx context.Context, runID resource.TfeID) ([]*Variable, error)
- func (s *Service) ListVariableSets(ctx context.Context, organization organization.Name) ([]*VariableSet, error)
- func (s *Service) ListWorkspaceVariableSets(ctx context.Context, workspaceID resource.TfeID) ([]*VariableSet, error)
- func (s *Service) ListWorkspaceVariables(ctx context.Context, workspaceID resource.TfeID) ([]*Variable, error)
- func (s *Service) UpdateVariableSet(ctx context.Context, setID resource.TfeID, opts UpdateVariableSetOptions) (*VariableSet, error)
- func (s *Service) UpdateVariableSetVariable(ctx context.Context, variableID resource.TfeID, opts UpdateVariableOptions) (*VariableSet, error)
- func (s *Service) UpdateWorkspaceVariable(ctx context.Context, variableID resource.TfeID, opts UpdateVariableOptions) (*WorkspaceVariable, error)
- type TFEVariable
- type TFEVariableCreateOptions
- type TFEVariableList
- type TFEVariableSet
- type TFEVariableSetCreateOptions
- type TFEVariableSetUpdateOptions
- type TFEVariableSetVariable
- type TFEVariableSetVariableCreateOptions
- type TFEVariableSetVariableUpdateOptions
- type TFEVariableUpdateOptions
- type TFEWorkspace
- type TFEWorkspaceVariable
- type UpdateVariableOptions
- type UpdateVariableSetOptions
- type Variable
- type VariableCategory
- type VariableSet
- type WorkspaceVariable
Constants ¶
const ( // https://developer.hashicorp.com/terraform/cloud-docs/workspaces/variables/managing-variables#character-limits VariableDescriptionMaxChars = 512 VariableKeyMaxChars = 128 VariableValueMaxKB = 256 // 256*1024 bytes )
Variables ¶
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 ¶
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 CreateVariableSetOptions ¶ added in v0.1.9
type ListOptions ¶ added in v0.3.17
type ListOptions struct {
resource.PageOptions
Organization organization.Name `schema:"organization_name"`
}
type Service ¶
type Service struct {
logr.Logger
*authz.Authorizer
// contains filtered or unexported fields
}
func NewService ¶
func (*Service) AddHandlers ¶ added in v0.2.2
func (*Service) CreateVariableSet ¶ added in v0.3.27
func (s *Service) CreateVariableSet(ctx context.Context, organization organization.Name, opts CreateVariableSetOptions) (*VariableSet, error)
func (*Service) CreateVariableSetVariable ¶ added in v0.3.27
func (*Service) CreateWorkspaceVariable ¶ added in v0.1.9
func (*Service) DeleteVariableSet ¶ added in v0.4.8
func (*Service) DeleteVariableSetVariable ¶ added in v0.4.8
func (*Service) DeleteWorkspaceVariable ¶ added in v0.1.9
func (*Service) GetVariableSet ¶ added in v0.4.8
func (*Service) GetVariableSetByVariableID ¶ added in v0.4.8
func (*Service) GetWorkspaceVariable ¶ added in v0.1.9
func (*Service) ListEffectiveVariables ¶ added in v0.1.9
func (*Service) ListVariableSets ¶ added in v0.4.8
func (s *Service) ListVariableSets(ctx context.Context, organization organization.Name) ([]*VariableSet, error)
func (*Service) ListWorkspaceVariableSets ¶ added in v0.4.8
func (*Service) ListWorkspaceVariables ¶ added in v0.1.9
func (*Service) UpdateVariableSet ¶ added in v0.4.8
func (s *Service) UpdateVariableSet(ctx context.Context, setID resource.TfeID, opts UpdateVariableSetOptions) (*VariableSet, error)
func (*Service) UpdateVariableSetVariable ¶ added in v0.4.8
func (s *Service) UpdateVariableSetVariable(ctx context.Context, variableID resource.TfeID, opts UpdateVariableOptions) (*VariableSet, error)
func (*Service) UpdateWorkspaceVariable ¶ added in v0.1.9
func (s *Service) UpdateWorkspaceVariable(ctx context.Context, variableID resource.TfeID, opts UpdateVariableOptions) (*WorkspaceVariable, 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"`
}
TFEVariable is a workspace 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"`
// Relations
Organization *organization.TFEOrganization `jsonapi:"relationship" json:"organization"`
Workspaces []*workspace.TFEWorkspace `jsonapi:"relationship" json:"workspaces,omitempty"`
Variables []*TFEVariableSetVariable `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"`
}
TFEVariableSetUpdateOptions represents the options for updating a variable set.
type TFEVariableSetVariable ¶ added in v0.3.17
type TFEVariableSetVariable struct {
*TFEVariable
// Relations
VariableSet *TFEVariableSet `jsonapi:"relationship" json:"varset"`
}
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 TFEWorkspaceVariable ¶ added in v0.3.17
type TFEWorkspaceVariable struct {
*TFEVariable
// Relations
Workspace *workspace.TFEWorkspace `jsonapi:"relationship" json:"configurable"`
}
TFEWorkspaceVariable is a workspace variable.
type UpdateVariableOptions ¶
type UpdateVariableSetOptions ¶ added in v0.1.9
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"`
// 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.
type VariableCategory ¶
type VariableCategory string
VariableCategory is the category of variable
const ( CategoryTerraform VariableCategory = "terraform" CategoryEnv VariableCategory = "env" )
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) GetVariableByID ¶ added in v0.4.8
func (s *VariableSet) GetVariableByID(variableID resource.TfeID) *Variable
func (*VariableSet) LogValue ¶ added in v0.1.9
func (s *VariableSet) LogValue() slog.Value