tfconv

package module
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2025 License: MIT Imports: 6 Imported by: 0

README

Terraform Converter

tfconv provides Terraform Resource data conversion and Terraform schema generation, helping to easy the burden of creating Terraform Providers.

Overview

Install with:

go get github.com/nitrado/tfconv

Usage

Examples can be found in the godoc.

License

Copyright 2023 marbis GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files ( the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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 New

func New(tag string) *Converter

New returns a new converter.

func NewWithName added in v1.2.1

func NewWithName(nameFn NameFunc, tag string) *Converter

NewWithName returns a new converter with the give nameFn.

func (*Converter) Expand

func (c *Converter) Expand(v, obj any) error

Expand converts Terraform-formatted data into the given object.

func (*Converter) Flatten

func (c *Converter) Flatten(obj any, s map[string]*schema.Schema) (any, error)

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

type ConverterFn func(v any) (any, error)

ConverterFn is a function that can convert a value.

type NameFunc added in v1.2.1

type NameFunc = func(name string) string

NameFunc is a function used to define a field name.

Directories

Path Synopsis
Package schemagen provides Terraform schema generation.
Package schemagen provides Terraform schema generation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL