-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
SDK: Strongly-Typed Data Sources & Resources #9421
Conversation
Co-authored-by: Matthew Frahry <[email protected]>
…n package Co-authored-by: Matthew Frahry <[email protected]>
Co-authored-by: Matthew Frahry <[email protected]>
This commit introduces support for strongly-typed Data Sources and Resources. Ultimately this allows us to use native Go objects rather than `d.Get` and `d.Set` to parse values from/back to the State. This also allows the Data Sources and Resources themselves to become Typed - meaning we can lean more heavily on the compiler and unit tests to catch errors. Co-authored-by: Matthew Frahry <[email protected]>
This allows them to be mixed and matched Co-authored-by: Matthew Frahry <[email protected]>
Co-authored-by: Matthew Frahry <[email protected]>
Co-authored-by: Matthew Frahry <[email protected]>
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.
Hi @tombuildsstuff / @mbfrahry - Couple really minor comments, but otherwise LGTM 👍
This has been released in version 2.38.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example: provider "azurerm" {
version = "~> 2.38.0"
}
# ... other configuration ... |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks! |
This PR introduces an SDK for strongly-typed Data Sources and Resources - allowing the use of native Go types for creating Terraform Resources.
A quick note to passers-by: this is more of a prototype than ready for production usage, but will likely form the foundation for Terraform Resources going forward.
There's several components to this Pull Request:
Introduction of "Typed" Data Sources and Resources
interface{}
in favour of typed objects - meaning we can rely on higher-level types rather than casting in every resource.Introduction of Encode and Decode functions - to enable encoding/decoding values from the Terraform State from/to a native Go struct
hcl
tags to be defined twice (in the schema and the Go struct) - rather than 5/6 times at present (one time per schema, and once per CRUD method)hcl
values in the struct tags exist in the schemaFixing up the Provider Registration and associated Tooling to support both Typed (new) and Untyped (existing) resources
Notably the Typed Resources which are being introduced enable falling back to mutating
ResourceData
directly (for example to callHasChanges
in an update function) - so this is a wrapper rather than an outright replacement.For the purposes of completeness I've reimplemented the Resource Group resource using this new SDK (you can find it in the Readme, I've pulled it out of the history) and the tests for that resource pass 👍🏻
As mentioned above, at this point in time this is still a prototype, so whilst there's a bunch of tests there's almost certainly some bugs too - as such new functionality should still be built using the Terraform Plugin SDK directly at this time.
As such whilst we don't plan to accept external PR's using this new SDK at this time - we're hoping to enable doing so in the coming weeks - at the same time we'll look to add more documentation to solve #2688 too.