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 {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
// Copyright (c) STACKIT
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
// Copyright (c) STACKIT
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -1,71 +0,0 @@
|
|||
package sqlserverflexalpha
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
sqlserverflexUtils "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/utils"
|
||||
|
||||
sqlserverflexalphaGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/version/datasources_gen"
|
||||
)
|
||||
|
||||
var (
|
||||
_ datasource.DataSource = (*versionDataSource)(nil)
|
||||
_ datasource.DataSourceWithConfigure = (*versionDataSource)(nil)
|
||||
)
|
||||
|
||||
func NewVersionDataSource() datasource.DataSource {
|
||||
return &versionDataSource{}
|
||||
}
|
||||
|
||||
type versionDataSource struct {
|
||||
client *sqlserverflexalpha.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
|
||||
func (d *versionDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_sqlserverflexalpha_version"
|
||||
}
|
||||
|
||||
func (d *versionDataSource) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = sqlserverflexalphaGen.VersionDataSourceSchema(ctx)
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *versionDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
var ok bool
|
||||
d.providerData, ok = conversion.ParseProviderData(ctx, req.ProviderData, &resp.Diagnostics)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
apiClient := sqlserverflexUtils.ConfigureClient(ctx, &d.providerData, &resp.Diagnostics)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
d.client = apiClient
|
||||
tflog.Info(ctx, "SQL SERVER Flex version client configured")
|
||||
}
|
||||
|
||||
func (d *versionDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
var data sqlserverflexalphaGen.VersionModel
|
||||
|
||||
// Read Terraform configuration data into the model
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
||||
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
// Todo: Read API call logic
|
||||
|
||||
// Example data value setting
|
||||
// data.Id = types.StringValue("example-id")
|
||||
|
||||
// Save data into Terraform state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||
}
|
||||
|
|
@ -1,569 +0,0 @@
|
|||
// Code generated by terraform-plugin-framework-generator DO NOT EDIT.
|
||||
|
||||
package sqlserverflexalpha
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||
"github.com/hashicorp/terraform-plugin-go/tftypes"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
)
|
||||
|
||||
func VersionDataSourceSchema(ctx context.Context) schema.Schema {
|
||||
return schema.Schema{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"project_id": schema.StringAttribute{
|
||||
Required: true,
|
||||
Description: "The STACKIT project ID.",
|
||||
MarkdownDescription: "The STACKIT project ID.",
|
||||
},
|
||||
"region": schema.StringAttribute{
|
||||
Required: true,
|
||||
Description: "The region which should be addressed",
|
||||
MarkdownDescription: "The region which should be addressed",
|
||||
Validators: []validator.String{
|
||||
stringvalidator.OneOf(
|
||||
"eu01",
|
||||
),
|
||||
},
|
||||
},
|
||||
"versions": schema.ListNestedAttribute{
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"beta": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
Description: "Flag if the version is a beta version. If set the version may contain bugs and is not fully tested.",
|
||||
MarkdownDescription: "Flag if the version is a beta version. If set the version may contain bugs and is not fully tested.",
|
||||
},
|
||||
"deprecated": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Description: "Timestamp in RFC3339 format which says when the version will no longer be supported by STACKIT.",
|
||||
MarkdownDescription: "Timestamp in RFC3339 format which says when the version will no longer be supported by STACKIT.",
|
||||
},
|
||||
"recommend": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
Description: "Flag if the version is recommend by the STACKIT Team.",
|
||||
MarkdownDescription: "Flag if the version is recommend by the STACKIT Team.",
|
||||
},
|
||||
"version": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Description: "The sqlserver version used for the instance.",
|
||||
MarkdownDescription: "The sqlserver version used for the instance.",
|
||||
},
|
||||
},
|
||||
CustomType: VersionsType{
|
||||
ObjectType: types.ObjectType{
|
||||
AttrTypes: VersionsValue{}.AttributeTypes(ctx),
|
||||
},
|
||||
},
|
||||
},
|
||||
Computed: true,
|
||||
Description: "A list containing available sqlserver versions.",
|
||||
MarkdownDescription: "A list containing available sqlserver versions.",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type VersionModel struct {
|
||||
ProjectId types.String `tfsdk:"project_id"`
|
||||
Region types.String `tfsdk:"region"`
|
||||
Versions types.List `tfsdk:"versions"`
|
||||
}
|
||||
|
||||
var _ basetypes.ObjectTypable = VersionsType{}
|
||||
|
||||
type VersionsType struct {
|
||||
basetypes.ObjectType
|
||||
}
|
||||
|
||||
func (t VersionsType) Equal(o attr.Type) bool {
|
||||
other, ok := o.(VersionsType)
|
||||
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
return t.ObjectType.Equal(other.ObjectType)
|
||||
}
|
||||
|
||||
func (t VersionsType) String() string {
|
||||
return "VersionsType"
|
||||
}
|
||||
|
||||
func (t VersionsType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) {
|
||||
var diags diag.Diagnostics
|
||||
|
||||
attributes := in.Attributes()
|
||||
|
||||
betaAttribute, ok := attributes["beta"]
|
||||
|
||||
if !ok {
|
||||
diags.AddError(
|
||||
"Attribute Missing",
|
||||
`beta is missing from object`)
|
||||
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
betaVal, ok := betaAttribute.(basetypes.BoolValue)
|
||||
|
||||
if !ok {
|
||||
diags.AddError(
|
||||
"Attribute Wrong Type",
|
||||
fmt.Sprintf(`beta expected to be basetypes.BoolValue, was: %T`, betaAttribute))
|
||||
}
|
||||
|
||||
deprecatedAttribute, ok := attributes["deprecated"]
|
||||
|
||||
if !ok {
|
||||
diags.AddError(
|
||||
"Attribute Missing",
|
||||
`deprecated is missing from object`)
|
||||
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
deprecatedVal, ok := deprecatedAttribute.(basetypes.StringValue)
|
||||
|
||||
if !ok {
|
||||
diags.AddError(
|
||||
"Attribute Wrong Type",
|
||||
fmt.Sprintf(`deprecated expected to be basetypes.StringValue, was: %T`, deprecatedAttribute))
|
||||
}
|
||||
|
||||
recommendAttribute, ok := attributes["recommend"]
|
||||
|
||||
if !ok {
|
||||
diags.AddError(
|
||||
"Attribute Missing",
|
||||
`recommend is missing from object`)
|
||||
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
recommendVal, ok := recommendAttribute.(basetypes.BoolValue)
|
||||
|
||||
if !ok {
|
||||
diags.AddError(
|
||||
"Attribute Wrong Type",
|
||||
fmt.Sprintf(`recommend expected to be basetypes.BoolValue, was: %T`, recommendAttribute))
|
||||
}
|
||||
|
||||
versionAttribute, ok := attributes["version"]
|
||||
|
||||
if !ok {
|
||||
diags.AddError(
|
||||
"Attribute Missing",
|
||||
`version is missing from object`)
|
||||
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
versionVal, ok := versionAttribute.(basetypes.StringValue)
|
||||
|
||||
if !ok {
|
||||
diags.AddError(
|
||||
"Attribute Wrong Type",
|
||||
fmt.Sprintf(`version expected to be basetypes.StringValue, was: %T`, versionAttribute))
|
||||
}
|
||||
|
||||
if diags.HasError() {
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
return VersionsValue{
|
||||
Beta: betaVal,
|
||||
Deprecated: deprecatedVal,
|
||||
Recommend: recommendVal,
|
||||
Version: versionVal,
|
||||
state: attr.ValueStateKnown,
|
||||
}, diags
|
||||
}
|
||||
|
||||
func NewVersionsValueNull() VersionsValue {
|
||||
return VersionsValue{
|
||||
state: attr.ValueStateNull,
|
||||
}
|
||||
}
|
||||
|
||||
func NewVersionsValueUnknown() VersionsValue {
|
||||
return VersionsValue{
|
||||
state: attr.ValueStateUnknown,
|
||||
}
|
||||
}
|
||||
|
||||
func NewVersionsValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (VersionsValue, diag.Diagnostics) {
|
||||
var diags diag.Diagnostics
|
||||
|
||||
// Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521
|
||||
ctx := context.Background()
|
||||
|
||||
for name, attributeType := range attributeTypes {
|
||||
attribute, ok := attributes[name]
|
||||
|
||||
if !ok {
|
||||
diags.AddError(
|
||||
"Missing VersionsValue Attribute Value",
|
||||
"While creating a VersionsValue value, a missing attribute value was detected. "+
|
||||
"A VersionsValue must contain values for all attributes, even if null or unknown. "+
|
||||
"This is always an issue with the provider and should be reported to the provider developers.\n\n"+
|
||||
fmt.Sprintf("VersionsValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()),
|
||||
)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if !attributeType.Equal(attribute.Type(ctx)) {
|
||||
diags.AddError(
|
||||
"Invalid VersionsValue Attribute Type",
|
||||
"While creating a VersionsValue value, an invalid attribute value was detected. "+
|
||||
"A VersionsValue must use a matching attribute type for the value. "+
|
||||
"This is always an issue with the provider and should be reported to the provider developers.\n\n"+
|
||||
fmt.Sprintf("VersionsValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+
|
||||
fmt.Sprintf("VersionsValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
for name := range attributes {
|
||||
_, ok := attributeTypes[name]
|
||||
|
||||
if !ok {
|
||||
diags.AddError(
|
||||
"Extra VersionsValue Attribute Value",
|
||||
"While creating a VersionsValue value, an extra attribute value was detected. "+
|
||||
"A VersionsValue must not contain values beyond the expected attribute types. "+
|
||||
"This is always an issue with the provider and should be reported to the provider developers.\n\n"+
|
||||
fmt.Sprintf("Extra VersionsValue Attribute Name: %s", name),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if diags.HasError() {
|
||||
return NewVersionsValueUnknown(), diags
|
||||
}
|
||||
|
||||
betaAttribute, ok := attributes["beta"]
|
||||
|
||||
if !ok {
|
||||
diags.AddError(
|
||||
"Attribute Missing",
|
||||
`beta is missing from object`)
|
||||
|
||||
return NewVersionsValueUnknown(), diags
|
||||
}
|
||||
|
||||
betaVal, ok := betaAttribute.(basetypes.BoolValue)
|
||||
|
||||
if !ok {
|
||||
diags.AddError(
|
||||
"Attribute Wrong Type",
|
||||
fmt.Sprintf(`beta expected to be basetypes.BoolValue, was: %T`, betaAttribute))
|
||||
}
|
||||
|
||||
deprecatedAttribute, ok := attributes["deprecated"]
|
||||
|
||||
if !ok {
|
||||
diags.AddError(
|
||||
"Attribute Missing",
|
||||
`deprecated is missing from object`)
|
||||
|
||||
return NewVersionsValueUnknown(), diags
|
||||
}
|
||||
|
||||
deprecatedVal, ok := deprecatedAttribute.(basetypes.StringValue)
|
||||
|
||||
if !ok {
|
||||
diags.AddError(
|
||||
"Attribute Wrong Type",
|
||||
fmt.Sprintf(`deprecated expected to be basetypes.StringValue, was: %T`, deprecatedAttribute))
|
||||
}
|
||||
|
||||
recommendAttribute, ok := attributes["recommend"]
|
||||
|
||||
if !ok {
|
||||
diags.AddError(
|
||||
"Attribute Missing",
|
||||
`recommend is missing from object`)
|
||||
|
||||
return NewVersionsValueUnknown(), diags
|
||||
}
|
||||
|
||||
recommendVal, ok := recommendAttribute.(basetypes.BoolValue)
|
||||
|
||||
if !ok {
|
||||
diags.AddError(
|
||||
"Attribute Wrong Type",
|
||||
fmt.Sprintf(`recommend expected to be basetypes.BoolValue, was: %T`, recommendAttribute))
|
||||
}
|
||||
|
||||
versionAttribute, ok := attributes["version"]
|
||||
|
||||
if !ok {
|
||||
diags.AddError(
|
||||
"Attribute Missing",
|
||||
`version is missing from object`)
|
||||
|
||||
return NewVersionsValueUnknown(), diags
|
||||
}
|
||||
|
||||
versionVal, ok := versionAttribute.(basetypes.StringValue)
|
||||
|
||||
if !ok {
|
||||
diags.AddError(
|
||||
"Attribute Wrong Type",
|
||||
fmt.Sprintf(`version expected to be basetypes.StringValue, was: %T`, versionAttribute))
|
||||
}
|
||||
|
||||
if diags.HasError() {
|
||||
return NewVersionsValueUnknown(), diags
|
||||
}
|
||||
|
||||
return VersionsValue{
|
||||
Beta: betaVal,
|
||||
Deprecated: deprecatedVal,
|
||||
Recommend: recommendVal,
|
||||
Version: versionVal,
|
||||
state: attr.ValueStateKnown,
|
||||
}, diags
|
||||
}
|
||||
|
||||
func NewVersionsValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) VersionsValue {
|
||||
object, diags := NewVersionsValue(attributeTypes, attributes)
|
||||
|
||||
if diags.HasError() {
|
||||
// This could potentially be added to the diag package.
|
||||
diagsStrings := make([]string, 0, len(diags))
|
||||
|
||||
for _, diagnostic := range diags {
|
||||
diagsStrings = append(diagsStrings, fmt.Sprintf(
|
||||
"%s | %s | %s",
|
||||
diagnostic.Severity(),
|
||||
diagnostic.Summary(),
|
||||
diagnostic.Detail()))
|
||||
}
|
||||
|
||||
panic("NewVersionsValueMust received error(s): " + strings.Join(diagsStrings, "\n"))
|
||||
}
|
||||
|
||||
return object
|
||||
}
|
||||
|
||||
func (t VersionsType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) {
|
||||
if in.Type() == nil {
|
||||
return NewVersionsValueNull(), nil
|
||||
}
|
||||
|
||||
if !in.Type().Equal(t.TerraformType(ctx)) {
|
||||
return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type())
|
||||
}
|
||||
|
||||
if !in.IsKnown() {
|
||||
return NewVersionsValueUnknown(), nil
|
||||
}
|
||||
|
||||
if in.IsNull() {
|
||||
return NewVersionsValueNull(), nil
|
||||
}
|
||||
|
||||
attributes := map[string]attr.Value{}
|
||||
|
||||
val := map[string]tftypes.Value{}
|
||||
|
||||
err := in.As(&val)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for k, v := range val {
|
||||
a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
attributes[k] = a
|
||||
}
|
||||
|
||||
return NewVersionsValueMust(VersionsValue{}.AttributeTypes(ctx), attributes), nil
|
||||
}
|
||||
|
||||
func (t VersionsType) ValueType(ctx context.Context) attr.Value {
|
||||
return VersionsValue{}
|
||||
}
|
||||
|
||||
var _ basetypes.ObjectValuable = VersionsValue{}
|
||||
|
||||
type VersionsValue struct {
|
||||
Beta basetypes.BoolValue `tfsdk:"beta"`
|
||||
Deprecated basetypes.StringValue `tfsdk:"deprecated"`
|
||||
Recommend basetypes.BoolValue `tfsdk:"recommend"`
|
||||
Version basetypes.StringValue `tfsdk:"version"`
|
||||
state attr.ValueState
|
||||
}
|
||||
|
||||
func (v VersionsValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) {
|
||||
attrTypes := make(map[string]tftypes.Type, 4)
|
||||
|
||||
var val tftypes.Value
|
||||
var err error
|
||||
|
||||
attrTypes["beta"] = basetypes.BoolType{}.TerraformType(ctx)
|
||||
attrTypes["deprecated"] = basetypes.StringType{}.TerraformType(ctx)
|
||||
attrTypes["recommend"] = basetypes.BoolType{}.TerraformType(ctx)
|
||||
attrTypes["version"] = basetypes.StringType{}.TerraformType(ctx)
|
||||
|
||||
objectType := tftypes.Object{AttributeTypes: attrTypes}
|
||||
|
||||
switch v.state {
|
||||
case attr.ValueStateKnown:
|
||||
vals := make(map[string]tftypes.Value, 4)
|
||||
|
||||
val, err = v.Beta.ToTerraformValue(ctx)
|
||||
|
||||
if err != nil {
|
||||
return tftypes.NewValue(objectType, tftypes.UnknownValue), err
|
||||
}
|
||||
|
||||
vals["beta"] = val
|
||||
|
||||
val, err = v.Deprecated.ToTerraformValue(ctx)
|
||||
|
||||
if err != nil {
|
||||
return tftypes.NewValue(objectType, tftypes.UnknownValue), err
|
||||
}
|
||||
|
||||
vals["deprecated"] = val
|
||||
|
||||
val, err = v.Recommend.ToTerraformValue(ctx)
|
||||
|
||||
if err != nil {
|
||||
return tftypes.NewValue(objectType, tftypes.UnknownValue), err
|
||||
}
|
||||
|
||||
vals["recommend"] = val
|
||||
|
||||
val, err = v.Version.ToTerraformValue(ctx)
|
||||
|
||||
if err != nil {
|
||||
return tftypes.NewValue(objectType, tftypes.UnknownValue), err
|
||||
}
|
||||
|
||||
vals["version"] = val
|
||||
|
||||
if err := tftypes.ValidateValue(objectType, vals); err != nil {
|
||||
return tftypes.NewValue(objectType, tftypes.UnknownValue), err
|
||||
}
|
||||
|
||||
return tftypes.NewValue(objectType, vals), nil
|
||||
case attr.ValueStateNull:
|
||||
return tftypes.NewValue(objectType, nil), nil
|
||||
case attr.ValueStateUnknown:
|
||||
return tftypes.NewValue(objectType, tftypes.UnknownValue), nil
|
||||
default:
|
||||
panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state))
|
||||
}
|
||||
}
|
||||
|
||||
func (v VersionsValue) IsNull() bool {
|
||||
return v.state == attr.ValueStateNull
|
||||
}
|
||||
|
||||
func (v VersionsValue) IsUnknown() bool {
|
||||
return v.state == attr.ValueStateUnknown
|
||||
}
|
||||
|
||||
func (v VersionsValue) String() string {
|
||||
return "VersionsValue"
|
||||
}
|
||||
|
||||
func (v VersionsValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) {
|
||||
var diags diag.Diagnostics
|
||||
|
||||
attributeTypes := map[string]attr.Type{
|
||||
"beta": basetypes.BoolType{},
|
||||
"deprecated": basetypes.StringType{},
|
||||
"recommend": basetypes.BoolType{},
|
||||
"version": basetypes.StringType{},
|
||||
}
|
||||
|
||||
if v.IsNull() {
|
||||
return types.ObjectNull(attributeTypes), diags
|
||||
}
|
||||
|
||||
if v.IsUnknown() {
|
||||
return types.ObjectUnknown(attributeTypes), diags
|
||||
}
|
||||
|
||||
objVal, diags := types.ObjectValue(
|
||||
attributeTypes,
|
||||
map[string]attr.Value{
|
||||
"beta": v.Beta,
|
||||
"deprecated": v.Deprecated,
|
||||
"recommend": v.Recommend,
|
||||
"version": v.Version,
|
||||
})
|
||||
|
||||
return objVal, diags
|
||||
}
|
||||
|
||||
func (v VersionsValue) Equal(o attr.Value) bool {
|
||||
other, ok := o.(VersionsValue)
|
||||
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
if v.state != other.state {
|
||||
return false
|
||||
}
|
||||
|
||||
if v.state != attr.ValueStateKnown {
|
||||
return true
|
||||
}
|
||||
|
||||
if !v.Beta.Equal(other.Beta) {
|
||||
return false
|
||||
}
|
||||
|
||||
if !v.Deprecated.Equal(other.Deprecated) {
|
||||
return false
|
||||
}
|
||||
|
||||
if !v.Recommend.Equal(other.Recommend) {
|
||||
return false
|
||||
}
|
||||
|
||||
if !v.Version.Equal(other.Version) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (v VersionsValue) Type(ctx context.Context) attr.Type {
|
||||
return VersionsType{
|
||||
basetypes.ObjectType{
|
||||
AttrTypes: v.AttributeTypes(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (v VersionsValue) AttributeTypes(ctx context.Context) map[string]attr.Type {
|
||||
return map[string]attr.Type{
|
||||
"beta": basetypes.BoolType{},
|
||||
"deprecated": basetypes.StringType{},
|
||||
"recommend": basetypes.BoolType{},
|
||||
"version": basetypes.StringType{},
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue