Skip to content

Commit

Permalink
(Fix): Added enhanced user-agent header information (#373)
Browse files Browse the repository at this point in the history
* fix: Added enhaced user-agent header information

* Fix: version.go to receive exact provider binary version
  • Loading branch information
willguibr authored Oct 1, 2023
1 parent 7611748 commit 884afba
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 11 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 3.0.2 (September, 28 2023)

### Notes

- Release date: **(September, 28 2023)**
- Supported Terraform version: **v1.x**

### Fixes

- [PR #372](https://github.com/zscaler/terraform-provider-zpa/pull/372) - Provider HTTP Header now includes enhanced ``User-Agent`` information for troubleshooting assistance.
- i.e ``User-Agent: (darwin arm64) Terraform/1.5.5 Provider/3.0.2 CustomerID/xxxxxxxxxxxxxxx``

## 3.0.1-beta (September, 21 2023)

### Notes
Expand Down
6 changes: 3 additions & 3 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ testacc:
build13: GOOS=$(shell go env GOOS)
build13: GOARCH=$(shell go env GOARCH)
ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10...
build13: DESTINATION=$(APPDATA)/terraform.d/plugins/$(ZPA_PROVIDER_NAMESPACE)/3.0.1-beta/$(GOOS)_$(GOARCH)
build13: DESTINATION=$(APPDATA)/terraform.d/plugins/$(ZPA_PROVIDER_NAMESPACE)/3.0.2/$(GOOS)_$(GOARCH)
else
build13: DESTINATION=$(HOME)/.terraform.d/plugins/$(ZPA_PROVIDER_NAMESPACE)/3.0.1-beta/$(GOOS)_$(GOARCH)
build13: DESTINATION=$(HOME)/.terraform.d/plugins/$(ZPA_PROVIDER_NAMESPACE)/3.0.2/$(GOOS)_$(GOARCH)
endif
build13: fmtcheck
go mod tidy && go mod vendor
@echo "==> Installing plugin to $(DESTINATION)"
@mkdir -p $(DESTINATION)
go build -o $(DESTINATION)/terraform-provider-zpa_v3.0.1-beta
go build -o $(DESTINATION)/terraform-provider-zpa_v3.0.2

lint: vendor
@echo "✓ Linting source code with https://staticcheck.io/ ..."
Expand Down
14 changes: 13 additions & 1 deletion docs/guides/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,22 @@ Track all ZPA Terraform provider's releases. New resources, features, and bug fi

---

``Last updated: v3.0.1-beta``
``Last updated: v3.0.2``

---

## 3.0.2 (September, 28 2023)

### Notes

- Release date: **(September, 28 2023)**
- Supported Terraform version: **v1.x**

### Fixes

- [PR #372](https://github.com/zscaler/terraform-provider-zpa/pull/372) - Provider HTTP Header now includes enhanced ``User-Agent`` information for troubleshooting assistance.
- i.e ``User-Agent: (darwin arm64) Terraform/1.5.5 Provider/3.0.2 CustomerID/xxxxxxxxxxxxxxx``

## 3.0.1-beta (September, 21 2023)

### Notes
Expand Down
25 changes: 23 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
package main

import (
"fmt"
"log"
"os"

"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
"github.com/zscaler/terraform-provider-zpa/v3/zpa"
"github.com/zscaler/terraform-provider-zpa/v3/zpa/common"
)

func main() {
log.SetFlags(log.Flags() &^ (log.Ldate | log.Ltime))
log.SetFlags(0)
if len(os.Args) > 1 && os.Args[1] == "version" {
fmt.Println(common.Version())
return
}
var debug bool
if len(os.Args) > 1 && os.Args[1] == "debug" {
debug = true
}
log.Printf(`ZPA Terraform Provider
Version %s
https://registry.terraform.io/providers/zscaler/zpa/latest/docs
`, common.Version())
plugin.Serve(&plugin.ServeOpts{
ProviderFunc: zpa.Provider})
ProviderFunc: zpa.ZPAProvider,
ProviderAddr: "registry.terraform.io/zscaler/zpa",
Debug: debug,
})
}
10 changes: 10 additions & 0 deletions zpa/common/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package common

var (
version = "3.0.2"
)

// Version returns version of provider
func Version() string {
return version
}
8 changes: 6 additions & 2 deletions zpa/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,35 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/zscaler/terraform-provider-zpa/v3/zpa/common"
)

// Resource names, defined in place, used throughout the provider and tests
const (
zpaBrowserAccess = "zpa_application_segment_browser_access"
)

func Provider() *schema.Provider {
func ZPAProvider() *schema.Provider {
p := &schema.Provider{
Schema: map[string]*schema.Schema{
"zpa_client_id": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ZPA_CLIENT_ID", nil),
Description: "zpa client id",
},
"zpa_client_secret": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
DefaultFunc: schema.EnvDefaultFunc("ZPA_CLIENT_SECRET", nil),
Description: "zpa client secret",
},
"zpa_customer_id": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
DefaultFunc: schema.EnvDefaultFunc("ZPA_CUSTOMER_ID", nil),
Description: "zpa customer id",
},
"zpa_cloud": {
Expand Down Expand Up @@ -158,7 +162,7 @@ func zscalerConfigure(d *schema.ResourceData, terraformVersion string) (interfac
ClientSecret: d.Get("zpa_client_secret").(string),
CustomerID: d.Get("zpa_customer_id").(string),
BaseURL: d.Get("zpa_cloud").(string),
UserAgent: fmt.Sprintf("(%s %s) Terraform/%s", runtime.GOOS, runtime.GOARCH, terraformVersion),
UserAgent: fmt.Sprintf("(%s %s) Terraform/%s Provider/%s Customer/%s", runtime.GOOS, runtime.GOARCH, terraformVersion, common.Version(), d.Get("zpa_customer_id").(string)),
}

return config.Client()
Expand Down
2 changes: 1 addition & 1 deletion zpa/provider_sweeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestRunForcedSweeper(t *testing.T) {
return
}

provider := Provider()
provider := ZPAProvider()
c := terraform.NewResourceConfigRaw(nil)
diag := provider.Configure(context.TODO(), c)
if diag.HasError() {
Expand Down
4 changes: 2 additions & 2 deletions zpa/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
)

func init() {
testAccProvider = Provider()
testAccProvider = ZPAProvider()
testAccProviders = map[string]*schema.Provider{
"zpa": testAccProvider,
}
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestMain(m *testing.M) {
}

func TestProvider(t *testing.T) {
if err := Provider().InternalValidate(); err != nil {
if err := ZPAProvider().InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
}
}
Expand Down

0 comments on commit 884afba

Please sign in to comment.