Skip to content

feat: Support merging Object attributes #9

@bbckr

Description

@bbckr

Currently the library only supports merging hcl Blocks and nested Blocks recursively. When it comes to attributes (in setAttrs), this is all or nothing, which means both objects and arrays are replaced entirely w/o attempting to merge.

Attributes are represented as a list of hcl Tokens, so in order to merge attributes, we need to be able to parse the list of Tokens to make sense of the type of value we are dealing with.

Acceptance criteria:

  • Be able to recursively merge nested objects
  • Any MR should have this (or a similar) test case added to hcl_test.go:
	tests := []struct {
		name    string
		input   input
		want    string
		wantErr error
	}{
		{
			name: "merge nested duplicate",
			input: input{
				a: `module "b" {

	c = {
		"foo" = {
			value = 1
		},
	}
}
			`,
				b: `module "b" {

	c = {
		"bar" = {
			value = 2
		},
	}
}
			`,
			},
			want: `module "b" {

	c = {
		"foo" = {
			value = 1
		},
		"bar" = {
			value = 2
		},
	}
}
`,
		},
	}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions