101 lines
3.6 KiB
Go
101 lines
3.6 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"reflect"
|
|
|
|
"github.com/hashicorp/terraform-plugin-framework/attr"
|
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
|
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
|
"github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha"
|
|
"github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/responseMapper"
|
|
"github.com/mhenselin/terraform-provider-stackitprivatepreview/tmp/temp"
|
|
)
|
|
|
|
type Model struct {
|
|
Id types.String `tfsdk:"id"` // needed by TF
|
|
InstanceId types.String `tfsdk:"instance_id"`
|
|
ProjectId types.String `tfsdk:"project_id"`
|
|
Name types.String `tfsdk:"name"`
|
|
BackupSchedule types.String `tfsdk:"backup_schedule"`
|
|
FlavorId types.String `tfsdk:"flavor_id"`
|
|
Replicas types.Int64 `tfsdk:"replicas"`
|
|
RetentionDays types.Int64 `tfsdk:"retention_days"`
|
|
Storage types.Object `tfsdk:"storage"`
|
|
Version types.String `tfsdk:"version"`
|
|
Region types.String `tfsdk:"region"`
|
|
Encryption types.Object `tfsdk:"encryption"`
|
|
Network types.Object `tfsdk:"network"`
|
|
IsDeletable types.Bool `tfsdk:"is_deletable"`
|
|
}
|
|
|
|
func Ptr[T any](val T) *T {
|
|
return &val
|
|
}
|
|
|
|
func main() {
|
|
|
|
ctx := context.Background()
|
|
resp := postgresflexalpha.GetInstanceResponse{
|
|
BackupSchedule: Ptr("backupSchedule"),
|
|
FlavorId: Ptr("2.4"),
|
|
Id: Ptr("myId"),
|
|
IsDeletable: Ptr(true),
|
|
Encryption: &postgresflexalpha.InstanceEncryption{
|
|
KekKeyId: Ptr("myKekKeyId"),
|
|
KekKeyRingId: nil,
|
|
KekKeyVersion: nil,
|
|
ServiceAccount: nil,
|
|
},
|
|
Name: Ptr("NameFromMe"),
|
|
Network: &postgresflexalpha.InstanceNetwork{
|
|
AccessScope: postgresflexalpha.InstanceNetworkGetAccessScopeAttributeType(Ptr("PUBLIC")),
|
|
Acl: &[]string{"0.0.0.0/0"},
|
|
InstanceAddress: Ptr("10.0.0.1"),
|
|
RouterAddress: Ptr("192.168.0.1"),
|
|
},
|
|
Replicas: postgresflexalpha.GetInstanceResponseGetReplicasAttributeType(Ptr(int32(7))),
|
|
RetentionDays: Ptr(int64(42)),
|
|
Status: postgresflexalpha.GetInstanceResponseGetStatusAttributeType(Ptr("READY")),
|
|
Storage: &postgresflexalpha.Storage{
|
|
PerformanceClass: Ptr("class007"),
|
|
Size: Ptr(int64(123)),
|
|
},
|
|
Version: Ptr("11"),
|
|
}
|
|
|
|
fmt.Println("======== TEST 1 ========")
|
|
enc, _ := basetypes.NewObjectValue(map[string]attr.Type{"id": types.StringType}, map[string]attr.Value{"id": basetypes.NewStringValue("")})
|
|
storage, _ := basetypes.NewObjectValue(map[string]attr.Type{"id": types.StringType}, map[string]attr.Value{"id": basetypes.NewStringValue("")})
|
|
net, _ := basetypes.NewObjectValue(map[string]attr.Type{"id": types.StringType}, map[string]attr.Value{"id": basetypes.NewStringValue("")})
|
|
model := Model{
|
|
Id: basetypes.NewStringValue(""),
|
|
InstanceId: basetypes.NewStringValue(""),
|
|
ProjectId: basetypes.NewStringValue(""),
|
|
Name: basetypes.NewStringValue(""),
|
|
BackupSchedule: basetypes.NewStringValue(""),
|
|
FlavorId: basetypes.NewStringValue(""),
|
|
Replicas: basetypes.NewInt64Value(0),
|
|
RetentionDays: basetypes.NewInt64Value(0),
|
|
Storage: storage,
|
|
Version: basetypes.NewStringValue(""),
|
|
Region: basetypes.NewStringValue(""),
|
|
Encryption: enc,
|
|
Network: net,
|
|
}
|
|
err := responseMapper.ToModel(ctx, resp, &model)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
fmt.Printf("model: %s (%+v)\n", reflect.TypeOf(model), model)
|
|
|
|
fmt.Println("======== TEST 2 ========")
|
|
model2 := temp.InstanceModel{}
|
|
err = responseMapper.ToModel(ctx, resp, &model2)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
fmt.Printf("model: %s (%+v)\n", reflect.TypeOf(model2), model2)
|
|
|
|
}
|