From 884afba0294bc426cc96e76b55825bf674a5484a Mon Sep 17 00:00:00 2001 From: William Guilherme Date: Sat, 30 Sep 2023 23:06:20 -0700 Subject: [PATCH] (Fix): Added enhanced user-agent header information (#373) * fix: Added enhaced user-agent header information * Fix: version.go to receive exact provider binary version --- CHANGELOG.md | 12 ++++++++++++ GNUmakefile | 6 +++--- docs/guides/release-notes.md | 14 +++++++++++++- main.go | 25 +++++++++++++++++++++++-- zpa/common/version.go | 10 ++++++++++ zpa/provider.go | 8 ++++++-- zpa/provider_sweeper_test.go | 2 +- zpa/provider_test.go | 4 ++-- 8 files changed, 70 insertions(+), 11 deletions(-) create mode 100644 zpa/common/version.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cfe57b2..dee97162 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/GNUmakefile b/GNUmakefile index 06acfc3d..cb6d1096 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -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/ ..." diff --git a/docs/guides/release-notes.md b/docs/guides/release-notes.md index 671de225..0cc320e5 100644 --- a/docs/guides/release-notes.md +++ b/docs/guides/release-notes.md @@ -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 diff --git a/main.go b/main.go index 61713c6d..b7efeff3 100644 --- a/main.go +++ b/main.go @@ -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, + }) } diff --git a/zpa/common/version.go b/zpa/common/version.go new file mode 100644 index 00000000..8cf8157b --- /dev/null +++ b/zpa/common/version.go @@ -0,0 +1,10 @@ +package common + +var ( + version = "3.0.2" +) + +// Version returns version of provider +func Version() string { + return version +} diff --git a/zpa/provider.go b/zpa/provider.go index 890afa0b..c6aa8f47 100644 --- a/zpa/provider.go +++ b/zpa/provider.go @@ -10,6 +10,7 @@ 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 @@ -17,24 +18,27 @@ 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": { @@ -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() diff --git a/zpa/provider_sweeper_test.go b/zpa/provider_sweeper_test.go index bfe9ab5e..df38485e 100644 --- a/zpa/provider_sweeper_test.go +++ b/zpa/provider_sweeper_test.go @@ -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() { diff --git a/zpa/provider_test.go b/zpa/provider_test.go index 946e339d..a9ffc6de 100644 --- a/zpa/provider_test.go +++ b/zpa/provider_test.go @@ -19,7 +19,7 @@ var ( ) func init() { - testAccProvider = Provider() + testAccProvider = ZPAProvider() testAccProviders = map[string]*schema.Provider{ "zpa": testAccProvider, } @@ -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) } }