@@ -35,6 +35,7 @@ const (
35
35
_userAgent = "go-tfe"
36
36
_headerRateLimit = "X-RateLimit-Limit"
37
37
_headerRateReset = "X-RateLimit-Reset"
38
+ _headerAppName = "TFP-AppName"
38
39
_headerAPIVersion = "TFP-API-Version"
39
40
_headerTFEVersion = "X-TFE-Version"
40
41
_includeQueryParam = "include"
@@ -120,6 +121,7 @@ type Client struct {
120
121
retryServerErrors bool
121
122
remoteAPIVersion string
122
123
remoteTFEVersion string
124
+ appName string
123
125
124
126
Admin Admin
125
127
Agents Agents
@@ -361,6 +363,9 @@ func NewClient(cfg *Config) (*Client, error) {
361
363
// Save the TFE version
362
364
client .remoteTFEVersion = meta .TFEVersion
363
365
366
+ // Save the app name
367
+ client .appName = meta .AppName
368
+
364
369
// Create Admin
365
370
client .Admin = Admin {
366
371
Organizations : & adminOrganizations {client : client },
@@ -431,6 +436,23 @@ func NewClient(cfg *Config) (*Client, error) {
431
436
return client , nil
432
437
}
433
438
439
+ // IsCloud returns true if the client is configured against a Terraform Cloud
440
+ // instance.
441
+ //
442
+ // Whether an instance is TFC or TFE is derived from the TFP-AppName header.
443
+ func (c Client ) IsCloud () bool {
444
+ return c .appName == "Terraform Cloud"
445
+ }
446
+
447
+ // IsEnterprise returns true if the client is configured against a Terraform
448
+ // Enterprise instance.
449
+ //
450
+ // Whether an instance is TFC or TFE is derived from the TFP-AppName header. Note:
451
+ // not all TFE releases include this header in API responses.
452
+ func (c Client ) IsEnterprise () bool {
453
+ return ! c .IsCloud ()
454
+ }
455
+
434
456
// RemoteAPIVersion returns the server's declared API version string.
435
457
//
436
458
// A Terraform Cloud or Enterprise API server returns its API version in an
@@ -565,6 +587,9 @@ type rawAPIMetadata struct {
565
587
// X-RateLimit-Limit response header, or an empty string if that header
566
588
// field was not included in the response.
567
589
RateLimit string
590
+
591
+ // AppName is either 'Terraform Cloud' or 'Terraform Enterprise'
592
+ AppName string
568
593
}
569
594
570
595
func (c * Client ) getRawAPIMetadata () (rawAPIMetadata , error ) {
@@ -597,6 +622,7 @@ func (c *Client) getRawAPIMetadata() (rawAPIMetadata, error) {
597
622
meta .APIVersion = resp .Header .Get (_headerAPIVersion )
598
623
meta .RateLimit = resp .Header .Get (_headerRateLimit )
599
624
meta .TFEVersion = resp .Header .Get (_headerTFEVersion )
625
+ meta .AppName = resp .Header .Get (_headerAppName )
600
626
601
627
return meta , nil
602
628
}
0 commit comments