-
Notifications
You must be signed in to change notification settings - Fork 16
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
Generate custom type and value types and to/from methods for primitives #59
Conversation
… source bool attribute along with To/From method generation
…in schema and models if associated external type is defined
…tions for data source float64, int64, number, and string attributes
…tions for provider and resource bool, float64, int64, number, and string attributes
go.mod
Outdated
@@ -4,7 +4,7 @@ go 1.20 | |||
|
|||
require ( | |||
github.com/google/go-cmp v0.6.0 | |||
github.com/hashicorp/terraform-plugin-codegen-spec v0.1.0 | |||
github.com/hashicorp/terraform-plugin-codegen-spec v0.1.1-0.20231017164028-264c2bd37f5f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be updated to v0.2.0
once hashicorp/terraform-plugin-codegen-spec#55 is merged and the v0.2.0
release is cut.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We chatted about this earlier, but maybe we can wait until codegen-framework
needs a v0.2.0
release and then re-assess how we want to bump codegen-spec
. SHAs are fine I'm sure 🧨
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, we'll stick with using SHAs until we want to release 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, would love to start looking at getting a more comprehensive e2e test once we get the rest of external types implemented 🚀 🚀
func (c CustomBoolType) renderEqual() ([]byte, error) { | ||
var buf bytes.Buffer | ||
|
||
t, err := template.New("").Parse(c.templates["equal"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
template.New("")
curious q: is there a reason to keep the template name empty? I don't fully grasp what it does, but never kept it empty lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a detailed explanation of template naming on an SO post. TLDR: If you don't want/need to refer to the template, the name doesn't really matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome! thanks for sharing 👍🏻
internal/schema/custom_string.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the custom strings have tests as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well spotted. Added
internal/schema/to_from_string.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, does string get tests for this too? 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well spotted. Added
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. |
Closes: #70
This PR extends the generation of custom type and value types for primitives that have an associated external type, and generates the methods for converting to/from the associated external type.
At this point, the implementation only coversBoolAttribute
for data sources, but will be extended to encompass all primitive attributes (Bool, Float64, Int64, Number & String), if we're agreed on the approach.For example, given the following spec:
The generated code is as follows:
Outstanding Tasks
The generation of the schema needs to be modified to use the generated custom type.The generation of the data model needs to be modified to use the generated custom value.GeneratorAttributes
andGeneratorBlocks
(i.e.,AttributeTypes()
/BlockTypes()
,AttrTypes()
,AttrValues()
,FromFuncs()
, andToFuncs()
), with calls that delegate to the individual attribute or block.Dependency