Skip to content

Commit

Permalink
rename GetIgnoredFields to GetTerraformIgnoreChanges
Browse files Browse the repository at this point in the history
Signed-off-by: lsviben <sviben.lovro@gmail.com>
  • Loading branch information
lsviben committed Jul 28, 2023
1 parent f341367 commit 5d137e6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions pkg/resource/ignored.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import (
"sort"
)

// GetIgnorableFields returns a sorted list of ignorable fields by looking for
// differences between the `initProvider` and `forProvider` maps. The ignored
// fields are the ones that are present in initProvider, but not in forProvider.
func GetIgnorableFields(forProvider, initProvider map[string]any) []string {
ignored := []string{}
ignored = append(ignored, getIgnoredFieldsMap("%s", forProvider, initProvider)...)
// GetTerraformIgnoreChanges returns a sorted Terraform `ignore_changes`
// lifecycle meta-argument expression by looking for differences between
// the `initProvider` and `forProvider` maps. The ignored fields are the ones
// that are present in initProvider, but not in forProvider.
func GetTerraformIgnoreChanges(forProvider, initProvider map[string]any) []string {
ignored := getIgnoredFieldsMap("%s", forProvider, initProvider)
// sort the ignored fields so that we can compare them easily
sort.Strings(ignored)
return ignored
}

func getIgnoredFieldsMap(format string, forProvider, initProvider map[string]any) []string {
var ignored []string
ignored := []string{}

for k := range initProvider {
if _, ok := forProvider[k]; !ok {
Expand Down
2 changes: 1 addition & 1 deletion pkg/resource/ignored_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func TestGetIgnoredFields(t *testing.T) {
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
got := GetIgnorableFields(tc.args.forProvider, tc.args.initProvider)
got := GetTerraformIgnoreChanges(tc.args.forProvider, tc.args.initProvider)
if diff := cmp.Diff(tc.want.ignored, got); diff != "" {
t.Errorf("GetIgnorableFields() got = %v, want %v", got, tc.want.ignored)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/terraform/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func NewFileProducer(ctx context.Context, client resource.SecretClient, dir stri
}

// get fields which should be in the ignore_changes lifecycle block
fp.ignored = resource.GetIgnorableFields(params, initParams)
fp.ignored = resource.GetTerraformIgnoreChanges(params, initParams)

// TODO(lsviben): Currently initProvider fields override forProvider
// fields if set. It should be the other way around.
Expand Down

0 comments on commit 5d137e6

Please sign in to comment.