Documentation
¶
Overview ¶
Package tfconv provides Terraform schema format conversion.
Example ¶
package main import ( "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/nitrado/tfconv" ) func main() { type TestObject struct { Test string `json:"test"` } testSchema := map[string]*schema.Schema{ "test": { Type: schema.TypeString, }, } conv := tfconv.New("json") // This would be used in the Resource read functions. in := TestObject{ Test: "Hello, World!", } data, err := conv.Flatten(in, testSchema) if err != nil { panic(err) } // This would be used in the Resource write functions. var out TestObject if err = conv.Expand(data, &out); err != nil { panic(err) } fmt.Printf("%v", out) }
Output: {Hello, World!}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Converter ¶
type Converter struct {
// contains filtered or unexported fields
}
Converter converts Terraform formatted data to and from object types.
func NewWithName ¶ added in v1.2.1
NewWithName returns a new converter with the give nameFn.
func (*Converter) Flatten ¶
Flatten converts an object into a Terraform data structure using its schema.
func (*Converter) Register ¶
func (c *Converter) Register(v any, expand, flatten ConverterFn)
Register registers a custom type conversion.
type ConverterFn ¶
ConverterFn is a function that can convert a value.
Click to show internal directories.
Click to hide internal directories.