chore: updated files - work save
This commit is contained in:
parent
e91e10e29a
commit
b4c5b3774b
110 changed files with 1498 additions and 3013 deletions
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package postgresflexalpha
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package postgresflexalpha
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package postgresflexalpha
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package postgresflexalpha
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package postgresflexalpha
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package postgresFlexAlphaFlavor
|
||||
|
||||
import (
|
||||
|
|
@ -10,7 +13,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||
"github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha"
|
||||
"github.com/mhenselin/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
postgresflex "github.com/mhenselin/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha"
|
||||
postgresflexalphaGen "github.com/mhenselin/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/flavors/datasources_gen"
|
||||
postgresflexUtils "github.com/mhenselin/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/utils"
|
||||
"github.com/mhenselin/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
|
||||
|
|
@ -143,9 +146,9 @@ func (r *flavorDataSource) Schema(ctx context.Context, _ datasource.SchemaReques
|
|||
Computed: true,
|
||||
},
|
||||
},
|
||||
CustomType: postgresflex.StorageClassesType{
|
||||
CustomType: postgresflexalphaGen.StorageClassesType{
|
||||
ObjectType: types.ObjectType{
|
||||
AttrTypes: postgresflex.StorageClassesValue{}.AttributeTypes(ctx),
|
||||
AttrTypes: postgresflexalphaGen.StorageClassesValue{}.AttributeTypes(ctx),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -210,9 +213,9 @@ func (r *flavorDataSource) Read(ctx context.Context, req datasource.ReadRequest,
|
|||
model.MinGb = types.Int64Value(*f.MinGB)
|
||||
|
||||
if f.StorageClasses == nil {
|
||||
model.StorageClasses = types.ListNull(postgresflex.StorageClassesType{
|
||||
model.StorageClasses = types.ListNull(postgresflexalphaGen.StorageClassesType{
|
||||
ObjectType: basetypes.ObjectType{
|
||||
AttrTypes: postgresflex.StorageClassesValue{}.AttributeTypes(ctx),
|
||||
AttrTypes: postgresflexalphaGen.StorageClassesValue{}.AttributeTypes(ctx),
|
||||
},
|
||||
})
|
||||
} else {
|
||||
|
|
@ -220,8 +223,8 @@ func (r *flavorDataSource) Read(ctx context.Context, req datasource.ReadRequest,
|
|||
for _, sc := range *f.StorageClasses {
|
||||
scList = append(
|
||||
scList,
|
||||
postgresflex.NewStorageClassesValueMust(
|
||||
postgresflex.StorageClassesValue{}.AttributeTypes(ctx),
|
||||
postgresflexalphaGen.NewStorageClassesValueMust(
|
||||
postgresflexalphaGen.StorageClassesValue{}.AttributeTypes(ctx),
|
||||
map[string]attr.Value{
|
||||
"class": types.StringValue(*sc.Class),
|
||||
"max_io_per_sec": types.Int64Value(*sc.MaxIoPerSec),
|
||||
|
|
@ -231,9 +234,9 @@ func (r *flavorDataSource) Read(ctx context.Context, req datasource.ReadRequest,
|
|||
)
|
||||
}
|
||||
storageClassesList := types.ListValueMust(
|
||||
postgresflex.StorageClassesType{
|
||||
postgresflexalphaGen.StorageClassesType{
|
||||
ObjectType: basetypes.ObjectType{
|
||||
AttrTypes: postgresflex.StorageClassesValue{}.AttributeTypes(ctx),
|
||||
AttrTypes: postgresflexalphaGen.StorageClassesValue{}.AttributeTypes(ctx),
|
||||
},
|
||||
},
|
||||
scList,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package postgresFlexAlphaFlavor
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package postgresFlexAlphaFlavor
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package postgresflexalpha
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha"
|
||||
"github.com/mhenselin/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
"github.com/mhenselin/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
postgresflexalphaGen "github.com/mhenselin/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/flavors/datasources_gen"
|
||||
postgresflexUtils "github.com/mhenselin/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
_ datasource.DataSource = &flavorsDataSource{}
|
||||
_ datasource.DataSourceWithConfigure = &flavorsDataSource{}
|
||||
)
|
||||
|
||||
func NewFlavorsDataSource() datasource.DataSource {
|
||||
return &flavorsDataSource{}
|
||||
}
|
||||
|
||||
type flavorsDataSource struct {
|
||||
client *postgresflexalpha.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
|
||||
func (d *flavorsDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_postgresflexalpha_flavors"
|
||||
}
|
||||
|
||||
func (d *flavorsDataSource) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = postgresflexalphaGen.FlavorsDataSourceSchema(ctx)
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *flavorsDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
var ok bool
|
||||
d.providerData, ok = conversion.ParseProviderData(ctx, req.ProviderData, &resp.Diagnostics)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
apiClient := postgresflexUtils.ConfigureClient(ctx, &d.providerData, &resp.Diagnostics)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
d.client = apiClient
|
||||
tflog.Info(ctx, "Postgres Flex version client configured")
|
||||
}
|
||||
|
||||
func (d *flavorsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
var data postgresflexalphaGen.FlavorsModel
|
||||
|
||||
// Read Terraform configuration data into the model
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
||||
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
// Todo: Read API call logic
|
||||
|
||||
// Example data value setting
|
||||
// data.Id = types.StringValue("example-id")
|
||||
|
||||
// Save data into Terraform state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||
}
|
||||
|
|
@ -1,12 +1,10 @@
|
|||
// Code generated by terraform-plugin-framework-generator DO NOT EDIT.
|
||||
|
||||
package postgresflex
|
||||
package postgresflexalpha
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
|
|
@ -14,42 +12,18 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||
"github.com/hashicorp/terraform-plugin-go/tftypes"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
)
|
||||
|
||||
func FlavorDataSourceSchema(ctx context.Context) schema.Schema {
|
||||
func FlavorsDataSourceSchema(ctx context.Context) schema.Schema {
|
||||
return schema.Schema{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"cpu": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
//Description: "The cpu count of the instance.",
|
||||
//MarkdownDescription: "The cpu count of the instance.",
|
||||
},
|
||||
"ram": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
//Description: "The cpu count of the instance.",
|
||||
//MarkdownDescription: "The cpu count of the instance.",
|
||||
},
|
||||
"node_type": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
//Description: "The cpu count of the instance.",
|
||||
//MarkdownDescription: "The cpu count of the instance.",
|
||||
},
|
||||
"storage_class": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
//Description: "The cpu count of the instance.",
|
||||
//MarkdownDescription: "The cpu count of the instance.",
|
||||
},
|
||||
"flavors": schema.ListNestedAttribute{
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"cpu": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "The cpu count of the instance.",
|
||||
MarkdownDescription: "The cpu count of the instance.",
|
||||
|
|
@ -70,7 +44,6 @@ func FlavorDataSourceSchema(ctx context.Context) schema.Schema {
|
|||
MarkdownDescription: "maximum storage which can be ordered for the flavor in Gigabyte.",
|
||||
},
|
||||
"memory": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "The memory of the instance in Gibibyte.",
|
||||
MarkdownDescription: "The memory of the instance in Gibibyte.",
|
||||
|
|
@ -81,7 +54,6 @@ func FlavorDataSourceSchema(ctx context.Context) schema.Schema {
|
|||
MarkdownDescription: "minimum storage which is required to order in Gigabyte.",
|
||||
},
|
||||
"node_type": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "defines the nodeType it can be either single or replica",
|
||||
MarkdownDescription: "defines the nodeType it can be either single or replica",
|
||||
|
|
@ -205,9 +177,6 @@ func FlavorDataSourceSchema(ctx context.Context) schema.Schema {
|
|||
}
|
||||
|
||||
type FlavorsModel struct {
|
||||
Cpu types.Int64 `tfsdk:"cpu"`
|
||||
Ram types.Int64 `tfsdk:"ram"`
|
||||
NodeType types.String `tfsdk:"node_type"`
|
||||
Flavors types.List `tfsdk:"flavors"`
|
||||
Page types.Int64 `tfsdk:"page"`
|
||||
Pagination PaginationValue `tfsdk:"pagination"`
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package postgresflexalpha
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package postgresflexalpha
|
||||
|
||||
import (
|
||||
|
|
@ -6,6 +9,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||
postgresflex "github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha"
|
||||
postgresflexalphadatasource "github.com/mhenselin/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/instance/datasources_gen"
|
||||
postgresflexalpharesource "github.com/mhenselin/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/instance/resources_gen"
|
||||
|
|
@ -15,7 +19,7 @@ import (
|
|||
func mapGetInstanceResponseToModel(ctx context.Context, m *postgresflexalpharesource.InstanceModel, resp *postgresflex.GetInstanceResponse) error {
|
||||
m.BackupSchedule = types.StringValue(resp.GetBackupSchedule())
|
||||
// need to leave out encryption, as the GetInstance endpoint does not provide it
|
||||
//m.Encryption = postgresflexalpharesource.NewEncryptionValueMust(
|
||||
// m.Encryption = postgresflexalpharesource.NewEncryptionValueMust(
|
||||
// m.Encryption.AttributeTypes(ctx),
|
||||
// map[string]attr.Value{
|
||||
// "kek_key_id": types.StringValue(resp.Encryption.GetKekKeyId()),
|
||||
|
|
@ -23,13 +27,17 @@ func mapGetInstanceResponseToModel(ctx context.Context, m *postgresflexalphareso
|
|||
// "kek_key_version": types.StringValue(resp.Encryption.GetKekKeyVersion()),
|
||||
// "service_account": types.StringValue(resp.Encryption.GetServiceAccount()),
|
||||
// },
|
||||
//)
|
||||
// )
|
||||
m.FlavorId = types.StringValue(resp.GetFlavorId())
|
||||
if m.Id.IsNull() || m.Id.IsUnknown() {
|
||||
m.Id = utils.BuildInternalTerraformId(m.ProjectId.ValueString(), m.Region.ValueString(), m.InstanceId.ValueString())
|
||||
}
|
||||
m.InstanceId = types.StringPointerValue(resp.Id)
|
||||
m.IsDeletable = types.BoolValue(resp.GetIsDeletable())
|
||||
|
||||
m.IsDeletable = types.BoolUnknown()
|
||||
if isDel, ok := resp.GetIsDeletableOk(); ok {
|
||||
m.IsDeletable = types.BoolValue(isDel)
|
||||
}
|
||||
m.Name = types.StringValue(resp.GetName())
|
||||
|
||||
netAcl, diags := types.ListValueFrom(ctx, types.StringType, resp.Network.GetAcl())
|
||||
|
|
@ -37,13 +45,23 @@ func mapGetInstanceResponseToModel(ctx context.Context, m *postgresflexalphareso
|
|||
return fmt.Errorf("failed converting network acl from response")
|
||||
}
|
||||
|
||||
netInstAdd := types.StringUnknown()
|
||||
if instAdd, ok := resp.Network.GetInstanceAddressOk(); ok {
|
||||
netInstAdd = types.StringValue(instAdd)
|
||||
}
|
||||
|
||||
netRtrAdd := types.StringUnknown()
|
||||
if rtrAdd, ok := resp.Network.GetRouterAddressOk(); ok {
|
||||
netRtrAdd = types.StringValue(rtrAdd)
|
||||
}
|
||||
|
||||
net, diags := postgresflexalpharesource.NewNetworkValue(
|
||||
postgresflexalpharesource.NetworkValue{}.AttributeTypes(ctx),
|
||||
map[string]attr.Value{
|
||||
"access_scope": types.StringValue(string(resp.Network.GetAccessScope())),
|
||||
"access_scope": basetypes.NewStringValue(string(resp.Network.GetAccessScope())),
|
||||
"acl": netAcl,
|
||||
"instance_address": types.StringValue(resp.Network.GetInstanceAddress()),
|
||||
"router_address": types.StringValue(resp.Network.GetRouterAddress()),
|
||||
"instance_address": netInstAdd,
|
||||
"router_address": netRtrAdd,
|
||||
},
|
||||
)
|
||||
if diags.HasError() {
|
||||
|
|
@ -53,7 +71,13 @@ func mapGetInstanceResponseToModel(ctx context.Context, m *postgresflexalphareso
|
|||
m.Network = net
|
||||
m.Replicas = types.Int64Value(int64(resp.GetReplicas()))
|
||||
m.RetentionDays = types.Int64Value(resp.GetRetentionDays())
|
||||
m.Status = types.StringValue(string(resp.GetStatus()))
|
||||
|
||||
m.Name = types.StringValue(resp.GetName())
|
||||
|
||||
m.Status = types.StringUnknown()
|
||||
if status, ok := resp.GetStatusOk(); ok {
|
||||
m.Status = types.StringValue(string(status))
|
||||
}
|
||||
|
||||
storage, diags := postgresflexalpharesource.NewStorageValue(
|
||||
postgresflexalpharesource.StorageValue{}.AttributeTypes(ctx),
|
||||
|
|
@ -66,18 +90,20 @@ func mapGetInstanceResponseToModel(ctx context.Context, m *postgresflexalphareso
|
|||
return fmt.Errorf("failed converting storage from response")
|
||||
}
|
||||
m.Storage = storage
|
||||
|
||||
m.Version = types.StringValue(resp.GetVersion())
|
||||
return nil
|
||||
}
|
||||
|
||||
func mapGetDataInstanceResponseToModel(ctx context.Context, m *postgresflexalphadatasource.InstanceModel, resp *postgresflex.GetInstanceResponse) error {
|
||||
m.BackupSchedule = types.StringValue(resp.GetBackupSchedule())
|
||||
//m.Encryption = postgresflexalpharesource.EncryptionValue{
|
||||
//nolint:gocritic
|
||||
// m.Encryption = postgresflexalpharesource.EncryptionValue{
|
||||
// KekKeyId: types.StringValue(resp.Encryption.GetKekKeyId()),
|
||||
// KekKeyRingId: types.StringValue(resp.Encryption.GetKekKeyRingId()),
|
||||
// KekKeyVersion: types.StringValue(resp.Encryption.GetKekKeyVersion()),
|
||||
// ServiceAccount: types.StringValue(resp.Encryption.GetServiceAccount()),
|
||||
//}
|
||||
// }
|
||||
m.FlavorId = types.StringValue(resp.GetFlavorId())
|
||||
m.Id = utils.BuildInternalTerraformId(m.ProjectId.ValueString(), m.Region.ValueString(), m.InstanceId.ValueString())
|
||||
m.InstanceId = types.StringPointerValue(resp.Id)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package postgresflexalpha
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -1,63 +0,0 @@
|
|||
package postgresflexalpha
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||
)
|
||||
|
||||
type Model struct {
|
||||
Id types.String `tfsdk:"id"` // needed by TF
|
||||
InstanceId types.String `tfsdk:"instance_id"`
|
||||
ProjectId types.String `tfsdk:"project_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
BackupSchedule types.String `tfsdk:"backup_schedule"`
|
||||
FlavorId types.String `tfsdk:"flavor_id"`
|
||||
Replicas types.Int64 `tfsdk:"replicas"`
|
||||
RetentionDays types.Int64 `tfsdk:"retention_days"`
|
||||
Storage types.Object `tfsdk:"storage"`
|
||||
Version types.String `tfsdk:"version"`
|
||||
Region types.String `tfsdk:"region"`
|
||||
Encryption types.Object `tfsdk:"encryption"`
|
||||
Network types.Object `tfsdk:"network"`
|
||||
}
|
||||
|
||||
type encryptionModel struct {
|
||||
KeyRingId types.String `tfsdk:"keyring_id"`
|
||||
KeyId types.String `tfsdk:"key_id"`
|
||||
KeyVersion types.String `tfsdk:"key_version"`
|
||||
ServiceAccount types.String `tfsdk:"service_account"`
|
||||
}
|
||||
|
||||
var encryptionTypes = map[string]attr.Type{
|
||||
"keyring_id": basetypes.StringType{},
|
||||
"key_id": basetypes.StringType{},
|
||||
"key_version": basetypes.StringType{},
|
||||
"service_account": basetypes.StringType{},
|
||||
}
|
||||
|
||||
type networkModel struct {
|
||||
ACL types.List `tfsdk:"acl"`
|
||||
AccessScope types.String `tfsdk:"access_scope"`
|
||||
InstanceAddress types.String `tfsdk:"instance_address"`
|
||||
RouterAddress types.String `tfsdk:"router_address"`
|
||||
}
|
||||
|
||||
var networkTypes = map[string]attr.Type{
|
||||
"acl": basetypes.ListType{ElemType: types.StringType},
|
||||
"access_scope": basetypes.StringType{},
|
||||
"instance_address": basetypes.StringType{},
|
||||
"router_address": basetypes.StringType{},
|
||||
}
|
||||
|
||||
// Struct corresponding to Model.Storage
|
||||
type storageModel struct {
|
||||
Class types.String `tfsdk:"class"`
|
||||
Size types.Int64 `tfsdk:"size"`
|
||||
}
|
||||
|
||||
// Types corresponding to storageModel
|
||||
var storageTypes = map[string]attr.Type{
|
||||
"class": basetypes.StringType{},
|
||||
"size": basetypes.Int64Type{},
|
||||
}
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package postgresflexalpha
|
||||
|
||||
import (
|
||||
|
|
@ -9,9 +12,6 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
postgresflex "github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha"
|
||||
|
|
@ -47,7 +47,6 @@ type instanceResource struct {
|
|||
|
||||
func (r *instanceResource) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) {
|
||||
var data postgresflexalpha.InstanceModel
|
||||
// var data Model
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
||||
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
|
@ -68,7 +67,6 @@ func (r *instanceResource) ValidateConfig(ctx context.Context, req resource.Vali
|
|||
// Use the modifier to set the effective region in the current plan.
|
||||
func (r *instanceResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // nolint:gocritic // function signature required by Terraform
|
||||
var configModel postgresflexalpha.InstanceModel
|
||||
// var configModel Model
|
||||
// skip initial empty configuration to avoid follow-up errors
|
||||
if req.Config.Raw.IsNull() {
|
||||
return
|
||||
|
|
@ -79,7 +77,6 @@ func (r *instanceResource) ModifyPlan(ctx context.Context, req resource.ModifyPl
|
|||
}
|
||||
|
||||
var planModel postgresflexalpha.InstanceModel
|
||||
// var planModel Model
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &planModel)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
|
|
@ -124,16 +121,6 @@ func (r *instanceResource) Configure(
|
|||
// Schema defines the schema for the resource.
|
||||
func (r *instanceResource) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
resp.Schema = postgresflexalpha.InstanceResourceSchema(ctx)
|
||||
resp.Schema = addPlanModifiers(resp.Schema)
|
||||
}
|
||||
|
||||
func addPlanModifiers(s schema.Schema) schema.Schema {
|
||||
attr := s.Attributes["backup_schedule"].(schema.StringAttribute)
|
||||
attr.PlanModifiers = []planmodifier.String{
|
||||
stringplanmodifier.UseStateForUnknown(),
|
||||
}
|
||||
s.Attributes["backup_schedule"] = attr
|
||||
return s
|
||||
}
|
||||
|
||||
// Create creates the resource and sets the initial Terraform state.
|
||||
|
|
@ -143,7 +130,7 @@ func (r *instanceResource) Create(
|
|||
resp *resource.CreateResponse,
|
||||
) { // nolint:gocritic // function signature required by Terraform
|
||||
var model postgresflexalpha.InstanceModel
|
||||
//var model Model
|
||||
|
||||
diags := req.Plan.Get(ctx, &model)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
|
@ -211,7 +198,6 @@ func (r *instanceResource) Create(
|
|||
|
||||
func modelToCreateInstancePayload(netAcl []string, model postgresflexalpha.InstanceModel, replVal int32) postgresflex.CreateInstanceRequestPayload {
|
||||
payload := postgresflex.CreateInstanceRequestPayload{
|
||||
Acl: &netAcl,
|
||||
BackupSchedule: model.BackupSchedule.ValueStringPointer(),
|
||||
Encryption: &postgresflex.InstanceEncryption{
|
||||
KekKeyId: model.Encryption.KekKeyId.ValueStringPointer(),
|
||||
|
|
@ -243,7 +229,6 @@ func modelToCreateInstancePayload(netAcl []string, model postgresflexalpha.Insta
|
|||
// Read refreshes the Terraform state with the latest data.
|
||||
func (r *instanceResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { // nolint:gocritic // function signature required by Terraform
|
||||
var model postgresflexalpha.InstanceModel
|
||||
//var model Model
|
||||
diags := req.State.Get(ctx, &model)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
|
@ -290,7 +275,7 @@ func (r *instanceResource) Read(ctx context.Context, req resource.ReadRequest, r
|
|||
// Update updates the resource and sets the updated Terraform state on success.
|
||||
func (r *instanceResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { // nolint:gocritic // function signature required by Terraform
|
||||
var model postgresflexalpha.InstanceModel
|
||||
//var model Model
|
||||
|
||||
diags := req.Plan.Get(ctx, &model)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
|
@ -312,7 +297,13 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques
|
|||
if diag.HasError() {
|
||||
return
|
||||
}
|
||||
replInt32 := int32(model.Replicas.ValueInt64())
|
||||
|
||||
if model.Replicas.ValueInt64() > math.MaxInt32 {
|
||||
resp.Diagnostics.AddError("invalid int32 value", "provided int64 value does not fit into int32")
|
||||
return
|
||||
}
|
||||
replInt32 := int32(model.Replicas.ValueInt64()) // nolint:gosec // check is performed above
|
||||
|
||||
payload := postgresflex.UpdateInstancePartiallyRequestPayload{
|
||||
BackupSchedule: model.BackupSchedule.ValueStringPointer(),
|
||||
FlavorId: model.FlavorId.ValueStringPointer(),
|
||||
|
|
@ -368,7 +359,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques
|
|||
// Delete deletes the resource and removes the Terraform state on success.
|
||||
func (r *instanceResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { // nolint:gocritic // function signature required by Terraform
|
||||
var model postgresflexalpha.InstanceModel
|
||||
//var model Model
|
||||
|
||||
diags := req.State.Get(ctx, &model)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package postgresflexalpha
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package postgresflexalpha
|
||||
|
||||
import (
|
||||
|
|
|
|||
4
stackit/internal/services/postgresflexalpha/main.go
Normal file
4
stackit/internal/services/postgresflexalpha/main.go
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package postgresflexalpha
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Copyright (c) STACKIT
|
||||
|
||||
package postgresflex_test
|
||||
package postgresflexalpha_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
@ -23,7 +23,7 @@ import (
|
|||
|
||||
var (
|
||||
//go:embed testdata/resource-complete.tf
|
||||
resourceSecurityGroupMinConfig string
|
||||
resourceSecurityGroupMinConfig string //nolint:unused // needs implementation
|
||||
)
|
||||
|
||||
// Instance resource data
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
# Copyright (c) HashiCorp, Inc.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package postgresflexalpha
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package postgresflexalpha
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package postgresflexalpha
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package postgresflexalpha
|
||||
|
||||
import (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue