tfe

package module
v2.0.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultAddress     = "https://app.terraform.io"
	DefaultBasePath    = "/api/v2"
	ContentTypeJSONAPI = "application/vnd.api+json"
	ContentTypeJSON    = "application/json"
)

Variables

View Source
var (
	// ErrUnauthorized, ErrNotFound, ErrInternalServer, ErrForbidden, ErrBadRequest, and
	// ErrUnprocessableEntity are common API errors that can be used with errors.Is for
	// easy comparison.
	ErrUnauthorized        = &APIError{StatusCode: http.StatusUnauthorized, Message: http.StatusText(http.StatusUnauthorized)}
	ErrNotFound            = &APIError{StatusCode: http.StatusNotFound, Message: http.StatusText(http.StatusNotFound)}
	ErrInternalServer      = &APIError{StatusCode: http.StatusInternalServerError, Message: http.StatusText(http.StatusInternalServerError)}
	ErrForbidden           = &APIError{StatusCode: http.StatusForbidden, Message: http.StatusText(http.StatusForbidden)}
	ErrBadRequest          = &APIError{StatusCode: http.StatusBadRequest, Message: http.StatusText(http.StatusBadRequest)}
	ErrUnprocessableEntity = &APIError{StatusCode: http.StatusUnprocessableEntity, Message: http.StatusText(http.StatusUnprocessableEntity)}
	ErrTooManyRequests     = &APIError{StatusCode: http.StatusTooManyRequests, Message: http.StatusText(http.StatusTooManyRequests)}
)

Functions

func APIErrorFactory

func APIErrorFactory(resp *http.Response, pipelineErr error) error

APIErrorFactory is a function that takes an HTTP response and a pipeline error, and returns an APIError. The response must have a status code of 400 or above.

func NewHTTPClient

func NewHTTPClient(options []middleware.MiddlewareOption) (*nethttp.Client, error)

Types

type APIError

type APIError struct {
	StatusCode int
	Message    string
	Details    []string
}

func (*APIError) Error

func (e *APIError) Error() string

Error implements the error interface for APIError.

func (*APIError) Is

func (e *APIError) Is(target error) bool

Is allows errors.Is to work with APIError, comparing based on StatusCode.

type Client

type Client struct {
	API *api.ApiClient

	Meta Meta
	// contains filtered or unexported fields
}

Client is the Terraform Enterprise API client. It provides the basic connectivity and configuration for accessing the TFE API

func NewClient

func NewClient(cfg *Config) (*Client, error)

NewClient creates a new Terraform Enterprise API client.

func (Client) BaseURL

func (c Client) BaseURL() url.URL

BaseURL returns the base URL as configured in the client

func (*Client) GetStream

func (c *Client) GetStream(ctx context.Context, uriOrPath string, headers http.Header) (*http.Response, error)

GetStream sends a GET request using the client's configured middleware and authentication, returning the raw *http.Response without buffering the body. The caller is responsible for closing the response body. This method is useful for API endpoints that return large responses, such as log files or streaming data.

Usually, calling an endpoint using the API interface will return a deserialized struct or buffered []byte slice. However, for endpoints that return large responses, you can choose to use GetStream to get the raw *http.Response and stream the body directly without buffering it in memory.

type Config

type Config struct {
	// The address of the Terraform Enterprise API.
	Address string

	// The base path on which the API is served.
	BasePath string

	// API token used to access the Terraform Enterprise API.
	Token string

	// Headers that will be added to every request.
	Headers http.Header

	// RetryHook is invoked each time a request is retried.
	RetryHook RetryHook

	// Retry enables automatic retries for rate limited requests.
	RetryRateLimited bool

	// RetryServerErrors enables the retry logic in the client.
	RetryServerErrors bool

	// RetryMaxRetries sets the maximum number of retries for a request before giving up.
	RetryMaxRetries int
}

Config provides configuration details to the API client.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default config structure.

type IPRange

type IPRange struct {
	// List of IP ranges in CIDR notation used for connections from user site to HCP Terraform APIs
	API []string `json:"api,omitempty"`
	// List of IP ranges in CIDR notation used for notifications
	Notifications []string `json:"notifications,omitempty"`
	// List of IP ranges in CIDR notation used for outbound requests from Sentinel policies
	Sentinel []string `json:"sentinel,omitempty"`
	// List of IP ranges in CIDR notation used for connecting to VCS providers
	VCS []string `json:"vcs,omitempty"`
}

IPRange represents a list of HCP Terraform's IP ranges

type IPRanges

type IPRanges interface {
	// Retrieve HCP Terraform IP ranges. If `modifiedSince` is not nil
	// then it will only return the IP ranges changes since that date.
	// The format for `modifiedSince` can be found here:
	// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since
	Read(ctx context.Context, modifiedSince *time.Time) (*IPRangesResponse, error)
}

IP Ranges provides a list of HCP Terraform or Terraform Enterprise's IP ranges.

TFE API docs: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/ip-ranges

type IPRangesResponse

type IPRangesResponse struct {
	WithLastModified
	IPRange *IPRange
}

type JSONAPIError

type JSONAPIError struct {
	Errors []struct {
		Status string `json:"status"`
		Title  string `json:"title"`
		Detail string `json:"detail"`
	} `json:"errors"`
}

type Meta

type Meta struct {
	IPRanges IPRanges
	OpenAPI  OpenAPI
}

Meta contains any HCP Terraform APIs which provide data about the API itself.

type OpenAPI

type OpenAPI interface {
	Read(ctx context.Context, prerelease bool, modifiedSince *time.Time) (*OpenAPIResponse, error)
}

OpenAPI provides access to the OpenAPI specification for HCP Terraform or Terraform Enterprise.

type OpenAPIResponse

type OpenAPIResponse struct {
	WithLastModified
	Bytes []byte
}

OpenAPIResponse represents the response from reading the OpenAPI specification, including the raw bytes and the last modified time.

type RetryHook

type RetryHook = middleware.RetryHookCallback

RetryHook allows a function to run before each retry.

type TFERequestAdapter

type TFERequestAdapter struct {
	khttp.NetHttpRequestAdapter
	Client *nethttp.Client
}

DefaultRequestAdapter is the core service used by GraphServiceClient to make requests to Microsoft Graph.

func NewRequestAdapter

func NewRequestAdapter(baseURL string, options []middleware.MiddlewareOption, authenticationProvider absauth.AuthenticationProvider) (*TFERequestAdapter, error)

NewRequestAdapter creates a new TFERequestAdapter with the given parameters

type WithLastModified

type WithLastModified struct {
	LastModified *time.Time
}

WithLastModified represents a response that contains a last modified time.

func (*WithLastModified) IsNotModified

func (o *WithLastModified) IsNotModified() bool

IsNotModified returns true if the response does not contain data or a last modified time.

Directories

Path Synopsis
api
Package middleware contains the custom middleware used by the go-tfe SDK, as well as options for configuring the default middlewares.
Package middleware contains the custom middleware used by the go-tfe SDK, as well as options for configuring the default middlewares.

Jump to

Keyboard shortcuts

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