From 6a9a5470ad39c6c6ec894112c9ec5745a28b410f Mon Sep 17 00:00:00 2001 From: Tyler Gillson Date: Wed, 21 Aug 2024 23:57:09 -0600 Subject: [PATCH] fix: propagate insecureSkipTLSVerify to Palette client (#503) * fix: configure client.WithInsecureSkipVerify; tidy Signed-off-by: Tyler Gillson * fix: properly ignore __debug_bin dirs Signed-off-by: Tyler Gillson * fix: make toMachinePoolTke deterministic Signed-off-by: Tyler Gillson --------- Signed-off-by: Tyler Gillson --- .gitignore | 2 +- spectrocloud/provider.go | 42 ++++++++++------------- spectrocloud/resource_cluster_tke.go | 2 ++ spectrocloud/resource_cluster_tke_test.go | 6 ++-- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index b5c22c07..1b37ea61 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ .DS_Store bin -__debug_bin +__debug_bin* profile.cov terraform.tfplan diff --git a/spectrocloud/provider.go b/spectrocloud/provider.go index 3389dbbe..691ead40 100644 --- a/spectrocloud/provider.go +++ b/spectrocloud/provider.go @@ -185,28 +185,20 @@ func New(_ string) func() *schema.Provider { } func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) { - host := d.Get("host").(string) - apiKey := "" - transportDebug := false - retryAttempts := 10 + var diags diag.Diagnostics - if d.Get("trace") != nil { - transportDebug = d.Get("trace").(bool) - } + host := d.Get("host").(string) + projectName := d.Get("project_name").(string) - if d.Get("retry_attempts") != nil { - retryAttempts = d.Get("retry_attempts").(int) + insecure := d.Get("ignore_insecure_tls_error").(bool) + if insecure { + http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} } + apiKey := "" if d.Get("api_key") != nil { apiKey = d.Get("api_key").(string) } - projectName := d.Get("project_name").(string) - ignoreTlsError := d.Get("ignore_insecure_tls_error").(bool) - - // Warning or errors can be collected in a slice type - var diags diag.Diagnostics - if apiKey == "" { diags = append(diags, diag.Diagnostic{ Severity: diag.Error, @@ -216,30 +208,34 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{} return nil, diags } - if ignoreTlsError { - http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} + retryAttempts := 10 + if d.Get("retry_attempts") != nil { + retryAttempts = d.Get("retry_attempts").(int) + } + + transportDebug := false + if d.Get("trace") != nil { + transportDebug = d.Get("trace").(bool) } c := client.New( client.WithPaletteURI(host), client.WithAPIKey(apiKey), - client.WithRetries(retryAttempts)) - + client.WithInsecureSkipVerify(insecure), + client.WithRetries(retryAttempts), + ) if transportDebug { client.WithTransportDebug()(c) } + uid, err := c.GetProjectUID(projectName) if err != nil { return nil, diag.FromErr(err) } - if uid != "" { ProviderInitProjectUid = uid client.WithScopeProject(uid)(c) } - //else { - // client.WithScopeTenant()(c) - //} return c, diags diff --git a/spectrocloud/resource_cluster_tke.go b/spectrocloud/resource_cluster_tke.go index e3342d8f..00b04b95 100644 --- a/spectrocloud/resource_cluster_tke.go +++ b/spectrocloud/resource_cluster_tke.go @@ -3,6 +3,7 @@ package spectrocloud import ( "context" "log" + "slices" "time" "github.com/spectrocloud/terraform-provider-spectrocloud/spectrocloud/schemas" @@ -593,6 +594,7 @@ func toMachinePoolTke(machinePool interface{}) *models.V1TencentMachinePoolConfi for k := range m["az_subnets"].(map[string]interface{}) { azs = append(azs, k) } + slices.Sort(azs) min := int32(m["count"].(int)) max := int32(m["count"].(int)) diff --git a/spectrocloud/resource_cluster_tke_test.go b/spectrocloud/resource_cluster_tke_test.go index 74050d76..26462f90 100644 --- a/spectrocloud/resource_cluster_tke_test.go +++ b/spectrocloud/resource_cluster_tke_test.go @@ -1,12 +1,14 @@ package spectrocloud import ( + "testing" + "github.com/google/go-cmp/cmp" - "github.com/spectrocloud/terraform-provider-spectrocloud/types" "github.com/stretchr/testify/assert" - "testing" "github.com/spectrocloud/palette-api-go/models" + + "github.com/spectrocloud/terraform-provider-spectrocloud/types" ) func TestFlattenMachinePoolConfigsTke(t *testing.T) {