Skip to content

Commit d885db1

Browse files
bodgitfbreckle
andauthored
feat: Allow setting a CA file in the provider (#765)
* feat: Allow setting a CA file in the provider * chore: regenerate docs --------- Co-authored-by: Fabian Breckle <fabian.breckle@breuninger.de>
1 parent f93126c commit d885db1

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ provider "netbox" {
6767
### Optional
6868

6969
- `allow_insecure_https` (Boolean) Flag to set whether to allow https with invalid certificates. Can be set via the `NETBOX_ALLOW_INSECURE_HTTPS` environment variable. Defaults to `false`.
70+
- `ca_cert_file` (String) Path to a PEM-encoded CA certificate for verifying the Netbox server certificate. Can be set via the `NETBOX_CA_CERT_FILE` environment variable.
7071
- `default_tags` (Set of String) Tags to add to every resource managed by this provider.
7172
- `headers` (Map of String) Set these header on all requests to Netbox. Can be set via the `NETBOX_HEADERS` environment variable.
7273
- `request_timeout` (Number) Netbox API HTTP request timeout in seconds. Can be set via the `NETBOX_REQUEST_TIMEOUT` environment variable.

netbox/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Config struct {
1919
Headers map[string]interface{}
2020
RequestTimeout int
2121
StripTrailingSlashesFromURL bool
22+
CACertFile string
2223
}
2324

2425
// customHeaderTransport is a transport that adds the specified headers on
@@ -52,6 +53,7 @@ func (cfg *Config) Client() (*netboxclient.NetBoxAPI, error) {
5253

5354
// build http client
5455
clientOpts := httptransport.TLSClientOptions{
56+
CA: cfg.CACertFile,
5557
InsecureSkipVerify: cfg.AllowInsecureHTTPS,
5658
}
5759

netbox/provider.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ func Provider() *schema.Provider {
263263
Optional: true,
264264
Description: "Tags to add to every resource managed by this provider",
265265
},
266+
"ca_cert_file": {
267+
Type: schema.TypeString,
268+
Optional: true,
269+
DefaultFunc: schema.EnvDefaultFunc("NETBOX_CA_CERT_FILE", nil),
270+
Description: "Path to a PEM-encoded CA certificate for verifying the Netbox server certificate. Can be set via the `NETBOX_CA_CERT_FILE` environment variable.",
271+
},
266272
},
267273
ConfigureContextFunc: providerConfigure,
268274
}
@@ -291,6 +297,7 @@ func providerConfigure(ctx context.Context, data *schema.ResourceData) (interfac
291297
Headers: data.Get("headers").(map[string]interface{}),
292298
RequestTimeout: data.Get("request_timeout").(int),
293299
StripTrailingSlashesFromURL: data.Get("strip_trailing_slashes_from_url").(bool),
300+
CACertFile: data.Get("ca_cert_file").(string),
294301
}
295302

296303
serverURL := data.Get("server_url").(string)

0 commit comments

Comments
 (0)