@@ -11,6 +11,7 @@ import (
1111
1212	"github.com/elastic/go-elasticsearch/v8" 
1313	fwdiags "github.com/hashicorp/terraform-plugin-framework/diag" 
14+ 	"github.com/hashicorp/terraform-plugin-framework/types/basetypes" 
1415	sdkdiags "github.com/hashicorp/terraform-plugin-sdk/v2/diag" 
1516	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging" 
1617	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 
@@ -43,15 +44,10 @@ func newElasticsearchConfigFromSDK(d *schema.ResourceData, base baseConfig, key
4344			config .config .Addresses  =  addrs 
4445		}
4546
46- 		if  headers , ok  :=  esConfig ["headers" ]; ok  &&  len (headers .([]interface {})) >  0  {
47- 			var  header_values  []string 
48- 			for  _ , e  :=  range  headers .([]interface {}) {
49- 				header_values  =  append (header_values , e .(string ))
50- 			}
51- 
52- 			for  _ , header  :=  range  header_values  {
53- 				headerParts  :=  strings .Split (header , ":" )
54- 				config .config .Header .Add (strings .TrimSpace (headerParts [0 ]), strings .TrimSpace (headerParts [1 ]))
47+ 		if  headers , ok  :=  esConfig ["headers" ]; ok  &&  len (headers .(map [string ]interface {})) >  0  {
48+ 			headersMap  :=  headers .(map [string ]interface {})
49+ 			for  header , value  :=  range  headersMap  {
50+ 				config .config .Header .Add (strings .TrimSpace (header ), strings .TrimSpace (value .(string )))
5551			}
5652		}
5753
@@ -157,22 +153,10 @@ func newElasticsearchConfigFromFramework(ctx context.Context, cfg ProviderConfig
157153		config .config .Addresses  =  endpoints 
158154	}
159155
160- 	var  headers  []string 
161- 	headerDiags  :=  esConfig .Headers .ElementsAs (ctx , & headers , true )
162- 	if  headerDiags .HasError () {
163- 		return  nil , diags 
164- 	}
165- 
166- 	if  len (headers ) >  0  {
167- 		for  _ , header  :=  range  headers  {
168- 			headerParts  :=  strings .Split (header , ":" )
169- 			if  len (headerParts ) !=  2  {
170- 				diags .Append (fwdiags .NewErrorDiagnostic ("Invalid header format" , "Headers must be in the format 'key:value'" ))
171- 				return  nil , diags 
172- 			}
173- 			// trim the strings to remove any leading/trailing whitespace 
174- 			config .config .Header .Add (strings .TrimSpace (headerParts [0 ]), strings .TrimSpace (headerParts [1 ]))
175- 		}
156+ 	for  header , value  :=  range  esConfig .Headers .Elements () {
157+ 		strValue  :=  value .(basetypes.StringValue )
158+ 		// trim the strings to remove any leading/trailing whitespace 
159+ 		config .config .Header .Add (strings .TrimSpace (header ), strings .TrimSpace (strValue .ValueString ()))
176160	}
177161
178162	if  esConfig .BearerToken .ValueString () !=  ""  {
0 commit comments