go-tfe dep update to 0.3.22
Signed-off-by: Paul Thrasher <pthrasher@hashicorp.com>
This commit is contained in:
parent
979bba0f32
commit
29c8ca485e
5
go.mod
5
go.mod
|
@ -39,7 +39,6 @@ require (
|
|||
github.com/golang/mock v1.3.1
|
||||
github.com/golang/protobuf v1.3.2
|
||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect
|
||||
github.com/google/btree v1.0.0 // indirect
|
||||
github.com/google/go-cmp v0.3.0
|
||||
github.com/google/uuid v1.1.1
|
||||
github.com/gophercloud/gophercloud v0.0.0-20190208042652-bc37892e1968
|
||||
|
@ -64,7 +63,7 @@ require (
|
|||
github.com/hashicorp/go-retryablehttp v0.5.2
|
||||
github.com/hashicorp/go-rootcerts v1.0.0
|
||||
github.com/hashicorp/go-sockaddr v0.0.0-20180320115054-6d291a969b86 // indirect
|
||||
github.com/hashicorp/go-tfe v0.3.16
|
||||
github.com/hashicorp/go-tfe v0.3.22
|
||||
github.com/hashicorp/go-uuid v1.0.1
|
||||
github.com/hashicorp/go-version v1.1.0
|
||||
github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f
|
||||
|
@ -133,3 +132,5 @@ require (
|
|||
gopkg.in/ini.v1 v1.42.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.2.2
|
||||
)
|
||||
|
||||
go 1.13
|
||||
|
|
6
go.sum
6
go.sum
|
@ -198,8 +198,10 @@ github.com/hashicorp/go-slug v0.3.0 h1:L0c+AvH/J64iMNF4VqRaRku2DMTEuHioPVS7kMjWI
|
|||
github.com/hashicorp/go-slug v0.3.0/go.mod h1:I5tq5Lv0E2xcNXNkmx7BSfzi1PsJ2cNjs3cC3LwyhK8=
|
||||
github.com/hashicorp/go-sockaddr v0.0.0-20180320115054-6d291a969b86 h1:7YOlAIO2YWnJZkQp7B5eFykaIY7C9JndqAFQyVV5BhM=
|
||||
github.com/hashicorp/go-sockaddr v0.0.0-20180320115054-6d291a969b86/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
|
||||
github.com/hashicorp/go-tfe v0.3.16 h1:GS2yv580p0co4j3FBVaC6Zahd9mxdCGehhJ0qqzFMH0=
|
||||
github.com/hashicorp/go-tfe v0.3.16/go.mod h1:SuPHR+OcxvzBZNye7nGPfwZTEyd3rWPfLVbCgyZPezM=
|
||||
github.com/hashicorp/go-tfe v0.3.21 h1:JVB+DqX4zevWmaVHGsJfElyScf1ZjbF6EUDLPzU96OE=
|
||||
github.com/hashicorp/go-tfe v0.3.21/go.mod h1:SuPHR+OcxvzBZNye7nGPfwZTEyd3rWPfLVbCgyZPezM=
|
||||
github.com/hashicorp/go-tfe v0.3.22 h1:Wodv4Y3kiC6bTPHQzhrn026V3HLhfwhc1rVlLY8suKs=
|
||||
github.com/hashicorp/go-tfe v0.3.22/go.mod h1:SuPHR+OcxvzBZNye7nGPfwZTEyd3rWPfLVbCgyZPezM=
|
||||
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE=
|
||||
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
|
|
|
@ -0,0 +1,129 @@
|
|||
package tfe
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Compile-time proof of interface implementation.
|
||||
var _ CostEstimates = (*costEstimates)(nil)
|
||||
|
||||
// CostEstimates describes all the costEstimate related methods that
|
||||
// the Terraform Enterprise API supports.
|
||||
//
|
||||
// TFE API docs: https://www.terraform.io/docs/enterprise/api/ (TBD)
|
||||
type CostEstimates interface {
|
||||
// Read a costEstimate by its ID.
|
||||
Read(ctx context.Context, costEstimateID string) (*CostEstimate, error)
|
||||
|
||||
// Logs retrieves the logs of a costEstimate.
|
||||
Logs(ctx context.Context, costEstimateID string) (io.Reader, error)
|
||||
}
|
||||
|
||||
// costEstimates implements CostEstimates.
|
||||
type costEstimates struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
// CostEstimateStatus represents a costEstimate state.
|
||||
type CostEstimateStatus string
|
||||
|
||||
//List all available costEstimate statuses.
|
||||
const (
|
||||
CostEstimateCanceled CostEstimateStatus = "canceled"
|
||||
CostEstimateErrored CostEstimateStatus = "errored"
|
||||
CostEstimateFinished CostEstimateStatus = "finished"
|
||||
CostEstimatePending CostEstimateStatus = "pending"
|
||||
CostEstimateQueued CostEstimateStatus = "queued"
|
||||
)
|
||||
|
||||
// CostEstimate represents a Terraform Enterprise costEstimate.
|
||||
type CostEstimate struct {
|
||||
ID string `jsonapi:"primary,cost-estimates"`
|
||||
DeltaMonthlyCost string `jsonapi:"attr,delta-monthly-cost"`
|
||||
ErrorMessage string `jsonapi:"attr,error-message"`
|
||||
MatchedResourcesCount string `jsonapi:"attr,matched-resources-count"`
|
||||
PriorMonthlyCost string `jsonapi:"attr,prior-monthly-cost"`
|
||||
ProposedMonthlyCost string `jsonapi:"attr,proposed-monthly-cost"`
|
||||
ResourcesCount string `jsonapi:"attr,resources-count"`
|
||||
Status CostEstimateStatus `jsonapi:"attr,status"`
|
||||
StatusTimestamps *CostEstimateStatusTimestamps `jsonapi:"attr,status-timestamps"`
|
||||
UnmatchedResourcesCount string `jsonapi:"attr,unmatched-resources-count"`
|
||||
}
|
||||
|
||||
// CostEstimateStatusTimestamps holds the timestamps for individual costEstimate statuses.
|
||||
type CostEstimateStatusTimestamps struct {
|
||||
CanceledAt time.Time `json:"canceled-at"`
|
||||
ErroredAt time.Time `json:"errored-at"`
|
||||
FinishedAt time.Time `json:"finished-at"`
|
||||
PendingAt time.Time `json:"pending-at"`
|
||||
QueuedAt time.Time `json:"queued-at"`
|
||||
}
|
||||
|
||||
// Read a costEstimate by its ID.
|
||||
func (s *costEstimates) Read(ctx context.Context, costEstimateID string) (*CostEstimate, error) {
|
||||
if !validStringID(&costEstimateID) {
|
||||
return nil, errors.New("invalid value for cost estimate ID")
|
||||
}
|
||||
|
||||
u := fmt.Sprintf("cost-estimates/%s", url.QueryEscape(costEstimateID))
|
||||
req, err := s.client.newRequest("GET", u, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ce := &CostEstimate{}
|
||||
err = s.client.do(ctx, req, ce)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ce, nil
|
||||
}
|
||||
|
||||
// Logs retrieves the logs of a costEstimate.
|
||||
func (s *costEstimates) Logs(ctx context.Context, costEstimateID string) (io.Reader, error) {
|
||||
if !validStringID(&costEstimateID) {
|
||||
return nil, errors.New("invalid value for cost estimate ID")
|
||||
}
|
||||
|
||||
// Loop until the context is canceled or the cost estimate is finished
|
||||
// running. The cost estimate logs are not streamed and so only available
|
||||
// once the estimate is finished.
|
||||
for {
|
||||
// Get the costEstimate to make sure it exists.
|
||||
ce, err := s.Read(ctx, costEstimateID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch ce.Status {
|
||||
case CostEstimateQueued:
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
case <-time.After(1000 * time.Millisecond):
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
u := fmt.Sprintf("cost-estimates/%s/output", url.QueryEscape(costEstimateID))
|
||||
req, err := s.client.newRequest("GET", u, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logs := bytes.NewBuffer(nil)
|
||||
err = s.client.do(ctx, req, logs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return logs, nil
|
||||
}
|
||||
}
|
|
@ -315,7 +315,7 @@ github.com/hashicorp/go-rootcerts
|
|||
github.com/hashicorp/go-safetemp
|
||||
# github.com/hashicorp/go-slug v0.3.0
|
||||
github.com/hashicorp/go-slug
|
||||
# github.com/hashicorp/go-tfe v0.3.16
|
||||
# github.com/hashicorp/go-tfe v0.3.22
|
||||
github.com/hashicorp/go-tfe
|
||||
# github.com/hashicorp/go-uuid v1.0.1
|
||||
github.com/hashicorp/go-uuid
|
||||
|
|
Loading…
Reference in New Issue