Choosing Your Weapon
If you decide to write a provider today, you must choose between two official Go libraries. This is not a minor stylistic choice — it affects how you model data, handle errors, and reason about null values throughout your entire codebase.
SDKv2 (The Legacy Standard)
SDKv2 has been used to build the massive AWS, Azure, and Google providers for years. It represents the accumulated wisdom of the Terraform ecosystem, but also its accumulated technical debt.
- Style: Relies heavily on Go reflection and untyped maps (
map[string]interface{}). You define your schema as a flat map ofschema.Schemastructs, and data flows throughd *schema.ResourceData— a generic accessor where you calld.Get("name").(string)and hope the type assertion is correct. - Null vs. Unknown: SDKv2 conflates
null(attribute not set) andunknown(value computed at apply time) into a single zero value. This causes subtle bugs when dealing with optional attributes. - Pros: Battle-tested, thousands of examples, most Stack Overflow answers reference it.
- Cons: Type assertions are messy, the compiler cannot catch schema mismatches, and the
null/unknowndistinction is a persistent source of bugs.
The Terraform Plugin Framework (The Future)
The Plugin Framework was released by HashiCorp to solve SDKv2's pain points from first principles.
- Style: Fully type-safe. You define Go structs that map directly to your Terraform schema using struct tags. The compiler validates that your code handles the data correctly.
- Null vs. Unknown: The Framework uses explicit types —
types.String,types.Bool,types.Int64— each of which can be in one of three states:Null,Unknown, or a concreteValue. You must handle all three states explicitly. - Pros: Compiler catches errors, modern
context.Contextpropagation throughout, cleaner separation of schema definition from business logic. - Cons: Fewer community examples (though the official documentation is excellent and growing fast).
Verdict: Start with the Plugin Framework for any new provider. Use SDKv2 only if you are contributing to an existing provider that has not yet migrated.
A common interview question is: "Why does Terraform distinguish between null and unknown?" The answer: null means the attribute was explicitly not set (or doesn't exist). unknown means the value will exist after apply, but cannot be known during plan — for example, an auto-generated ID from an API. SDKv2 collapses both into a zero value, which causes plan-time errors when you try to use a computed value as input to another resource. The Plugin Framework's explicit type system prevents this entire class of bugs.