@@ -419,6 +419,7 @@ func resourceElasticsearchIndex() *schema.Resource {
419419 Update : resourceElasticsearchIndexUpdate ,
420420 Delete : resourceElasticsearchIndexDelete ,
421421 Schema : configSchema ,
422+ CustomizeDiff : verifyIndexMappingUpdates ,
422423 Importer : & schema.ResourceImporter {
423424 StateContext : schema .ImportStatePassthroughContext ,
424425 },
@@ -679,25 +680,15 @@ func resourceElasticsearchIndexUpdate(d *schema.ResourceData, meta interface{})
679680 }
680681 }
681682
682- o , n := d .GetChange ("mappings" )
683- difference , _ := jsondiff .Compare ([]byte (n .(string )), []byte (o .(string )), & jsondiff.Options {})
684-
685- // if we're not changing any settings, no-op this function
686- if len (settings ) == 0 && difference == jsondiff .FullMatch {
687- return resourceElasticsearchIndexRead (d , meta )
688- }
689-
690683 if len (settings ) != 0 {
691684 err = updateIndexSettings (d , meta , settings )
692685 }
693686 if err != nil {
694687 return err
695688 }
696689
697- if difference == jsondiff .SupersetMatch {
698- err = updateIndexMappings (d , meta , n .(string ))
699- }
700- if err != nil {
690+ mappings := d .Get ("mappings" )
691+ if err = updateIndexMappings (d , meta , mappings .(string )); err != nil {
701692 return err
702693 }
703694
@@ -758,6 +749,15 @@ func updateIndexMappings(d *schema.ResourceData, meta interface{}, mapping strin
758749 return err
759750}
760751
752+ func verifyIndexMappingUpdates (ctx context.Context , resourceDiff * schema.ResourceDiff , meta interface {}) error {
753+ oldMapping , newMapping := resourceDiff .GetChange ("mappings" )
754+ difference , _ := jsondiff .Compare ([]byte (newMapping .(string )), []byte (oldMapping .(string )), & jsondiff.Options {})
755+ if difference == jsondiff .NoMatch {
756+ return resourceDiff .ForceNew ("mappings" )
757+ }
758+ return nil
759+ }
760+
761761func getWriteIndexByAlias (alias string , d * schema.ResourceData , meta interface {}) string {
762762 var (
763763 index = d .Id ()
0 commit comments