Documentation
¶
Overview ¶
Package tferun provides a single simplified methods to schedule runs and retrieve outputs from a remote workspace on Terraform Enterprise or Cloud.
These methods are intended to be run as part of a CLI and will print information to stdout.
Example ¶
ctx := context.TODO()
token := os.Getenv("TFE_TOKEN")
cfg := ClientConfig{
Token: token,
Organization: "kvrhdn",
Workspace: "tfe-run",
}
client, err := NewClient(ctx, cfg)
if err != nil {
fmt.Printf("could not create client: %v\n", err)
os.Exit(1)
}
options := RunOptions{
Message: String("Run created using tfe-run"),
}
output, err := client.Run(ctx, options)
if err != nil {
fmt.Printf("run failed: %v\n", err)
os.Exit(1)
}
fmt.Printf("Run created: %v", output.RunURL)
Example (TfVars) ¶
ctx := context.TODO()
token := os.Getenv("TFE_TOKEN")
cfg := ClientConfig{
Token: token,
Organization: "kvrhdn",
Workspace: "tfe-run",
}
client, err := NewClient(ctx, cfg)
if err != nil {
fmt.Printf("could not create client: %v\n", err)
os.Exit(1)
}
options := RunOptions{
TfVars: String("my_var = \"foo\""),
}
output, err := client.Run(ctx, options)
if err != nil {
fmt.Printf("run failed: %v\n", err)
os.Exit(1)
}
fmt.Printf("Run created: %v", output.RunURL)
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTimeout is returned when an operation timed out. ErrTimeout = errors.New("timed out while polling") )
Functions ¶
Types ¶
type Client ¶ added in v0.2.0
type Client struct {
// contains filtered or unexported fields
}
Client is used to interact with the Run API of a single workspace on Terraform Cloud.
func NewClient ¶ added in v0.2.0
func NewClient(ctx context.Context, cfg ClientConfig) (*Client, error)
NewClient creates a Client from ClientConfig.
func (*Client) GetTerraformOutputs ¶ added in v0.2.0
GetTerraformOutputs retrieves the outputs from the current Terraform state.
Example ¶
ctx := context.TODO()
token := os.Getenv("TFE_TOKEN")
cfg := ClientConfig{
Token: token,
Organization: "kvrhdn",
Workspace: "tfe-run",
}
client, err := NewClient(ctx, cfg)
if err != nil {
fmt.Printf("could not create client: %v\n", err)
os.Exit(1)
}
outputs, err := client.GetTerraformOutputs(ctx)
if err != nil {
fmt.Printf("could not create client: %v\n", err)
os.Exit(1)
}
fmt.Printf("Current outputs: %v", outputs)
func (*Client) Run ¶ added in v0.2.0
Run creates a new run on Terraform Cloud.
If RunOptions.WaitForCompletion is set this method will block until the run is finished, except if the run is non-speculative and the workspace has disabled auto-apply (to avoid blocking indefinitely). If the run does not complete within one hour, ErrTimeout is returned. This will not cancel the remote operation.
type ClientConfig ¶ added in v0.2.0
type ClientConfig struct {
// Token used to communicate with the Terraform Cloud API. Must be a user
// or team API token.
Token string
// The organization on Terraform Cloud.
Organization string
// The workspace on Terraform Cloud.
Workspace string
}
ClientConfig groups properties to configure a Client.
type RunOptions ¶
type RunOptions struct {
// Message to use as name of the run. This field is optional.
Message *string
// The directory that is uploaded to Terraform Cloud, respects
// .terraformignore. Defaults to the current directory.
Directory *string
// The type of run to schedule.
Type RunType
// A list of resource addresses that are passed to the -target flag. For
// more details, check https://www.terraform.io/docs/commands/plan.html#resource-targeting
TargetAddrs []string
// Whether we should wait for the non-speculative run to be applied. This
// will block until the run is finished.
WaitForCompletion bool
// Contents of a auto.tfvars file that will be uploaded to Terraform Cloud.
// This can be used to set temporary Terraform variables. These variables
// will not be preserved across runs.
TfVars *string
}
RunOptions groups all options available when creating a new run.
type RunOutput ¶
type RunOutput struct {
// URL to the run on Terraform Cloud.
RunURL string
// Whether this run has changes. After a speculative plan this would
// indicate whether an apply would cause changes, after a non-speculative
// plan this indicates whether the run has caused any changes.
// This is not populated for non-speculative runs on workspaces that do not
// have auto-apply configured or when WaitForCompletion is not set.
HasChanges *bool
}
RunOutput holds the data that is generated by a run.