Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions internal/clients/config/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,24 @@ func newElasticsearchConfigFromFramework(ctx context.Context, cfg ProviderConfig
config.config.Addresses = endpoints
}

var headers []string
headerDiags := esConfig.Headers.ElementsAs(ctx, &headers, true)
if headerDiags.HasError() {
return nil, diags
}

if len(headers) > 0 {
for _, header := range headers {
headerParts := strings.Split(header, ":")
if len(headerParts) != 2 {
diags.Append(fwdiags.NewErrorDiagnostic("Invalid header format", "Headers must be in the format 'key:value'"))
return nil, diags
}
// trim the strings to remove any leading/trailing whitespace
config.config.Header.Add(strings.TrimSpace(headerParts[0]), strings.TrimSpace(headerParts[1]))
}
}

if esConfig.BearerToken.ValueString() != "" {
config.bearerToken = esConfig.BearerToken.ValueString()
if esConfig.ESClientAuthentication.ValueString() != "" {
Expand Down
1 change: 1 addition & 0 deletions internal/clients/config/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type ElasticsearchConnection struct {
BearerToken types.String `tfsdk:"bearer_token"`
ESClientAuthentication types.String `tfsdk:"es_client_authentication"`
Endpoints types.List `tfsdk:"endpoints"`
Headers types.List `tfsdk:"headers"`
Insecure types.Bool `tfsdk:"insecure"`
CAFile types.String `tfsdk:"ca_file"`
CAData types.String `tfsdk:"ca_data"`
Expand Down
15 changes: 15 additions & 0 deletions internal/schema/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ func GetEsFWConnectionBlock(keyName string, isProviderConfiguration bool) fwsche
Sensitive: true,
ElementType: types.StringType,
},
"headers": fwschema.ListAttribute{
MarkdownDescription: "A list of headers to be sent with each request to Elasticsearch.",
Optional: true,
Sensitive: true,
ElementType: types.StringType,
},
"insecure": fwschema.BoolAttribute{
MarkdownDescription: "Disable TLS certificate validation",
Optional: true,
Expand Down Expand Up @@ -311,6 +317,15 @@ func GetEsConnectionSchema(keyName string, isProviderConfiguration bool) *schema
Type: schema.TypeString,
},
},
"headers": {
Description: "A list of headers to be sent with each request to Elasticsearch.",
Type: schema.TypeList,
Optional: true,
Sensitive: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"insecure": {
Description: "Disable TLS certificate validation",
Type: schema.TypeBool,
Expand Down
Loading