feat: initial copy of v0.1.0
This commit is contained in:
parent
4cc801a7f3
commit
7d4cbb6b08
538 changed files with 63361 additions and 55213 deletions
|
|
@ -1,232 +1,125 @@
|
|||
package sqlserverflex
|
||||
package sqlserverflexalpha
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
sqlserverflexUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/sqlserverflexalpha/utils"
|
||||
|
||||
sqlserverflex "github.com/stackitcloud/terraform-provider-stackit/pkg/sqlserverflexalpha"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"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"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
|
||||
"github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3alpha1api"
|
||||
|
||||
sqlserverflexalphaGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/instance/datasources_gen"
|
||||
)
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ datasource.DataSource = &instanceDataSource{}
|
||||
)
|
||||
var _ datasource.DataSource = (*instanceDataSource)(nil)
|
||||
|
||||
const errorPrefix = "[sqlserverflexalpha - Instance]"
|
||||
|
||||
// NewInstanceDataSource is a helper function to simplify the provider implementation.
|
||||
func NewInstanceDataSource() datasource.DataSource {
|
||||
return &instanceDataSource{}
|
||||
}
|
||||
|
||||
// instanceDataSource is the data source implementation.
|
||||
// dataSourceModel maps the data source schema data.
|
||||
type dataSourceModel struct {
|
||||
sqlserverflexalphaGen.InstanceModel
|
||||
TerraformID types.String `tfsdk:"id"`
|
||||
}
|
||||
|
||||
type instanceDataSource struct {
|
||||
client *sqlserverflex.APIClient
|
||||
client *v3alpha1api.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
|
||||
// Metadata returns the data source type name.
|
||||
func (r *instanceDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
func (d *instanceDataSource) Metadata(
|
||||
_ context.Context,
|
||||
req datasource.MetadataRequest,
|
||||
resp *datasource.MetadataResponse,
|
||||
) {
|
||||
resp.TypeName = req.ProviderTypeName + "_sqlserverflexalpha_instance"
|
||||
}
|
||||
|
||||
func (d *instanceDataSource) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = sqlserverflexalphaGen.InstanceDataSourceSchema(ctx)
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (r *instanceDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
func (d *instanceDataSource) Configure(
|
||||
ctx context.Context,
|
||||
req datasource.ConfigureRequest,
|
||||
resp *datasource.ConfigureResponse,
|
||||
) {
|
||||
var ok bool
|
||||
r.providerData, ok = conversion.ParseProviderData(ctx, req.ProviderData, &resp.Diagnostics)
|
||||
d.providerData, ok = conversion.ParseProviderData(ctx, req.ProviderData, &resp.Diagnostics)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
apiClient := sqlserverflexUtils.ConfigureClient(ctx, &r.providerData, &resp.Diagnostics)
|
||||
if resp.Diagnostics.HasError() {
|
||||
apiClientConfigOptions := []config.ConfigurationOption{
|
||||
config.WithCustomAuth(d.providerData.RoundTripper),
|
||||
utils.UserAgentConfigOption(d.providerData.Version),
|
||||
}
|
||||
if d.providerData.SQLServerFlexCustomEndpoint != "" {
|
||||
apiClientConfigOptions = append(
|
||||
apiClientConfigOptions,
|
||||
config.WithEndpoint(d.providerData.SQLServerFlexCustomEndpoint),
|
||||
)
|
||||
} else {
|
||||
apiClientConfigOptions = append(
|
||||
apiClientConfigOptions,
|
||||
config.WithRegion(d.providerData.GetRegion()),
|
||||
)
|
||||
}
|
||||
apiClient, err := v3alpha1api.NewAPIClient(apiClientConfigOptions...)
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError(
|
||||
"Error configuring API client",
|
||||
fmt.Sprintf(
|
||||
"Configuring client: %v. This is an error related to the provider configuration, not to the resource configuration",
|
||||
err,
|
||||
),
|
||||
)
|
||||
return
|
||||
}
|
||||
r.client = apiClient
|
||||
tflog.Info(ctx, "SQLServer Flex instance client configured")
|
||||
d.client = apiClient
|
||||
tflog.Info(ctx, fmt.Sprintf("%s client configured", errorPrefix))
|
||||
}
|
||||
|
||||
// Schema defines the schema for the data source.
|
||||
func (r *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
descriptions := map[string]string{
|
||||
"main": "SQLServer Flex instance data source schema. Must have a `region` specified in the provider configuration.",
|
||||
"id": "Terraform's internal data source. ID. It is structured as \"`project_id`,`region`,`instance_id`\".",
|
||||
"instance_id": "ID of the SQLServer Flex instance.",
|
||||
"project_id": "STACKIT project ID to which the instance is associated.",
|
||||
"name": "Instance name.",
|
||||
"acl": "The Access Control List (ACL) for the SQLServer Flex instance.",
|
||||
"backup_schedule": `The backup schedule. Should follow the cron scheduling system format (e.g. "0 0 * * *").`,
|
||||
"options": "Custom parameters for the SQLServer Flex instance.",
|
||||
"region": "The resource region. If not defined, the provider region is used.",
|
||||
// TODO
|
||||
}
|
||||
func (d *instanceDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
var data dataSourceModel
|
||||
|
||||
resp.Schema = schema.Schema{
|
||||
Description: descriptions["main"],
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"id": schema.StringAttribute{
|
||||
Description: descriptions["id"],
|
||||
Computed: true,
|
||||
},
|
||||
"instance_id": schema.StringAttribute{
|
||||
Description: descriptions["instance_id"],
|
||||
Required: true,
|
||||
Validators: []validator.String{
|
||||
validate.UUID(),
|
||||
validate.NoSeparator(),
|
||||
},
|
||||
},
|
||||
"project_id": schema.StringAttribute{
|
||||
Description: descriptions["project_id"],
|
||||
Required: true,
|
||||
Validators: []validator.String{
|
||||
validate.UUID(),
|
||||
validate.NoSeparator(),
|
||||
},
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Description: descriptions["name"],
|
||||
Computed: true,
|
||||
},
|
||||
"backup_schedule": schema.StringAttribute{
|
||||
Description: descriptions["backup_schedule"],
|
||||
Computed: true,
|
||||
},
|
||||
"flavor": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"description": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"cpu": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ram": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"replicas": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"storage": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"class": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"size": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"version": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"edition": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"retention_days": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"region": schema.StringAttribute{
|
||||
// the region cannot be found, so it has to be passed
|
||||
Optional: true,
|
||||
Description: descriptions["region"],
|
||||
},
|
||||
"encryption": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"key_id": schema.StringAttribute{
|
||||
Description: descriptions["key_id"],
|
||||
Computed: true,
|
||||
},
|
||||
"key_version": schema.StringAttribute{
|
||||
Description: descriptions["key_version"],
|
||||
Computed: true,
|
||||
},
|
||||
"keyring_id": schema.StringAttribute{
|
||||
Description: descriptions["keyring_id"],
|
||||
Computed: true,
|
||||
},
|
||||
"service_account": schema.StringAttribute{
|
||||
Description: descriptions["service_account"],
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
Description: descriptions["encryption"],
|
||||
},
|
||||
"network": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"access_scope": schema.StringAttribute{
|
||||
Description: descriptions["access_scope"],
|
||||
Computed: true,
|
||||
},
|
||||
"instance_address": schema.StringAttribute{
|
||||
Description: descriptions["instance_address"],
|
||||
Computed: true,
|
||||
},
|
||||
"router_address": schema.StringAttribute{
|
||||
Description: descriptions["router_address"],
|
||||
Computed: true,
|
||||
},
|
||||
"acl": schema.ListAttribute{
|
||||
Description: descriptions["acl"],
|
||||
ElementType: types.StringType,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
Description: descriptions["network"],
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
// Read Terraform configuration data into the model
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
||||
|
||||
// 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 Model
|
||||
diags := req.Config.Get(ctx, &model)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
projectId := model.ProjectId.ValueString()
|
||||
instanceId := model.InstanceId.ValueString()
|
||||
region := r.providerData.GetRegionWithOverride(model.Region)
|
||||
projectId := data.ProjectId.ValueString()
|
||||
region := d.providerData.GetRegionWithOverride(data.Region)
|
||||
instanceId := data.InstanceId.ValueString()
|
||||
|
||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
||||
ctx = tflog.SetField(ctx, "region", region)
|
||||
instanceResp, err := r.client.GetInstanceRequest(ctx, projectId, region, instanceId).Execute()
|
||||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
||||
|
||||
instanceResp, err := d.client.DefaultAPI.GetInstanceRequest(ctx, projectId, region, instanceId).Execute()
|
||||
if err != nil {
|
||||
utils.LogError(
|
||||
ctx,
|
||||
&resp.Diagnostics,
|
||||
err,
|
||||
"Reading instance",
|
||||
fmt.Sprintf("Instance with ID %q does not exist in project %q.", instanceId, projectId),
|
||||
fmt.Sprintf("instance with ID %q does not exist in project %q.", instanceId, projectId),
|
||||
map[int]string{
|
||||
http.StatusForbidden: fmt.Sprintf("Project with ID %q not found or forbidden access", projectId),
|
||||
},
|
||||
|
|
@ -237,59 +130,17 @@ func (r *instanceDataSource) Read(ctx context.Context, req datasource.ReadReques
|
|||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
var flavor = &flavorModel{}
|
||||
if model.Flavor.IsNull() || model.Flavor.IsUnknown() {
|
||||
flavor.Id = types.StringValue(*instanceResp.FlavorId)
|
||||
if flavor.Id.IsNull() || flavor.Id.IsUnknown() || flavor.Id.String() == "" {
|
||||
panic("WTF FlavorId can not be null or empty string")
|
||||
}
|
||||
err = getFlavorModelById(ctx, r.client, &model, flavor)
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError(err.Error(), err.Error())
|
||||
return
|
||||
}
|
||||
if flavor.CPU.IsNull() || flavor.CPU.IsUnknown() || flavor.CPU.String() == "" {
|
||||
panic("WTF FlavorId can not be null or empty string")
|
||||
}
|
||||
}
|
||||
|
||||
var storage = &storageModel{}
|
||||
if !(model.Storage.IsNull() || model.Storage.IsUnknown()) {
|
||||
diags = model.Storage.As(ctx, storage, basetypes.ObjectAsOptions{})
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
var encryption = &encryptionModel{}
|
||||
if !(model.Encryption.IsNull() || model.Encryption.IsUnknown()) {
|
||||
diags = model.Encryption.As(ctx, encryption, basetypes.ObjectAsOptions{})
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
var network = &networkModel{}
|
||||
if !(model.Network.IsNull() || model.Network.IsUnknown()) {
|
||||
diags = model.Network.As(ctx, network, basetypes.ObjectAsOptions{})
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err = mapFields(ctx, instanceResp, &model, flavor, storage, encryption, network, region)
|
||||
err = mapDataResponseToModel(ctx, instanceResp, &data, resp.Diagnostics)
|
||||
if err != nil {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading instance", fmt.Sprintf("Processing API payload: %v", err))
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
&resp.Diagnostics,
|
||||
fmt.Sprintf("%s Read", errorPrefix),
|
||||
fmt.Sprintf("Processing API payload: %v", err),
|
||||
)
|
||||
return
|
||||
}
|
||||
// Set refreshed state
|
||||
diags = resp.State.Set(ctx, model)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "SQLServer Flex instance read")
|
||||
|
||||
// Save data into Terraform state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,430 +1,277 @@
|
|||
package sqlserverflex
|
||||
package sqlserverflexalpha
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"math"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||
sqlserverflex "github.com/stackitcloud/terraform-provider-stackit/pkg/sqlserverflexalpha"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
|
||||
sqlserverflexalpha "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3alpha1api"
|
||||
|
||||
sqlserverflexalphaDataGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/instance/datasources_gen"
|
||||
sqlserverflexalphaResGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/instance/resources_gen"
|
||||
)
|
||||
|
||||
type sqlserverflexClient interface {
|
||||
GetFlavorsRequestExecute(ctx context.Context, projectId, region string, page, size *int64, sort sqlserverflex.FlavorSort) (*sqlserverflex.GetFlavorsResponse, error)
|
||||
}
|
||||
|
||||
func mapFields(ctx context.Context, resp *sqlserverflex.GetInstanceResponse, model *Model, flavor *flavorModel, 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 flavorValues map[string]attr.Value
|
||||
if instance.FlavorId == nil {
|
||||
return fmt.Errorf("instance has no flavor id")
|
||||
}
|
||||
if *instance.FlavorId != flavor.Id.ValueString() {
|
||||
return fmt.Errorf("instance has different flavor id %s - %s", *instance.FlavorId, flavor.Id.ValueString())
|
||||
}
|
||||
|
||||
flavorValues = map[string]attr.Value{
|
||||
"id": flavor.Id,
|
||||
"description": flavor.Description,
|
||||
"cpu": flavor.CPU,
|
||||
"ram": flavor.RAM,
|
||||
"node_type": flavor.NodeType,
|
||||
}
|
||||
flavorObject, diags := types.ObjectValue(flavorTypes, flavorValues)
|
||||
func mapResponseToModel(
|
||||
ctx context.Context,
|
||||
resp *sqlserverflexalpha.GetInstanceResponse,
|
||||
m *sqlserverflexalphaResGen.InstanceModel,
|
||||
tfDiags diag.Diagnostics,
|
||||
) error {
|
||||
m.BackupSchedule = types.StringValue(resp.GetBackupSchedule())
|
||||
m.Edition = types.StringValue(string(resp.GetEdition()))
|
||||
m.Encryption = handleEncryption(m, resp)
|
||||
m.FlavorId = types.StringValue(resp.GetFlavorId())
|
||||
m.Id = types.StringValue(resp.GetId())
|
||||
m.InstanceId = types.StringValue(resp.GetId())
|
||||
m.IsDeletable = types.BoolValue(resp.GetIsDeletable())
|
||||
m.Name = types.StringValue(resp.GetName())
|
||||
netAcl, diags := types.ListValueFrom(ctx, types.StringType, resp.Network.GetAcl())
|
||||
tfDiags.Append(diags...)
|
||||
if diags.HasError() {
|
||||
return fmt.Errorf("creating flavor: %w", core.DiagsToError(diags))
|
||||
return fmt.Errorf(
|
||||
"error converting network acl response value",
|
||||
)
|
||||
}
|
||||
|
||||
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)
|
||||
net, diags := sqlserverflexalphaResGen.NewNetworkValue(
|
||||
sqlserverflexalphaResGen.NetworkValue{}.AttributeTypes(ctx),
|
||||
map[string]attr.Value{
|
||||
"access_scope": types.StringValue(string(resp.Network.GetAccessScope())),
|
||||
"acl": netAcl,
|
||||
"instance_address": types.StringValue(resp.Network.GetInstanceAddress()),
|
||||
"router_address": types.StringValue(resp.Network.GetRouterAddress()),
|
||||
},
|
||||
)
|
||||
tfDiags.Append(diags...)
|
||||
if diags.HasError() {
|
||||
return fmt.Errorf("creating storage: %w", core.DiagsToError(diags))
|
||||
return errors.New("error converting network response value")
|
||||
}
|
||||
m.Network = net
|
||||
m.Replicas = types.Int64Value(int64(resp.GetReplicas()))
|
||||
m.RetentionDays = types.Int64Value(int64(resp.GetRetentionDays()))
|
||||
m.Status = types.StringValue(string(resp.GetStatus()))
|
||||
|
||||
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)
|
||||
stor, diags := sqlserverflexalphaResGen.NewStorageValue(
|
||||
sqlserverflexalphaResGen.StorageValue{}.AttributeTypes(ctx),
|
||||
map[string]attr.Value{
|
||||
"class": types.StringValue(resp.Storage.GetClass()),
|
||||
"size": types.Int64Value(resp.Storage.GetSize()),
|
||||
},
|
||||
)
|
||||
tfDiags.Append(diags...)
|
||||
if diags.HasError() {
|
||||
return fmt.Errorf("creating encryption: %w", core.DiagsToError(diags))
|
||||
return fmt.Errorf("error converting storage response value")
|
||||
}
|
||||
m.Storage = stor
|
||||
|
||||
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.Flavor = flavorObject
|
||||
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)
|
||||
m.Version = types.StringValue(string(resp.GetVersion()))
|
||||
return nil
|
||||
}
|
||||
|
||||
func toCreatePayload(model *Model, storage *storageModel, encryption *encryptionModel, network *networkModel) (*sqlserverflex.CreateInstanceRequestPayload, error) {
|
||||
func mapDataResponseToModel(
|
||||
ctx context.Context,
|
||||
resp *sqlserverflexalpha.GetInstanceResponse,
|
||||
m *dataSourceModel,
|
||||
tfDiags diag.Diagnostics,
|
||||
) error {
|
||||
m.BackupSchedule = types.StringValue(resp.GetBackupSchedule())
|
||||
m.Edition = types.StringValue(string(resp.GetEdition()))
|
||||
m.Encryption = handleDSEncryption(m, resp)
|
||||
m.FlavorId = types.StringValue(resp.GetFlavorId())
|
||||
m.Id = types.StringValue(resp.GetId())
|
||||
m.InstanceId = types.StringValue(resp.GetId())
|
||||
m.IsDeletable = types.BoolValue(resp.GetIsDeletable())
|
||||
m.Name = types.StringValue(resp.GetName())
|
||||
netAcl, diags := types.ListValueFrom(ctx, types.StringType, resp.Network.GetAcl())
|
||||
tfDiags.Append(diags...)
|
||||
if diags.HasError() {
|
||||
return fmt.Errorf(
|
||||
"error converting network acl response value",
|
||||
)
|
||||
}
|
||||
net, diags := sqlserverflexalphaDataGen.NewNetworkValue(
|
||||
sqlserverflexalphaDataGen.NetworkValue{}.AttributeTypes(ctx),
|
||||
map[string]attr.Value{
|
||||
"access_scope": types.StringValue(string(resp.Network.GetAccessScope())),
|
||||
"acl": netAcl,
|
||||
"instance_address": types.StringValue(resp.Network.GetInstanceAddress()),
|
||||
"router_address": types.StringValue(resp.Network.GetRouterAddress()),
|
||||
},
|
||||
)
|
||||
tfDiags.Append(diags...)
|
||||
if diags.HasError() {
|
||||
return errors.New("error converting network response value")
|
||||
}
|
||||
m.Network = net
|
||||
m.Replicas = types.Int64Value(int64(resp.GetReplicas()))
|
||||
m.RetentionDays = types.Int64Value(int64(resp.GetRetentionDays()))
|
||||
m.Status = types.StringValue(string(resp.GetStatus()))
|
||||
|
||||
stor, diags := sqlserverflexalphaDataGen.NewStorageValue(
|
||||
sqlserverflexalphaDataGen.StorageValue{}.AttributeTypes(ctx),
|
||||
map[string]attr.Value{
|
||||
"class": types.StringValue(resp.Storage.GetClass()),
|
||||
"size": types.Int64Value(resp.Storage.GetSize()),
|
||||
},
|
||||
)
|
||||
tfDiags.Append(diags...)
|
||||
if diags.HasError() {
|
||||
return fmt.Errorf("error converting storage response value")
|
||||
}
|
||||
m.Storage = stor
|
||||
|
||||
m.Version = types.StringValue(string(resp.GetVersion()))
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleEncryption(
|
||||
m *sqlserverflexalphaResGen.InstanceModel,
|
||||
resp *sqlserverflexalpha.GetInstanceResponse,
|
||||
) sqlserverflexalphaResGen.EncryptionValue {
|
||||
if !resp.HasEncryption() ||
|
||||
resp.Encryption == nil ||
|
||||
resp.Encryption.KekKeyId == "" ||
|
||||
resp.Encryption.KekKeyRingId == "" ||
|
||||
resp.Encryption.KekKeyVersion == "" ||
|
||||
resp.Encryption.ServiceAccount == "" {
|
||||
if m.Encryption.IsNull() || m.Encryption.IsUnknown() {
|
||||
return sqlserverflexalphaResGen.NewEncryptionValueNull()
|
||||
}
|
||||
return m.Encryption
|
||||
}
|
||||
|
||||
enc := sqlserverflexalphaResGen.NewEncryptionValueNull()
|
||||
if kVal, ok := resp.Encryption.GetKekKeyIdOk(); ok {
|
||||
enc.KekKeyId = types.StringValue(*kVal)
|
||||
}
|
||||
if kkVal, ok := resp.Encryption.GetKekKeyRingIdOk(); ok {
|
||||
enc.KekKeyRingId = types.StringValue(*kkVal)
|
||||
}
|
||||
if kkvVal, ok := resp.Encryption.GetKekKeyVersionOk(); ok {
|
||||
enc.KekKeyVersion = types.StringValue(*kkvVal)
|
||||
}
|
||||
if sa, ok := resp.Encryption.GetServiceAccountOk(); ok {
|
||||
enc.ServiceAccount = types.StringValue(*sa)
|
||||
}
|
||||
return enc
|
||||
}
|
||||
|
||||
func handleDSEncryption(
|
||||
m *dataSourceModel,
|
||||
resp *sqlserverflexalpha.GetInstanceResponse,
|
||||
) sqlserverflexalphaDataGen.EncryptionValue {
|
||||
if !resp.HasEncryption() ||
|
||||
resp.Encryption == nil ||
|
||||
resp.Encryption.KekKeyId == "" ||
|
||||
resp.Encryption.KekKeyRingId == "" ||
|
||||
resp.Encryption.KekKeyVersion == "" ||
|
||||
resp.Encryption.ServiceAccount == "" {
|
||||
if m.Encryption.IsNull() || m.Encryption.IsUnknown() {
|
||||
return sqlserverflexalphaDataGen.NewEncryptionValueNull()
|
||||
}
|
||||
return m.Encryption
|
||||
}
|
||||
|
||||
enc := sqlserverflexalphaDataGen.NewEncryptionValueNull()
|
||||
if kVal, ok := resp.Encryption.GetKekKeyIdOk(); ok {
|
||||
enc.KekKeyId = types.StringValue(*kVal)
|
||||
}
|
||||
if kkVal, ok := resp.Encryption.GetKekKeyRingIdOk(); ok {
|
||||
enc.KekKeyRingId = types.StringValue(*kkVal)
|
||||
}
|
||||
if kkvVal, ok := resp.Encryption.GetKekKeyVersionOk(); ok {
|
||||
enc.KekKeyVersion = types.StringValue(*kkvVal)
|
||||
}
|
||||
if sa, ok := resp.Encryption.GetServiceAccountOk(); ok {
|
||||
enc.ServiceAccount = types.StringValue(*sa)
|
||||
}
|
||||
return enc
|
||||
}
|
||||
|
||||
func toCreatePayload(
|
||||
ctx context.Context,
|
||||
model *sqlserverflexalphaResGen.InstanceModel,
|
||||
) (*sqlserverflexalpha.CreateInstanceRequestPayload, error) {
|
||||
if model == nil {
|
||||
return nil, fmt.Errorf("nil model")
|
||||
}
|
||||
|
||||
if model.Flavor.IsNull() || model.Flavor.IsUnknown() {
|
||||
return nil, fmt.Errorf("nil flavor")
|
||||
storagePayload := sqlserverflexalpha.StorageCreate{}
|
||||
if !model.Storage.IsNull() && !model.Storage.IsUnknown() {
|
||||
storagePayload.Class = model.Storage.Class.ValueString()
|
||||
storagePayload.Size = model.Storage.Size.ValueInt64()
|
||||
}
|
||||
|
||||
storagePayload := &sqlserverflex.CreateInstanceRequestPayloadGetStorageArgType{}
|
||||
if storage != nil {
|
||||
storagePayload.Class = conversion.StringValueToPointer(storage.Class)
|
||||
storagePayload.Size = conversion.Int64ValueToPointer(storage.Size)
|
||||
}
|
||||
|
||||
encryptionPayload := &sqlserverflex.CreateInstanceRequestPayloadGetEncryptionArgType{}
|
||||
if encryption != nil {
|
||||
encryptionPayload.KekKeyId = conversion.StringValueToPointer(encryption.KeyId)
|
||||
encryptionPayload.KekKeyVersion = conversion.StringValueToPointer(encryption.KeyVersion)
|
||||
encryptionPayload.KekKeyRingId = conversion.StringValueToPointer(encryption.KeyRingId)
|
||||
encryptionPayload.ServiceAccount = conversion.StringValueToPointer(encryption.ServiceAccount)
|
||||
}
|
||||
|
||||
networkPayload := &sqlserverflex.CreateInstanceRequestPayloadGetNetworkArgType{}
|
||||
if network != nil {
|
||||
networkPayload.AccessScope = sqlserverflex.CreateInstanceRequestPayloadNetworkGetAccessScopeAttributeType(conversion.StringValueToPointer(network.AccessScope))
|
||||
}
|
||||
|
||||
flavorId := ""
|
||||
if !(model.Flavor.IsNull() || model.Flavor.IsUnknown()) {
|
||||
modelValues := model.Flavor.Attributes()
|
||||
if _, ok := modelValues["id"]; !ok {
|
||||
return nil, fmt.Errorf("flavor has not yet been created")
|
||||
var encryptionPayload *sqlserverflexalpha.InstanceEncryption = nil
|
||||
if !model.Encryption.IsNull() && !model.Encryption.IsUnknown() &&
|
||||
!model.Encryption.KekKeyId.IsNull() && model.Encryption.KekKeyId.IsUnknown() && model.Encryption.KekKeyId.ValueString() != "" &&
|
||||
!model.Encryption.KekKeyRingId.IsNull() && !model.Encryption.KekKeyRingId.IsUnknown() && model.Encryption.KekKeyRingId.ValueString() != "" &&
|
||||
!model.Encryption.KekKeyVersion.IsNull() && !model.Encryption.KekKeyVersion.IsUnknown() && model.Encryption.KekKeyVersion.ValueString() != "" &&
|
||||
!model.Encryption.ServiceAccount.IsNull() && !model.Encryption.ServiceAccount.IsUnknown() && model.Encryption.ServiceAccount.ValueString() != "" {
|
||||
encryptionPayload = &sqlserverflexalpha.InstanceEncryption{
|
||||
KekKeyId: model.Encryption.KekKeyId.ValueString(),
|
||||
KekKeyRingId: model.Encryption.KekKeyVersion.ValueString(),
|
||||
KekKeyVersion: model.Encryption.KekKeyRingId.ValueString(),
|
||||
ServiceAccount: model.Encryption.ServiceAccount.ValueString(),
|
||||
}
|
||||
flavorId = strings.Trim(modelValues["id"].String(), "\"")
|
||||
}
|
||||
|
||||
var aclElements []string
|
||||
if network != nil && !(network.ACL.IsNull() || network.ACL.IsUnknown()) {
|
||||
aclElements = make([]string, 0, len(network.ACL.Elements()))
|
||||
diags := network.ACL.ElementsAs(nil, &aclElements, false)
|
||||
networkPayload := sqlserverflexalpha.CreateInstanceRequestPayloadNetwork{}
|
||||
if !model.Network.IsNull() && !model.Network.IsUnknown() {
|
||||
networkPayload.AccessScope = (*sqlserverflexalpha.InstanceNetworkAccessScope)(model.Network.AccessScope.ValueStringPointer())
|
||||
|
||||
var resList []string
|
||||
diags := model.Network.Acl.ElementsAs(ctx, &resList, false)
|
||||
if diags.HasError() {
|
||||
return nil, fmt.Errorf("creating network: %w", core.DiagsToError(diags))
|
||||
return nil, fmt.Errorf("error converting network acl list")
|
||||
}
|
||||
networkPayload.Acl = resList
|
||||
}
|
||||
|
||||
return &sqlserverflex.CreateInstanceRequestPayload{
|
||||
Acl: &aclElements,
|
||||
BackupSchedule: conversion.StringValueToPointer(model.BackupSchedule),
|
||||
FlavorId: &flavorId,
|
||||
Name: conversion.StringValueToPointer(model.Name),
|
||||
Storage: storagePayload,
|
||||
Version: sqlserverflex.CreateInstanceRequestPayloadGetVersionAttributeType(conversion.StringValueToPointer(model.Version)),
|
||||
return &sqlserverflexalpha.CreateInstanceRequestPayload{
|
||||
BackupSchedule: model.BackupSchedule.ValueString(),
|
||||
Encryption: encryptionPayload,
|
||||
RetentionDays: conversion.Int64ValueToPointer(model.RetentionDays),
|
||||
FlavorId: model.FlavorId.ValueString(),
|
||||
Name: model.Name.ValueString(),
|
||||
Network: networkPayload,
|
||||
RetentionDays: int32(model.RetentionDays.ValueInt64()), //nolint:gosec // TODO
|
||||
Storage: storagePayload,
|
||||
Version: sqlserverflexalpha.InstanceVersion(model.Version.ValueString()),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func toUpdatePayload(model *Model, storage *storageModel, network *networkModel) (*sqlserverflex.UpdateInstancePartiallyRequestPayload, error) {
|
||||
if model == nil {
|
||||
func toUpdatePayload(
|
||||
ctx context.Context,
|
||||
m *sqlserverflexalphaResGen.InstanceModel,
|
||||
resp *resource.UpdateResponse,
|
||||
) (*sqlserverflexalpha.UpdateInstanceRequestPayload, error) {
|
||||
if m == nil {
|
||||
return nil, fmt.Errorf("nil model")
|
||||
}
|
||||
if model.Flavor.IsNull() || model.Flavor.IsUnknown() {
|
||||
return nil, fmt.Errorf("nil flavor")
|
||||
}
|
||||
var flavorMdl flavorModel
|
||||
diag := model.Flavor.As(context.Background(), &flavorMdl, basetypes.ObjectAsOptions{
|
||||
UnhandledNullAsEmpty: true,
|
||||
UnhandledUnknownAsEmpty: false,
|
||||
})
|
||||
if diag.HasError() {
|
||||
return nil, fmt.Errorf("flavor conversion error: %v", diag.Errors())
|
||||
if m.Replicas.ValueInt64() > math.MaxUint32 {
|
||||
return nil, fmt.Errorf("replicas value is too big for uint32")
|
||||
}
|
||||
replVal := sqlserverflexalpha.Replicas(uint32(m.Replicas.ValueInt64())) // nolint:gosec // check is performed above
|
||||
|
||||
storagePayload := &sqlserverflex.UpdateInstanceRequestPayloadGetStorageArgType{}
|
||||
if storage != nil {
|
||||
storagePayload.Size = conversion.Int64ValueToPointer(storage.Size)
|
||||
var netAcl []string
|
||||
diags := m.Network.Acl.ElementsAs(ctx, &netAcl, false)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if diags.HasError() {
|
||||
return nil, fmt.Errorf("error converting model network acl value")
|
||||
}
|
||||
|
||||
var aclElements []string
|
||||
if network != nil && !(network.ACL.IsNull() || network.ACL.IsUnknown()) {
|
||||
aclElements = make([]string, 0, len(network.ACL.Elements()))
|
||||
diags := network.ACL.ElementsAs(nil, &aclElements, false)
|
||||
if diags.HasError() {
|
||||
return nil, fmt.Errorf("creating network: %w", core.DiagsToError(diags))
|
||||
}
|
||||
}
|
||||
|
||||
// TODO - implement network.ACL as soon as it becomes available
|
||||
replCount := int32(model.Replicas.ValueInt64())
|
||||
flavorId := flavorMdl.Id.ValueString()
|
||||
return &sqlserverflex.UpdateInstancePartiallyRequestPayload{
|
||||
Acl: &aclElements,
|
||||
BackupSchedule: conversion.StringValueToPointer(model.BackupSchedule),
|
||||
FlavorId: &flavorId,
|
||||
Name: conversion.StringValueToPointer(model.Name),
|
||||
Replicas: sqlserverflex.UpdateInstancePartiallyRequestPayloadGetReplicasAttributeType(&replCount),
|
||||
RetentionDays: conversion.Int64ValueToPointer(model.RetentionDays),
|
||||
Storage: storagePayload,
|
||||
Version: sqlserverflex.UpdateInstancePartiallyRequestPayloadGetVersionAttributeType(conversion.StringValueToPointer(model.Version)),
|
||||
return &sqlserverflexalpha.UpdateInstanceRequestPayload{
|
||||
BackupSchedule: m.BackupSchedule.ValueString(),
|
||||
FlavorId: m.FlavorId.ValueString(),
|
||||
Name: m.Name.ValueString(),
|
||||
Network: sqlserverflexalpha.UpdateInstanceRequestPayloadNetwork{Acl: netAcl},
|
||||
Replicas: replVal,
|
||||
RetentionDays: int32(m.RetentionDays.ValueInt64()), //nolint:gosec // TODO
|
||||
Storage: sqlserverflexalpha.StorageUpdate{Size: m.Storage.Size.ValueInt64Pointer()},
|
||||
Version: sqlserverflexalpha.InstanceVersion(m.Version.ValueString()),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getAllFlavors(ctx context.Context, client sqlserverflexClient, projectId, region string) ([]sqlserverflex.ListFlavors, error) {
|
||||
if projectId == "" || region == "" {
|
||||
return nil, fmt.Errorf("listing sqlserverflex flavors: projectId and region are required")
|
||||
}
|
||||
var flavorList []sqlserverflex.ListFlavors
|
||||
|
||||
page := int64(1)
|
||||
size := int64(10)
|
||||
for {
|
||||
res, err := client.GetFlavorsRequestExecute(ctx, projectId, region, &page, &size, sqlserverflex.FLAVORSORT_INDEX_ASC)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("listing sqlserverflex flavors: %w", err)
|
||||
}
|
||||
if res.Flavors == nil {
|
||||
return nil, fmt.Errorf("finding flavors for project %s", projectId)
|
||||
}
|
||||
pagination := res.GetPagination()
|
||||
flavorList = append(flavorList, *res.Flavors...)
|
||||
|
||||
if *pagination.TotalRows == int64(len(flavorList)) {
|
||||
break
|
||||
}
|
||||
page++
|
||||
}
|
||||
return flavorList, nil
|
||||
}
|
||||
|
||||
func loadFlavorId(ctx context.Context, client sqlserverflexClient, model *Model, flavor *flavorModel, storage *storageModel) error {
|
||||
if model == nil {
|
||||
return fmt.Errorf("nil model")
|
||||
}
|
||||
if flavor == nil {
|
||||
return fmt.Errorf("nil flavor")
|
||||
}
|
||||
cpu := conversion.Int64ValueToPointer(flavor.CPU)
|
||||
if cpu == nil {
|
||||
return fmt.Errorf("nil CPU")
|
||||
}
|
||||
ram := conversion.Int64ValueToPointer(flavor.RAM)
|
||||
if ram == nil {
|
||||
return fmt.Errorf("nil RAM")
|
||||
}
|
||||
nodeType := conversion.StringValueToPointer(flavor.NodeType)
|
||||
if nodeType == nil {
|
||||
return fmt.Errorf("nil NodeType")
|
||||
}
|
||||
storageClass := conversion.StringValueToPointer(storage.Class)
|
||||
if storageClass == nil {
|
||||
return fmt.Errorf("nil StorageClass")
|
||||
}
|
||||
storageSize := conversion.Int64ValueToPointer(storage.Size)
|
||||
if storageSize == nil {
|
||||
return fmt.Errorf("nil StorageSize")
|
||||
}
|
||||
|
||||
projectId := model.ProjectId.ValueString()
|
||||
region := model.Region.ValueString()
|
||||
|
||||
flavorList, err := getAllFlavors(ctx, client, projectId, region)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
avl := ""
|
||||
foundFlavorCount := 0
|
||||
for _, f := range flavorList {
|
||||
if f.Id == nil || f.Cpu == nil || f.Memory == nil {
|
||||
continue
|
||||
}
|
||||
if strings.ToLower(*f.NodeType) != strings.ToLower(*nodeType) {
|
||||
continue
|
||||
}
|
||||
if *f.Cpu == *cpu && *f.Memory == *ram {
|
||||
var useSc *sqlserverflex.FlavorStorageClassesStorageClass
|
||||
for _, sc := range *f.StorageClasses {
|
||||
if *sc.Class != *storageClass {
|
||||
continue
|
||||
}
|
||||
if *storageSize < *f.MinGB || *storageSize > *f.MaxGB {
|
||||
return fmt.Errorf("storage size %d out of bounds (min: %d - max: %d)", *storageSize, *f.MinGB, *f.MaxGB)
|
||||
}
|
||||
useSc = &sc
|
||||
}
|
||||
if useSc == nil {
|
||||
return fmt.Errorf("no storage class found for %s", *storageClass)
|
||||
}
|
||||
|
||||
flavor.Id = types.StringValue(*f.Id)
|
||||
flavor.Description = types.StringValue(*f.Description)
|
||||
foundFlavorCount++
|
||||
}
|
||||
for _, cls := range *f.StorageClasses {
|
||||
avl = fmt.Sprintf("%s\n- %d CPU, %d GB RAM, storage %s (min: %d - max: %d)", avl, *f.Cpu, *f.Memory, *cls.Class, *f.MinGB, *f.MaxGB)
|
||||
}
|
||||
}
|
||||
if foundFlavorCount > 1 {
|
||||
return fmt.Errorf("multiple flavors found: %d flavors", foundFlavorCount)
|
||||
}
|
||||
if flavor.Id.ValueString() == "" {
|
||||
return fmt.Errorf("couldn't find flavor, available specs are:%s", avl)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getFlavorModelById(ctx context.Context, client sqlserverflexClient, model *Model, flavor *flavorModel) error {
|
||||
if model == nil {
|
||||
return fmt.Errorf("nil model")
|
||||
}
|
||||
if flavor == nil {
|
||||
return fmt.Errorf("nil flavor")
|
||||
}
|
||||
id := conversion.StringValueToPointer(flavor.Id)
|
||||
if id == nil {
|
||||
return fmt.Errorf("nil flavor ID")
|
||||
}
|
||||
|
||||
flavor.Id = types.StringValue("")
|
||||
|
||||
projectId := model.ProjectId.ValueString()
|
||||
region := model.Region.ValueString()
|
||||
|
||||
flavorList, err := getAllFlavors(ctx, client, projectId, region)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
avl := ""
|
||||
for _, f := range flavorList {
|
||||
if f.Id == nil || f.Cpu == nil || f.Memory == nil {
|
||||
continue
|
||||
}
|
||||
if *f.Id == *id {
|
||||
flavor.Id = types.StringValue(*f.Id)
|
||||
flavor.Description = types.StringValue(*f.Description)
|
||||
flavor.CPU = types.Int64Value(*f.Cpu)
|
||||
flavor.RAM = types.Int64Value(*f.Memory)
|
||||
flavor.NodeType = types.StringValue(*f.NodeType)
|
||||
break
|
||||
}
|
||||
avl = fmt.Sprintf("%s\n- %d CPU, %d GB RAM", avl, *f.Cpu, *f.Memory)
|
||||
}
|
||||
if flavor.Id.ValueString() == "" {
|
||||
return fmt.Errorf("couldn't find flavor, available specs are: %s", avl)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,124 @@
|
|||
fields:
|
||||
- name: 'id'
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
|
||||
- name: 'instance_id'
|
||||
validators:
|
||||
- validate.NoSeparator
|
||||
- validate.UUID
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
|
||||
- name: 'project_id'
|
||||
validators:
|
||||
- validate.NoSeparator
|
||||
- validate.UUID
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
- 'RequiresReplace'
|
||||
|
||||
- name: 'name'
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
|
||||
- name: 'backup_schedule'
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
|
||||
- name: 'encryption.kek_key_id'
|
||||
validators:
|
||||
- validate.NoSeparator
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
- 'RequiresReplace'
|
||||
|
||||
- name: 'encryption.kek_key_version'
|
||||
validators:
|
||||
- validate.NoSeparator
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
- 'RequiresReplace'
|
||||
|
||||
- name: 'encryption.kek_key_ring_id'
|
||||
validators:
|
||||
- validate.NoSeparator
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
- 'RequiresReplace'
|
||||
|
||||
- name: 'encryption.service_account'
|
||||
validators:
|
||||
- validate.NoSeparator
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
- 'RequiresReplace'
|
||||
|
||||
- name: 'network.access_scope'
|
||||
validators:
|
||||
- validate.NoSeparator
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
- 'RequiresReplace'
|
||||
|
||||
- name: 'network.acl'
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
|
||||
- name: 'network.instance_address'
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
|
||||
- name: 'network.router_address'
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
|
||||
- name: 'status'
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
|
||||
- name: 'region'
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
- 'RequiresReplace'
|
||||
|
||||
- name: 'retention_days'
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
|
||||
- name: 'edition'
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
- 'RequiresReplace'
|
||||
|
||||
- name: 'version'
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
- 'RequiresReplace'
|
||||
|
||||
- name: 'replicas'
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
- 'RequiresReplace'
|
||||
|
||||
- name: 'storage'
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
|
||||
- name: 'storage.class'
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
- 'RequiresReplace'
|
||||
|
||||
- name: 'storage.size'
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
|
||||
- name: 'flavor_id'
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
- 'RequiresReplace'
|
||||
|
||||
- name: 'is_deletable'
|
||||
modifiers:
|
||||
- 'UseStateForUnknown'
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,282 +0,0 @@
|
|||
// Copyright (c) STACKIT
|
||||
|
||||
package sqlserverflex
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
||||
|
||||
sqlserverflex "github.com/stackitcloud/terraform-provider-stackit/pkg/sqlserverflexalpha"
|
||||
)
|
||||
|
||||
func TestNewInstanceResource(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
want resource.Resource
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := NewInstanceResource(); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("NewInstanceResource() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_instanceResource_Configure(t *testing.T) {
|
||||
type fields struct {
|
||||
client *sqlserverflex.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
req resource.ConfigureRequest
|
||||
resp *resource.ConfigureResponse
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &instanceResource{
|
||||
client: tt.fields.client,
|
||||
providerData: tt.fields.providerData,
|
||||
}
|
||||
r.Configure(tt.args.ctx, tt.args.req, tt.args.resp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_instanceResource_Create(t *testing.T) {
|
||||
type fields struct {
|
||||
client *sqlserverflex.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
req resource.CreateRequest
|
||||
resp *resource.CreateResponse
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &instanceResource{
|
||||
client: tt.fields.client,
|
||||
providerData: tt.fields.providerData,
|
||||
}
|
||||
r.Create(tt.args.ctx, tt.args.req, tt.args.resp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_instanceResource_Delete(t *testing.T) {
|
||||
type fields struct {
|
||||
client *sqlserverflex.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
req resource.DeleteRequest
|
||||
resp *resource.DeleteResponse
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &instanceResource{
|
||||
client: tt.fields.client,
|
||||
providerData: tt.fields.providerData,
|
||||
}
|
||||
r.Delete(tt.args.ctx, tt.args.req, tt.args.resp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_instanceResource_ImportState(t *testing.T) {
|
||||
type fields struct {
|
||||
client *sqlserverflex.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
req resource.ImportStateRequest
|
||||
resp *resource.ImportStateResponse
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &instanceResource{
|
||||
client: tt.fields.client,
|
||||
providerData: tt.fields.providerData,
|
||||
}
|
||||
r.ImportState(tt.args.ctx, tt.args.req, tt.args.resp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_instanceResource_Metadata(t *testing.T) {
|
||||
type fields struct {
|
||||
client *sqlserverflex.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
type args struct {
|
||||
in0 context.Context
|
||||
req resource.MetadataRequest
|
||||
resp *resource.MetadataResponse
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &instanceResource{
|
||||
client: tt.fields.client,
|
||||
providerData: tt.fields.providerData,
|
||||
}
|
||||
r.Metadata(tt.args.in0, tt.args.req, tt.args.resp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_instanceResource_ModifyPlan(t *testing.T) {
|
||||
type fields struct {
|
||||
client *sqlserverflex.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
req resource.ModifyPlanRequest
|
||||
resp *resource.ModifyPlanResponse
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &instanceResource{
|
||||
client: tt.fields.client,
|
||||
providerData: tt.fields.providerData,
|
||||
}
|
||||
r.ModifyPlan(tt.args.ctx, tt.args.req, tt.args.resp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_instanceResource_Read(t *testing.T) {
|
||||
type fields struct {
|
||||
client *sqlserverflex.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
req resource.ReadRequest
|
||||
resp *resource.ReadResponse
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &instanceResource{
|
||||
client: tt.fields.client,
|
||||
providerData: tt.fields.providerData,
|
||||
}
|
||||
r.Read(tt.args.ctx, tt.args.req, tt.args.resp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_instanceResource_Schema(t *testing.T) {
|
||||
type fields struct {
|
||||
client *sqlserverflex.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
type args struct {
|
||||
in0 context.Context
|
||||
in1 resource.SchemaRequest
|
||||
resp *resource.SchemaResponse
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &instanceResource{
|
||||
client: tt.fields.client,
|
||||
providerData: tt.fields.providerData,
|
||||
}
|
||||
r.Schema(tt.args.in0, tt.args.in1, tt.args.resp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_instanceResource_Update(t *testing.T) {
|
||||
type fields struct {
|
||||
client *sqlserverflex.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
req resource.UpdateRequest
|
||||
resp *resource.UpdateResponse
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &instanceResource{
|
||||
client: tt.fields.client,
|
||||
providerData: tt.fields.providerData,
|
||||
}
|
||||
r.Update(tt.args.ctx, tt.args.req, tt.args.resp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -1,862 +0,0 @@
|
|||
package sqlserverflex
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"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 "github.com/stackitcloud/terraform-provider-stackit/pkg/sqlserverflexalpha"
|
||||
)
|
||||
|
||||
type sqlserverflexClientMocked struct {
|
||||
returnError bool
|
||||
listFlavorsResp *sqlserverflex.GetFlavorsResponse
|
||||
}
|
||||
|
||||
func (c *sqlserverflexClientMocked) GetFlavorsExecute(_ context.Context, _, _ string) (*sqlserverflex.GetFlavorsResponse, error) {
|
||||
if c.returnError {
|
||||
return nil, fmt.Errorf("get flavors failed")
|
||||
}
|
||||
|
||||
return c.listFlavorsResp, nil
|
||||
}
|
||||
|
||||
func TestMapFields(t *testing.T) {
|
||||
const testRegion = "region"
|
||||
tests := []struct {
|
||||
description string
|
||||
state Model
|
||||
input *sqlserverflex.GetInstanceResponse
|
||||
flavor *flavorModel
|
||||
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),
|
||||
Flavor: types.ObjectValueMust(flavorTypes, map[string]attr.Value{
|
||||
"id": types.StringValue("flavor_id"),
|
||||
"description": types.StringNull(),
|
||||
"cpu": types.Int64Null(),
|
||||
"ram": types.Int64Null(),
|
||||
"node_type": types.StringNull(),
|
||||
}),
|
||||
},
|
||||
&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),
|
||||
},
|
||||
&flavorModel{
|
||||
Id: types.StringValue("flavor_id"),
|
||||
},
|
||||
&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(),
|
||||
Flavor: types.ObjectValueMust(flavorTypes, map[string]attr.Value{
|
||||
"id": types.StringValue("flavor_id"),
|
||||
"description": types.StringNull(),
|
||||
"cpu": types.Int64Null(),
|
||||
"ram": types.Int64Null(),
|
||||
"node_type": 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{
|
||||
Acl: &[]string{
|
||||
"ip1",
|
||||
"ip2",
|
||||
"",
|
||||
},
|
||||
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,
|
||||
},
|
||||
&flavorModel{
|
||||
Id: basetypes.NewStringValue("flavor_id"),
|
||||
Description: basetypes.NewStringValue("description"),
|
||||
CPU: basetypes.NewInt64Value(12),
|
||||
RAM: basetypes.NewInt64Value(34),
|
||||
NodeType: basetypes.NewStringValue("node_type"),
|
||||
},
|
||||
&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"),
|
||||
Flavor: types.ObjectValueMust(flavorTypes, map[string]attr.Value{
|
||||
"id": types.StringValue("flavor_id"),
|
||||
"description": types.StringValue("description"),
|
||||
"cpu": types.Int64Value(12),
|
||||
"ram": types.Int64Value(34),
|
||||
"node_type": types.StringValue("node_type"),
|
||||
}),
|
||||
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.flavor, 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 {
|
||||
// description string
|
||||
// input *Model
|
||||
// inputAcl []string
|
||||
// inputFlavor *flavorModel
|
||||
// inputStorage *storageModel
|
||||
// inputOptions *optionsModel
|
||||
// expected *sqlserverflex.CreateInstanceRequestPayload
|
||||
// isValid bool
|
||||
// }{
|
||||
// {
|
||||
// "default_values",
|
||||
// &Model{},
|
||||
// []string{},
|
||||
// &flavorModel{},
|
||||
// &storageModel{},
|
||||
// &optionsModel{},
|
||||
// &sqlserverflex.CreateInstanceRequestPayload{
|
||||
// Acl: &sqlserverflex.CreateInstanceRequestPayloadGetAclArgType{},
|
||||
// Storage: &sqlserverflex.CreateInstanceRequestPayloadGetStorageArgType{},
|
||||
// },
|
||||
// true,
|
||||
// },
|
||||
// {
|
||||
// "simple_values",
|
||||
// &Model{
|
||||
// BackupSchedule: types.StringValue("schedule"),
|
||||
// Name: types.StringValue("name"),
|
||||
// Replicas: types.Int64Value(12),
|
||||
// Version: types.StringValue("version"),
|
||||
// },
|
||||
// []string{
|
||||
// "ip_1",
|
||||
// "ip_2",
|
||||
// },
|
||||
// &flavorModel{
|
||||
// Id: types.StringValue("flavor_id"),
|
||||
// },
|
||||
// &storageModel{
|
||||
// Class: types.StringValue("class"),
|
||||
// Size: types.Int64Value(34),
|
||||
// },
|
||||
// &optionsModel{
|
||||
// Edition: types.StringValue("edition"),
|
||||
// RetentionDays: types.Int64Value(1),
|
||||
// },
|
||||
// &sqlserverflex.CreateInstancePayload{
|
||||
// Acl: &sqlserverflex.CreateInstancePayloadAcl{
|
||||
// Items: &[]string{
|
||||
// "ip_1",
|
||||
// "ip_2",
|
||||
// },
|
||||
// },
|
||||
// BackupSchedule: utils.Ptr("schedule"),
|
||||
// FlavorId: utils.Ptr("flavor_id"),
|
||||
// Name: utils.Ptr("name"),
|
||||
// Storage: &sqlserverflex.CreateInstancePayloadStorage{
|
||||
// Class: utils.Ptr("class"),
|
||||
// Size: utils.Ptr(int64(34)),
|
||||
// },
|
||||
// Options: &sqlserverflex.CreateInstancePayloadOptions{
|
||||
// Edition: utils.Ptr("edition"),
|
||||
// RetentionDays: utils.Ptr("1"),
|
||||
// },
|
||||
// Version: utils.Ptr("version"),
|
||||
// },
|
||||
// true,
|
||||
// },
|
||||
// {
|
||||
// "null_fields_and_int_conversions",
|
||||
// &Model{
|
||||
// BackupSchedule: types.StringNull(),
|
||||
// Name: types.StringNull(),
|
||||
// Replicas: types.Int64Value(2123456789),
|
||||
// Version: types.StringNull(),
|
||||
// },
|
||||
// []string{
|
||||
// "",
|
||||
// },
|
||||
// &flavorModel{
|
||||
// Id: types.StringNull(),
|
||||
// },
|
||||
// &storageModel{
|
||||
// Class: types.StringNull(),
|
||||
// Size: types.Int64Null(),
|
||||
// },
|
||||
// &optionsModel{
|
||||
// Edition: types.StringNull(),
|
||||
// RetentionDays: types.Int64Null(),
|
||||
// },
|
||||
// &sqlserverflex.CreateInstancePayload{
|
||||
// Acl: &sqlserverflex.CreateInstancePayloadAcl{
|
||||
// Items: &[]string{
|
||||
// "",
|
||||
// },
|
||||
// },
|
||||
// BackupSchedule: nil,
|
||||
// FlavorId: nil,
|
||||
// Name: nil,
|
||||
// Storage: &sqlserverflex.CreateInstancePayloadStorage{
|
||||
// Class: nil,
|
||||
// Size: nil,
|
||||
// },
|
||||
// Options: &sqlserverflex.CreateInstancePayloadOptions{},
|
||||
// Version: nil,
|
||||
// },
|
||||
// true,
|
||||
// },
|
||||
// {
|
||||
// "nil_model",
|
||||
// nil,
|
||||
// []string{},
|
||||
// &flavorModel{},
|
||||
// &storageModel{},
|
||||
// &optionsModel{},
|
||||
// nil,
|
||||
// false,
|
||||
// },
|
||||
// {
|
||||
// "nil_acl",
|
||||
// &Model{},
|
||||
// nil,
|
||||
// &flavorModel{},
|
||||
// &storageModel{},
|
||||
// &optionsModel{},
|
||||
// &sqlserverflex.CreateInstancePayload{
|
||||
// Acl: &sqlserverflex.CreateInstancePayloadAcl{},
|
||||
// Storage: &sqlserverflex.CreateInstancePayloadStorage{},
|
||||
// Options: &sqlserverflex.CreateInstancePayloadOptions{},
|
||||
// },
|
||||
// true,
|
||||
// },
|
||||
// {
|
||||
// "nil_flavor",
|
||||
// &Model{},
|
||||
// []string{},
|
||||
// nil,
|
||||
// &storageModel{},
|
||||
// &optionsModel{},
|
||||
// nil,
|
||||
// false,
|
||||
// },
|
||||
// {
|
||||
// "nil_storage",
|
||||
// &Model{},
|
||||
// []string{},
|
||||
// &flavorModel{},
|
||||
// nil,
|
||||
// &optionsModel{},
|
||||
// &sqlserverflex.CreateInstancePayload{
|
||||
// Acl: &sqlserverflex.CreateInstancePayloadAcl{
|
||||
// Items: &[]string{},
|
||||
// },
|
||||
// Storage: &sqlserverflex.CreateInstancePayloadStorage{},
|
||||
// Options: &sqlserverflex.CreateInstancePayloadOptions{},
|
||||
// },
|
||||
// true,
|
||||
// },
|
||||
// {
|
||||
// "nil_options",
|
||||
// &Model{},
|
||||
// []string{},
|
||||
// &flavorModel{},
|
||||
// &storageModel{},
|
||||
// nil,
|
||||
// &sqlserverflex.CreateInstancePayload{
|
||||
// Acl: &sqlserverflex.CreateInstancePayloadAcl{
|
||||
// Items: &[]string{},
|
||||
// },
|
||||
// Storage: &sqlserverflex.CreateInstancePayloadStorage{},
|
||||
// Options: &sqlserverflex.CreateInstancePayloadOptions{},
|
||||
// },
|
||||
// true,
|
||||
// },
|
||||
// }
|
||||
// for _, tt := range tests {
|
||||
// t.Run(tt.description, func(t *testing.T) {
|
||||
// output, err := toCreatePayload(tt.input, tt.inputAcl, tt.inputFlavor, tt.inputStorage, tt.inputOptions)
|
||||
// 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(output, tt.expected)
|
||||
// if diff != "" {
|
||||
// t.Fatalf("Data does not match: %s", diff)
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//func TestToUpdatePayload(t *testing.T) {
|
||||
// tests := []struct {
|
||||
// description string
|
||||
// input *Model
|
||||
// inputAcl []string
|
||||
// inputFlavor *flavorModel
|
||||
// expected *sqlserverflex.PartialUpdateInstancePayload
|
||||
// isValid bool
|
||||
// }{
|
||||
// {
|
||||
// "default_values",
|
||||
// &Model{},
|
||||
// []string{},
|
||||
// &flavorModel{},
|
||||
// &sqlserverflex.PartialUpdateInstancePayload{
|
||||
// Acl: &sqlserverflex.CreateInstancePayloadAcl{
|
||||
// Items: &[]string{},
|
||||
// },
|
||||
// },
|
||||
// true,
|
||||
// },
|
||||
// {
|
||||
// "simple_values",
|
||||
// &Model{
|
||||
// BackupSchedule: types.StringValue("schedule"),
|
||||
// Name: types.StringValue("name"),
|
||||
// Replicas: types.Int64Value(12),
|
||||
// Version: types.StringValue("version"),
|
||||
// },
|
||||
// []string{
|
||||
// "ip_1",
|
||||
// "ip_2",
|
||||
// },
|
||||
// &flavorModel{
|
||||
// Id: types.StringValue("flavor_id"),
|
||||
// },
|
||||
// &sqlserverflex.PartialUpdateInstancePayload{
|
||||
// Acl: &sqlserverflex.CreateInstancePayloadAcl{
|
||||
// Items: &[]string{
|
||||
// "ip_1",
|
||||
// "ip_2",
|
||||
// },
|
||||
// },
|
||||
// BackupSchedule: utils.Ptr("schedule"),
|
||||
// FlavorId: utils.Ptr("flavor_id"),
|
||||
// Name: utils.Ptr("name"),
|
||||
// Version: utils.Ptr("version"),
|
||||
// },
|
||||
// true,
|
||||
// },
|
||||
// {
|
||||
// "null_fields_and_int_conversions",
|
||||
// &Model{
|
||||
// BackupSchedule: types.StringNull(),
|
||||
// Name: types.StringNull(),
|
||||
// Replicas: types.Int64Value(2123456789),
|
||||
// Version: types.StringNull(),
|
||||
// },
|
||||
// []string{
|
||||
// "",
|
||||
// },
|
||||
// &flavorModel{
|
||||
// Id: types.StringNull(),
|
||||
// },
|
||||
// &sqlserverflex.PartialUpdateInstancePayload{
|
||||
// Acl: &sqlserverflex.CreateInstancePayloadAcl{
|
||||
// Items: &[]string{
|
||||
// "",
|
||||
// },
|
||||
// },
|
||||
// BackupSchedule: nil,
|
||||
// FlavorId: nil,
|
||||
// Name: nil,
|
||||
// Version: nil,
|
||||
// },
|
||||
// true,
|
||||
// },
|
||||
// {
|
||||
// "nil_model",
|
||||
// nil,
|
||||
// []string{},
|
||||
// &flavorModel{},
|
||||
// nil,
|
||||
// false,
|
||||
// },
|
||||
// {
|
||||
// "nil_acl",
|
||||
// &Model{},
|
||||
// nil,
|
||||
// &flavorModel{},
|
||||
// &sqlserverflex.PartialUpdateInstancePayload{
|
||||
// Acl: &sqlserverflex.CreateInstancePayloadAcl{},
|
||||
// },
|
||||
// true,
|
||||
// },
|
||||
// {
|
||||
// "nil_flavor",
|
||||
// &Model{},
|
||||
// []string{},
|
||||
// nil,
|
||||
// nil,
|
||||
// false,
|
||||
// },
|
||||
// }
|
||||
// for _, tt := range tests {
|
||||
// t.Run(tt.description, func(t *testing.T) {
|
||||
// output, err := toUpdatePayload(tt.input, tt.inputAcl, tt.inputFlavor)
|
||||
// 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(output, tt.expected)
|
||||
// if diff != "" {
|
||||
// t.Fatalf("Data does not match: %s", diff)
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//func TestLoadFlavorId(t *testing.T) {
|
||||
// tests := []struct {
|
||||
// description string
|
||||
// inputFlavor *flavorModel
|
||||
// mockedResp *sqlserverflex.ListFlavorsResponse
|
||||
// expected *flavorModel
|
||||
// getFlavorsFails bool
|
||||
// isValid bool
|
||||
// }{
|
||||
// {
|
||||
// "ok_flavor",
|
||||
// &flavorModel{
|
||||
// CPU: types.Int64Value(2),
|
||||
// RAM: types.Int64Value(8),
|
||||
// },
|
||||
// &sqlserverflex.ListFlavorsResponse{
|
||||
// Flavors: &[]sqlserverflex.InstanceFlavorEntry{
|
||||
// {
|
||||
// Id: utils.Ptr("fid-1"),
|
||||
// Cpu: utils.Ptr(int64(2)),
|
||||
// Description: utils.Ptr("description"),
|
||||
// Memory: utils.Ptr(int64(8)),
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// &flavorModel{
|
||||
// Id: types.StringValue("fid-1"),
|
||||
// Description: types.StringValue("description"),
|
||||
// CPU: types.Int64Value(2),
|
||||
// RAM: types.Int64Value(8),
|
||||
// },
|
||||
// false,
|
||||
// true,
|
||||
// },
|
||||
// {
|
||||
// "ok_flavor_2",
|
||||
// &flavorModel{
|
||||
// CPU: types.Int64Value(2),
|
||||
// RAM: types.Int64Value(8),
|
||||
// },
|
||||
// &sqlserverflex.ListFlavorsResponse{
|
||||
// Flavors: &[]sqlserverflex.InstanceFlavorEntry{
|
||||
// {
|
||||
// Id: utils.Ptr("fid-1"),
|
||||
// Cpu: utils.Ptr(int64(2)),
|
||||
// Description: utils.Ptr("description"),
|
||||
// Memory: utils.Ptr(int64(8)),
|
||||
// },
|
||||
// {
|
||||
// Id: utils.Ptr("fid-2"),
|
||||
// Cpu: utils.Ptr(int64(1)),
|
||||
// Description: utils.Ptr("description"),
|
||||
// Memory: utils.Ptr(int64(4)),
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// &flavorModel{
|
||||
// Id: types.StringValue("fid-1"),
|
||||
// Description: types.StringValue("description"),
|
||||
// CPU: types.Int64Value(2),
|
||||
// RAM: types.Int64Value(8),
|
||||
// },
|
||||
// false,
|
||||
// true,
|
||||
// },
|
||||
// {
|
||||
// "no_matching_flavor",
|
||||
// &flavorModel{
|
||||
// CPU: types.Int64Value(2),
|
||||
// RAM: types.Int64Value(8),
|
||||
// },
|
||||
// &sqlserverflex.ListFlavorsResponse{
|
||||
// Flavors: &[]sqlserverflex.InstanceFlavorEntry{
|
||||
// {
|
||||
// Id: utils.Ptr("fid-1"),
|
||||
// Cpu: utils.Ptr(int64(1)),
|
||||
// Description: utils.Ptr("description"),
|
||||
// Memory: utils.Ptr(int64(8)),
|
||||
// },
|
||||
// {
|
||||
// Id: utils.Ptr("fid-2"),
|
||||
// Cpu: utils.Ptr(int64(1)),
|
||||
// Description: utils.Ptr("description"),
|
||||
// Memory: utils.Ptr(int64(4)),
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// &flavorModel{
|
||||
// CPU: types.Int64Value(2),
|
||||
// RAM: types.Int64Value(8),
|
||||
// },
|
||||
// false,
|
||||
// false,
|
||||
// },
|
||||
// {
|
||||
// "nil_response",
|
||||
// &flavorModel{
|
||||
// CPU: types.Int64Value(2),
|
||||
// RAM: types.Int64Value(8),
|
||||
// },
|
||||
// &sqlserverflex.ListFlavorsResponse{},
|
||||
// &flavorModel{
|
||||
// CPU: types.Int64Value(2),
|
||||
// RAM: types.Int64Value(8),
|
||||
// },
|
||||
// false,
|
||||
// false,
|
||||
// },
|
||||
// {
|
||||
// "error_response",
|
||||
// &flavorModel{
|
||||
// CPU: types.Int64Value(2),
|
||||
// RAM: types.Int64Value(8),
|
||||
// },
|
||||
// &sqlserverflex.ListFlavorsResponse{},
|
||||
// &flavorModel{
|
||||
// CPU: types.Int64Value(2),
|
||||
// RAM: types.Int64Value(8),
|
||||
// },
|
||||
// true,
|
||||
// false,
|
||||
// },
|
||||
// }
|
||||
// for _, tt := range tests {
|
||||
// t.Run(tt.description, func(t *testing.T) {
|
||||
// client := &sqlserverflexClientMocked{
|
||||
// returnError: tt.getFlavorsFails,
|
||||
// listFlavorsResp: tt.mockedResp,
|
||||
// }
|
||||
// model := &Model{
|
||||
// ProjectId: types.StringValue("pid"),
|
||||
// }
|
||||
// flavorModel := &flavorModel{
|
||||
// CPU: tt.inputFlavor.CPU,
|
||||
// RAM: tt.inputFlavor.RAM,
|
||||
// }
|
||||
// err := loadFlavorId(context.Background(), client, model, flavorModel)
|
||||
// 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(flavorModel, tt.expected)
|
||||
// if diff != "" {
|
||||
// t.Fatalf("Data does not match: %s", diff)
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
//}
|
||||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue