Skip to content

New function ValueFrom that takes a Go value and populates a compatible attr.Value, given a descriptive attr.Type #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 30, 2022

Conversation

megan07
Copy link
Contributor

@megan07 megan07 commented May 26, 2022

fixes #323

@detro detro self-assigned this May 26, 2022
@detro
Copy link
Contributor

detro commented May 27, 2022

Testing this locally now

@detro detro force-pushed the megan_value_from branch from 34afab2 to 4ddcc37 Compare May 27, 2022 16:04
@detro detro changed the title add value_from New function ValueFrom that takes a Go value and populates a compatible attr.Value, given a descriptive attr.Type May 27, 2022
@detro detro force-pushed the megan_value_from branch from 4ddcc37 to 6b5910c Compare May 27, 2022 16:05
@detro detro marked this pull request as ready for review May 27, 2022 16:05
@detro detro requested a review from a team as a code owner May 27, 2022 16:05
@detro detro added this to the v0.9.0 milestone May 27, 2022
@detro detro added enhancement New feature or request types Issues and pull requests about our types abstraction and implementations. reflection Issues and PRs about the reflection subsystem used to convert between attr.Values and Go values. labels May 27, 2022
Name types.String `tfsdk:"name"`
Age types.Int64 `tfsdk:"age"`
OptedIn types.Bool `tfsdk:"opted_in"`
Address types.List `tfsdk:"address"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth testing other types (e.g., types.Map), along the lines of

	Address types.Map    `tfsdk:"address"`

Then using the following in personAttrTypes:

		"address": types.MapType{
			ElemType: types.StringType,
		},

Populating mrX with:

		Address: types.Map{
			ElemType: types.StringType,
			Elems: map[string]attr.Value{
				"number": types.String{Value: "1"},
				"street": types.String{Value: "Beckford Close"},
				"town":   types.String{Value: "Gotham"},
			},
		},

And finally testing expectedMrXObj:

			"address": types.Map{
				ElemType: types.StringType,
				Elems: map[string]attr.Value{
					"number": types.String{Value: "1"},
					"street": types.String{Value: "Beckford Close"},
					"town":   types.String{Value: "Gotham"},
				},
			},

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added it ;)

Copy link
Contributor

@bendbennett bendbennett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Just a minor comment.

@detro detro force-pushed the megan_value_from branch from 6b5910c to 2c2622e Compare May 30, 2022 08:41
@detro detro merged commit b097d2f into hashicorp:main May 30, 2022
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request reflection Issues and PRs about the reflection subsystem used to convert between attr.Values and Go values. types Issues and pull requests about our types abstraction and implementations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Have something like ValueFrom as the opposite of ValueAs
3 participants