@@ -419,7 +419,7 @@ func resourceElasticsearchIndex() *schema.Resource {
419419 Update : resourceElasticsearchIndexUpdate ,
420420 Delete : resourceElasticsearchIndexDelete ,
421421 Schema : configSchema ,
422- CustomizeDiff : verifyIndexMappingUpdates ,
422+ CustomizeDiff : verifyIndexMappingUpdates ,
423423 Importer : & schema.ResourceImporter {
424424 StateContext : schema .ImportStatePassthroughContext ,
425425 },
@@ -671,91 +671,91 @@ func allowIndexDestroy(indexName string, d *schema.ResourceData, meta interface{
671671}
672672
673673func resourceElasticsearchIndexUpdate (d * schema.ResourceData , meta interface {}) error {
674- var err error
675- settings := make (map [string ]interface {})
676- for _ , key := range settingsKeys {
677- schemaName := strings .Replace (key , "." , "_" , - 1 )
678- if d .HasChange (schemaName ) {
679- settings [key ] = d .Get (schemaName )
680- }
681- }
682-
683- if len (settings ) != 0 {
684- err = updateIndexSettings (d , meta , settings )
685- }
686- if err != nil {
687- return err
688- }
689-
690- mappings := d .Get ("mappings" )
691- if err = updateIndexMappings (d , meta , mappings .(string )); err != nil {
692- return err
693- }
694-
695- return resourceElasticsearchIndexRead (d , meta .(* ProviderConf ))
674+ var err error
675+ settings := make (map [string ]interface {})
676+ for _ , key := range settingsKeys {
677+ schemaName := strings .Replace (key , "." , "_" , - 1 )
678+ if d .HasChange (schemaName ) {
679+ settings [key ] = d .Get (schemaName )
680+ }
681+ }
682+
683+ if len (settings ) != 0 {
684+ err = updateIndexSettings (d , meta , settings )
685+ }
686+ if err != nil {
687+ return err
688+ }
689+
690+ mappings := d .Get ("mappings" )
691+ if err = updateIndexMappings (d , meta , mappings .(string )); err != nil {
692+ return err
693+ }
694+
695+ return resourceElasticsearchIndexRead (d , meta .(* ProviderConf ))
696696}
697697
698698func updateIndexSettings (d * schema.ResourceData , meta interface {}, settings map [string ]interface {}) error {
699- body := map [string ]interface {}{
700- // Note you do not have to explicitly specify the `index` section inside
701- // the `settings` section
702- "settings" : settings ,
703- }
704-
705- var (
706- name = d .Id ()
707- ctx = context .Background ()
708- err error
709- )
710-
711- if alias , ok := d .GetOk ("rollover_alias" ); ok {
712- name = getWriteIndexByAlias (alias .(string ), d , meta )
713- }
714-
715- esClient , err := getClient (meta .(* ProviderConf ))
716- if err != nil {
717- return err
718- }
719- switch client := esClient .(type ) {
720- case * elastic7.Client :
721- _ , err = client .IndexPutSettings (name ).BodyJson (body ).Do (ctx )
722- case * elastic6.Client :
723- _ , err = client .IndexPutSettings (name ).BodyJson (body ).Do (ctx )
724- default :
725- return errors .New ("Elasticsearch version not supported" )
726- }
727- return err
699+ body := map [string ]interface {}{
700+ // Note you do not have to explicitly specify the `index` section inside
701+ // the `settings` section
702+ "settings" : settings ,
703+ }
704+
705+ var (
706+ name = d .Id ()
707+ ctx = context .Background ()
708+ err error
709+ )
710+
711+ if alias , ok := d .GetOk ("rollover_alias" ); ok {
712+ name = getWriteIndexByAlias (alias .(string ), d , meta )
713+ }
714+
715+ esClient , err := getClient (meta .(* ProviderConf ))
716+ if err != nil {
717+ return err
718+ }
719+ switch client := esClient .(type ) {
720+ case * elastic7.Client :
721+ _ , err = client .IndexPutSettings (name ).BodyJson (body ).Do (ctx )
722+ case * elastic6.Client :
723+ _ , err = client .IndexPutSettings (name ).BodyJson (body ).Do (ctx )
724+ default :
725+ return errors .New ("Elasticsearch version not supported" )
726+ }
727+ return err
728728}
729729
730730func updateIndexMappings (d * schema.ResourceData , meta interface {}, mapping string ) error {
731- var (
732- name = d .Id ()
733- ctx = context .Background ()
734- err error
735- )
736- esClient , err := getClient (meta .(* ProviderConf ))
737- if err != nil {
738- return err
739- }
740- switch client := esClient .(type ) {
741- case * elastic7.Client :
742- _ , err = client .PutMapping ().Index (name ).BodyString (mapping ).Do (ctx )
743- case * elastic6.Client :
744- _ , err = client .PutMapping ().Index (name ).BodyString (mapping ).Do (ctx )
745- default :
746- return errors .New ("Elasticsearch version not supported" )
731+ var (
732+ name = d .Id ()
733+ ctx = context .Background ()
734+ err error
735+ )
736+ esClient , err := getClient (meta .(* ProviderConf ))
737+ if err != nil {
738+ return err
739+ }
740+ switch client := esClient .(type ) {
741+ case * elastic7.Client :
742+ _ , err = client .PutMapping ().Index (name ).BodyString (mapping ).Do (ctx )
743+ case * elastic6.Client :
744+ _ , err = client .PutMapping ().Index (name ).BodyString (mapping ).Do (ctx )
745+ default :
746+ return errors .New ("Elasticsearch version not supported" )
747747}
748748
749- return err
749+ return err
750750}
751751
752752func 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
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
759759}
760760
761761func getWriteIndexByAlias (alias string , d * schema.ResourceData , meta interface {}) string {
0 commit comments