feat: refactor data source models and update mapping functions for improved consistency
This commit is contained in:
parent
f0e7c19cdf
commit
184e133a2a
34 changed files with 980 additions and 1017 deletions
|
|
@ -7,6 +7,8 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
sqlserverflexalpha "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/instance/datasources_gen"
|
||||
sqlserverflexalpha2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/instance/resources_gen"
|
||||
|
|
@ -20,6 +22,12 @@ import (
|
|||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
)
|
||||
|
||||
// dataSourceModel maps the data source schema data.
|
||||
type dataSourceModel struct {
|
||||
sqlserverflexalpha2.InstanceModel
|
||||
TerraformID types.String `tfsdk:"id"`
|
||||
}
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ datasource.DataSource = &instanceDataSource{}
|
||||
|
|
@ -37,12 +45,20 @@ type instanceDataSource struct {
|
|||
}
|
||||
|
||||
// Metadata returns the data source type name.
|
||||
func (r *instanceDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
func (r *instanceDataSource) Metadata(
|
||||
_ context.Context,
|
||||
req datasource.MetadataRequest,
|
||||
resp *datasource.MetadataResponse,
|
||||
) {
|
||||
resp.TypeName = req.ProviderTypeName + "_sqlserverflexalpha_instance"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (r *instanceDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
func (r *instanceDataSource) Configure(
|
||||
ctx context.Context,
|
||||
req datasource.ConfigureRequest,
|
||||
resp *datasource.ConfigureResponse,
|
||||
) {
|
||||
var ok bool
|
||||
r.providerData, ok = conversion.ParseProviderData(ctx, req.ProviderData, &resp.Diagnostics)
|
||||
if !ok {
|
||||
|
|
@ -59,167 +75,22 @@ func (r *instanceDataSource) Configure(ctx context.Context, req datasource.Confi
|
|||
|
||||
// Schema defines the schema for the data source.
|
||||
func (r *instanceDataSource) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
//descriptions := map[string]string{
|
||||
// "main": "SQLServer Flex ALPHA instance resource schema. Must have a `region` specified in the provider configuration.",
|
||||
// "id": "Terraform's internal resource 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.",
|
||||
// "access_scope": "The access scope of the instance. (e.g. SNA)",
|
||||
// "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 * * *")`,
|
||||
// "region": "The resource region. If not defined, the provider region is used.",
|
||||
// "encryption": "The encryption block.",
|
||||
// "network": "The network block.",
|
||||
// "keyring_id": "STACKIT KMS - KeyRing ID of the encryption key to use.",
|
||||
// "key_id": "STACKIT KMS - Key ID of the encryption key to use.",
|
||||
// "key_version": "STACKIT KMS - Key version to use in the encryption key.",
|
||||
// "service:account": "STACKIT KMS - service account to use in the encryption key.",
|
||||
// "instance_address": "The returned instance IP address of the SQLServer Flex instance.",
|
||||
// "router_address": "The returned router IP address of the SQLServer Flex instance.",
|
||||
//}
|
||||
s := sqlserverflexalpha.InstanceDataSourceSchema(ctx)
|
||||
s.Attributes["id"] = schema.StringAttribute{
|
||||
Description: "Terraform's internal resource ID. It is structured as \\\"`project_id`,`region`,`instance_id`\\\".",
|
||||
Computed: true,
|
||||
}
|
||||
|
||||
resp.Schema = sqlserverflexalpha.InstanceDataSourceSchema(ctx)
|
||||
|
||||
//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,
|
||||
// },
|
||||
// "is_deletable": schema.BoolAttribute{
|
||||
// Description: descriptions["is_deletable"],
|
||||
// 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,
|
||||
// },
|
||||
// "node_type": schema.StringAttribute{
|
||||
// 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"],
|
||||
// },
|
||||
// },
|
||||
//}
|
||||
resp.Schema = s
|
||||
}
|
||||
|
||||
// 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
|
||||
func (r *instanceDataSource) Read(
|
||||
ctx context.Context,
|
||||
req datasource.ReadRequest,
|
||||
resp *datasource.ReadResponse,
|
||||
) { // nolint:gocritic // function signature required by Terraform
|
||||
var model dataSourceModel
|
||||
diags := req.Config.Get(ctx, &model)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
|
@ -279,10 +150,15 @@ func (r *instanceDataSource) Read(ctx context.Context, req datasource.ReadReques
|
|||
// }
|
||||
//}
|
||||
|
||||
err = mapResponseToModel(ctx, instanceResp, &model, resp.Diagnostics)
|
||||
err = mapFields(ctx, instanceResp, &model, resp.Diagnostics)
|
||||
//err = mapFields(ctx, instanceResp, &model, storage, encryption, network, region)
|
||||
if err != nil {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading instance", fmt.Sprintf("Processing API payload: %v", err))
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
&resp.Diagnostics,
|
||||
"Error reading instance",
|
||||
fmt.Sprintf("Processing API payload: %v", err),
|
||||
)
|
||||
return
|
||||
}
|
||||
// Set refreshed state
|
||||
|
|
|
|||
|
|
@ -14,26 +14,21 @@ import (
|
|||
sqlserverflexResGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/instance/resources_gen"
|
||||
)
|
||||
|
||||
func mapResponseToModel(
|
||||
// instanceModel is a type constraint for models that can be mapped from a GetInstanceResponse.
|
||||
type instanceModel interface {
|
||||
*dataSourceModel | *resourceModel
|
||||
}
|
||||
|
||||
func mapFields[T instanceModel](
|
||||
ctx context.Context,
|
||||
resp *sqlserverflex.GetInstanceResponse,
|
||||
m *sqlserverflexResGen.InstanceModel,
|
||||
m T,
|
||||
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(
|
||||
"error converting network acl response value",
|
||||
)
|
||||
return fmt.Errorf("error converting network acl response value")
|
||||
}
|
||||
net, diags := sqlserverflexResGen.NewNetworkValue(
|
||||
sqlserverflexResGen.NetworkValue{}.AttributeTypes(ctx),
|
||||
|
|
@ -46,22 +41,8 @@ func mapResponseToModel(
|
|||
)
|
||||
tfDiags.Append(diags...)
|
||||
if diags.HasError() {
|
||||
return fmt.Errorf(
|
||||
"error converting network response 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()),
|
||||
)
|
||||
return fmt.Errorf("error converting network response value")
|
||||
}
|
||||
m.Network = net
|
||||
m.Replicas = types.Int64Value(int64(resp.GetReplicas()))
|
||||
m.RetentionDays = types.Int64Value(resp.GetRetentionDays())
|
||||
m.Status = types.StringValue(string(resp.GetStatus()))
|
||||
|
||||
stor, diags := sqlserverflexResGen.NewStorageValue(
|
||||
sqlserverflexResGen.StorageValue{}.AttributeTypes(ctx),
|
||||
|
|
@ -74,14 +55,47 @@ func mapResponseToModel(
|
|||
if diags.HasError() {
|
||||
return fmt.Errorf("error converting storage response value")
|
||||
}
|
||||
m.Storage = stor
|
||||
|
||||
m.Version = types.StringValue(string(resp.GetVersion()))
|
||||
// The interface conversion is safe due to the type constraint.
|
||||
model := any(m)
|
||||
|
||||
if rm, ok := model.(*resourceModel); ok {
|
||||
rm.BackupSchedule = types.StringValue(resp.GetBackupSchedule())
|
||||
rm.Edition = types.StringValue(string(resp.GetEdition()))
|
||||
rm.Encryption = handleEncryption(rm.Encryption, resp)
|
||||
rm.FlavorId = types.StringValue(resp.GetFlavorId())
|
||||
rm.Id = types.StringValue(resp.GetId())
|
||||
rm.InstanceId = types.StringValue(resp.GetId())
|
||||
rm.IsDeletable = types.BoolValue(resp.GetIsDeletable())
|
||||
rm.Name = types.StringValue(resp.GetName())
|
||||
rm.Network = net
|
||||
rm.Replicas = types.Int64Value(int64(resp.GetReplicas()))
|
||||
rm.RetentionDays = types.Int64Value(resp.GetRetentionDays())
|
||||
rm.Status = types.StringValue(string(resp.GetStatus()))
|
||||
rm.Storage = stor
|
||||
rm.Version = types.StringValue(string(resp.GetVersion()))
|
||||
} else if dm, ok := model.(*dataSourceModel); ok {
|
||||
dm.BackupSchedule = types.StringValue(resp.GetBackupSchedule())
|
||||
dm.Edition = types.StringValue(string(resp.GetEdition()))
|
||||
dm.Encryption = handleEncryption(dm.Encryption, resp)
|
||||
dm.FlavorId = types.StringValue(resp.GetFlavorId())
|
||||
dm.Id = types.StringValue(resp.GetId())
|
||||
dm.InstanceId = types.StringValue(resp.GetId())
|
||||
dm.IsDeletable = types.BoolValue(resp.GetIsDeletable())
|
||||
dm.Name = types.StringValue(resp.GetName())
|
||||
dm.Network = net
|
||||
dm.Replicas = types.Int64Value(int64(resp.GetReplicas()))
|
||||
dm.RetentionDays = types.Int64Value(resp.GetRetentionDays())
|
||||
dm.Status = types.StringValue(string(resp.GetStatus()))
|
||||
dm.Storage = stor
|
||||
dm.Version = types.StringValue(string(resp.GetVersion()))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleEncryption(
|
||||
m *sqlserverflexResGen.InstanceModel,
|
||||
encryptionValue sqlserverflexResGen.EncryptionValue,
|
||||
resp *sqlserverflex.GetInstanceResponse,
|
||||
) sqlserverflexResGen.EncryptionValue {
|
||||
if !resp.HasEncryption() ||
|
||||
|
|
@ -91,10 +105,10 @@ func handleEncryption(
|
|||
resp.Encryption.KekKeyVersion == nil ||
|
||||
resp.Encryption.ServiceAccount == nil {
|
||||
|
||||
if m.Encryption.IsNull() || m.Encryption.IsUnknown() {
|
||||
if encryptionValue.IsNull() || encryptionValue.IsUnknown() {
|
||||
return sqlserverflexResGen.NewEncryptionValueNull()
|
||||
}
|
||||
return m.Encryption
|
||||
return encryptionValue
|
||||
}
|
||||
|
||||
enc := sqlserverflexResGen.NewEncryptionValueNull()
|
||||
|
|
|
|||
|
|
@ -37,23 +37,26 @@ var (
|
|||
_ resource.ResourceWithIdentity = &instanceResource{}
|
||||
)
|
||||
|
||||
// NewInstanceResource is a helper function to simplify the provider implementation.
|
||||
func NewInstanceResource() resource.Resource {
|
||||
return &instanceResource{}
|
||||
}
|
||||
|
||||
//nolint:unused // TODO: remove if not needed later
|
||||
var validNodeTypes []string = []string{
|
||||
"Single",
|
||||
"Replica",
|
||||
}
|
||||
|
||||
// resourceModel describes the resource data model.
|
||||
type resourceModel = sqlserverflexalpha2.InstanceModel
|
||||
|
||||
type InstanceResourceIdentityModel struct {
|
||||
ProjectID types.String `tfsdk:"project_id"`
|
||||
Region types.String `tfsdk:"region"`
|
||||
InstanceID types.String `tfsdk:"instance_id"`
|
||||
}
|
||||
|
||||
// NewInstanceResource is a helper function to simplify the provider implementation.
|
||||
func NewInstanceResource() resource.Resource {
|
||||
return &instanceResource{}
|
||||
}
|
||||
|
||||
// instanceResource is the resource implementation.
|
||||
type instanceResource struct {
|
||||
client *sqlserverflexalpha.APIClient
|
||||
|
|
@ -140,27 +143,6 @@ var modifiersFileByte []byte
|
|||
|
||||
// Schema defines the schema for the resource.
|
||||
func (r *instanceResource) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
//descriptions := map[string]string{
|
||||
// "main": "SQLServer Flex ALPHA instance resource schema. Must have a `region` specified in the provider configuration.",
|
||||
// "id": "Terraform's internal resource 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.",
|
||||
// "access_scope": "The access scope of the instance. (SNA | PUBLIC)",
|
||||
// "flavor_id": "The flavor ID of the instance.",
|
||||
// "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 * * *")`,
|
||||
// "region": "The resource region. If not defined, the provider region is used.",
|
||||
// "encryption": "The encryption block.",
|
||||
// "replicas": "The number of replicas of the SQLServer Flex instance.",
|
||||
// "network": "The network block.",
|
||||
// "keyring_id": "STACKIT KMS - KeyRing ID of the encryption key to use.",
|
||||
// "key_id": "STACKIT KMS - Key ID of the encryption key to use.",
|
||||
// "key_version": "STACKIT KMS - Key version to use in the encryption key.",
|
||||
// "service:account": "STACKIT KMS - service account to use in the encryption key.",
|
||||
// "instance_address": "The returned instance IP address of the SQLServer Flex instance.",
|
||||
// "router_address": "The returned router IP address of the SQLServer Flex instance.",
|
||||
//}
|
||||
|
||||
schema := sqlserverflexalpha2.InstanceResourceSchema(ctx)
|
||||
|
||||
|
|
@ -176,234 +158,13 @@ func (r *instanceResource) Schema(ctx context.Context, _ resource.SchemaRequest,
|
|||
return
|
||||
}
|
||||
resp.Schema = schema
|
||||
|
||||
//resp.Schema = schema.Schema{
|
||||
// Description: descriptions["main"],
|
||||
// Attributes: map[string]schema.Attribute{
|
||||
// "id": schema.StringAttribute{
|
||||
// Description: descriptions["id"],
|
||||
// Computed: true,
|
||||
// PlanModifiers: []planmodifier.String{
|
||||
// stringplanmodifier.UseStateForUnknown(),
|
||||
// },
|
||||
// },
|
||||
// "instance_id": schema.StringAttribute{
|
||||
// Description: descriptions["instance_id"],
|
||||
// Computed: true,
|
||||
// PlanModifiers: []planmodifier.String{
|
||||
// stringplanmodifier.UseStateForUnknown(),
|
||||
// },
|
||||
// Validators: []validator.String{
|
||||
// validate.UUID(),
|
||||
// validate.NoSeparator(),
|
||||
// },
|
||||
// },
|
||||
// "project_id": schema.StringAttribute{
|
||||
// Description: descriptions["project_id"],
|
||||
// Required: true,
|
||||
// PlanModifiers: []planmodifier.String{
|
||||
// stringplanmodifier.RequiresReplace(),
|
||||
// },
|
||||
// Validators: []validator.String{
|
||||
// validate.UUID(),
|
||||
// validate.NoSeparator(),
|
||||
// },
|
||||
// },
|
||||
// "name": schema.StringAttribute{
|
||||
// Description: descriptions["name"],
|
||||
// Required: true,
|
||||
// Validators: []validator.String{
|
||||
// stringvalidator.LengthAtLeast(1),
|
||||
// stringvalidator.RegexMatches(
|
||||
// regexp.MustCompile("^[a-z]([-a-z0-9]*[a-z0-9])?$"),
|
||||
// "must start with a letter, must have lower case letters, numbers or hyphens, and no hyphen at the end",
|
||||
// ),
|
||||
// },
|
||||
// },
|
||||
// "backup_schedule": schema.StringAttribute{
|
||||
// Description: descriptions["backup_schedule"],
|
||||
// Optional: true,
|
||||
// Computed: true,
|
||||
// PlanModifiers: []planmodifier.String{
|
||||
// stringplanmodifier.UseStateForUnknown(),
|
||||
// },
|
||||
// },
|
||||
// "is_deletable": schema.BoolAttribute{
|
||||
// Description: descriptions["is_deletable"],
|
||||
// Optional: true,
|
||||
// Computed: true,
|
||||
// PlanModifiers: []planmodifier.Bool{
|
||||
// boolplanmodifier.UseStateForUnknown(),
|
||||
// },
|
||||
// },
|
||||
// "flavor_id": schema.StringAttribute{
|
||||
// PlanModifiers: []planmodifier.String{
|
||||
// stringplanmodifier.RequiresReplace(),
|
||||
// stringplanmodifier.UseStateForUnknown(),
|
||||
// },
|
||||
// Required: true,
|
||||
// },
|
||||
// "replicas": schema.Int64Attribute{
|
||||
// Computed: true,
|
||||
// PlanModifiers: []planmodifier.Int64{
|
||||
// int64planmodifier.UseStateForUnknown(),
|
||||
// },
|
||||
// },
|
||||
// "storage": schema.SingleNestedAttribute{
|
||||
// Optional: true,
|
||||
// Computed: true,
|
||||
// PlanModifiers: []planmodifier.Object{
|
||||
// objectplanmodifier.UseStateForUnknown(),
|
||||
// },
|
||||
// Attributes: map[string]schema.Attribute{
|
||||
// "class": schema.StringAttribute{
|
||||
// Optional: true,
|
||||
// Computed: true,
|
||||
// PlanModifiers: []planmodifier.String{
|
||||
// stringplanmodifier.RequiresReplace(),
|
||||
// stringplanmodifier.UseStateForUnknown(),
|
||||
// },
|
||||
// },
|
||||
// "size": schema.Int64Attribute{
|
||||
// Optional: true,
|
||||
// Computed: true,
|
||||
// PlanModifiers: []planmodifier.Int64{
|
||||
// int64planmodifier.UseStateForUnknown(),
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// "version": schema.StringAttribute{
|
||||
// Optional: true,
|
||||
// Computed: true,
|
||||
// PlanModifiers: []planmodifier.String{
|
||||
// stringplanmodifier.RequiresReplace(),
|
||||
// stringplanmodifier.UseStateForUnknown(),
|
||||
// },
|
||||
// },
|
||||
// "edition": schema.StringAttribute{
|
||||
// Computed: true,
|
||||
// PlanModifiers: []planmodifier.String{
|
||||
// stringplanmodifier.RequiresReplace(),
|
||||
// stringplanmodifier.UseStateForUnknown(),
|
||||
// },
|
||||
// },
|
||||
// "retention_days": schema.Int64Attribute{
|
||||
// Optional: true,
|
||||
// Computed: true,
|
||||
// PlanModifiers: []planmodifier.Int64{
|
||||
// int64planmodifier.UseStateForUnknown(),
|
||||
// },
|
||||
// },
|
||||
// "region": schema.StringAttribute{
|
||||
// Optional: true,
|
||||
// // must be computed to allow for storing the override value from the provider
|
||||
// Computed: true,
|
||||
// Description: descriptions["region"],
|
||||
// PlanModifiers: []planmodifier.String{
|
||||
// stringplanmodifier.RequiresReplace(),
|
||||
// },
|
||||
// },
|
||||
// "status": schema.StringAttribute{
|
||||
// Optional: true,
|
||||
// // must be computed to allow for storing the override value from the provider
|
||||
// Computed: true,
|
||||
// Description: descriptions["status"],
|
||||
// },
|
||||
// "encryption": schema.SingleNestedAttribute{
|
||||
// Optional: true,
|
||||
// PlanModifiers: []planmodifier.Object{
|
||||
// objectplanmodifier.RequiresReplace(),
|
||||
// objectplanmodifier.UseStateForUnknown(),
|
||||
// },
|
||||
// Attributes: map[string]schema.Attribute{
|
||||
// "key_id": schema.StringAttribute{
|
||||
// Description: descriptions["key_id"],
|
||||
// Required: true,
|
||||
// PlanModifiers: []planmodifier.String{
|
||||
// stringplanmodifier.RequiresReplace(),
|
||||
// },
|
||||
// Validators: []validator.String{
|
||||
// validate.NoSeparator(),
|
||||
// },
|
||||
// },
|
||||
// "key_version": schema.StringAttribute{
|
||||
// Description: descriptions["key_version"],
|
||||
// Required: true,
|
||||
// PlanModifiers: []planmodifier.String{
|
||||
// stringplanmodifier.RequiresReplace(),
|
||||
// },
|
||||
// Validators: []validator.String{
|
||||
// validate.NoSeparator(),
|
||||
// },
|
||||
// },
|
||||
// "keyring_id": schema.StringAttribute{
|
||||
// Description: descriptions["keyring_id"],
|
||||
// Required: true,
|
||||
// PlanModifiers: []planmodifier.String{
|
||||
// stringplanmodifier.RequiresReplace(),
|
||||
// },
|
||||
// Validators: []validator.String{
|
||||
// validate.NoSeparator(),
|
||||
// },
|
||||
// },
|
||||
// "service_account": schema.StringAttribute{
|
||||
// Description: descriptions["service_account"],
|
||||
// Required: true,
|
||||
// PlanModifiers: []planmodifier.String{
|
||||
// stringplanmodifier.RequiresReplace(),
|
||||
// },
|
||||
// Validators: []validator.String{
|
||||
// validate.NoSeparator(),
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// Description: descriptions["encryption"],
|
||||
// },
|
||||
// "network": schema.SingleNestedAttribute{
|
||||
// Required: true,
|
||||
// Attributes: map[string]schema.Attribute{
|
||||
// "access_scope": schema.StringAttribute{
|
||||
// Description: descriptions["access_scope"],
|
||||
// Required: true,
|
||||
// PlanModifiers: []planmodifier.String{
|
||||
// stringplanmodifier.RequiresReplace(),
|
||||
// stringplanmodifier.UseStateForUnknown(),
|
||||
// },
|
||||
// Validators: []validator.String{
|
||||
// validate.NoSeparator(),
|
||||
// },
|
||||
// },
|
||||
// "acl": schema.ListAttribute{
|
||||
// Description: descriptions["acl"],
|
||||
// ElementType: types.StringType,
|
||||
// Required: true,
|
||||
// PlanModifiers: []planmodifier.List{
|
||||
// listplanmodifier.UseStateForUnknown(),
|
||||
// },
|
||||
// },
|
||||
// "instance_address": schema.StringAttribute{
|
||||
// Description: descriptions["instance_address"],
|
||||
// Computed: true,
|
||||
// PlanModifiers: []planmodifier.String{
|
||||
// stringplanmodifier.UseStateForUnknown(),
|
||||
// },
|
||||
// },
|
||||
// "router_address": schema.StringAttribute{
|
||||
// Description: descriptions["router_address"],
|
||||
// Computed: true,
|
||||
// PlanModifiers: []planmodifier.String{
|
||||
// stringplanmodifier.UseStateForUnknown(),
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// Description: descriptions["network"],
|
||||
// },
|
||||
// },
|
||||
//}
|
||||
}
|
||||
|
||||
func (r *instanceResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) {
|
||||
func (r *instanceResource) IdentitySchema(
|
||||
_ context.Context,
|
||||
_ resource.IdentitySchemaRequest,
|
||||
resp *resource.IdentitySchemaResponse,
|
||||
) {
|
||||
resp.IdentitySchema = identityschema.Schema{
|
||||
Attributes: map[string]identityschema.Attribute{
|
||||
"project_id": identityschema.StringAttribute{
|
||||
|
|
@ -425,7 +186,7 @@ func (r *instanceResource) Create(
|
|||
req resource.CreateRequest,
|
||||
resp *resource.CreateResponse,
|
||||
) { // nolint:gocritic // function signature required by Terraform
|
||||
var model sqlserverflexalpha2.InstanceModel
|
||||
var model resourceModel
|
||||
diags := req.Plan.Get(ctx, &model)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
|
@ -528,7 +289,7 @@ func (r *instanceResource) Create(
|
|||
|
||||
// Map response body to schema
|
||||
// err = mapFields(ctx, waitResp, &model, storage, encryption, network, region)
|
||||
err = mapResponseToModel(ctx, waitResp, &model, resp.Diagnostics)
|
||||
err = mapFields(ctx, waitResp, &model, resp.Diagnostics)
|
||||
if err != nil {
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
|
|
@ -554,7 +315,7 @@ func (r *instanceResource) Read(
|
|||
req resource.ReadRequest,
|
||||
resp *resource.ReadResponse,
|
||||
) { // nolint:gocritic // function signature required by Terraform
|
||||
var model sqlserverflexalpha2.InstanceModel
|
||||
var model resourceModel
|
||||
diags := req.State.Get(ctx, &model)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
|
@ -592,7 +353,7 @@ func (r *instanceResource) Read(
|
|||
ctx = core.LogResponse(ctx)
|
||||
|
||||
// Map response body to schema
|
||||
err = mapResponseToModel(ctx, instanceResp, &model, resp.Diagnostics)
|
||||
err = mapFields(ctx, instanceResp, &model, resp.Diagnostics)
|
||||
if err != nil {
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
|
|
@ -629,7 +390,7 @@ func (r *instanceResource) Update(
|
|||
resp *resource.UpdateResponse,
|
||||
) { // nolint:gocritic // function signature required by Terraform
|
||||
// Retrieve values from plan
|
||||
var model sqlserverflexalpha2.InstanceModel
|
||||
var model resourceModel
|
||||
diags := req.Plan.Get(ctx, &model)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
|
@ -683,7 +444,7 @@ func (r *instanceResource) Update(
|
|||
}
|
||||
|
||||
// Map response body to schema
|
||||
err = mapResponseToModel(ctx, waitResp, &model, resp.Diagnostics)
|
||||
err = mapFields(ctx, waitResp, &model, resp.Diagnostics)
|
||||
// err = mapFields(ctx, waitResp, &model, storage, encryption, network, region)
|
||||
if err != nil {
|
||||
core.LogAndAddError(
|
||||
|
|
@ -709,7 +470,7 @@ func (r *instanceResource) Delete(
|
|||
resp *resource.DeleteResponse,
|
||||
) { // nolint:gocritic // function signature required by Terraform
|
||||
// Retrieve values from state
|
||||
var model sqlserverflexalpha2.InstanceModel
|
||||
var model resourceModel
|
||||
diags := req.State.Get(ctx, &model)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue