Documentation
¶
Index ¶
- Constants
- func AddOrUpdateVariable(cfg UpdateConfig) (string, error)
- func AddRemoteStateConsumers(workspaceID string, consumerIDs []string) error
- func ApplyVariableSet(varsetID string, workspaceIDs []string) error
- func ApplyVariableSetsToWorkspace(sets VariableSetList, workspaceID string) error
- func AssignTeamAccess(workspaceID string, allTeamData AllTeamWorkspaceData)
- func CloneWorkspace(cfg CloneConfig) ([]string, error)
- func ConvertHCLVariable(tfVar *Var)
- func CreateAllVariables(organization, workspaceName string, tfVars []Var)
- func CreateRun(config RunConfig) error
- func CreateRunTrigger(config RunTriggerConfig) error
- func CreateVariable(organization, workspaceName string, tfVar Var)
- func CreateWorkspace(oc OpsConfig, vcsTokenID string) (string, error)
- func DeleteVariable(variableID string)
- func EnableDebug()
- func EnableReadOnlyMode()
- func FindWorkspaces(organization, workspaceFilter string) map[string]string
- func GetCreateVariablePayload(organization, workspaceName string, tfVar Var) string
- func GetCreateWorkspacePayload(oc OpsConfig, vcsTokenID string) string
- func GetToken() string
- func GetUpdateVariablePayload(organization, workspaceName, variableID string, tfVar Var) string
- func GetWorkspaceAttributes(organization string, attributes []string) ([][]string, error)
- func OrganizationExists(organization string) (bool, error)
- func RunTFInit(oc OpsConfig, tfTokenDestination string) error
- func SearchVarsInAllWorkspaces(wsData []Workspace, organization, keyContains, valueContains string) (map[string][]Var, error)
- func SetToken(t string)
- func UpdateVariable(organization, workspaceName, variableID string, tfVar Var)
- func UpdateWorkspace(params WorkspaceUpdateParams) error
- type AllTeamWorkspaceData
- type CloneConfig
- type Config
- type FindRunTriggerConfig
- type ListRunTriggerConfig
- type OAuthTokens
- type OpsConfig
- type RunConfig
- type RunTrigger
- type RunTriggerConfig
- type TeamWorkspaceData
- type TfcUrl
- type UpdateConfig
- type Var
- type VariableSet
- type VariableSetList
- type VarsResponse
- type Workspace
- type WorkspaceJSON
- type WorkspaceList
- type WorkspaceUpdateParams
Constants ¶
const ( WsAttrID = "id" WsAttrAutoApply = "auto-apply" WsAttrCreatedAt = "created-at" WsAttrEnvironment = "environment" WsAttrName = "name" WsAttrStructuredRunOutput = "structured-run-output-enabled" WsAttrTerraformVersion = "terraform-version" WsAttrVcsDisplayIdentifier = "vcs-repo.display-identifier" WsAttrVcsTokenID = "vcs-repo.oauth-token-id" WsAttrWorkingDirectory = "working-directory" )
Variables ¶
This section is empty.
Functions ¶
func AddOrUpdateVariable ¶
func AddOrUpdateVariable(cfg UpdateConfig) (string, error)
AddOrUpdateVariable adds or updates an existing Terraform Cloud workspace variable If the copyVariables param is set to true, then all the non-sensitive variable values will be added to the new workspace. Otherwise, they will be set to "REPLACE_THIS_VALUE"
func AddRemoteStateConsumers ¶
func ApplyVariableSet ¶
TODO: make a config struct for this call?
func ApplyVariableSetsToWorkspace ¶
func ApplyVariableSetsToWorkspace(sets VariableSetList, workspaceID string) error
func AssignTeamAccess ¶
func AssignTeamAccess(workspaceID string, allTeamData AllTeamWorkspaceData)
AssignTeamAccess assigns the requested team access to a workspace on Terraform Cloud
func CloneWorkspace ¶
func CloneWorkspace(cfg CloneConfig) ([]string, error)
CloneWorkspace gets the data, variables and team access data for an existing Terraform Cloud workspace and then creates a clone of it with the same data.
If the copyVariables param is set to true, then all the non-sensitive variable values will be added to the new workspace. Otherwise, they will be set to "REPLACE_THIS_VALUE"
func ConvertHCLVariable ¶
func ConvertHCLVariable(tfVar *Var)
ConvertHCLVariable changes a Var struct in place by escaping the double quotes and line endings in the Value attribute
func CreateAllVariables ¶
CreateAllVariables makes several Terraform vars API POSTs to create variables for a given organization and workspace
func CreateRun ¶
CreateRun creates a Run, which starts a Plan, which can later be Applied. https://developer.hashicorp.com/terraform/cloud-docs/api-docs/run
func CreateRunTrigger ¶
func CreateRunTrigger(config RunTriggerConfig) error
func CreateVariable ¶
CreateVariable makes a Terraform vars API POST to create a variable for a given organization and workspace
func CreateWorkspace ¶
CreateWorkspace makes a Terraform workspaces API call to create a workspace for a given organization, including setting up its VCS repo integration
func DeleteVariable ¶
func DeleteVariable(variableID string)
DeleteVariable deletes a variable from a workspace
func EnableDebug ¶
func EnableDebug()
func EnableReadOnlyMode ¶
func EnableReadOnlyMode()
func FindWorkspaces ¶
FindWorkspaces uses the `search[name]` parameter to retrieve a list of workspaces in Terraform Cloud that match the workspaceFilter by the workspace name. The list is returned as a map with the ID in the key and the name in the value.
func GetCreateVariablePayload ¶
GetCreateVariablePayload returns the json needed to make a Post to the Terraform vars api
func GetCreateWorkspacePayload ¶
GetCreateWorkspacePayload returns the JSON needed to make a POST to the Terraform workspaces API
func GetUpdateVariablePayload ¶
GetUpdateVariablePayload returns the json needed to make a Post to the Terraform vars api
func GetWorkspaceAttributes ¶
GetWorkspaceAttributes returns a list of all workspaces in `organization` and the values of the attributes requested in the `attributes` list. The value of unrecognized attribute names will be returned as `null`.
func OrganizationExists ¶
OrganizationExists returns whether an organization with the given name exists
func RunTFInit ¶
RunTFInit ...
- removes old terraform.tfstate files
- runs terraform init with old versions
- runs terraform init with new version
NOTE: This procedure can be used to copy/migrate a workspace's state to a new one. (see the -backend-config mention below and the backend.tf file in this repo)
func SearchVarsInAllWorkspaces ¶
func SearchVarsInAllWorkspaces(wsData []Workspace, organization, keyContains, valueContains string) (map[string][]Var, error)
SearchVarsInAllWorkspaces returns all the variables that match the search terms 'keyContains' and 'valueContains' in all workspaces given. The return value is a map of variable lists with the workspace name as the key.
func UpdateVariable ¶
UpdateVariable makes a Terraform vars API call to update a variable for a given organization and workspace
func UpdateWorkspace ¶
func UpdateWorkspace(params WorkspaceUpdateParams) error
UpdateWorkspace updates one attribute of one or more Terraform Cloud workspaces.
Types ¶
type AllTeamWorkspaceData ¶
type AllTeamWorkspaceData struct {
Data []TeamWorkspaceData `json:"data"`
}
AllTeamWorkspaceData is what is returned by the api when requesting the team access data for a workspace
func GetTeamAccessFrom ¶
func GetTeamAccessFrom(workspaceID string) (AllTeamWorkspaceData, error)
GetTeamAccessFrom returns the team access data from an existing workspace
type CloneConfig ¶
type FindRunTriggerConfig ¶
type ListRunTriggerConfig ¶
type OAuthTokens ¶
type OAuthTokens struct {
Data []struct {
ID string `json:"id"`
Type string `json:"type"`
Attributes struct {
CreatedAt time.Time `json:"created-at"`
ServiceProviderUser string `json:"service-provider-user"`
HasSSHKey bool `json:"has-ssh-key"`
} `json:"attributes"`
Relationships struct {
OauthClient struct {
Data struct {
ID string `json:"id"`
Type string `json:"type"`
} `json:"data"`
Links struct {
Related string `json:"related"`
} `json:"links"`
} `json:"oauth-client"`
} `json:"relationships"`
Links struct {
Self string `json:"self"`
} `json:"links"`
} `json:"data"`
}
type OpsConfig ¶
type OpsConfig struct {
SourceOrg string
SourceName string
NewOrg string
NewName string
TerraformVersion string
RepoID string
Branch string
Directory string
}
OpsConfig represents one row of the plan.csv file's contents
type RunTrigger ¶
type RunTrigger struct {
CreatedAt time.Time
SourceName string
SourceID string
WorkspaceName string
WorkspaceID string
}
func FindRunTrigger ¶
func FindRunTrigger(config FindRunTriggerConfig) (*RunTrigger, error)
FindRunTrigger searches all the run triggers inbound to the given WorkspaceID. If a run trigger is configured for the given SourceWorkspaceID, that trigger is returned. Otherwise, nil is returned.
func ListRunTriggers ¶
func ListRunTriggers(config ListRunTriggerConfig) ([]RunTrigger, error)
ListRunTriggers returns a list of run triggers configured for the given workspace https://developer.hashicorp.com/terraform/cloud-docs/api-docs/run-triggers#list-run-triggers
type RunTriggerConfig ¶
type TeamWorkspaceData ¶
type TeamWorkspaceData struct {
ID string `json:"id"`
Type string `json:"type"`
Attributes struct {
Access string `json:"access"`
} `json:"attributes"`
Relationships struct {
Team struct {
Data struct {
ID string `json:"id"`
Type string `json:"type"`
} `json:"data"`
Links struct {
Related string `json:"related"`
} `json:"links"`
} `json:"team"`
Workspace struct {
Data struct {
ID string `json:"id"`
Type string `json:"type"`
} `json:"data"`
Links struct {
Related string `json:"related"`
} `json:"links"`
} `json:"workspace"`
} `json:"relationships"`
Links struct {
Self string `json:"self"`
} `json:"links"`
}
TeamWorkspaceData is what is returned by the api for one team access object for a workspace
type UpdateConfig ¶
type UpdateConfig struct {
Organization string
Workspace string
SearchString string // must be an exact case-insensitive match (i.e. not a partial match)
NewValue string
AddKeyIfNotFound bool // If true, then SearchOnVariableValue will be treated as false
SearchOnVariableValue bool // If false, then will filter on variable key
SensitiveVariable bool // Whether to mark the variable as sensitive
}
type Var ¶
type Var struct {
ID string `json:"-"`
Key string `json:"key"`
Value string `json:"value"`
Sensitive bool `json:"sensitive"`
Category string `json:"category"`
Hcl bool `json:"hcl"`
}
Var is what is returned by the api for one variable
func GetVarsFromWorkspace ¶
GetVarsFromWorkspace returns a list of Terraform variables for a given workspace
func GetWorkspaceVar ¶
GetWorkspaceVar retrieves the variables from a Workspace and returns the Var that matches the given key
func SearchVariables ¶
SearchVariables returns a list of variables in the given workspace that match the search terms 'keyContains' and 'valueContains'
type VariableSet ¶
type VariableSet struct {
ID string `json:"id"`
Type string `json:"type"`
Attributes struct {
Name string `json:"name"`
Description string `json:"description"`
Global bool `json:"global"`
UpdatedAt time.Time `json:"updated-at"`
VarCount int `json:"var-count"`
WorkspaceCount int `json:"workspace-count"`
} `json:"attributes"`
Relationships struct {
Organization struct {
Data struct {
ID string `json:"id"`
Type string `json:"type"`
} `json:"data"`
} `json:"organization"`
Vars struct {
Data []struct {
ID string `json:"id"`
Type string `json:"type"`
} `json:"data"`
} `json:"vars"`
Workspaces struct {
Data []struct {
ID string `json:"id"`
Type string `json:"type"`
} `json:"data"`
} `json:"workspaces"`
} `json:"relationships"`
}
func GetVariableSet ¶
func GetVariableSet(org, vsName string) (*VariableSet, error)
type VariableSetList ¶
type VariableSetList struct {
Data []VariableSet `json:"data"`
Links struct {
Self string `json:"self"`
First string `json:"first"`
Prev any `json:"prev"`
Next any `json:"next"`
Last string `json:"last"`
} `json:"links"`
}
func GetAllVariableSets ¶
func GetAllVariableSets(organizationName string) (VariableSetList, error)
func ListWorkspaceVariableSets ¶
func ListWorkspaceVariableSets(workspaceID string) (VariableSetList, error)
type VarsResponse ¶
type VarsResponse struct {
Data []struct {
ID string `json:"id"`
Type string `json:"type"`
Variable Var `json:"attributes"`
Relationships struct {
Configurable struct {
Data struct {
ID string `json:"id"`
Type string `json:"type"`
} `json:"data"`
Links struct {
Related string `json:"related"`
} `json:"links"`
} `json:"configurable"`
} `json:"relationships"`
Links struct {
Self string `json:"self"`
} `json:"links"`
} `json:"data"`
}
VarsResponse is what is returned by the api when requesting the variables of a workspace
type Workspace ¶
type Workspace struct {
ID string `json:"id"`
Type string `json:"type"`
Attributes struct {
Name string `json:"name"`
Environment string `json:"environment"`
AutoApply bool `json:"auto-apply"`
Locked bool `json:"locked"`
CreatedAt time.Time `json:"created-at"`
WorkingDirectory string `json:"working-directory"`
VCSRepo struct {
Branch string `json:"branch"`
Identifier string `json:"identifier"`
DisplayIdentifier string `json:"display-identifier"`
TokenID string `json:"oauth-token-id"`
} `json:"vcs-repo"`
StructuredRunOutputEnabled bool `json:"structured-run-output-enabled"`
TerraformVersion string `json:"terraform-version"`
Permissions struct {
CanUpdate bool `json:"can-update"`
CanDestroy bool `json:"can-destroy"`
CanQueueDestroy bool `json:"can-queue-destroy"`
CanQueueRun bool `json:"can-queue-run"`
CanUpdateVariable bool `json:"can-update-variable"`
CanLock bool `json:"can-lock"`
CanReadSettings bool `json:"can-read-settings"`
} `json:"permissions"`
Actions struct {
IsDestroyable bool `json:"is-destroyable"`
} `json:"actions"`
} `json:"attributes"`
Relationships struct {
Organization struct {
Data struct {
ID string `json:"id"`
Type string `json:"type"`
} `json:"data"`
} `json:"organization"`
LatestRun struct {
Data any `json:"data"`
} `json:"latest-run"`
CurrentRun struct {
Data any `json:"data"`
} `json:"current-run"`
} `json:"relationships"`
Links struct {
Self string `json:"self"`
} `json:"links"`
}
Workspace is what is returned by the api for each workspace
func CreateWorkspace2 ¶
CreateWorkspace2 makes a Terraform workspaces API call to create a workspace for a given organization, including setting up its VCS repo integration. Returns the properties of the new workspace.
func GetAllWorkspaces ¶
GetAllWorkspaces retrieves all workspaces from Terraform Cloud and returns a list of Workspace objects
func GetWorkspaceByName ¶
type WorkspaceJSON ¶
type WorkspaceJSON struct {
Data Workspace `json:"data"`
}
WorkspaceJSON is what is returned by the api when requesting the data for a workspace
func GetWorkspaceData ¶
func GetWorkspaceData(organization, workspaceName string) (WorkspaceJSON, error)
type WorkspaceList ¶
type WorkspaceList struct {
Data []Workspace `json:"data"`
}
WorkspaceList is returned by the API when requesting a list of workspaces