Skip to content

Commit 2e4482f

Browse files
committed
Only PUT mappings if there is actually a change
1 parent 610907d commit 2e4482f

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

es/resource_elasticsearch_index.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,9 +687,10 @@ func resourceElasticsearchIndexUpdate(d *schema.ResourceData, meta interface{})
687687
return err
688688
}
689689

690-
mappings := d.Get("mappings")
691-
if err = updateIndexMappings(d, meta, mappings.(string)); err != nil {
692-
return err
690+
if d.HasChange("mappings") {
691+
if err = updateIndexMappings(d, meta, d.Get("mappings").(string)); err != nil {
692+
return err
693+
}
693694
}
694695

695696
return resourceElasticsearchIndexRead(d, meta.(*ProviderConf))
@@ -750,9 +751,12 @@ func updateIndexMappings(d *schema.ResourceData, meta interface{}, mapping strin
750751
}
751752

752753
func verifyIndexMappingUpdates(ctx context.Context, resourceDiff *schema.ResourceDiff, meta interface{}) error {
754+
if !resourceDiff.HasChange("mappings") {
755+
return nil
756+
}
753757
oldMapping, newMapping := resourceDiff.GetChange("mappings")
754758
difference, _ := jsondiff.Compare([]byte(newMapping.(string)), []byte(oldMapping.(string)), &jsondiff.Options{})
755-
if difference == jsondiff.NoMatch {
759+
if difference > jsondiff.SupersetMatch {
756760
return resourceDiff.ForceNew("mappings")
757761
}
758762
return nil

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ require (
1818
github.com/olivere/elastic v6.2.26+incompatible
1919
github.com/olivere/elastic/v7 v7.0.32
2020
github.com/onsi/gomega v1.27.1 // indirect
21+
github.com/spf13/viper v1.7.0 // indirect
2122
gopkg.in/olivere/elastic.v6 v6.2.37
2223
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E
846846
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
847847
golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA=
848848
golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
849+
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
849850
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
850851
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
851852
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -961,6 +962,7 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
961962
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
962963
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
963964
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
965+
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
964966
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
965967
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
966968
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)