Skip to content

Commit a5d7657

Browse files
authored
Merge pull request #35 from utilitynerd/custom-ca
add "ca_file" option to the elasticstack provider
2 parents 4ff16d8 + 8956b80 commit a5d7657

13 files changed

+41
-0
lines changed

docs/data-sources/elasticsearch_security_user.md

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ output "user" {
5151

5252
Optional:
5353

54+
- **ca_file** (String) Path to a custom Certificate Authority certificate
5455
- **endpoints** (List of String, Sensitive) A list of endpoints the Terraform provider will point to. They must include the http(s) schema and port number.
5556
- **insecure** (Boolean) Disable TLS certificate validation
5657
- **password** (String, Sensitive) A password to use for API authentication to Elasticsearch.

docs/data-sources/elasticsearch_snapshot_repository.md

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ output "repo_url" {
7979

8080
Optional:
8181

82+
- **ca_file** (String) Path to a custom Certificate Authority certificate
8283
- **endpoints** (List of String, Sensitive) A list of endpoints the Terraform provider will point to. They must include the http(s) schema and port number.
8384
- **insecure** (Boolean) Disable TLS certificate validation
8485
- **password** (String, Sensitive) A password to use for API authentication to Elasticsearch.

docs/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ provider "elasticstack" {
8080

8181
Optional:
8282

83+
- **ca_file** (String) Path to a custom Certificate Authority certificate
8384
- **endpoints** (List of String, Sensitive) A comma-separated list of endpoints where the terraform provider will point to, this must include the http(s) schema and port number.
8485
- **insecure** (Boolean) Disable TLS certificate validation
8586
- **password** (String, Sensitive) Password to use for API authentication to Elasticsearch.

docs/resources/elasticsearch_cluster_settings.md

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ resource "elasticstack_elasticsearch_cluster_settings" "my_cluster_settings" {
6161

6262
Optional:
6363

64+
- **ca_file** (String) Path to a custom Certificate Authority certificate
6465
- **endpoints** (List of String, Sensitive) A list of endpoints the Terraform provider will point to. They must include the http(s) schema and port number.
6566
- **insecure** (Boolean) Disable TLS certificate validation
6667
- **password** (String, Sensitive) A password to use for API authentication to Elasticsearch.

docs/resources/elasticsearch_index_lifecycle.md

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ Required:
169169

170170
Optional:
171171

172+
- **ca_file** (String) Path to a custom Certificate Authority certificate
172173
- **endpoints** (List of String, Sensitive) A list of endpoints the Terraform provider will point to. They must include the http(s) schema and port number.
173174
- **insecure** (Boolean) Disable TLS certificate validation
174175
- **password** (String, Sensitive) A password to use for API authentication to Elasticsearch.

docs/resources/elasticsearch_index_template.md

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Optional:
7474

7575
Optional:
7676

77+
- **ca_file** (String) Path to a custom Certificate Authority certificate
7778
- **endpoints** (List of String, Sensitive) A list of endpoints the Terraform provider will point to. They must include the http(s) schema and port number.
7879
- **insecure** (Boolean) Disable TLS certificate validation
7980
- **password** (String, Sensitive) A password to use for API authentication to Elasticsearch.

docs/resources/elasticsearch_security_role.md

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Required:
7777

7878
Optional:
7979

80+
- **ca_file** (String) Path to a custom Certificate Authority certificate
8081
- **endpoints** (List of String, Sensitive) A list of endpoints the Terraform provider will point to. They must include the http(s) schema and port number.
8182
- **insecure** (Boolean) Disable TLS certificate validation
8283
- **password** (String, Sensitive) A password to use for API authentication to Elasticsearch.

docs/resources/elasticsearch_security_user.md

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ resource "elasticstack_elasticsearch_security_user" "dev" {
7777

7878
Optional:
7979

80+
- **ca_file** (String) Path to a custom Certificate Authority certificate
8081
- **endpoints** (List of String, Sensitive) A list of endpoints the Terraform provider will point to. They must include the http(s) schema and port number.
8182
- **insecure** (Boolean) Disable TLS certificate validation
8283
- **password** (String, Sensitive) A password to use for API authentication to Elasticsearch.

docs/resources/elasticsearch_snapshot_lifecycle.md

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ resource "elasticstack_elasticsearch_snapshot_lifecycle" "slm_policy" {
7676

7777
Optional:
7878

79+
- **ca_file** (String) Path to a custom Certificate Authority certificate
7980
- **endpoints** (List of String, Sensitive) A list of endpoints the Terraform provider will point to. They must include the http(s) schema and port number.
8081
- **insecure** (Boolean) Disable TLS certificate validation
8182
- **password** (String, Sensitive) A password to use for API authentication to Elasticsearch.

docs/resources/elasticsearch_snapshot_repository.md

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Optional:
7979

8080
Optional:
8181

82+
- **ca_file** (String) Path to a custom Certificate Authority certificate
8283
- **endpoints** (List of String, Sensitive) A list of endpoints the Terraform provider will point to. They must include the http(s) schema and port number.
8384
- **insecure** (Boolean) Disable TLS certificate validation
8485
- **password** (String, Sensitive) A password to use for API authentication to Elasticsearch.

internal/clients/api_client.go

+21
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"crypto/tls"
77
"encoding/json"
88
"fmt"
9+
"io/ioutil"
910
"log"
1011
"net/http"
1112
"os"
@@ -89,6 +90,19 @@ func NewApiClientFunc(version string, p *schema.Provider) func(context.Context,
8990
tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
9091
config.Transport = tr
9192
}
93+
94+
if caFile, ok := esConfig["ca_file"]; ok && caFile.(string) != "" {
95+
caCert, err := ioutil.ReadFile(caFile.(string))
96+
if err != nil {
97+
diags = append(diags, diag.Diagnostic{
98+
Severity: diag.Error,
99+
Summary: "Unable to read CA File",
100+
Detail: err.Error(),
101+
})
102+
return nil, diags
103+
}
104+
config.CACert = caCert
105+
}
92106
}
93107
}
94108

@@ -133,6 +147,13 @@ func NewApiClient(d *schema.ResourceData, meta interface{}) (*ApiClient, error)
133147
tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
134148
config.Transport = tr
135149
}
150+
if caFile, ok := conn["ca_file"]; ok && caFile.(string) != "" {
151+
caCert, err := ioutil.ReadFile(caFile.(string))
152+
if err != nil {
153+
return nil, fmt.Errorf("Unable to read ca_file: %w", err)
154+
}
155+
config.CACert = caCert
156+
}
136157

137158
es, err := elasticsearch.NewClient(config)
138159
if err != nil {

internal/provider/provider.go

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ func New(version string) func() *schema.Provider {
5454
Optional: true,
5555
Default: false,
5656
},
57+
"ca_file": {
58+
Description: "Path to a custom Certificate Authority certificate",
59+
Type: schema.TypeString,
60+
Optional: true,
61+
},
5762
},
5863
},
5964
},

internal/utils/utils.go

+5
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ func AddConnectionSchema(providedSchema map[string]*schema.Schema) {
151151
Optional: true,
152152
Default: false,
153153
},
154+
"ca_file": {
155+
Description: "Path to a custom Certificate Authority certificate",
156+
Type: schema.TypeString,
157+
Optional: true,
158+
},
154159
},
155160
},
156161
}

0 commit comments

Comments
 (0)