Skip to content

Commit 23b1e07

Browse files
committed
feat: Add options to skip TLS validation
Signed-off-by: Federico Barcelona <[email protected]>
1 parent 7832e1b commit 23b1e07

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

sysdig/monitor/client.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package monitor
22

33
import (
4+
"crypto/tls"
45
"io"
56
"net/http"
67
)
@@ -12,11 +13,17 @@ type SysdigMonitorClient interface {
1213
GetAlertById(int) (Alert, error)
1314
}
1415

15-
func NewSysdigMonitorClient(apiToken string, url string) SysdigMonitorClient {
16+
func NewSysdigMonitorClient(apiToken string, url string, insecure bool) SysdigMonitorClient {
17+
httpClient := &http.Client{
18+
Transport: &http.Transport{
19+
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecure},
20+
},
21+
}
22+
1623
return &sysdigMonitorClient{
1724
SysdigMonitorAPIToken: apiToken,
1825
URL: url,
19-
httpClient: http.DefaultClient,
26+
httpClient: httpClient,
2027
}
2128
}
2229

sysdig/provider.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ func Provider() terraform.ResourceProvider {
1919
Optional: true,
2020
DefaultFunc: schema.EnvDefaultFunc("SYSDIG_SECURE_URL", "https://secure.sysdig.com"),
2121
},
22+
"sysdig_secure_insecure_tls": {
23+
Type: schema.TypeBool,
24+
Optional: true,
25+
DefaultFunc: schema.EnvDefaultFunc("SYSDIG_SECURE_INSECURE_TLS", false),
26+
},
2227
"sysdig_monitor_api_token": {
2328
Type: schema.TypeString,
2429
Optional: true,
@@ -30,6 +35,11 @@ func Provider() terraform.ResourceProvider {
3035
Optional: true,
3136
DefaultFunc: schema.EnvDefaultFunc("SYSDIG_MONITOR_URL", "https://app.sysdigcloud.com"),
3237
},
38+
"sysdig_monitor_insecure_tls": {
39+
Type: schema.TypeBool,
40+
Optional: true,
41+
DefaultFunc: schema.EnvDefaultFunc("SYSDIG_MONITOR_INSECURE_TLS", false),
42+
},
3343
},
3444
ResourcesMap: map[string]*schema.Resource{
3545
"sysdig_user": resourceSysdigUser(),

sysdig/secure/client.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package secure
22

33
import (
4+
"crypto/tls"
45
"io"
56
"log"
67
"net/http"
@@ -45,11 +46,17 @@ type SysdigSecureClient interface {
4546
UpdateMacro(Macro) (Macro, error)
4647
}
4748

48-
func NewSysdigSecureClient(sysdigSecureAPIToken string, url string) SysdigSecureClient {
49+
func NewSysdigSecureClient(sysdigSecureAPIToken string, url string, insecure bool) SysdigSecureClient {
50+
httpClient := &http.Client{
51+
Transport: &http.Transport{
52+
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecure},
53+
},
54+
}
55+
4956
return &sysdigSecureClient{
5057
SysdigSecureAPIToken: sysdigSecureAPIToken,
5158
URL: url,
52-
httpClient: http.DefaultClient,
59+
httpClient: httpClient,
5360
}
5461
}
5562

sysdig/sysdig_clients.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func (c *sysdigClients) sysdigMonitorClient() (m monitor.SysdigMonitorClient, er
3232
c.monitorClient = monitor.NewSysdigMonitorClient(
3333
monitorAPIToken,
3434
c.d.Get("sysdig_monitor_url").(string),
35+
c.d.Get("sysdig_monitor_insecure_tls").(bool),
3536
)
3637
})
3738

@@ -49,6 +50,7 @@ func (c *sysdigClients) sysdigSecureClient() (s secure.SysdigSecureClient, err e
4950
c.secureClient = secure.NewSysdigSecureClient(
5051
secureAPIToken,
5152
c.d.Get("sysdig_secure_url").(string),
53+
c.d.Get("sysdig_secure_insecure_tls").(bool),
5254
)
5355
})
5456

0 commit comments

Comments
 (0)