Documentation ¶
Index ¶
- Constants
- func InstallTfVersion(tfVersion string) (string, error)
- type Client
- func (c *Client) ApplyPlanJSON(w io.Writer, opts ...tfexec.ApplyOption) error
- func (c *Client) DestroyJSON(w io.Writer, opts ...tfexec.DestroyOption) error
- func (c *Client) InitTerraform(opts ...tfexec.InitOption) error
- func (c *Client) Output(opts ...tfexec.OutputOption) ([]map[string]any, error)
- func (c *Client) PlanJSON(w io.Writer, opts ...tfexec.PlanOption) error
- func (c *Client) SetupWorkspace(opts ...tfexec.WorkspaceNewCmdOption) error
- func (c *Client) ShowState(opts ...tfexec.ShowOption) (*tfjson.State, error)
- func (c *Client) WorkingDir() string
- func (c *Client) WorkspaceExists(workspace string) (bool, error)
- type Config
- type PlanOptions
Constants ¶
const (
ConfigurationFileKey = "tfexec"
)
Variables ¶
This section is empty.
Functions ¶
func InstallTfVersion ¶
InstallTfVersion uses hc-install in order to install the desired Terraform version Returns the execPath of the newly installed Terraform binary and/or an error
Types ¶
type Client ¶
type Client struct { // Client used to access Terraform Terraform *tfexec.Terraform TerraformConfig *Config }
A representation of shepherd's tfexec client which wraps the upstream tfexec.Terraform struct client and its own custom Config struct
func NewClient ¶
NewClient loads the tfexec client's config, initializes a new instance of the upstream Terraform Client and/or returns an error
func (*Client) ApplyPlanJSON ¶
ApplyPlanJSON effectively runs the `terraform apply -json` command. Takes an io.Writer and any number of tfexec.ApplyOptions. The writer is used to determine where to send any output, all ApplyOptions will be respected. If a tfexec.DirOrPlanOption is NOT passed, and there is a configured PlanFilePath, then that path will be used. Returns an error if any
func (*Client) DestroyJSON ¶
DestroyJSON effectively runs the `terraform destroy -json` command Takes an io.Writer and any number of tfexec.DestroyOptions. The writer is used to determine where to send any output, all DestroyOptions will be respected. If the -var-file option is not passed, and a VarFilePath is configured, then it will use this path for the -var-file option. Returns an error if any
func (*Client) InitTerraform ¶
func (c *Client) InitTerraform(opts ...tfexec.InitOption) error
InitTerraform initializes the Terraform module (effectively the `terraform init` command) This function should be called if the Terraform module in use has not been initialized before Returns an error or nil
func (*Client) Output ¶
Output effectively runs the `terraform output -json` command It takes any number of tfexec.OutputOptions as inputs and respects them. This function will parse the machine-readable JSON into a []map[string]any that can be further manipulated. Returns a []map[string]any of the generated output, and an error if any
func (*Client) PlanJSON ¶
PlanJSON generates a JSON-formatted terraform planfile, it effectively runs the `terraform plan -json“ command. Takes an io.Writer and any number of tfexec.PlanOptions. The writer is used to determine where to send any output, all PlanOptions will be respected. If no -out option is passed, and the PlanFilePath has NOT been configured, then it will generate a timestamped PlanFilePath using the PlanOpts.OutDir, tfPlanFilePathPrefix string, and timestamp. If no -var-file option is passed, and the VarFilePath has been configured, then it will use the VarFilePath. Returns an error if any
func (*Client) SetupWorkspace ¶
func (c *Client) SetupWorkspace(opts ...tfexec.WorkspaceNewCmdOption) error
SetupWorkspace will effectively select an existing workspace or create a new one based on if the given workspace name already exists. It effectively runs one of the following scenarios:
- workspaceName input provided in Config > terraform workspace list > workspaceName in list > terraform workspace select workspaceName
- workspaceName input provided in Config > terraform workspace list > workspaceName NOT in list > terraform workspace new workspaceName
- workspaceName input NOT provided in Config > terraform workspace new "shepherd-<randomString>"
Returns an error if any
func (*Client) ShowState ¶
ShowState effectively runs the `terraform show` command which reads the default state path and outputs the current state Returns the state representation as a struct or an error if any
func (*Client) WorkingDir ¶
WorkingDir simply returns the configured terraform working directory for terraform The WorkingDir is the directory that terraform is targeting when it runs a command
func (*Client) WorkspaceExists ¶
WorkspaceExists lists the existing workspaces for the module in use and verifies that the given workspace name exists in the list (effectively runs the `terraform workspace list` command) Returns a bool signaling if the workspace exists and an error if any
type Config ¶
type Config struct { WorkspaceName string `json:"workspaceName" yaml:"workspaceName"` WorkingDir string `json:"workingDir" yaml:"workingDir"` ExecPath string `json:"execPath" yaml:"execPath"` VarFilePath string `json:"varFilePath" yaml:"varFilePath"` PlanFilePath string `json:"planFilePath" yaml:"planFilePath"` PlanOpts *PlanOptions `json:"planOpts" yaml:"planOpts"` }
A representative struct for the configuration options used by the tfexec client
func TerraformConfig ¶
func TerraformConfig() *Config
TerraformConfig loads the tfexec configuration inputs into a tfexec.Config struct and returns a pointer to it
type PlanOptions ¶
type PlanOptions struct {
OutDir string `json:"outDir" yaml:"outDir"`
}
A representation of the upstream PlanOptions that are typically used by this client