tfe

package
v0.0.0-...-bd9d91d Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2018 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccessRead  = "read"
	AccessWrite = "write"
	AccessAdmin = "admin"
)
View Source
const (
	TrialVersion = "trial"
)

Variables

View Source
var ErrAuth = fmt.Errorf("authentication failed")

ErrAuth is the error returned if a 401 is returned by an API request.

View Source
var ErrNotFound = fmt.Errorf("resource not found")

ErrNotFound is the error returned if a 404 is returned by an API request.

Functions

func CheckResp

func CheckResp(resp *http.Response, err error) (*http.Response, error)

CheckResp wraps http.Client.Do() and verifies that the request was successful. A non-200 request returns an error formatted to included any validation problems or otherwise.

Types

type Client

type Client struct {
	// URL is the API endpoint
	URL *url.URL

	// HTTPClient is the underlying http client with which to make requests.
	HTTPClient *retryablehttp.Client

	// DefaultHeaders is a set of headers that will be added to every request.
	// This minimally includes the atlas user-agent string.
	DefaultHeader http.Header
}

func NewClient

func NewClient(opts *ClientOptions) (*Client, error)

func TestingClientServer

func TestingClientServer(t *testing.T) (*Client, *testutils.Server)

func (*Client) CreateOrganization

func (c *Client) CreateOrganization(org *Organization) (*Organization, error)

func (*Client) CreateTeam

func (c *Client) CreateTeam(org string, t *Team) (*Team, error)

func (*Client) CreateTeamAccess

func (c *Client) CreateTeamAccess(ta *TeamAccess) (*TeamAccess, error)

func (*Client) CreateVariable

func (c *Client) CreateVariable(organization string, workspace string, variable *Variable) (*Variable, error)

func (*Client) CreateWorkspace

func (c *Client) CreateWorkspace(organization string, workspace *Workspace) (*Workspace, error)

CreateWorkspace creates a workspace.

func (*Client) DeleteOrganization

func (c *Client) DeleteOrganization(id string) error

func (*Client) DeleteTeam

func (c *Client) DeleteTeam(id string) error

func (*Client) DeleteTeamAccess

func (c *Client) DeleteTeamAccess(id string) error

func (*Client) DeleteVariable

func (c *Client) DeleteVariable(id string) error

func (*Client) DeleteWorkspace

func (c *Client) DeleteWorkspace(organization string, workspaceName string) error

func (*Client) GetOrganizationByID

func (c *Client) GetOrganizationByID(id string) (*Organization, error)

func (*Client) GetTeamAccessByID

func (c *Client) GetTeamAccessByID(id string) (*TeamAccess, error)

func (*Client) GetTeamByID

func (c *Client) GetTeamByID(id string) (*Team, error)

func (*Client) GetVariableByID

func (c *Client) GetVariableByID(organization string, workspace string, id string) (*Variable, error)

func (*Client) GetVariableByKey

func (c *Client) GetVariableByKey(organization string, workspace string, key string) (*Variable, error)

func (*Client) GetWorkspaceByID

func (c *Client) GetWorkspaceByID(organization string, workspaceId string) (*Workspace, error)

func (*Client) GetWorkspaceByName

func (c *Client) GetWorkspaceByName(organization string, workspaceName string) (*Workspace, error)

func (*Client) ListLinkableRepos

func (c *Client) ListLinkableRepos(oauthTokenID string) ([]*LinkableRepo, error)

func (*Client) ListOAuthTokens

func (c *Client) ListOAuthTokens(organization string) ([]*OAuthToken, error)

func (*Client) ListTeams

func (c *Client) ListTeams(organization string) ([]*Team, error)

func (*Client) ListVariables

func (c *Client) ListVariables(organization string, workspace string) ([]*Variable, error)

func (*Client) NewRequest

func (c *Client) NewRequest(verb, spath string, ro *RequestOptions) (*Request, error)

Request creates a new HTTP request using the given verb and sub path.

func (*Client) UpdateVariable

func (c *Client) UpdateVariable(variable *Variable) (*Variable, error)

func (*Client) UpdateWorkspace

func (c *Client) UpdateWorkspace(organization string, w *Workspace) (*Workspace, error)

type ClientOptions

type ClientOptions struct {
	BaseURL       string
	DefaultHeader http.Header
	NoVerifyTLS   bool
	CAPath        string
	CAFile        string
}

func DefaultClientOptions

func DefaultClientOptions() *ClientOptions

func (*ClientOptions) SetToken

func (c *ClientOptions) SetToken(token string)

type LinkableRepo

type LinkableRepo struct {
	// ID is a string identifying the repo. It appears to be the
	// name of the repo according to the repo hosting provider,
	// i.e. Grab/SecretProject for github.com/Grab/SecretProject.
	ID string `jsonapi:"primary,authorized-repos"`
}

LinkableRepo represents a linkable repository, i.e. a repository hosted on a VCS hosting system like GitHub, Bitbucket, Gitlab, etc.

type OAuthClientT

type OAuthClientT struct {
	ID string `jsonapi:"primary,oauth-clients"`
}

OauthClientT represents an OAuth Client. This is not directly manipulatable in the API, but it is used as part of the OAuthToken type.

type OAuthToken

type OAuthToken struct {
	ID                  string       `jsonapi:"primary,oauth-tokens"`
	CreatedAt           time.Time    `jsonapi:"attr,created-at,iso8601"`
	ServiceProviderUser string       `jsonapi:"attr,service-provider-user"`
	HasSSHKey           bool         `jsonapi:"attr,has-ssh-key"`
	OAuthClient         OAuthClientT `jsonapi:"relation,oauth-client`
}

OAuthToken represents the OAuth Token associated with an OAuth Client.

type Organization

type Organization struct {
	ID             string `jsonapi:"primary,organizations"`
	Name           string `jsonapi:"attr,name"`
	Email          string `jsonapi:"attr,email"`
	EnterprisePlan string `jsonapi:"attr,enterprise-plan"`
}

Organization represents an organization in Terraform Enterprise. The API to manipulate organizations is undocumented.

type Request

type Request = retryablehttp.Request

type RequestOptions

type RequestOptions struct {
	// Params is a map of key-value pairs that will be added to the Request.
	Params map[string]string

	// Headers is a map of key-value pairs that will be added to the Request.
	Headers map[string]string

	// Body is a bytes.Buffer object that will be streamed or uploaded with the
	// Request. BodyLength is the final size of the Body.
	Body       *bytes.Buffer
	BodyLength int64
}

RequestOptions is the list of options to pass to the request.

type Team

type Team struct {
	ID         string `jsonapi:"primary,teams"`
	Name       string `jsonapi:"attr,name"`
	UsersCount int    `jsonapi:"attr,users-count,omitempty"`
}

Team is a collection of users that may be granted permissions. https://www.terraform.io/docs/enterprise/api/teams.html

type TeamAccess

type TeamAccess struct {
	ID string `jsonapi:"primary,team-workspaces"`

	// Access should be "read", "write" or "admin"
	Access string `jsonapi:"attr,access"`

	Team      *Team      `jsonapi:"relation,team"`
	Workspace *Workspace `jsonapi:"relation,workspace"`
}

TeamAccess represents a permission for a given Team to access a given Workspace. https://www.terraform.io/docs/enterprise/api/team-access.html

type VCSRepoT

type VCSRepoT struct {
	// LinkableRepiID is the name of the repository this workspace
	// is linked to. If you're using Github or Bitbucket this is
	// in the format "$user/$repo".
	LinkableRepoID string `json:"identifier"`

	// OAuthTokenID is the ID of a previously registered OAuth
	// token for Terraform to connect to your VCS system (Github,
	// Bitbucket, Gitlab...).
	OAuthTokenID string `json:"oauth-token-id"`

	Branch            string `json:"branch"`
	DefaultBranch     bool   `json:"default-branch"`
	IngressSubmodules bool   `json:"ingress-submodules"`
}

type Variable

type Variable struct {
	ID        string     `jsonapi:"primary,vars"`
	Key       string     `jsonapi:"attr,key"`
	Value     string     `jsonapi:"attr,value"`
	Sensitive bool       `jsonapi:"attr,sensitive"`
	Category  string     `jsonapi:"attr,category"`
	HCL       bool       `jsonapi:"attr,hcl"`
	Workspace *Workspace `jsonapi:"relation,configurable"`
	// contains filtered or unexported fields
}

Variable represents a workspace variable. https://www.terraform.io/docs/enterprise/api/variables.html

func (*Variable) JSONAPIFilter

func (v *Variable) JSONAPIFilter() *jsonapi.Filter

This is a mild hack: because TFE's API expects the workspace and organization to be passed as a "filter" object (similar to a "meta" or "links", except it's not standard JSONAPI behavior), we use a forked version of google/jsonapi that supports these objects. To add this object, we implement the method below.

type Workspace

type Workspace struct {
	// ID is the ID of the workspace. Generated server-side.
	ID string `jsonapi:"primary,workspaces"`

	// Name is the human-friendly name of the workspace.
	Name string `jsonapi:"attr,name,omitempty"`

	// TODO what's that
	Environment string `jsonapi:"attr,environment,omitempty"`

	// AutoApply is whether changes get applied without human
	// approval
	AutoApply bool `jsonapi:"attr,auto-apply,omitempty"`

	// Locked is a read-only attribute that indicates whether the
	// workspace is locked.
	Locked bool `jsonapi:"attr,locked,omitempty"`

	// CreatedAt is the timestamp of this workspace's creation
	CreatedAt time.Time `jsonapi:"attr,created-at,iso8601,omitempty"`

	// WorkingDirectory is the working directory within the VCS
	// repository used to run Terraform for this workspace.
	WorkingDirectory string `jsonapi:"attr,working-directory"`

	// TerraformVersion is the version of Terraform in use in this
	// workspace.
	TerraformVersion string `jsonapi:"attr,terraform-version,omitempty"`

	// CanQueueDestroyPlan indicates whether the workspace allows
	// creating a destroy plan.
	CanQueueDestroyPlan bool `jsonapi:"attr,can-queue-destroy-plan,omitempty"`

	// IngressTriggerAttributes is the settings struct for VCS
	// integration
	VCSRepo VCSRepoT `jsonapi:"attr,vcs-repo,omitempty"`
}

Workspace represents a workspace in Terraform Enterprise. To create a Workspace with a VCS connection, use CompoundWorkspace instead. https://www.terraform.io/docs/enterprise/api/workspaces.html

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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