Skip to content

Commit

Permalink
fix: propagate insecureSkipTLSVerify to Palette client (#503)
Browse files Browse the repository at this point in the history
* fix: configure client.WithInsecureSkipVerify; tidy

Signed-off-by: Tyler Gillson <[email protected]>

* fix: properly ignore __debug_bin dirs

Signed-off-by: Tyler Gillson <[email protected]>

* fix: make toMachinePoolTke deterministic

Signed-off-by: Tyler Gillson <[email protected]>

---------

Signed-off-by: Tyler Gillson <[email protected]>
  • Loading branch information
TylerGillson authored Aug 22, 2024
1 parent d113161 commit 6a9a547
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.DS_Store

bin
__debug_bin
__debug_bin*
profile.cov

terraform.tfplan
Expand Down
42 changes: 19 additions & 23 deletions spectrocloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions spectrocloud/resource_cluster_tke.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package spectrocloud
import (
"context"
"log"
"slices"
"time"

"github.com/spectrocloud/terraform-provider-spectrocloud/spectrocloud/schemas"
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 4 additions & 2 deletions spectrocloud/resource_cluster_tke_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down

0 comments on commit 6a9a547

Please sign in to comment.