Skip to content

Commit cb4371a

Browse files
committed
[opendistro ism] Add support for opensearch.
1 parent a95114d commit cb4371a

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

es/resource_elasticsearch_opendistro_ism_policy_mapping.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ func resourceElasticsearchOpendistroPolicyIndices(indexPattern string, policyID
127127
p, ok := parameters.(map[string]interface{})
128128
if ok && p["index.opendistro.index_state_management.policy_id"] == policyID {
129129
mappedIndexes = append(mappedIndexes, indexName)
130+
} else if ok && p["index.plugins.index_state_management.policy_id"] == policyID {
131+
mappedIndexes = append(mappedIndexes, indexName)
130132
}
131133
}
132134

@@ -239,7 +241,7 @@ func resourceElasticsearchPostOpendistroPolicyMapping(d *schema.ResourceData, m
239241
Body: requestBody,
240242
})
241243
if err != nil {
242-
return response, fmt.Errorf("error posting policy attachement: %+v : %+v : %+v", path, requestBody, err)
244+
return response, fmt.Errorf("error posting policy attachment: %+v : %+v : %+v", path, requestBody, err)
243245
}
244246
body = &res.Body
245247
default:
@@ -279,7 +281,7 @@ func resourceElasticsearchGetOpendistroPolicyMapping(indexPattern string, m inte
279281
Path: path,
280282
})
281283
if err != nil {
282-
return *response, fmt.Errorf("error getting policy attachement: %+v : %+v", path, err)
284+
return *response, fmt.Errorf("error getting policy attachment: %+v, %w", path, err)
283285
}
284286
body = &res.Body
285287
default:

es/resource_elasticsearch_opendistro_ism_policy_mapping_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package es
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"testing"
78

@@ -113,6 +114,8 @@ func indicesMappedToPolicy(policy string) ([]string, error) {
113114
p, ok := parameters.(map[string]interface{})
114115
if ok && p["index.opendistro.index_state_management.policy_id"] == policy {
115116
mappedIndices = append(mappedIndices, indexName)
117+
} else if ok && p["index.plugins.index_state_management.policy_id"] == policy {
118+
mappedIndices = append(mappedIndices, indexName)
116119
}
117120
}
118121
return mappedIndices, nil
@@ -126,6 +129,14 @@ func testCheckElasticsearchOpenDistroISMPolicyMappingDestroy(s *terraform.State)
126129

127130
mappedIndices, err := indicesMappedToPolicy(rs.Primary.ID)
128131

132+
// if the underlying index is deleted, it triggers a cascading delete for
133+
// the mapping and the mapping explain endpoint returns a 400, so we know
134+
// it's been cleaned up
135+
var e *elastic7.Error
136+
if err != nil && errors.As(err, &e) && e.Status == 400 {
137+
return nil
138+
}
139+
129140
if err != nil {
130141
return err
131142
}

0 commit comments

Comments
 (0)