api

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetupRouter added in v0.1.2

func SetupRouter(api Api) (*gin.Engine, error)

SetupRouter initializes an API Router for production

func SetupTerraform added in v0.2.0

func SetupTerraform(ctx context.Context, terraformVersion, workingDir string) (*tfexec.Terraform, error)

SetupTerraform installs Terraform and initializes Terraform struct object

Types

type Api added in v0.2.0

type Api struct {
	Configuration Configuration
	Terraform     *tfexec.Terraform
	Router        *gin.Engine
}

Api holds the main API object

func SetupApi added in v0.2.0

func SetupApi() (Api, error)

SetupApi sets up the API by setting its Configuration, Terraform installation and Router

func (Api) ApplyHandler added in v0.2.0

func (api Api) ApplyHandler(ctx *gin.Context)

ApplyHandler calls Terraform apply command @Summary Create or update infrastructure @Description Executes the actions proposed in a Terraform plan @Param refresh_only query bool false "If true updates the state to match remote systems" @Param replace query string false "An address of the resource to be marked as tainted (degraded or damaged object)" @Param vars query []string false "Values for input variables, each var supplied as a single string (e,g., 'foo=bar')" collectionFormat(multi) @Param var_files query []string false "Path tfvars file containing values for potentially many input variables" collectionFormat(multi) @Param parallelism query int false "Number of concurrent operation as Terraform walks the graph (default is 10)" minimum(1) @Produce json @Success 200 {object} JSONResult @Failure 400 {object} QueryError @Failure 500 {object} TerraformError @Failure 500 {object} NeedsInitError @Router /apply [post]

func (Api) DestroyHandler added in v0.2.0

func (api Api) DestroyHandler(ctx *gin.Context)

DestroyHandler calls Terraform destroy command @Summary Destroys previously-created infrastructure @Description Destroys all remote objects managed by a particular api.Terraform Configuration @Param vars query []string false "Values for input variables, each var supplied as a single string (e,g., 'foo=bar'") collectionFormat(multi) @Param var_files query []string false "Path tfvars file containing values for potentially many input variables" collectionFormat(multi) @Param parallelism query int false "Number of concurrent operation as Terraform walks the graph (default is 10)" minimum(1) @Produce json @Success 200 {object} JSONResult @Failure 500 {object} TerraformError @Failure 500 {object} NeedsInitError @Router /destroy [post]

func (Api) FmtHandler added in v0.2.0

func (api Api) FmtHandler(ctx *gin.Context)

FmtHandler calls Terraform fmt command @Summary Reformats your Configuration in the standard style @Description Rewrites Terraform Configuration files to a canonical format and style @Produce json @Success 200 {object} JSONResult @Failure 500 {object} TerraformError @Failure 500 {object} JsonMarshalError @Router /fmt [post]

func (Api) ForceUnlockHandler added in v0.2.0

func (api Api) ForceUnlockHandler(ctx *gin.Context)

ForceUnlockHandler calls Terraform force-unlock command @Summary Releases a stuck lock on the current workspace @Description Manually unlocks the state for the defined Configuration @Param lock_id query string true "A unique lock id" @Produce json @Success 200 {object} JSONResult @Failure 400 {object} QueryError @Failure 500 {object} TerraformError @Failure 500 {object} NeedsInitError @Router /force-unlock [post]

func (Api) GetHandler added in v0.2.0

func (api Api) GetHandler(ctx *gin.Context)

GetHandler calls Terraform get command @Summary Installs or upgrades remote Terraform modules @Description Destroys all remote objects managed by a particular Terraform Configuration @Produce json @Success 200 {object} JSONResult @Failure 500 {object} TerraformError @Router /get [post]

func (Api) GraphHandler added in v0.2.0

func (api Api) GraphHandler(ctx *gin.Context)

GraphHandler calls Terraform graph command @Summary Generates a Graphviz graph of the steps in an operation @Description Generates a visual representation of either a Configuration or execution plan @Produce json @Success 200 {object} JSONResult @Failure 500 {object} TerraformError @Failure 500 {object} NeedsInitError @Router /graph [post]

func (Api) ImportHandler added in v0.2.0

func (api Api) ImportHandler(ctx *gin.Context)

ImportHandler calls Terraform import command @Summary Associates existing infrastructure with a Terraform resource @Description Imports existing resources into Terraform @Param address query string true "A valid resource address at which resource will be imported" @Param id query string true "An existing resource id that will be found by import" @Produce json @Success 200 {object} JSONResult @Failure 400 {object} QueryError @Failure 500 {object} TerraformError @Failure 500 {object} NeedsInitError @Router /import [post]

func (Api) InitHandler added in v0.2.0

func (api Api) InitHandler(ctx *gin.Context)

InitHandler calls Terraform init command @Summary Prepares your working directory for other commands @Description Initializes a working directory containing Terraform Configuration files @Produce json @Success 200 {object} JSONResult @Failure 500 {object} TerraformError @Router /init [post]

func (Api) OutputHandler added in v0.2.0

func (api Api) OutputHandler(ctx *gin.Context)

OutputHandler calls Terraform output command @Summary Shows output values from your root module @Description Extracts the value of an output variable from the state file @Produce json @Success 200 {object} JSONResult @Failure 500 {object} TerraformError @Failure 500 {object} NeedsInitError @Failure 500 {object} JsonMarshalError @Router /output [get]

func (Api) PlanHandler added in v0.2.0

func (api Api) PlanHandler(ctx *gin.Context)

PlanHandler calls Terraform plan command @Summary Shows changes required by the current Configuration @Description Creates an execution plan, which lets you preview the changes for your infrastructure @Param vars query []string false "Values for input variables, each var supplied as a single string (e,g., 'foo=bar'") collectionFormat(multi) @Param var_files query []string false "Path tfvars file containing values for potentially many input variables" collectionFormat(multi) @Produce json @Success 200 {object} JSONResult @Failure 400 {object} QueryError @Failure 500 {object} TerraformError @Failure 500 {object} NeedsInitError @Failure 500 {object} JsonMarshalError @Router /plan [post]

func (Api) ProvidersLockHandler added in v0.2.0

func (api Api) ProvidersLockHandler(ctx *gin.Context)

ProvidersLockHandler calls Terraform providers lock command @Summary Updates the dependency lock file to include a selected version for each provider @Description Consults upstream registries to write provider dependency information into the dependency lock file @Produce json @Success 200 {object} JSONResult @Failure 500 {object} TerraformError @Failure 500 {object} NeedsInitError @Router /providers/lock [post]

func (Api) ProvidersSchemaHandler added in v0.2.0

func (api Api) ProvidersSchemaHandler(ctx *gin.Context)

ProvidersSchemaHandler calls Terraform providers schema command @Summary Shows the providers required for this Configuration @Description Prints detailed schemas for the providers used in the current Configuration @Produce json @Success 200 {object} JSONResult @Failure 500 {object} TerraformError @Failure 500 {object} NeedsInitError @Failure 500 {object} JsonMarshalError @Router /providers/schema [get]

func (Api) ShowHandler added in v0.2.0

func (api Api) ShowHandler(ctx *gin.Context)

ShowHandler calls Terraform show command @Summary Shows the current state or a saved plan @Description Provides human-readable output from a state or plan file @Produce json @Success 200 {object} JSONResult @Failure 500 {object} NeedsInitError @Failure 500 {object} TerraformError @Failure 500 {object} JsonMarshalError @Router /show [get]

func (Api) StateMvHandler added in v0.2.0

func (api Api) StateMvHandler(ctx *gin.Context)

StateMvHandler calls Terraform state mv command @Summary Moves the remote objects currently associated with the source to be tracked instead by the destination @Description Retains an existing remote object but track it as a different resource instance address @Param source query string true "A valid resource address for source" @Param destination query string true "A valid resource address for destination" @Produce json @Success 200 {object} JSONResult @Failure 400 {object} QueryError @Failure 500 {object} TerraformError @Failure 500 {object} NeedsInitError @Router /state/mv [post]

func (Api) StateRmHandler added in v0.2.0

func (api Api) StateRmHandler(ctx *gin.Context)

StateRmHandler calls Terraform state rm command @Summary Forgets the resource, while it continues to exist in the remote system @Description Removes a binding to an existing remote object without first destroying it @Param address query string true "A valid resource address to be removed from record" @Produce json @Success 200 {object} JSONResult @Failure 400 {object} QueryError @Failure 500 {object} TerraformError @Failure 500 {object} NeedsInitError @Router /state/rm [delete]

func (Api) UntaintHandler added in v0.2.0

func (api Api) UntaintHandler(ctx *gin.Context)

UntaintHandler calls Terraform untaint command @Summary Removes the tainted state from a resource instance @Description Removes the taint marker from the object (will not modify remote objects, will modify the state) @Param address query string true "A resource address for particular resource instance which is currently tainted" @Produce json @Success 200 {object} JSONResult @Failure 400 {object} QueryError @Failure 500 {object} TerraformError @Failure 500 {object} NeedsInitError @Router /untaint [delete]

func (Api) ValidateHandler added in v0.2.0

func (api Api) ValidateHandler(ctx *gin.Context)

ValidateHandler calls Terraform validate command @Summary Checks whether the Configuration is valid @Description Validates the Configuration files in a directory @Produce json @Success 200 {object} JSONResult @Failure 500 {object} TerraformError @Failure 500 {object} JsonMarshalError @Router /validate [post]

func (Api) VersionHandler added in v0.2.0

func (api Api) VersionHandler(ctx *gin.Context)

VersionHandler calls Terraform version command @Summary Shows the current Terraform version @Description Displays the current version of Terraform and all installed plugins @Produce json @Success 200 {object} JSONResult @Failure 500 {object} TerraformError @Failure 500 {object} JsonMarshalError @Router /version [get]

func (Api) WorkspaceDeleteHandler added in v0.2.0

func (api Api) WorkspaceDeleteHandler(ctx *gin.Context)

WorkspaceDeleteHandler calls Terraform workspace delete command @Summary Deletes a workspace @Description Deletes an existing Terraform workspace @Param name query string true "A name of existing Terraform workspace to be deleted" @Produce json @Success 200 {object} JSONResult @Failure 400 {object} QueryError @Failure 500 {object} TerraformError @Failure 500 {object} NeedsInitError @Router /workspace/delete [delete]

func (Api) WorkspaceListHandler added in v0.2.0

func (api Api) WorkspaceListHandler(ctx *gin.Context)

WorkspaceListHandler calls Terraform workspace list command @Summary Lists Terraform workspaces @Description Lists all existing Terraform workspaces @Produce json @Success 200 {object} JSONResult @Failure 400 {object} QueryError @Failure 500 {object} TerraformError @Failure 500 {object} NeedsInitError @Failure 500 {object} JsonMarshalError @Router /workspace/list [get]

func (Api) WorkspaceNewHandler added in v0.2.0

func (api Api) WorkspaceNewHandler(ctx *gin.Context)

WorkspaceNewHandler calls Terraform workspace new command @Summary Creates a new workspace @Description Creates a new Terraform workspace with the given name @Param name query string true "A name of (unexisting) Terraform workspace to be created" @Produce json @Success 200 {object} JSONResult @Failure 400 {object} QueryError @Failure 500 {object} TerraformError @Failure 500 {object} NeedsInitError @Router /workspace/new [post]

func (Api) WorkspaceSelectHandler added in v0.2.0

func (api Api) WorkspaceSelectHandler(ctx *gin.Context)

WorkspaceSelectHandler calls Terraform workspace select command @Summary Select a workspace @Description Chooses a different Terraform workspace to use for further operations @Param name query string true "A name of existing Terraform workspace" @Produce json @Success 200 {object} JSONResult @Failure 400 {object} QueryError @Failure 500 {object} TerraformError @Failure 500 {object} NeedsInitError @Router /workspace/select [post]

func (Api) WorkspaceShowHandler added in v0.2.0

func (api Api) WorkspaceShowHandler(ctx *gin.Context)

WorkspaceShowHandler calls Terraform workspace show command @Summary Shows the name of the current workspace @Description Outputs the current Terraform workspace @Produce json @Success 200 {object} JSONResult @Failure 500 {object} TerraformError @Failure 500 {object} JsonMarshalError @Router /workspace/show [get]

type ApplyQueryParams

type ApplyQueryParams struct {
	RefreshOnly bool     `form:"refresh_only"`
	Replace     string   `form:"replace"`
	Vars        []string `form:"vars"`
	VarFiles    []string `form:"var_files"`
	Parallelism int      `form:"parallelism"`
}

ApplyQueryParams represents query params for /apply handle

type Configuration added in v0.2.0

type Configuration struct {
	Version          string
	TerraformVersion string
	WorkingDirectory string
	DebugMode        bool
	Port             string
	SwaggerUrl       string
	TrustedProxy     string
}

Configuration holds API configuration settings

func SetupApiConfiguration added in v0.2.0

func SetupApiConfiguration() Configuration

SetupApiConfiguration configures and returns API settings (sets vars by reading environment variables)

type DestroyQueryParams added in v0.1.4

type DestroyQueryParams struct {
	Vars        []string `form:"vars"`
	VarFiles    []string `form:"var_files"`
	Parallelism int      `form:"parallelism"`
}

DestroyQueryParams represents query params for /destroy handle

type ForceUnlockQueryParams

type ForceUnlockQueryParams struct {
	LockId string `form:"lock_id"`
}

ForceUnlockQueryParams represents query params for /force-unlock handle

type ImportQueryParams

type ImportQueryParams struct {
	Address string `form:"address"`
	Id      string `form:"id"`
}

ImportQueryParams represents query params for /import handle

type JSONResult

type JSONResult struct {
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data"`
}

JSONResult represents API JSON response

type JsonMarshalError added in v0.2.0

type JsonMarshalError struct {
	// contains filtered or unexported fields
}

JsonMarshalError is returned when building JSON object fails

func (JsonMarshalError) Error added in v0.2.0

func (e JsonMarshalError) Error() string

Error prints out JsonMarshalError as string

type NeedsInitError added in v0.2.0

type NeedsInitError struct {
	// contains filtered or unexported fields
}

NeedsInitError is returned when the folder containing the Terraform files is not initialized yet

func (NeedsInitError) Error added in v0.2.0

func (e NeedsInitError) Error() string

Error prints out NeedsInitError as string

type PlanQueryParams added in v0.1.4

type PlanQueryParams struct {
	Vars     []string `form:"vars"`
	VarFiles []string `form:"var_files"`
}

PlanQueryParams represents query params for /plan handle

type QueryError added in v0.2.0

type QueryError struct {
	// contains filtered or unexported fields
}

QueryError is returned when the provided queries don't match the target struct

func (QueryError) Error added in v0.2.0

func (e QueryError) Error() string

Error prints out QueryError as string

type StateMvQueryParams

type StateMvQueryParams struct {
	Source      string `form:"source"`
	Destination string `form:"destination"`
}

StateMvQueryParams represents query params for /state/mv handle

type StateRmQueryParams

type StateRmQueryParams struct {
	Address string `form:"address"`
}

StateRmQueryParams represents query params for /state/rm handle

type TerraformError added in v0.2.0

type TerraformError struct {
	// contains filtered or unexported fields
}

TerraformError is returned whenever something regarding Terraform fails if there is a more specific error regarding Terraform, the other is returned instead

func (TerraformError) Error added in v0.2.0

func (e TerraformError) Error() string

Error prints out TerraformError as string

type TerraformFormatOutput added in v0.1.2

type TerraformFormatOutput struct {
	Formatted    bool     `json:"formatted,omitempty"`
	ChangedFiles []string `json:"changed_files,omitempty"`
}

TerraformFormatOutput represents output for /fmt handle

type TerraformGraphOutput added in v0.1.2

type TerraformGraphOutput struct {
	Output string `json:"formatted,omitempty"`
}

TerraformGraphOutput represents output for /graph handle

type TerraformOutputOutput added in v0.1.2

type TerraformOutputOutput struct {
	Output map[string]tfexec.OutputMeta `json:"output,omitempty"`
}

TerraformOutputOutput represents output for /output handle

type TerraformPlanOutput added in v0.1.2

type TerraformPlanOutput struct {
	Changed bool `json:"formatted,omitempty"`
}

TerraformPlanOutput represents output for /plan handle

type TerraformProvidersSchemaOutput added in v0.1.2

type TerraformProvidersSchemaOutput struct {
	tfjson.ProviderSchemas
}

TerraformProvidersSchemaOutput represents output for /providers/schema handle

type TerraformShowOutput added in v0.1.2

type TerraformShowOutput struct {
	tfjson.State
}

TerraformShowOutput represents output for /show handle

type TerraformValidateOutput added in v0.1.2

type TerraformValidateOutput struct {
	tfjson.ValidateOutput
}

TerraformValidateOutput represents output for /validate handle

type TerraformVersionOutput added in v0.1.2

type TerraformVersionOutput struct {
	Version   string            `json:"version,omitempty"`
	Providers map[string]string `json:"providers,omitempty"`
}

TerraformVersionOutput represents output for /version handle

type TerraformWorkspaceListOutput added in v0.1.2

type TerraformWorkspaceListOutput struct {
	Current string   `json:"current,omitempty"`
	List    []string `json:"list,omitempty"`
}

TerraformWorkspaceListOutput represents output for /workspace/list handle

type TerraformWorkspaceShowOutput added in v0.2.0

type TerraformWorkspaceShowOutput struct {
	Current string `json:"formatted,omitempty"`
}

TerraformWorkspaceShowOutput represents output for /workspace/show handle

type UntaintQueryParams

type UntaintQueryParams struct {
	Address string `form:"address"`
}

UntaintQueryParams represents query params for /untaint handle

type WorkspaceDeleteQueryParams

type WorkspaceDeleteQueryParams struct {
	Name string `form:"name"`
}

WorkspaceDeleteQueryParams represents query params for /workspace/delete handle

type WorkspaceNewQueryParams

type WorkspaceNewQueryParams struct {
	Name string `form:"name"`
}

WorkspaceNewQueryParams represents query params for /workspace/new handle

type WorkspaceSelectQueryParams

type WorkspaceSelectQueryParams struct {
	Name string `form:"name"`
}

WorkspaceSelectQueryParams represents query params for /workspace/select handle

Jump to

Keyboard shortcuts

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