@@ -32,13 +32,14 @@ import (
3232)
3333
3434const (
35- _userAgent = "go-tfe"
36- _headerRateLimit = "X-RateLimit-Limit"
37- _headerRateReset = "X-RateLimit-Reset"
38- _headerAppName = "TFP-AppName"
39- _headerAPIVersion = "TFP-API-Version"
40- _headerTFEVersion = "X-TFE-Version"
41- _includeQueryParam = "include"
35+ _userAgent = "go-tfe"
36+ _headerRateLimit = "X-RateLimit-Limit"
37+ _headerRateReset = "X-RateLimit-Reset"
38+ _headerAppName = "TFP-AppName"
39+ _headerAPIVersion = "TFP-API-Version"
40+ _headerTFEVersion = "X-TFE-Version"
41+ _headerTFENumericVersion = "X-TFE-Current-Version"
42+ _includeQueryParam = "include"
4243
4344 DefaultAddress = "https://app.terraform.io"
4445 DefaultBasePath = "/api/v2/"
@@ -111,17 +112,18 @@ func DefaultConfig() *Config {
111112// Client is the Terraform Enterprise API client. It provides the basic
112113// connectivity and configuration for accessing the TFE API
113114type Client struct {
114- baseURL * url.URL
115- registryBaseURL * url.URL
116- token string
117- headers http.Header
118- http * retryablehttp.Client
119- limiter * rate.Limiter
120- retryLogHook RetryLogHook
121- retryServerErrors bool
122- remoteAPIVersion string
123- remoteTFEVersion string
124- appName string
115+ baseURL * url.URL
116+ registryBaseURL * url.URL
117+ token string
118+ headers http.Header
119+ http * retryablehttp.Client
120+ limiter * rate.Limiter
121+ retryLogHook RetryLogHook
122+ retryServerErrors bool
123+ remoteAPIVersion string
124+ remoteTFEVersion string
125+ remoteTFENumericVersion string
126+ appName string
125127
126128 Admin Admin
127129 Agents Agents
@@ -449,6 +451,9 @@ func NewClient(cfg *Config) (*Client, error) {
449451 // Save the TFE version
450452 client .remoteTFEVersion = meta .TFEVersion
451453
454+ // Save the TFE Numeric version
455+ client .remoteTFENumericVersion = meta .TFENumericVersion
456+
452457 // Save the app name
453458 client .appName = meta .AppName
454459
@@ -613,7 +618,7 @@ func (c *Client) SetFakeRemoteAPIVersion(fakeAPIVersion string) {
613618 c .remoteAPIVersion = fakeAPIVersion
614619}
615620
616- // RemoteTFEVersion returns the server's declared TFE version string.
621+ // RemoteTFEVersion returns the server's declared TFE monthly version string.
617622//
618623// A Terraform Enterprise API server includes its current version in an
619624// HTTP header field in all responses. This value is saved by the client
@@ -624,6 +629,17 @@ func (c Client) RemoteTFEVersion() string {
624629 return c .remoteTFEVersion
625630}
626631
632+ // RemoteTFENumericVersion returns the server's declared TFE version string.
633+ //
634+ // A Terraform Enterprise API server includes its current numeric version in an
635+ // HTTP header field in all responses. This value is saved by the client
636+ // during the initial setup request and RemoteTFENumericVersion returns that cached
637+ // value. This function returns an empty string for any Terraform Enterprise version
638+ // earlier than 1.0.3 and for HCP Terraform.
639+ func (c Client ) RemoteTFENumericVersion () string {
640+ return c .remoteTFENumericVersion
641+ }
642+
627643// RetryServerErrors configures the retry HTTP check to also retry
628644// unexpected errors or requests that failed with a server error.
629645func (c * Client ) RetryServerErrors (retry bool ) {
@@ -699,11 +715,16 @@ type rawAPIMetadata struct {
699715 // field was not included in the response.
700716 APIVersion string
701717
702- // TFEVersion is the raw TFE version string reported by the server in the
718+ // TFEVersion is the raw TFE monthly version string reported by the server in the
703719 // X-TFE-Version response header, or an empty string if that header
704720 // field was not included in the response.
705721 TFEVersion string
706722
723+ // TFENumericVersion is the raw TFE Numeric version string reported by the server in the
724+ // X-TFE-Current-Version response header, or an empty string if that header
725+ // field was not included in the response.
726+ TFENumericVersion string
727+
707728 // RateLimit is the raw API version string reported by the server in the
708729 // X-RateLimit-Limit response header, or an empty string if that header
709730 // field was not included in the response.
@@ -743,6 +764,7 @@ func (c *Client) getRawAPIMetadata() (rawAPIMetadata, error) {
743764 meta .APIVersion = resp .Header .Get (_headerAPIVersion )
744765 meta .RateLimit = resp .Header .Get (_headerRateLimit )
745766 meta .TFEVersion = resp .Header .Get (_headerTFEVersion )
767+ meta .TFENumericVersion = resp .Header .Get (_headerTFENumericVersion )
746768 meta .AppName = resp .Header .Get (_headerAppName )
747769
748770 return meta , nil
0 commit comments