Skip to content

Commit

Permalink
Actually return errors which occur (#262)
Browse files Browse the repository at this point in the history
* Actually return errors which occur

* Update changelog

* Regenerate docs?!
  • Loading branch information
tobio authored Feb 1, 2023
1 parent da849cf commit cdfcffb
Show file tree
Hide file tree
Showing 44 changed files with 88 additions and 87 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- Refactor API client functions and return diagnostics ([#220](https://github.com/elastic/terraform-provider-elasticstack/pull/220))
- Fix not to recreate index when field is removed from mapping ([#232](https://github.com/elastic/terraform-provider-elasticstack/pull/232))
- Add query params fields to index resource ([#244](https://github.com/elastic/terraform-provider-elasticstack/pull/244))
- Properly handle errors which occur during provider execution ([#262](https://github.com/elastic/terraform-provider-elasticstack/pull/262))

## [0.5.0] - 2022-12-07

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/elasticsearch_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ resource "elasticstack_elasticsearch_index" "my_index" {
- `mapping_coerce` (Boolean) Set index level coercion setting that is applied to all mapping types.
- `mappings` (String) Mapping for fields in the index.
If specified, this mapping can include: field names, [field data types](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html), [mapping parameters](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-params.html).
**NOTE:**
**NOTE:**
- Changing datatypes in the existing _mappings_ will force index to be re-created.
- Removing field will be ignored by default same as elasticsearch. You need to recreate the index to remove field completely.
- `master_timeout` (String) Period to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error. Defaults to `30s`.
Expand Down
4 changes: 2 additions & 2 deletions internal/clients/elasticsearch/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ func PutSettings(ctx context.Context, apiClient *clients.ApiClient, settings map
var diags diag.Diagnostics
settingsBytes, err := json.Marshal(settings)
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
esClient, err := apiClient.GetESClient()
if err != nil {
return diag.FromErr(err)
}
res, err := esClient.Cluster.PutSettings(bytes.NewReader(settingsBytes), esClient.Cluster.PutSettings.WithContext(ctx))
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
defer res.Body.Close()
if diags := utils.CheckError(res, "Unable to update cluster settings."); diags.HasError() {
Expand Down
6 changes: 3 additions & 3 deletions internal/clients/elasticsearch/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func PutIndex(ctx context.Context, apiClient *clients.ApiClient, index *models.I
opts...,
)
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
defer res.Body.Close()
if diags := utils.CheckError(res, fmt.Sprintf("Unable to create index: %s", index.Name)); diags.HasError() {
Expand Down Expand Up @@ -351,7 +351,7 @@ func UpdateIndexAlias(ctx context.Context, apiClient *clients.ApiClient, index s
var diags diag.Diagnostics
aliasBytes, err := json.Marshal(alias)
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
esClient, err := apiClient.GetESClient()
if err != nil {
Expand All @@ -373,7 +373,7 @@ func UpdateIndexSettings(ctx context.Context, apiClient *clients.ApiClient, inde
var diags diag.Diagnostics
settingsBytes, err := json.Marshal(settings)
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
esClient, err := apiClient.GetESClient()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/elasticsearch/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ func ResourceIndex() *schema.Resource {
"mappings": {
Description: `Mapping for fields in the index.
If specified, this mapping can include: field names, [field data types](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html), [mapping parameters](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-params.html).
**NOTE:**
**NOTE:**
- Changing datatypes in the existing _mappings_ will force index to be re-created.
- Removing field will be ignored by default same as elasticsearch. You need to recreate the index to remove field completely.
`,
Expand Down Expand Up @@ -930,7 +930,7 @@ func resourceIndexRead(ctx context.Context, d *schema.ResourceData, meta interfa
return diags
}
if err := d.Set("alias", aliases); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
}
if index.Mappings != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/elasticsearch/ingest/processor_append_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ func dataSourceProcessorAppendRead(ctx context.Context, d *schema.ResourceData,

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorAppend{"append": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
4 changes: 2 additions & 2 deletions internal/elasticsearch/ingest/processor_bytes_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ func dataSourceProcessorBytesRead(ctx context.Context, d *schema.ResourceData, m

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorBytes{"bytes": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
4 changes: 2 additions & 2 deletions internal/elasticsearch/ingest/processor_circle_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ func dataSourceProcessorCircleRead(ctx context.Context, d *schema.ResourceData,

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorCircle{"circle": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ func dataSourceProcessorCommunityIdRead(ctx context.Context, d *schema.ResourceD

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorCommunityId{"community_id": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ func dataSourceProcessorConvertRead(ctx context.Context, d *schema.ResourceData,

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorConvert{"convert": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
4 changes: 2 additions & 2 deletions internal/elasticsearch/ingest/processor_csv_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ func dataSourceProcessorCSVRead(ctx context.Context, d *schema.ResourceData, met

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorCSV{"csv": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
4 changes: 2 additions & 2 deletions internal/elasticsearch/ingest/processor_date_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ func dataSourceProcessorDateRead(ctx context.Context, d *schema.ResourceData, me

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorDate{"date": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ func dataSourceProcessorDateIndexNameRead(ctx context.Context, d *schema.Resourc

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorDateIndexName{"date_index_name": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ func dataSourceProcessorDissectRead(ctx context.Context, d *schema.ResourceData,

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorDissect{"dissect": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ func dataSourceProcessorDotExpanderRead(ctx context.Context, d *schema.ResourceD

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorDotExpander{"dot_expander": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
4 changes: 2 additions & 2 deletions internal/elasticsearch/ingest/processor_drop_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ func dataSourceProcessorDropRead(ctx context.Context, d *schema.ResourceData, me

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorDrop{"drop": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
4 changes: 2 additions & 2 deletions internal/elasticsearch/ingest/processor_enrich_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ func dataSourceProcessorEnrichRead(ctx context.Context, d *schema.ResourceData,

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorEnrich{"enrich": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
4 changes: 2 additions & 2 deletions internal/elasticsearch/ingest/processor_fail_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ func dataSourceProcessorFailRead(ctx context.Context, d *schema.ResourceData, me

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorFail{"fail": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ func dataSourceProcessorFingerprintRead(ctx context.Context, d *schema.ResourceD

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorFingerprint{"fingerprint": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ func dataSourceProcessorForeachRead(ctx context.Context, d *schema.ResourceData,

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorForeach{"foreach": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
4 changes: 2 additions & 2 deletions internal/elasticsearch/ingest/processor_geoip_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ func dataSourceProcessorGeoipRead(ctx context.Context, d *schema.ResourceData, m

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorGeoip{"geoip": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
4 changes: 2 additions & 2 deletions internal/elasticsearch/ingest/processor_grok_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ func dataSourceProcessorGrokRead(ctx context.Context, d *schema.ResourceData, me

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorGrok{"grok": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
4 changes: 2 additions & 2 deletions internal/elasticsearch/ingest/processor_gsub_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ func dataSourceProcessorGsubRead(ctx context.Context, d *schema.ResourceData, me

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorGsub{"gsub": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ func dataSourceProcessorHtmlStripRead(ctx context.Context, d *schema.ResourceDat

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorHtmlStrip{"html_strip": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
4 changes: 2 additions & 2 deletions internal/elasticsearch/ingest/processor_join_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ func dataSourceProcessorJoinRead(ctx context.Context, d *schema.ResourceData, me

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorJoin{"join": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
4 changes: 2 additions & 2 deletions internal/elasticsearch/ingest/processor_json_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ func dataSourceProcessorJsonRead(ctx context.Context, d *schema.ResourceData, me

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorJson{"json": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
4 changes: 2 additions & 2 deletions internal/elasticsearch/ingest/processor_kv_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ func dataSourceProcessorKVRead(ctx context.Context, d *schema.ResourceData, meta

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorKV{"kv": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ func dataSourceProcessorLowercaseRead(ctx context.Context, d *schema.ResourceDat

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorLowercase{"lowercase": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ func dataSourceProcessorNetworkDirectionRead(ctx context.Context, d *schema.Reso

processorJson, err := json.MarshalIndent(map[string]*models.ProcessorNetworkDirection{"network_direction": processor}, "", " ")
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
if err := d.Set("json", string(processorJson)); err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}

hash, err := utils.StringToHash(string(processorJson))
Expand Down
Loading

0 comments on commit cdfcffb

Please sign in to comment.