Skip to content
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

add attr.ObjectType #44

Merged
merged 1 commit into from
Jun 8, 2021
Merged

add attr.ObjectType #44

merged 1 commit into from
Jun 8, 2021

Conversation

kmoe
Copy link
Member

@kmoe kmoe commented Jun 7, 2021

Adds the ObjectType interface, needed for reflection work.

The AttributeTypes() function could also be called GetAttributeTypes() - I've tried to make it consistent with Type.TerraformType().

Will add changelog entry when approved.

@kmoe kmoe requested a review from paddycarver June 7, 2021 13:39
Copy link
Contributor

@paddycarver paddycarver left a comment

Choose a reason for hiding this comment

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

One minor comment, but LGTM. 🚀

attr/type.go Outdated Show resolved Hide resolved
attr/type.go Outdated Show resolved Hide resolved
@kmoe
Copy link
Member Author

kmoe commented Jun 8, 2021

Thanks for highlighting the additional types added in #41 - since these will be used in a number of open PRs I think it's best to have the conversation here.

New proposal is to use naming consistent with the other types in types.go, i.e. TypeWith*. I think this is explicit; although it is unfortunate that a type called TypeWithAttributeTypes must have a method WithAttributeTypes, it shouldn't mean we have to read a stutter anywhere.

The versions proposed in #41 have the advantage of brevity but I think a method name of WithElementsTypes is inherently confusing.

@kmoe kmoe requested a review from paddycarver June 8, 2021 09:15
Copy link
Contributor

@paddycarver paddycarver left a comment

Choose a reason for hiding this comment

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

Yeah, I like where this landed.

@kmoe kmoe merged commit fefe01c into main Jun 8, 2021
@kmoe kmoe deleted the attr-objecttype branch June 8, 2021 09:53
paddycarver added a commit that referenced this pull request Jun 8, 2021
Reflection has A Problem:

We want to support using `attr.Value`s inside of structs, slices, etc.
and just having the reflection package Do The Right Thing. This means
the reflection package needs to be able to create them.

We originally solved that in #30 by just instantiating empty values of
their type, and then calling a `SetTerraformValue` method on that value.
This was super annoying, because then we needed two methods for getting
an `attr.Value` set to the right values: `attr.Type.ValueFromTerraform`
and `attr.Value.SetTerraformValue` were basically the same thing. But
whatever, it worked.

Except, no it didn't.

Complex types like lists and maps store their element/attribute types as
properties on their structs. It's important that these be set. Only the
`attr.Type` has this information, it's not passed in as part of the
`tftypes.Value`. So reflect couldn't set those values, and produced
broken `attr.Value`s as a result. (Their `ToTerraformValue` methods
would run into trouble, because they wouldn't know what `tftypes.Type`
to use for elements or attributes).

To solve this problem, we decided to supply the `attr.Type` from the
schema to the reflect package, wiring it through so that we could
instantiate new `attr.Value`s when the opportunity presented itself.

This solves our problem, because we got rid of the
`attr.Value.SetTerraformValue` method and used the
`attr.Type.ValueFromTerraform` directly to just instantiate a new value,
which made sure it was set up correctly. But now we have a new problem:
what if the `attr.Type` in the schema doesn't produce the `attr.Value`
they're trying to assign to? We decided to just throw an error on that
one, because there's no reasonable way around it.

Depends on #44.
paddycarver added a commit that referenced this pull request Jun 8, 2021
Reflection has A Problem:

We want to support using `attr.Value`s inside of structs, slices, etc.
and just having the reflection package Do The Right Thing. This means
the reflection package needs to be able to create them.

We originally solved that in #30 by just instantiating empty values of
their type, and then calling a `SetTerraformValue` method on that value.
This was super annoying, because then we needed two methods for getting
an `attr.Value` set to the right values: `attr.Type.ValueFromTerraform`
and `attr.Value.SetTerraformValue` were basically the same thing. But
whatever, it worked.

Except, no it didn't.

Complex types like lists and maps store their element/attribute types as
properties on their structs. It's important that these be set. Only the
`attr.Type` has this information, it's not passed in as part of the
`tftypes.Value`. So reflect couldn't set those values, and produced
broken `attr.Value`s as a result. (Their `ToTerraformValue` methods
would run into trouble, because they wouldn't know what `tftypes.Type`
to use for elements or attributes).

To solve this problem, we decided to supply the `attr.Type` from the
schema to the reflect package, wiring it through so that we could
instantiate new `attr.Value`s when the opportunity presented itself.

This solves our problem, because we got rid of the
`attr.Value.SetTerraformValue` method and used the
`attr.Type.ValueFromTerraform` directly to just instantiate a new value,
which made sure it was set up correctly. But now we have a new problem:
what if the `attr.Type` in the schema doesn't produce the `attr.Value`
they're trying to assign to? We decided to just throw an error on that
one, because there's no reasonable way around it.

Depends on #44.
kmoe added a commit that referenced this pull request Jun 11, 2021
paddycarver pushed a commit that referenced this pull request Jun 12, 2021
* Add changelog entry for #44

* Add changelog entry for #46
@github-actions
Copy link

github-actions bot commented Jul 9, 2021

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 Jul 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants