1.0.0
This commit is contained in:
19
internal/flattens/flatten_simple_type.go
Normal file
19
internal/flattens/flatten_simple_type.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
)
|
||||
|
||||
// FlattenSimpleTypeToList convert a slice of simple type to a types.List
|
||||
func FlattenSimpleTypeToList(ctx context.Context, elementType attr.Type, elements any) types.List {
|
||||
res, diags := types.ListValueFrom(ctx, elementType, elements)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error FlattenSimpleTypeToList", diags))
|
||||
}
|
||||
return res
|
||||
}
|
||||
38
internal/flattens/meta.go
Normal file
38
internal/flattens/meta.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
)
|
||||
|
||||
// Meta flattens []interface{} golang struct to a list of terraform framework types.StringType
|
||||
func Meta(ctx context.Context, m []interface{}) types.List {
|
||||
tflog.Info(ctx, "Start flattenMeta")
|
||||
tempSlice := make([]string, 0, len(m))
|
||||
for _, item := range m {
|
||||
switch d := item.(type) {
|
||||
case string:
|
||||
tempSlice = append(tempSlice, d)
|
||||
case int:
|
||||
tempSlice = append(tempSlice, strconv.Itoa(d))
|
||||
case int64:
|
||||
tempSlice = append(tempSlice, strconv.FormatInt(d, 10))
|
||||
case float64:
|
||||
tempSlice = append(tempSlice, strconv.FormatInt(int64(d), 10))
|
||||
default:
|
||||
tempSlice = append(tempSlice, "")
|
||||
}
|
||||
}
|
||||
|
||||
res, diags := types.ListValueFrom(ctx, types.StringType, tempSlice)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenMeta:", diags))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenMeta")
|
||||
return res
|
||||
}
|
||||
Reference in New Issue
Block a user