feat: SQL server beta and templates refactoring (#32)
## Description
<!-- **Please link some issue here describing what you are trying to achieve.**
In case there is no issue present for your PR, please consider creating one.
At least please give us some description what you are trying to achieve and why your change is needed. -->
relates to #1234
## Checklist
- [ ] Issue was linked above
- [ ] Code format was applied: `make fmt`
- [ ] Examples were added / adjusted (see `examples/` directory)
- [x] Docs are up-to-date: `make generate-docs` (will be checked by CI)
- [ ] Unit tests got implemented or updated
- [ ] Acceptance tests got implemented or updated (see e.g. [here](f5f99d1709/stackit/internal/services/dns/dns_acc_test.go))
- [x] Unit tests are passing: `make test` (will be checked by CI)
- [x] No linter issues: `make lint` (will be checked by CI)
Reviewed-on: #32
Reviewed-by: Andre_Harms <andre.harms@stackit.cloud>
Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
Co-committed-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
This commit is contained in:
parent
4549ba63e5
commit
581e45eb9c
74 changed files with 15985 additions and 1383 deletions
|
|
@ -1,6 +1,6 @@
|
|||
// Copyright (c) STACKIT
|
||||
|
||||
package sqlserverflex
|
||||
package sqlserverflexalpha
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
@ -218,6 +218,7 @@ func (r *instanceDataSource) Schema(ctx context.Context, _ datasource.SchemaRequ
|
|||
|
||||
// Read refreshes the Terraform state with the latest data.
|
||||
func (r *instanceDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { // nolint:gocritic // function signature required by Terraform
|
||||
//var model sqlserverflexalpha2.InstanceModel
|
||||
var model sqlserverflexalpha2.InstanceModel
|
||||
diags := req.Config.Get(ctx, &model)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package sqlserverflex
|
||||
package sqlserverflexalpha
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
@ -113,152 +113,6 @@ func handleEncryption(
|
|||
return enc
|
||||
}
|
||||
|
||||
//func mapFields(
|
||||
// ctx context.Context,
|
||||
// resp *sqlserverflex.GetInstanceResponse,
|
||||
// model *Model,
|
||||
// storage *storageModel,
|
||||
// encryption *encryptionModel,
|
||||
// network *networkModel,
|
||||
// region string,
|
||||
//) error {
|
||||
// if resp == nil {
|
||||
// return fmt.Errorf("response input is nil")
|
||||
// }
|
||||
// if model == nil {
|
||||
// return fmt.Errorf("model input is nil")
|
||||
// }
|
||||
// instance := resp
|
||||
//
|
||||
// var instanceId string
|
||||
// if model.InstanceId.ValueString() != "" {
|
||||
// instanceId = model.InstanceId.ValueString()
|
||||
// } else if instance.Id != nil {
|
||||
// instanceId = *instance.Id
|
||||
// } else {
|
||||
// return fmt.Errorf("instance id not present")
|
||||
// }
|
||||
//
|
||||
// var storageValues map[string]attr.Value
|
||||
// if instance.Storage == nil {
|
||||
// storageValues = map[string]attr.Value{
|
||||
// "class": storage.Class,
|
||||
// "size": storage.Size,
|
||||
// }
|
||||
// } else {
|
||||
// storageValues = map[string]attr.Value{
|
||||
// "class": types.StringValue(*instance.Storage.Class),
|
||||
// "size": types.Int64PointerValue(instance.Storage.Size),
|
||||
// }
|
||||
// }
|
||||
// storageObject, diags := types.ObjectValue(storageTypes, storageValues)
|
||||
// if diags.HasError() {
|
||||
// return fmt.Errorf("creating storage: %w", core.DiagsToError(diags))
|
||||
// }
|
||||
//
|
||||
// var encryptionValues map[string]attr.Value
|
||||
// if instance.Encryption == nil {
|
||||
// encryptionValues = map[string]attr.Value{
|
||||
// "keyring_id": encryption.KeyRingId,
|
||||
// "key_id": encryption.KeyId,
|
||||
// "key_version": encryption.KeyVersion,
|
||||
// "service_account": encryption.ServiceAccount,
|
||||
// }
|
||||
// } else {
|
||||
// encryptionValues = map[string]attr.Value{
|
||||
// "keyring_id": types.StringValue(*instance.Encryption.KekKeyRingId),
|
||||
// "key_id": types.StringValue(*instance.Encryption.KekKeyId),
|
||||
// "key_version": types.StringValue(*instance.Encryption.KekKeyVersion),
|
||||
// "service_account": types.StringValue(*instance.Encryption.ServiceAccount),
|
||||
// }
|
||||
// }
|
||||
// encryptionObject, diags := types.ObjectValue(encryptionTypes, encryptionValues)
|
||||
// if diags.HasError() {
|
||||
// return fmt.Errorf("creating encryption: %w", core.DiagsToError(diags))
|
||||
// }
|
||||
//
|
||||
// var networkValues map[string]attr.Value
|
||||
// if instance.Network == nil {
|
||||
// networkValues = map[string]attr.Value{
|
||||
// "acl": network.ACL,
|
||||
// "access_scope": network.AccessScope,
|
||||
// "instance_address": network.InstanceAddress,
|
||||
// "router_address": network.RouterAddress,
|
||||
// }
|
||||
// } else {
|
||||
// aclList, diags := types.ListValueFrom(ctx, types.StringType, *instance.Network.Acl)
|
||||
// if diags.HasError() {
|
||||
// return fmt.Errorf("creating network (acl list): %w", core.DiagsToError(diags))
|
||||
// }
|
||||
//
|
||||
// var routerAddress string
|
||||
// if instance.Network.RouterAddress != nil {
|
||||
// routerAddress = *instance.Network.RouterAddress
|
||||
// diags.AddWarning("field missing while mapping fields", "router_address was empty in API response")
|
||||
// }
|
||||
// if instance.Network.InstanceAddress == nil {
|
||||
// return fmt.Errorf("creating network: no instance address returned")
|
||||
// }
|
||||
// networkValues = map[string]attr.Value{
|
||||
// "acl": aclList,
|
||||
// "access_scope": types.StringValue(string(*instance.Network.AccessScope)),
|
||||
// "instance_address": types.StringValue(*instance.Network.InstanceAddress),
|
||||
// "router_address": types.StringValue(routerAddress),
|
||||
// }
|
||||
// }
|
||||
// networkObject, diags := types.ObjectValue(networkTypes, networkValues)
|
||||
// if diags.HasError() {
|
||||
// return fmt.Errorf("creating network: %w", core.DiagsToError(diags))
|
||||
// }
|
||||
//
|
||||
// simplifiedModelBackupSchedule := utils.SimplifyBackupSchedule(model.BackupSchedule.ValueString())
|
||||
// // If the value returned by the API is different from the one in the model after simplification,
|
||||
// // we update the model so that it causes an error in Terraform
|
||||
// if simplifiedModelBackupSchedule != types.StringPointerValue(instance.BackupSchedule).ValueString() {
|
||||
// model.BackupSchedule = types.StringPointerValue(instance.BackupSchedule)
|
||||
// }
|
||||
//
|
||||
// if instance.Replicas == nil {
|
||||
// return fmt.Errorf("instance has no replicas set")
|
||||
// }
|
||||
//
|
||||
// if instance.RetentionDays == nil {
|
||||
// return fmt.Errorf("instance has no retention days set")
|
||||
// }
|
||||
//
|
||||
// if instance.Version == nil {
|
||||
// return fmt.Errorf("instance has no version set")
|
||||
// }
|
||||
//
|
||||
// if instance.Edition == nil {
|
||||
// return fmt.Errorf("instance has no edition set")
|
||||
// }
|
||||
//
|
||||
// if instance.Status == nil {
|
||||
// return fmt.Errorf("instance has no status set")
|
||||
// }
|
||||
//
|
||||
// if instance.IsDeletable == nil {
|
||||
// return fmt.Errorf("instance has no IsDeletable set")
|
||||
// }
|
||||
//
|
||||
// model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), region, instanceId)
|
||||
// model.InstanceId = types.StringValue(instanceId)
|
||||
// model.Name = types.StringPointerValue(instance.Name)
|
||||
// model.FlavorId = types.StringPointerValue(instance.FlavorId)
|
||||
// model.Replicas = types.Int64Value(int64(*instance.Replicas))
|
||||
// model.Storage = storageObject
|
||||
// model.Version = types.StringValue(string(*instance.Version))
|
||||
// model.Edition = types.StringValue(string(*instance.Edition))
|
||||
// model.Region = types.StringValue(region)
|
||||
// model.Encryption = encryptionObject
|
||||
// model.Network = networkObject
|
||||
// model.RetentionDays = types.Int64Value(*instance.RetentionDays)
|
||||
// model.Status = types.StringValue(string(*instance.Status))
|
||||
// model.IsDeletable = types.BoolValue(*instance.IsDeletable)
|
||||
// return nil
|
||||
//}
|
||||
|
||||
func toCreatePayload(
|
||||
ctx context.Context,
|
||||
model *sqlserverflexResGen.InstanceModel,
|
||||
|
|
@ -313,52 +167,6 @@ func toCreatePayload(
|
|||
}, nil
|
||||
}
|
||||
|
||||
////nolint:unused // TODO: remove if not needed later
|
||||
//func toUpdatePartiallyPayload(
|
||||
// model *Model,
|
||||
// storage *storageModel,
|
||||
// network *networkModel,
|
||||
//) (*sqlserverflex.UpdateInstancePartiallyRequestPayload, error) {
|
||||
// if model == nil {
|
||||
// return nil, fmt.Errorf("nil model")
|
||||
// }
|
||||
//
|
||||
// storagePayload := &sqlserverflex.UpdateInstanceRequestPayloadGetStorageArgType{}
|
||||
// if storage != nil {
|
||||
// storagePayload.Size = conversion.Int64ValueToPointer(storage.Size)
|
||||
// }
|
||||
//
|
||||
// var aclElements []string
|
||||
// if network != nil && !network.ACL.IsNull() && !network.ACL.IsUnknown() {
|
||||
// aclElements = make([]string, 0, len(network.ACL.Elements()))
|
||||
// diags := network.ACL.ElementsAs(context.TODO(), &aclElements, false)
|
||||
// if diags.HasError() {
|
||||
// return nil, fmt.Errorf("creating network: %w", core.DiagsToError(diags))
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// networkPayload := &sqlserverflex.UpdateInstancePartiallyRequestPayloadGetNetworkArgType{}
|
||||
// if network != nil {
|
||||
// networkPayload.AccessScope = sqlserverflex.UpdateInstancePartiallyRequestPayloadNetworkGetAccessScopeAttributeType(conversion.StringValueToPointer(network.AccessScope))
|
||||
// networkPayload.Acl = &aclElements
|
||||
// }
|
||||
//
|
||||
// if model.Replicas.ValueInt64() > math.MaxInt32 {
|
||||
// return nil, fmt.Errorf("replica count too big: %d", model.Replicas.ValueInt64())
|
||||
// }
|
||||
// replCount := int32(model.Replicas.ValueInt64()) // nolint:gosec // check is performed above
|
||||
// return &sqlserverflex.UpdateInstancePartiallyRequestPayload{
|
||||
// BackupSchedule: conversion.StringValueToPointer(model.BackupSchedule),
|
||||
// FlavorId: conversion.StringValueToPointer(model.FlavorId),
|
||||
// Name: conversion.StringValueToPointer(model.Name),
|
||||
// Network: networkPayload,
|
||||
// Replicas: sqlserverflex.UpdateInstancePartiallyRequestPayloadGetReplicasAttributeType(&replCount),
|
||||
// RetentionDays: conversion.Int64ValueToPointer(model.RetentionDays),
|
||||
// Storage: storagePayload,
|
||||
// Version: sqlserverflex.UpdateInstancePartiallyRequestPayloadGetVersionAttributeType(conversion.StringValueToPointer(model.Version)),
|
||||
// }, nil
|
||||
//}
|
||||
|
||||
// TODO: check func with his args
|
||||
func toUpdatePayload(
|
||||
ctx context.Context,
|
||||
|
|
@ -380,9 +188,8 @@ func toUpdatePayload(
|
|||
BackupSchedule: m.BackupSchedule.ValueStringPointer(),
|
||||
FlavorId: m.FlavorId.ValueStringPointer(),
|
||||
Name: m.Name.ValueStringPointer(),
|
||||
Network: &sqlserverflex.CreateInstanceRequestPayloadNetwork{
|
||||
AccessScope: sqlserverflex.CreateInstanceRequestPayloadNetworkGetAccessScopeAttributeType(m.Network.AccessScope.ValueStringPointer()),
|
||||
Acl: &netAcl,
|
||||
Network: &sqlserverflex.UpdateInstanceRequestPayloadNetwork{
|
||||
Acl: &netAcl,
|
||||
},
|
||||
Replicas: &replVal,
|
||||
RetentionDays: m.RetentionDays.ValueInt64Pointer(),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Copyright (c) STACKIT
|
||||
|
||||
package sqlserverflex
|
||||
package sqlserverflexalpha
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
@ -592,7 +592,6 @@ func (r *instanceResource) Read(
|
|||
ctx = core.LogResponse(ctx)
|
||||
|
||||
// Map response body to schema
|
||||
// err = mapFields(ctx, instanceResp, &model, storage, encryption, network, region)
|
||||
err = mapResponseToModel(ctx, instanceResp, &model, resp.Diagnostics)
|
||||
if err != nil {
|
||||
core.LogAndAddError(
|
||||
|
|
@ -755,6 +754,7 @@ func (r *instanceResource) ImportState(
|
|||
req resource.ImportStateRequest,
|
||||
resp *resource.ImportStateResponse,
|
||||
) {
|
||||
// TODO
|
||||
idParts := strings.Split(req.ID, core.Separator)
|
||||
|
||||
if len(idParts) != 3 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" {
|
||||
|
|
|
|||
|
|
@ -1,18 +1,4 @@
|
|||
// Copyright (c) STACKIT
|
||||
|
||||
package sqlserverflex
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
sqlserverflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
)
|
||||
package sqlserverflexalpha
|
||||
|
||||
// type sqlserverflexClientMocked struct {
|
||||
// returnError bool
|
||||
|
|
@ -27,343 +13,343 @@ import (
|
|||
// return c.listFlavorsResp, nil
|
||||
// }
|
||||
|
||||
func TestMapFields(t *testing.T) {
|
||||
t.Skip("Skipping - needs refactoring")
|
||||
const testRegion = "region"
|
||||
tests := []struct {
|
||||
description string
|
||||
state Model
|
||||
input *sqlserverflex.GetInstanceResponse
|
||||
storage *storageModel
|
||||
encryption *encryptionModel
|
||||
network *networkModel
|
||||
region string
|
||||
expected Model
|
||||
isValid bool
|
||||
}{
|
||||
{
|
||||
"default_values",
|
||||
Model{
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
Replicas: types.Int64Value(1),
|
||||
RetentionDays: types.Int64Value(1),
|
||||
Version: types.StringValue("v1"),
|
||||
Edition: types.StringValue("edition 1"),
|
||||
Status: types.StringValue("status"),
|
||||
IsDeletable: types.BoolValue(true),
|
||||
},
|
||||
&sqlserverflex.GetInstanceResponse{
|
||||
FlavorId: utils.Ptr("flavor_id"),
|
||||
Replicas: sqlserverflex.GetInstanceResponseGetReplicasAttributeType(utils.Ptr(int32(1))),
|
||||
RetentionDays: utils.Ptr(int64(1)),
|
||||
Version: sqlserverflex.GetInstanceResponseGetVersionAttributeType(utils.Ptr("v1")),
|
||||
Edition: sqlserverflex.GetInstanceResponseGetEditionAttributeType(utils.Ptr("edition 1")),
|
||||
Status: sqlserverflex.GetInstanceResponseGetStatusAttributeType(utils.Ptr("status")),
|
||||
IsDeletable: utils.Ptr(true),
|
||||
},
|
||||
&storageModel{},
|
||||
&encryptionModel{},
|
||||
&networkModel{
|
||||
ACL: types.ListNull(basetypes.StringType{}),
|
||||
},
|
||||
testRegion,
|
||||
Model{
|
||||
Id: types.StringValue("pid,region,iid"),
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
Name: types.StringNull(),
|
||||
BackupSchedule: types.StringNull(),
|
||||
Replicas: types.Int64Value(1),
|
||||
Storage: types.ObjectValueMust(storageTypes, map[string]attr.Value{
|
||||
"class": types.StringNull(),
|
||||
"size": types.Int64Null(),
|
||||
}),
|
||||
Encryption: types.ObjectValueMust(encryptionTypes, map[string]attr.Value{
|
||||
"keyring_id": types.StringNull(),
|
||||
"key_id": types.StringNull(),
|
||||
"key_version": types.StringNull(),
|
||||
"service_account": types.StringNull(),
|
||||
}),
|
||||
Network: types.ObjectValueMust(networkTypes, map[string]attr.Value{
|
||||
"acl": types.ListNull(types.StringType),
|
||||
"access_scope": types.StringNull(),
|
||||
"instance_address": types.StringNull(),
|
||||
"router_address": types.StringNull(),
|
||||
}),
|
||||
IsDeletable: types.BoolValue(true),
|
||||
Edition: types.StringValue("edition 1"),
|
||||
Status: types.StringValue("status"),
|
||||
RetentionDays: types.Int64Value(1),
|
||||
Version: types.StringValue("v1"),
|
||||
Region: types.StringValue(testRegion),
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"simple_values",
|
||||
Model{
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
},
|
||||
&sqlserverflex.GetInstanceResponse{
|
||||
BackupSchedule: utils.Ptr("schedule"),
|
||||
FlavorId: utils.Ptr("flavor_id"),
|
||||
Id: utils.Ptr("iid"),
|
||||
Name: utils.Ptr("name"),
|
||||
Replicas: sqlserverflex.GetInstanceResponseGetReplicasAttributeType(utils.Ptr(int32(56))),
|
||||
Status: sqlserverflex.GetInstanceResponseGetStatusAttributeType(utils.Ptr("status")),
|
||||
Storage: &sqlserverflex.Storage{
|
||||
Class: utils.Ptr("class"),
|
||||
Size: utils.Ptr(int64(78)),
|
||||
},
|
||||
Edition: sqlserverflex.GetInstanceResponseGetEditionAttributeType(utils.Ptr("edition")),
|
||||
RetentionDays: utils.Ptr(int64(1)),
|
||||
Version: sqlserverflex.GetInstanceResponseGetVersionAttributeType(utils.Ptr("version")),
|
||||
IsDeletable: utils.Ptr(true),
|
||||
Encryption: nil,
|
||||
Network: &sqlserverflex.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: &[]string{
|
||||
"ip1",
|
||||
"ip2",
|
||||
"",
|
||||
},
|
||||
InstanceAddress: nil,
|
||||
RouterAddress: nil,
|
||||
},
|
||||
},
|
||||
&storageModel{},
|
||||
&encryptionModel{},
|
||||
&networkModel{
|
||||
ACL: types.ListValueMust(basetypes.StringType{}, []attr.Value{
|
||||
types.StringValue("ip1"),
|
||||
types.StringValue("ip2"),
|
||||
types.StringValue(""),
|
||||
}),
|
||||
},
|
||||
testRegion,
|
||||
Model{
|
||||
Id: types.StringValue("pid,region,iid"),
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
Name: types.StringValue("name"),
|
||||
BackupSchedule: types.StringValue("schedule"),
|
||||
Replicas: types.Int64Value(56),
|
||||
Storage: types.ObjectValueMust(storageTypes, map[string]attr.Value{
|
||||
"class": types.StringValue("class"),
|
||||
"size": types.Int64Value(78),
|
||||
}),
|
||||
Network: types.ObjectValueMust(networkTypes, map[string]attr.Value{
|
||||
"acl": types.ListValueMust(types.StringType, []attr.Value{
|
||||
types.StringValue("ip1"),
|
||||
types.StringValue("ip2"),
|
||||
types.StringValue(""),
|
||||
}),
|
||||
"access_scope": types.StringNull(),
|
||||
"instance_address": types.StringNull(),
|
||||
"router_address": types.StringNull(),
|
||||
}),
|
||||
Edition: types.StringValue("edition"),
|
||||
RetentionDays: types.Int64Value(1),
|
||||
Version: types.StringValue("version"),
|
||||
Region: types.StringValue(testRegion),
|
||||
IsDeletable: types.BoolValue(true),
|
||||
Encryption: types.ObjectValueMust(encryptionTypes, map[string]attr.Value{
|
||||
"keyring_id": types.StringNull(),
|
||||
"key_id": types.StringNull(),
|
||||
"key_version": types.StringNull(),
|
||||
"service_account": types.StringNull(),
|
||||
}),
|
||||
Status: types.StringValue("status"),
|
||||
},
|
||||
true,
|
||||
},
|
||||
// {
|
||||
// "simple_values_no_flavor_and_storage",
|
||||
// Model{
|
||||
// InstanceId: types.StringValue("iid"),
|
||||
// ProjectId: types.StringValue("pid"),
|
||||
// },
|
||||
// &sqlserverflex.GetInstanceResponse{
|
||||
// Acl: &[]string{
|
||||
// "ip1",
|
||||
// "ip2",
|
||||
// "",
|
||||
// },
|
||||
// BackupSchedule: utils.Ptr("schedule"),
|
||||
// FlavorId: nil,
|
||||
// Id: utils.Ptr("iid"),
|
||||
// Name: utils.Ptr("name"),
|
||||
// Replicas: sqlserverflex.GetInstanceResponseGetReplicasAttributeType(utils.Ptr(int32(56))),
|
||||
// Status: sqlserverflex.GetInstanceResponseGetStatusAttributeType(utils.Ptr("status")),
|
||||
// Storage: nil,
|
||||
// Edition: sqlserverflex.GetInstanceResponseGetEditionAttributeType(utils.Ptr("edition")),
|
||||
// RetentionDays: utils.Ptr(int64(1)),
|
||||
// Version: sqlserverflex.GetInstanceResponseGetVersionAttributeType(utils.Ptr("version")),
|
||||
// },
|
||||
// &flavorModel{
|
||||
// CPU: types.Int64Value(12),
|
||||
// RAM: types.Int64Value(34),
|
||||
// },
|
||||
// &storageModel{
|
||||
// Class: types.StringValue("class"),
|
||||
// Size: types.Int64Value(78),
|
||||
// },
|
||||
// &optionsModel{
|
||||
// Edition: types.StringValue("edition"),
|
||||
// RetentionDays: types.Int64Value(1),
|
||||
// },
|
||||
// testRegion,
|
||||
// Model{
|
||||
// Id: types.StringValue("pid,region,iid"),
|
||||
// InstanceId: types.StringValue("iid"),
|
||||
// ProjectId: types.StringValue("pid"),
|
||||
// Name: types.StringValue("name"),
|
||||
// ACL: types.ListValueMust(types.StringType, []attr.Value{
|
||||
// types.StringValue("ip1"),
|
||||
// types.StringValue("ip2"),
|
||||
// types.StringValue(""),
|
||||
// }),
|
||||
// BackupSchedule: types.StringValue("schedule"),
|
||||
// Flavor: types.ObjectValueMust(flavorTypes, map[string]attr.Value{
|
||||
// "id": types.StringNull(),
|
||||
// "description": types.StringNull(),
|
||||
// "cpu": types.Int64Value(12),
|
||||
// "ram": types.Int64Value(34),
|
||||
// }),
|
||||
// Replicas: types.Int64Value(56),
|
||||
// Storage: types.ObjectValueMust(storageTypes, map[string]attr.Value{
|
||||
// "class": types.StringValue("class"),
|
||||
// "size": types.Int64Value(78),
|
||||
// }),
|
||||
// Options: types.ObjectValueMust(optionsTypes, map[string]attr.Value{
|
||||
// "edition": types.StringValue("edition"),
|
||||
// "retention_days": types.Int64Value(1),
|
||||
// }),
|
||||
// Version: types.StringValue("version"),
|
||||
// Region: types.StringValue(testRegion),
|
||||
// },
|
||||
// true,
|
||||
// },
|
||||
// {
|
||||
// "acls_unordered",
|
||||
// Model{
|
||||
// InstanceId: types.StringValue("iid"),
|
||||
// ProjectId: types.StringValue("pid"),
|
||||
// ACL: types.ListValueMust(types.StringType, []attr.Value{
|
||||
// types.StringValue("ip2"),
|
||||
// types.StringValue(""),
|
||||
// types.StringValue("ip1"),
|
||||
// }),
|
||||
// },
|
||||
// &sqlserverflex.GetInstanceResponse{
|
||||
// Acl: &[]string{
|
||||
// "",
|
||||
// "ip1",
|
||||
// "ip2",
|
||||
// },
|
||||
// BackupSchedule: utils.Ptr("schedule"),
|
||||
// FlavorId: nil,
|
||||
// Id: utils.Ptr("iid"),
|
||||
// Name: utils.Ptr("name"),
|
||||
// Replicas: sqlserverflex.GetInstanceResponseGetReplicasAttributeType(utils.Ptr(int32(56))),
|
||||
// Status: sqlserverflex.GetInstanceResponseGetStatusAttributeType(utils.Ptr("status")),
|
||||
// Storage: nil,
|
||||
// //Options: &map[string]string{
|
||||
// // "edition": "edition",
|
||||
// // "retentionDays": "1",
|
||||
// //},
|
||||
// Version: sqlserverflex.GetInstanceResponseGetVersionAttributeType(utils.Ptr("version")),
|
||||
// },
|
||||
// &flavorModel{
|
||||
// CPU: types.Int64Value(12),
|
||||
// RAM: types.Int64Value(34),
|
||||
// },
|
||||
// &storageModel{
|
||||
// Class: types.StringValue("class"),
|
||||
// Size: types.Int64Value(78),
|
||||
// },
|
||||
// &optionsModel{},
|
||||
// testRegion,
|
||||
// Model{
|
||||
// Id: types.StringValue("pid,region,iid"),
|
||||
// InstanceId: types.StringValue("iid"),
|
||||
// ProjectId: types.StringValue("pid"),
|
||||
// Name: types.StringValue("name"),
|
||||
// ACL: types.ListValueMust(types.StringType, []attr.Value{
|
||||
// types.StringValue("ip2"),
|
||||
// types.StringValue(""),
|
||||
// types.StringValue("ip1"),
|
||||
// }),
|
||||
// BackupSchedule: types.StringValue("schedule"),
|
||||
// Flavor: types.ObjectValueMust(flavorTypes, map[string]attr.Value{
|
||||
// "id": types.StringNull(),
|
||||
// "description": types.StringNull(),
|
||||
// "cpu": types.Int64Value(12),
|
||||
// "ram": types.Int64Value(34),
|
||||
// }),
|
||||
// Replicas: types.Int64Value(56),
|
||||
// Storage: types.ObjectValueMust(storageTypes, map[string]attr.Value{
|
||||
// "class": types.StringValue("class"),
|
||||
// "size": types.Int64Value(78),
|
||||
// }),
|
||||
// Options: types.ObjectValueMust(optionsTypes, map[string]attr.Value{
|
||||
// "edition": types.StringValue("edition"),
|
||||
// "retention_days": types.Int64Value(1),
|
||||
// }),
|
||||
// Version: types.StringValue("version"),
|
||||
// Region: types.StringValue(testRegion),
|
||||
// },
|
||||
// true,
|
||||
// },
|
||||
// {
|
||||
// "nil_response",
|
||||
// Model{
|
||||
// InstanceId: types.StringValue("iid"),
|
||||
// ProjectId: types.StringValue("pid"),
|
||||
// },
|
||||
// nil,
|
||||
// &flavorModel{},
|
||||
// &storageModel{},
|
||||
// &optionsModel{},
|
||||
// testRegion,
|
||||
// Model{},
|
||||
// false,
|
||||
// },
|
||||
// {
|
||||
// "no_resource_id",
|
||||
// Model{
|
||||
// InstanceId: types.StringValue("iid"),
|
||||
// ProjectId: types.StringValue("pid"),
|
||||
// },
|
||||
// &sqlserverflex.GetInstanceResponse{},
|
||||
// &flavorModel{},
|
||||
// &storageModel{},
|
||||
// &optionsModel{},
|
||||
// testRegion,
|
||||
// Model{},
|
||||
// false,
|
||||
// },
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.description, func(t *testing.T) {
|
||||
err := mapFields(context.Background(), tt.input, &tt.state, tt.storage, tt.encryption, tt.network, tt.region)
|
||||
if !tt.isValid && err == nil {
|
||||
t.Fatalf("Should have failed")
|
||||
}
|
||||
if tt.isValid && err != nil {
|
||||
t.Fatalf("Should not have failed: %v", err)
|
||||
}
|
||||
if tt.isValid {
|
||||
diff := cmp.Diff(tt.state, tt.expected)
|
||||
if diff != "" {
|
||||
t.Fatalf("Data does not match: %s", diff)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
//func TestMapFields(t *testing.T) {
|
||||
// t.Skip("Skipping - needs refactoring")
|
||||
// const testRegion = "region"
|
||||
// tests := []struct {
|
||||
// description string
|
||||
// state Model
|
||||
// input *sqlserverflex.GetInstanceResponse
|
||||
// storage *storageModel
|
||||
// encryption *encryptionModel
|
||||
// network *networkModel
|
||||
// region string
|
||||
// expected Model
|
||||
// isValid bool
|
||||
// }{
|
||||
// {
|
||||
// "default_values",
|
||||
// Model{
|
||||
// InstanceId: types.StringValue("iid"),
|
||||
// ProjectId: types.StringValue("pid"),
|
||||
// Replicas: types.Int64Value(1),
|
||||
// RetentionDays: types.Int64Value(1),
|
||||
// Version: types.StringValue("v1"),
|
||||
// Edition: types.StringValue("edition 1"),
|
||||
// Status: types.StringValue("status"),
|
||||
// IsDeletable: types.BoolValue(true),
|
||||
// },
|
||||
// &sqlserverflex.GetInstanceResponse{
|
||||
// FlavorId: utils.Ptr("flavor_id"),
|
||||
// Replicas: sqlserverflex.GetInstanceResponseGetReplicasAttributeType(utils.Ptr(int32(1))),
|
||||
// RetentionDays: utils.Ptr(int64(1)),
|
||||
// Version: sqlserverflex.GetInstanceResponseGetVersionAttributeType(utils.Ptr("v1")),
|
||||
// Edition: sqlserverflex.GetInstanceResponseGetEditionAttributeType(utils.Ptr("edition 1")),
|
||||
// Status: sqlserverflex.GetInstanceResponseGetStatusAttributeType(utils.Ptr("status")),
|
||||
// IsDeletable: utils.Ptr(true),
|
||||
// },
|
||||
// &storageModel{},
|
||||
// &encryptionModel{},
|
||||
// &networkModel{
|
||||
// ACL: types.ListNull(basetypes.StringType{}),
|
||||
// },
|
||||
// testRegion,
|
||||
// Model{
|
||||
// Id: types.StringValue("pid,region,iid"),
|
||||
// InstanceId: types.StringValue("iid"),
|
||||
// ProjectId: types.StringValue("pid"),
|
||||
// Name: types.StringNull(),
|
||||
// BackupSchedule: types.StringNull(),
|
||||
// Replicas: types.Int64Value(1),
|
||||
// Storage: types.ObjectValueMust(storageTypes, map[string]attr.Value{
|
||||
// "class": types.StringNull(),
|
||||
// "size": types.Int64Null(),
|
||||
// }),
|
||||
// Encryption: types.ObjectValueMust(encryptionTypes, map[string]attr.Value{
|
||||
// "keyring_id": types.StringNull(),
|
||||
// "key_id": types.StringNull(),
|
||||
// "key_version": types.StringNull(),
|
||||
// "service_account": types.StringNull(),
|
||||
// }),
|
||||
// Network: types.ObjectValueMust(networkTypes, map[string]attr.Value{
|
||||
// "acl": types.ListNull(types.StringType),
|
||||
// "access_scope": types.StringNull(),
|
||||
// "instance_address": types.StringNull(),
|
||||
// "router_address": types.StringNull(),
|
||||
// }),
|
||||
// IsDeletable: types.BoolValue(true),
|
||||
// Edition: types.StringValue("edition 1"),
|
||||
// Status: types.StringValue("status"),
|
||||
// RetentionDays: types.Int64Value(1),
|
||||
// Version: types.StringValue("v1"),
|
||||
// Region: types.StringValue(testRegion),
|
||||
// },
|
||||
// true,
|
||||
// },
|
||||
// {
|
||||
// "simple_values",
|
||||
// Model{
|
||||
// InstanceId: types.StringValue("iid"),
|
||||
// ProjectId: types.StringValue("pid"),
|
||||
// },
|
||||
// &sqlserverflex.GetInstanceResponse{
|
||||
// BackupSchedule: utils.Ptr("schedule"),
|
||||
// FlavorId: utils.Ptr("flavor_id"),
|
||||
// Id: utils.Ptr("iid"),
|
||||
// Name: utils.Ptr("name"),
|
||||
// Replicas: sqlserverflex.GetInstanceResponseGetReplicasAttributeType(utils.Ptr(int32(56))),
|
||||
// Status: sqlserverflex.GetInstanceResponseGetStatusAttributeType(utils.Ptr("status")),
|
||||
// Storage: &sqlserverflex.Storage{
|
||||
// Class: utils.Ptr("class"),
|
||||
// Size: utils.Ptr(int64(78)),
|
||||
// },
|
||||
// Edition: sqlserverflex.GetInstanceResponseGetEditionAttributeType(utils.Ptr("edition")),
|
||||
// RetentionDays: utils.Ptr(int64(1)),
|
||||
// Version: sqlserverflex.GetInstanceResponseGetVersionAttributeType(utils.Ptr("version")),
|
||||
// IsDeletable: utils.Ptr(true),
|
||||
// Encryption: nil,
|
||||
// Network: &sqlserverflex.InstanceNetwork{
|
||||
// AccessScope: nil,
|
||||
// Acl: &[]string{
|
||||
// "ip1",
|
||||
// "ip2",
|
||||
// "",
|
||||
// },
|
||||
// InstanceAddress: nil,
|
||||
// RouterAddress: nil,
|
||||
// },
|
||||
// },
|
||||
// &storageModel{},
|
||||
// &encryptionModel{},
|
||||
// &networkModel{
|
||||
// ACL: types.ListValueMust(basetypes.StringType{}, []attr.Value{
|
||||
// types.StringValue("ip1"),
|
||||
// types.StringValue("ip2"),
|
||||
// types.StringValue(""),
|
||||
// }),
|
||||
// },
|
||||
// testRegion,
|
||||
// Model{
|
||||
// Id: types.StringValue("pid,region,iid"),
|
||||
// InstanceId: types.StringValue("iid"),
|
||||
// ProjectId: types.StringValue("pid"),
|
||||
// Name: types.StringValue("name"),
|
||||
// BackupSchedule: types.StringValue("schedule"),
|
||||
// Replicas: types.Int64Value(56),
|
||||
// Storage: types.ObjectValueMust(storageTypes, map[string]attr.Value{
|
||||
// "class": types.StringValue("class"),
|
||||
// "size": types.Int64Value(78),
|
||||
// }),
|
||||
// Network: types.ObjectValueMust(networkTypes, map[string]attr.Value{
|
||||
// "acl": types.ListValueMust(types.StringType, []attr.Value{
|
||||
// types.StringValue("ip1"),
|
||||
// types.StringValue("ip2"),
|
||||
// types.StringValue(""),
|
||||
// }),
|
||||
// "access_scope": types.StringNull(),
|
||||
// "instance_address": types.StringNull(),
|
||||
// "router_address": types.StringNull(),
|
||||
// }),
|
||||
// Edition: types.StringValue("edition"),
|
||||
// RetentionDays: types.Int64Value(1),
|
||||
// Version: types.StringValue("version"),
|
||||
// Region: types.StringValue(testRegion),
|
||||
// IsDeletable: types.BoolValue(true),
|
||||
// Encryption: types.ObjectValueMust(encryptionTypes, map[string]attr.Value{
|
||||
// "keyring_id": types.StringNull(),
|
||||
// "key_id": types.StringNull(),
|
||||
// "key_version": types.StringNull(),
|
||||
// "service_account": types.StringNull(),
|
||||
// }),
|
||||
// Status: types.StringValue("status"),
|
||||
// },
|
||||
// true,
|
||||
// },
|
||||
// // {
|
||||
// // "simple_values_no_flavor_and_storage",
|
||||
// // Model{
|
||||
// // InstanceId: types.StringValue("iid"),
|
||||
// // ProjectId: types.StringValue("pid"),
|
||||
// // },
|
||||
// // &sqlserverflex.GetInstanceResponse{
|
||||
// // Acl: &[]string{
|
||||
// // "ip1",
|
||||
// // "ip2",
|
||||
// // "",
|
||||
// // },
|
||||
// // BackupSchedule: utils.Ptr("schedule"),
|
||||
// // FlavorId: nil,
|
||||
// // Id: utils.Ptr("iid"),
|
||||
// // Name: utils.Ptr("name"),
|
||||
// // Replicas: sqlserverflex.GetInstanceResponseGetReplicasAttributeType(utils.Ptr(int32(56))),
|
||||
// // Status: sqlserverflex.GetInstanceResponseGetStatusAttributeType(utils.Ptr("status")),
|
||||
// // Storage: nil,
|
||||
// // Edition: sqlserverflex.GetInstanceResponseGetEditionAttributeType(utils.Ptr("edition")),
|
||||
// // RetentionDays: utils.Ptr(int64(1)),
|
||||
// // Version: sqlserverflex.GetInstanceResponseGetVersionAttributeType(utils.Ptr("version")),
|
||||
// // },
|
||||
// // &flavorModel{
|
||||
// // CPU: types.Int64Value(12),
|
||||
// // RAM: types.Int64Value(34),
|
||||
// // },
|
||||
// // &storageModel{
|
||||
// // Class: types.StringValue("class"),
|
||||
// // Size: types.Int64Value(78),
|
||||
// // },
|
||||
// // &optionsModel{
|
||||
// // Edition: types.StringValue("edition"),
|
||||
// // RetentionDays: types.Int64Value(1),
|
||||
// // },
|
||||
// // testRegion,
|
||||
// // Model{
|
||||
// // Id: types.StringValue("pid,region,iid"),
|
||||
// // InstanceId: types.StringValue("iid"),
|
||||
// // ProjectId: types.StringValue("pid"),
|
||||
// // Name: types.StringValue("name"),
|
||||
// // ACL: types.ListValueMust(types.StringType, []attr.Value{
|
||||
// // types.StringValue("ip1"),
|
||||
// // types.StringValue("ip2"),
|
||||
// // types.StringValue(""),
|
||||
// // }),
|
||||
// // BackupSchedule: types.StringValue("schedule"),
|
||||
// // Flavor: types.ObjectValueMust(flavorTypes, map[string]attr.Value{
|
||||
// // "id": types.StringNull(),
|
||||
// // "description": types.StringNull(),
|
||||
// // "cpu": types.Int64Value(12),
|
||||
// // "ram": types.Int64Value(34),
|
||||
// // }),
|
||||
// // Replicas: types.Int64Value(56),
|
||||
// // Storage: types.ObjectValueMust(storageTypes, map[string]attr.Value{
|
||||
// // "class": types.StringValue("class"),
|
||||
// // "size": types.Int64Value(78),
|
||||
// // }),
|
||||
// // Options: types.ObjectValueMust(optionsTypes, map[string]attr.Value{
|
||||
// // "edition": types.StringValue("edition"),
|
||||
// // "retention_days": types.Int64Value(1),
|
||||
// // }),
|
||||
// // Version: types.StringValue("version"),
|
||||
// // Region: types.StringValue(testRegion),
|
||||
// // },
|
||||
// // true,
|
||||
// // },
|
||||
// // {
|
||||
// // "acls_unordered",
|
||||
// // Model{
|
||||
// // InstanceId: types.StringValue("iid"),
|
||||
// // ProjectId: types.StringValue("pid"),
|
||||
// // ACL: types.ListValueMust(types.StringType, []attr.Value{
|
||||
// // types.StringValue("ip2"),
|
||||
// // types.StringValue(""),
|
||||
// // types.StringValue("ip1"),
|
||||
// // }),
|
||||
// // },
|
||||
// // &sqlserverflex.GetInstanceResponse{
|
||||
// // Acl: &[]string{
|
||||
// // "",
|
||||
// // "ip1",
|
||||
// // "ip2",
|
||||
// // },
|
||||
// // BackupSchedule: utils.Ptr("schedule"),
|
||||
// // FlavorId: nil,
|
||||
// // Id: utils.Ptr("iid"),
|
||||
// // Name: utils.Ptr("name"),
|
||||
// // Replicas: sqlserverflex.GetInstanceResponseGetReplicasAttributeType(utils.Ptr(int32(56))),
|
||||
// // Status: sqlserverflex.GetInstanceResponseGetStatusAttributeType(utils.Ptr("status")),
|
||||
// // Storage: nil,
|
||||
// // //Options: &map[string]string{
|
||||
// // // "edition": "edition",
|
||||
// // // "retentionDays": "1",
|
||||
// // //},
|
||||
// // Version: sqlserverflex.GetInstanceResponseGetVersionAttributeType(utils.Ptr("version")),
|
||||
// // },
|
||||
// // &flavorModel{
|
||||
// // CPU: types.Int64Value(12),
|
||||
// // RAM: types.Int64Value(34),
|
||||
// // },
|
||||
// // &storageModel{
|
||||
// // Class: types.StringValue("class"),
|
||||
// // Size: types.Int64Value(78),
|
||||
// // },
|
||||
// // &optionsModel{},
|
||||
// // testRegion,
|
||||
// // Model{
|
||||
// // Id: types.StringValue("pid,region,iid"),
|
||||
// // InstanceId: types.StringValue("iid"),
|
||||
// // ProjectId: types.StringValue("pid"),
|
||||
// // Name: types.StringValue("name"),
|
||||
// // ACL: types.ListValueMust(types.StringType, []attr.Value{
|
||||
// // types.StringValue("ip2"),
|
||||
// // types.StringValue(""),
|
||||
// // types.StringValue("ip1"),
|
||||
// // }),
|
||||
// // BackupSchedule: types.StringValue("schedule"),
|
||||
// // Flavor: types.ObjectValueMust(flavorTypes, map[string]attr.Value{
|
||||
// // "id": types.StringNull(),
|
||||
// // "description": types.StringNull(),
|
||||
// // "cpu": types.Int64Value(12),
|
||||
// // "ram": types.Int64Value(34),
|
||||
// // }),
|
||||
// // Replicas: types.Int64Value(56),
|
||||
// // Storage: types.ObjectValueMust(storageTypes, map[string]attr.Value{
|
||||
// // "class": types.StringValue("class"),
|
||||
// // "size": types.Int64Value(78),
|
||||
// // }),
|
||||
// // Options: types.ObjectValueMust(optionsTypes, map[string]attr.Value{
|
||||
// // "edition": types.StringValue("edition"),
|
||||
// // "retention_days": types.Int64Value(1),
|
||||
// // }),
|
||||
// // Version: types.StringValue("version"),
|
||||
// // Region: types.StringValue(testRegion),
|
||||
// // },
|
||||
// // true,
|
||||
// // },
|
||||
// // {
|
||||
// // "nil_response",
|
||||
// // Model{
|
||||
// // InstanceId: types.StringValue("iid"),
|
||||
// // ProjectId: types.StringValue("pid"),
|
||||
// // },
|
||||
// // nil,
|
||||
// // &flavorModel{},
|
||||
// // &storageModel{},
|
||||
// // &optionsModel{},
|
||||
// // testRegion,
|
||||
// // Model{},
|
||||
// // false,
|
||||
// // },
|
||||
// // {
|
||||
// // "no_resource_id",
|
||||
// // Model{
|
||||
// // InstanceId: types.StringValue("iid"),
|
||||
// // ProjectId: types.StringValue("pid"),
|
||||
// // },
|
||||
// // &sqlserverflex.GetInstanceResponse{},
|
||||
// // &flavorModel{},
|
||||
// // &storageModel{},
|
||||
// // &optionsModel{},
|
||||
// // testRegion,
|
||||
// // Model{},
|
||||
// // false,
|
||||
// // },
|
||||
// }
|
||||
// for _, tt := range tests {
|
||||
// t.Run(tt.description, func(t *testing.T) {
|
||||
// err := mapFields(context.Background(), tt.input, &tt.state, tt.storage, tt.encryption, tt.network, tt.region)
|
||||
// if !tt.isValid && err == nil {
|
||||
// t.Fatalf("Should have failed")
|
||||
// }
|
||||
// if tt.isValid && err != nil {
|
||||
// t.Fatalf("Should not have failed: %v", err)
|
||||
// }
|
||||
// if tt.isValid {
|
||||
// diff := cmp.Diff(tt.state, tt.expected)
|
||||
// if diff != "" {
|
||||
// t.Fatalf("Data does not match: %s", diff)
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
//}
|
||||
|
||||
// func TestToCreatePayload(t *testing.T) {
|
||||
// tests := []struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue