1.0.1
This commit is contained in:
91
internal/service/cloudbroker/lb/data_source_lb.go
Normal file
91
internal/service/cloudbroker/lb/data_source_lb.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/schemas"
|
||||
)
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ datasource.DataSource = &dataSourceLB{}
|
||||
)
|
||||
|
||||
func NewDataSourceLB() datasource.DataSource {
|
||||
return &dataSourceLB{}
|
||||
}
|
||||
|
||||
// dataSourceLB is the data source implementation.
|
||||
type dataSourceLB struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceLB) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.DataSourceLB
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceLB: Error get state")
|
||||
return
|
||||
}
|
||||
lbID := uint64(state.ID.ValueInt64())
|
||||
tflog.Info(ctx, "Read dataSourceLB: got state successfully", map[string]any{"lb_id": lbID})
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout180s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceLB: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceLB: set timeouts successfully", map[string]any{
|
||||
"lb_id": lbID,
|
||||
"readTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Map response body to schema
|
||||
resp.Diagnostics.Append(flattens.LBDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceLB: Error flatten")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceLB: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceLB", map[string]any{"lb_id": lbID})
|
||||
}
|
||||
|
||||
func (d *dataSourceLB) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceLB(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceLB) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_lb"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceLB) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceLB")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceLB successfully")
|
||||
}
|
||||
88
internal/service/cloudbroker/lb/data_source_lb_list.go
Normal file
88
internal/service/cloudbroker/lb/data_source_lb_list.go
Normal file
@@ -0,0 +1,88 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/schemas"
|
||||
)
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ datasource.DataSource = &dataSourceLBList{}
|
||||
)
|
||||
|
||||
func NewDataSourceLBList() datasource.DataSource {
|
||||
return &dataSourceLBList{}
|
||||
}
|
||||
|
||||
// dataSourceLBList is the data source implementation.
|
||||
type dataSourceLBList struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceLBList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.DataSourceLBList
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceLBList: Error get state")
|
||||
return
|
||||
}
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout180s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceLBList: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceLBList: set timeouts successfully", map[string]any{
|
||||
"readTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Map response body to schema
|
||||
resp.Diagnostics.Append(flattens.LBListDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceLBList: Error flatten")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceLBList: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceLBList")
|
||||
}
|
||||
|
||||
func (d *dataSourceLBList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceLBList(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceLBList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_lb_list"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceLBList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceLBList")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceLBList successfully")
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/schemas"
|
||||
)
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ datasource.DataSource = &dataSourceLBListDeleted{}
|
||||
)
|
||||
|
||||
func NewDataSourceLBListDeleted() datasource.DataSource {
|
||||
return &dataSourceLBListDeleted{}
|
||||
}
|
||||
|
||||
// dataSourceLBListDeleted is the data source implementation.
|
||||
type dataSourceLBListDeleted struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceLBListDeleted) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.DataSourceLBListDeleted
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceLBListDeleted: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceLBListDeleted: got state successfully")
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout180s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceLBListDeleted: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceLBListDeleted: set timeouts successfully", map[string]any{
|
||||
"readTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Map response body to schema
|
||||
resp.Diagnostics.Append(flattens.LBListDeletedDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceLBListDeleted: Error flatten")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceLBListDeleted: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceLBListDeleted")
|
||||
}
|
||||
|
||||
func (d *dataSourceLBListDeleted) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceLBListDeleted(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceLBListDeleted) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_lb_list_deleted"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceLBListDeleted) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceLBListDeleted")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceLBListDeleted successfully")
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/utilities"
|
||||
)
|
||||
|
||||
// LBDataSource flattens data source for lb.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func LBDataSource(ctx context.Context, state *models.DataSourceLB, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.LBDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
lbID := uint64(state.LBID.ValueInt64())
|
||||
|
||||
recordLB, diags := utilities.LBDataSourceCheckPresence(ctx, lbID, c)
|
||||
if diags.HasError() {
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.LBDataSource: before flatten", map[string]any{"lb_id": lbID})
|
||||
|
||||
acl, _ := json.Marshal(recordLB.ACL)
|
||||
|
||||
*state = models.DataSourceLB{
|
||||
LBID: state.LBID,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
HAMode: types.BoolValue(recordLB.HAMode),
|
||||
ACL: types.StringValue(string(acl)),
|
||||
BackendHAIP: types.StringValue(recordLB.BackendHAIP),
|
||||
Backends: flattenBackendsInLB(ctx, recordLB.Backends),
|
||||
CKey: types.StringValue(recordLB.CKey),
|
||||
Description: types.StringValue(recordLB.Description),
|
||||
DPAPIUser: types.StringValue(recordLB.DPAPIUser),
|
||||
DPAPIPassword: types.StringValue(recordLB.DPAPIPassword),
|
||||
ExtNetID: types.Int64Value(int64(recordLB.ExtNetID)),
|
||||
FrontendHAIP: types.StringValue(recordLB.FrontendHAIP),
|
||||
Frontends: flattenFrontendsInLB(ctx, recordLB.Frontends),
|
||||
GID: types.Int64Value(int64(recordLB.GID)),
|
||||
GUID: types.Int64Value(int64(recordLB.GUID)),
|
||||
ID: types.Int64Value(int64(recordLB.ID)),
|
||||
ImageID: types.Int64Value(int64(recordLB.ImageID)),
|
||||
ManagerId: types.Int64Value(int64(recordLB.ManagerId)),
|
||||
ManagerType: types.StringValue(recordLB.ManagerType),
|
||||
Meta: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &recordLB.Meta),
|
||||
Milestones: types.Int64Value(int64(recordLB.Milestones)),
|
||||
Name: types.StringValue(recordLB.Name),
|
||||
PartK8s: types.BoolValue(recordLB.PartK8s),
|
||||
PrimaryNode: flattenNodeInLB(ctx, recordLB.PrimaryNode),
|
||||
RGID: types.Int64Value(int64(recordLB.RGID)),
|
||||
SecondaryNode: flattenNodeInLB(ctx, recordLB.SecondaryNode),
|
||||
Status: types.StringValue(recordLB.Status),
|
||||
TechStatus: types.StringValue(recordLB.TechStatus),
|
||||
UserManaged: types.BoolValue(recordLB.UserManaged),
|
||||
VINSID: types.Int64Value(int64(recordLB.VINSID)),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattens.LBDataSource", map[string]any{"lb_id": state.ID.ValueInt64()})
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenBackendsInLB(ctx context.Context, backends []lb.ItemBackend) types.List {
|
||||
tflog.Info(ctx, "Start flattenBackendsInLB")
|
||||
tempSlice := make([]types.Object, 0, len(backends))
|
||||
for _, backend := range backends {
|
||||
b := models.ItemBackendModel{
|
||||
Algorithm: types.StringValue(backend.Algorithm),
|
||||
GUID: types.StringValue(backend.GUID),
|
||||
Name: types.StringValue(backend.Name),
|
||||
ServerDefaultSettings: flattenServersSettings(ctx, backend.ServerDefaultSettings),
|
||||
Servers: flattenServersInLB(ctx, backend.Servers),
|
||||
}
|
||||
obj, diags := types.ObjectValueFrom(ctx, models.ItemBackend, b)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenBackendsInLB struct to obj", diags))
|
||||
}
|
||||
tempSlice = append(tempSlice, obj)
|
||||
}
|
||||
|
||||
res, diags := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemBackend}, tempSlice)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenBackendsInLB", diags))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenBackendsInLB")
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenFrontendsInLB(ctx context.Context, frontends []lb.ItemFrontend) types.List {
|
||||
tflog.Info(ctx, "Start flattenFrontendsInLB")
|
||||
tempSlice := make([]types.Object, 0, len(frontends))
|
||||
for _, frontend := range frontends {
|
||||
b := models.ItemFrontendModel{
|
||||
Backend: types.StringValue(frontend.Backend),
|
||||
Bindings: flattenBindingsInLB(ctx, frontend.Bindings),
|
||||
GUID: types.StringValue(frontend.GUID),
|
||||
Name: types.StringValue(frontend.Name),
|
||||
}
|
||||
obj, diags := types.ObjectValueFrom(ctx, models.ItemFrontend, b)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenFrontendsInLB struct to obj", diags))
|
||||
}
|
||||
tempSlice = append(tempSlice, obj)
|
||||
}
|
||||
|
||||
res, diags := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemFrontend}, tempSlice)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenFrontendsInLB", diags))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenFrontendsInLB")
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenNodeInLB(ctx context.Context, node lb.Node) types.Object {
|
||||
tflog.Info(ctx, "Start flattenNodeInLB")
|
||||
n := models.RecordNodeModel{
|
||||
BackendIP: types.StringValue(node.BackendIP),
|
||||
ComputeID: types.Int64Value(int64(node.ComputeID)),
|
||||
FrontendIP: types.StringValue(node.FrontendIP),
|
||||
GUID: types.StringValue(node.GUID),
|
||||
MGMTIP: types.StringValue(node.MGMTIP),
|
||||
NetworkID: types.Int64Value(int64(node.NetworkID)),
|
||||
}
|
||||
obj, diags := types.ObjectValueFrom(ctx, models.ItemNode, n)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenNodeInLB struct to obj", diags))
|
||||
}
|
||||
tflog.Info(ctx, "End flattenNodeInLB")
|
||||
return obj
|
||||
}
|
||||
|
||||
func flattenServersSettings(ctx context.Context, settings lb.ServerSettings) types.Object {
|
||||
tflog.Info(ctx, "Start flattenServersSettings")
|
||||
s := models.RecordServerSettingsModel{
|
||||
Inter: types.Int64Value(int64(settings.Inter)),
|
||||
GUID: types.StringValue(settings.GUID),
|
||||
DownInter: types.Int64Value(int64(settings.DownInter)),
|
||||
Rise: types.Int64Value(int64(settings.Rise)),
|
||||
Fall: types.Int64Value(int64(settings.Fall)),
|
||||
SlowStart: types.Int64Value(int64(settings.SlowStart)),
|
||||
MaxConn: types.Int64Value(int64(settings.MaxConn)),
|
||||
MaxQueue: types.Int64Value(int64(settings.MaxQueue)),
|
||||
Weight: types.Int64Value(int64(settings.Weight)),
|
||||
}
|
||||
obj, diags := types.ObjectValueFrom(ctx, models.ItemServerSettings, s)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenServersSettings struct to obj", diags))
|
||||
}
|
||||
tflog.Info(ctx, "End flattenServersSettings")
|
||||
return obj
|
||||
}
|
||||
|
||||
func flattenServersInLB(ctx context.Context, servers []lb.ItemServer) types.List {
|
||||
tflog.Info(ctx, "Start flattenServersInLBBackend")
|
||||
tempSlice := make([]types.Object, 0, len(servers))
|
||||
for _, server := range servers {
|
||||
s := models.RecordServerModel{
|
||||
Address: types.StringValue(server.Address),
|
||||
Check: types.StringValue(server.Check),
|
||||
GUID: types.StringValue(server.GUID),
|
||||
Name: types.StringValue(server.Name),
|
||||
Port: types.Int64Value(int64(server.Port)),
|
||||
ServerSettings: flattenServersSettings(ctx, server.ServerSettings),
|
||||
}
|
||||
obj, diags := types.ObjectValueFrom(ctx, models.ItemServers, s)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenServersInLBBackend struct to obj", diags))
|
||||
}
|
||||
tempSlice = append(tempSlice, obj)
|
||||
}
|
||||
|
||||
res, diags := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemServers}, tempSlice)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenServersInLBBackend", diags))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenServersInLBBackend")
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenBindingsInLB(ctx context.Context, bindings []lb.ItemBinding) types.List {
|
||||
tflog.Info(ctx, "Start flattenBindingsInLBFrontend")
|
||||
tempSlice := make([]types.Object, 0, len(bindings))
|
||||
for _, binding := range bindings {
|
||||
s := models.ItemBindingModel{
|
||||
Address: types.StringValue(binding.Address),
|
||||
GUID: types.StringValue(binding.GUID),
|
||||
Name: types.StringValue(binding.Name),
|
||||
Port: types.Int64Value(int64(binding.Port)),
|
||||
}
|
||||
obj, diags := types.ObjectValueFrom(ctx, models.ItemBindings, s)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenBindingsInLBFrontend struct to obj", diags))
|
||||
}
|
||||
tempSlice = append(tempSlice, obj)
|
||||
}
|
||||
|
||||
res, diags := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemBindings}, tempSlice)
|
||||
if diags != nil {
|
||||
tflog.Error(ctx, fmt.Sprint("Error flattenBindingsInLBFrontend", diags))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattenBindingsInLBFrontend")
|
||||
return res
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/utilities"
|
||||
)
|
||||
|
||||
func LBListDataSource(ctx context.Context, state *models.DataSourceLBList, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.LBListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
lbList, err := utilities.LBListDataSourceCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about list lb", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.LBListDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceLBList{
|
||||
ByID: state.ByID,
|
||||
Name: state.Name,
|
||||
AccountID: state.AccountID,
|
||||
RgID: state.RgID,
|
||||
TechStatus: state.TechStatus,
|
||||
Status: state.Status,
|
||||
FrontIP: state.FrontIP,
|
||||
BackIP: state.BackIP,
|
||||
IncludeDeleted: state.IncludeDeleted,
|
||||
SortBy: state.SortBy,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
}
|
||||
|
||||
items := make([]models.ItemsLBListModel, 0, len(lbList.Data))
|
||||
for _, lbItem := range lbList.Data {
|
||||
acl, _ := json.Marshal(lbItem.ACL)
|
||||
|
||||
item := models.ItemsLBListModel{
|
||||
HAMode: types.BoolValue(lbItem.HAMode),
|
||||
ACL: types.StringValue(string(acl)),
|
||||
BackendHAIP: types.StringValue(lbItem.BackendHAIP),
|
||||
Backends: flattenBackendsInLB(ctx, lbItem.Backends),
|
||||
CreatedBy: types.StringValue(lbItem.CreatedBy),
|
||||
CreatedTime: types.Int64Value(int64(lbItem.CreatedTime)),
|
||||
DeletedBy: types.StringValue(lbItem.DeletedBy),
|
||||
DeletedTime: types.Int64Value(int64(lbItem.DeletedTime)),
|
||||
Description: types.StringValue(lbItem.Description),
|
||||
DPAPIUser: types.StringValue(lbItem.DPAPIUser),
|
||||
DPAPIPassword: types.StringValue(lbItem.DPAPIPassword),
|
||||
ExtNetID: types.Int64Value(int64(lbItem.ExtNetID)),
|
||||
FrontendHAIP: types.StringValue(lbItem.FrontendHAIP),
|
||||
Frontends: flattenFrontendsInLB(ctx, lbItem.Frontends),
|
||||
GID: types.Int64Value(int64(lbItem.GID)),
|
||||
GUID: types.Int64Value(int64(lbItem.GUID)),
|
||||
LBID: types.Int64Value(int64(lbItem.ID)),
|
||||
Milestones: types.Int64Value(int64(lbItem.Milestones)),
|
||||
Name: types.StringValue(lbItem.Name),
|
||||
PrimaryNode: flattenNodeInLB(ctx, lbItem.PrimaryNode),
|
||||
RGID: types.Int64Value(int64(lbItem.RGID)),
|
||||
RGName: types.StringValue(lbItem.RGName),
|
||||
SecondaryNode: flattenNodeInLB(ctx, lbItem.SecondaryNode),
|
||||
Status: types.StringValue(lbItem.Status),
|
||||
TechStatus: types.StringValue(lbItem.TechStatus),
|
||||
UpdatedBy: types.StringValue(lbItem.UpdatedBy),
|
||||
UpdatedTime: types.Int64Value(int64(lbItem.UpdatedTime)),
|
||||
VINSID: types.Int64Value(int64(lbItem.VINSID)),
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
state.Items = items
|
||||
state.EntryCount = types.Int64Value(int64(lbList.EntryCount))
|
||||
|
||||
tflog.Info(ctx, "flattens.LBListDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.LBListDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/utilities"
|
||||
)
|
||||
|
||||
func LBListDeletedDataSource(ctx context.Context, state *models.DataSourceLBListDeleted, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.LBListDeletedDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
lbList, err := utilities.LBListDeletedDataSourceCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about list deleted", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.LBListDeletedDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceLBListDeleted{
|
||||
ByID: state.ByID,
|
||||
Name: state.Name,
|
||||
AccountID: state.AccountID,
|
||||
RgID: state.RgID,
|
||||
TechStatus: state.TechStatus,
|
||||
FrontIP: state.FrontIP,
|
||||
BackIP: state.BackIP,
|
||||
SortBy: state.SortBy,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
}
|
||||
|
||||
items := make([]models.ItemsLBListDeletedModel, 0, len(lbList.Data))
|
||||
for _, lbItem := range lbList.Data {
|
||||
acl, _ := json.Marshal(lbItem.ACL)
|
||||
|
||||
item := models.ItemsLBListDeletedModel{
|
||||
HAMode: types.BoolValue(lbItem.HAMode),
|
||||
ACL: types.StringValue(string(acl)),
|
||||
BackendHAIP: types.StringValue(lbItem.BackendHAIP),
|
||||
Backends: flattenBackendsInLB(ctx, lbItem.Backends),
|
||||
CreatedBy: types.StringValue(lbItem.CreatedBy),
|
||||
CreatedTime: types.Int64Value(int64(lbItem.CreatedTime)),
|
||||
DeletedBy: types.StringValue(lbItem.DeletedBy),
|
||||
DeletedTime: types.Int64Value(int64(lbItem.DeletedTime)),
|
||||
Description: types.StringValue(lbItem.Description),
|
||||
DPAPIUser: types.StringValue(lbItem.DPAPIUser),
|
||||
DPAPIPassword: types.StringValue(lbItem.DPAPIPassword),
|
||||
ExtNetID: types.Int64Value(int64(lbItem.ExtNetID)),
|
||||
FrontendHAIP: types.StringValue(lbItem.FrontendHAIP),
|
||||
Frontends: flattenFrontendsInLB(ctx, lbItem.Frontends),
|
||||
GID: types.Int64Value(int64(lbItem.GID)),
|
||||
GUID: types.Int64Value(int64(lbItem.GUID)),
|
||||
LBID: types.Int64Value(int64(lbItem.ID)),
|
||||
Milestones: types.Int64Value(int64(lbItem.Milestones)),
|
||||
Name: types.StringValue(lbItem.Name),
|
||||
PrimaryNode: flattenNodeInLB(ctx, lbItem.PrimaryNode),
|
||||
RGID: types.Int64Value(int64(lbItem.RGID)),
|
||||
RGName: types.StringValue(lbItem.RGName),
|
||||
SecondaryNode: flattenNodeInLB(ctx, lbItem.SecondaryNode),
|
||||
Status: types.StringValue(lbItem.Status),
|
||||
TechStatus: types.StringValue(lbItem.TechStatus),
|
||||
UpdatedBy: types.StringValue(lbItem.UpdatedBy),
|
||||
UpdatedTime: types.Int64Value(int64(lbItem.UpdatedTime)),
|
||||
VINSID: types.Int64Value(int64(lbItem.VINSID)),
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
state.Items = items
|
||||
state.EntryCount = types.Int64Value(int64(lbList.EntryCount))
|
||||
|
||||
tflog.Info(ctx, "flattens.LBListDeletedDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.LBListDeletedDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/utilities"
|
||||
)
|
||||
|
||||
func LBResource(ctx context.Context, plan *models.ResourceLBModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.LBResource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
recordItemLB, diags := utilities.LBResourceCheckPresence(ctx, plan, c)
|
||||
if diags.HasError() {
|
||||
return diags
|
||||
}
|
||||
|
||||
acl, _ := json.Marshal(recordItemLB.ACL)
|
||||
|
||||
*plan = models.ResourceLBModel{
|
||||
RGID: plan.RGID,
|
||||
Name: plan.Name,
|
||||
ExtNetID: plan.ExtNetID,
|
||||
VINSID: plan.VINSID,
|
||||
Start: plan.Start,
|
||||
ID: plan.ID,
|
||||
|
||||
HAMode: types.BoolValue(recordItemLB.HAMode),
|
||||
Safe: plan.Safe,
|
||||
Timeouts: plan.Timeouts,
|
||||
SysctlParams: plan.SysctlParams,
|
||||
Permanently: plan.Permanently,
|
||||
Restart: plan.Restart,
|
||||
Enable: plan.Enable,
|
||||
ConfigReset: plan.ConfigReset,
|
||||
|
||||
ACL: types.StringValue(string(acl)),
|
||||
BackendHAIP: types.StringValue(recordItemLB.BackendHAIP),
|
||||
Backends: flattenBackendsInLB(ctx, recordItemLB.Backends),
|
||||
CKey: types.StringValue(recordItemLB.CKey),
|
||||
Description: types.StringValue(recordItemLB.Description),
|
||||
DPAPIUser: types.StringValue(recordItemLB.DPAPIUser),
|
||||
DPAPIPassword: types.StringValue(recordItemLB.DPAPIPassword),
|
||||
FrontendHAIP: types.StringValue(recordItemLB.FrontendHAIP),
|
||||
Frontends: flattenFrontendsInLB(ctx, recordItemLB.Frontends),
|
||||
GID: types.Int64Value(int64(recordItemLB.GID)),
|
||||
GUID: types.Int64Value(int64(recordItemLB.GUID)),
|
||||
ImageID: types.Int64Value(int64(recordItemLB.ImageID)),
|
||||
LBID: types.Int64Value(int64(recordItemLB.ID)),
|
||||
Meta: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &recordItemLB.Meta),
|
||||
Milestones: types.Int64Value(int64(recordItemLB.Milestones)),
|
||||
ManagerId: types.Int64Value(int64(recordItemLB.ManagerId)),
|
||||
ManagerType: types.StringValue(recordItemLB.ManagerType),
|
||||
PartK8s: types.BoolValue(recordItemLB.PartK8s),
|
||||
PrimaryNode: flattenNodeInLB(ctx, recordItemLB.PrimaryNode),
|
||||
SecondaryNode: flattenNodeInLB(ctx, recordItemLB.SecondaryNode),
|
||||
Status: types.StringValue(recordItemLB.Status),
|
||||
TechStatus: types.StringValue(recordItemLB.TechStatus),
|
||||
UserManaged: types.BoolValue(recordItemLB.UserManaged),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattens.LBResource", map[string]any{"id": plan.ID.ValueString()})
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/utilities"
|
||||
)
|
||||
|
||||
func LBBackendResource(ctx context.Context, plan *models.ResourceLBBackendModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.LBBackendResource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
recordItemBackend, diags := utilities.LBBackendResourceCheckPresence(ctx, plan, c)
|
||||
if diags.HasError() {
|
||||
return diags
|
||||
}
|
||||
|
||||
*plan = models.ResourceLBBackendModel{
|
||||
LBID: plan.LBID,
|
||||
Name: plan.Name,
|
||||
ID: plan.ID,
|
||||
Timeouts: plan.Timeouts,
|
||||
GUID: types.StringValue(recordItemBackend.GUID),
|
||||
Algorithm: types.StringValue(recordItemBackend.Algorithm),
|
||||
DownInter: types.Int64Value(int64(recordItemBackend.ServerDefaultSettings.DownInter)),
|
||||
Fall: types.Int64Value(int64(recordItemBackend.ServerDefaultSettings.Fall)),
|
||||
Inter: types.Int64Value(int64(recordItemBackend.ServerDefaultSettings.Inter)),
|
||||
MaxConn: types.Int64Value(int64(recordItemBackend.ServerDefaultSettings.MaxConn)),
|
||||
MaxQueue: types.Int64Value(int64(recordItemBackend.ServerDefaultSettings.MaxQueue)),
|
||||
Rise: types.Int64Value(int64(recordItemBackend.ServerDefaultSettings.Rise)),
|
||||
SlowStart: types.Int64Value(int64(recordItemBackend.ServerDefaultSettings.SlowStart)),
|
||||
Weight: types.Int64Value(int64(recordItemBackend.ServerDefaultSettings.Weight)),
|
||||
Servers: flattenServersInLB(ctx, recordItemBackend.Servers),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattens.LBBackendResource", map[string]any{"name": plan.Name.ValueString()})
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/utilities"
|
||||
)
|
||||
|
||||
func LBBackendServerResource(ctx context.Context, plan *models.ResourceLBBackendServerModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.LBBackendServerResource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
recordItemServer, diags := utilities.LBBackendServerResourceCheckPresence(ctx, plan, c)
|
||||
if diags.HasError() {
|
||||
return diags
|
||||
}
|
||||
|
||||
*plan = models.ResourceLBBackendServerModel{
|
||||
LBID: plan.LBID,
|
||||
Backend: plan.Backend,
|
||||
Name: plan.Name,
|
||||
Address: plan.Address,
|
||||
Port: plan.Port,
|
||||
ID: plan.ID,
|
||||
Timeouts: plan.Timeouts,
|
||||
Check: types.StringValue(recordItemServer.Check),
|
||||
Inter: types.Int64Value(int64(recordItemServer.ServerSettings.Inter)),
|
||||
DownInter: types.Int64Value(int64(recordItemServer.ServerSettings.DownInter)),
|
||||
Rise: types.Int64Value(int64(recordItemServer.ServerSettings.Rise)),
|
||||
Fall: types.Int64Value(int64(recordItemServer.ServerSettings.Fall)),
|
||||
SlowStart: types.Int64Value(int64(recordItemServer.ServerSettings.SlowStart)),
|
||||
MaxConn: types.Int64Value(int64(recordItemServer.ServerSettings.MaxConn)),
|
||||
MaxQueue: types.Int64Value(int64(recordItemServer.ServerSettings.MaxQueue)),
|
||||
Weight: types.Int64Value(int64(recordItemServer.ServerSettings.Weight)),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattens.LBBackendServerResource", map[string]any{"name": plan.Name.ValueString()})
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/utilities"
|
||||
)
|
||||
|
||||
func LBFrontendResource(ctx context.Context, plan *models.ResourceLBFrontendModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.LBFrontendResource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
recordItemFrontend, diags := utilities.LBFrontendResourceCheckPresence(ctx, plan, c)
|
||||
if diags.HasError() {
|
||||
return diags
|
||||
}
|
||||
|
||||
*plan = models.ResourceLBFrontendModel{
|
||||
LBID: plan.LBID,
|
||||
Name: plan.Name,
|
||||
Backend: plan.Backend,
|
||||
ID: plan.ID,
|
||||
Timeouts: plan.Timeouts,
|
||||
GUID: types.StringValue(recordItemFrontend.GUID),
|
||||
Bindings: flattenBindingsInLB(ctx, recordItemFrontend.Bindings),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattens.LBFrontendResource", map[string]any{"name": plan.Name.ValueString()})
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/utilities"
|
||||
)
|
||||
|
||||
func LBFrontendBindResource(ctx context.Context, plan *models.ResourceLBFrontendBindModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.LBFrontendBindResource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
recordItemFrontendBind, diags := utilities.LBFrontendBindResourceCheckPresence(ctx, plan, c)
|
||||
if diags.HasError() {
|
||||
return diags
|
||||
}
|
||||
|
||||
*plan = models.ResourceLBFrontendBindModel{
|
||||
Address: plan.Address,
|
||||
Frontend: plan.Frontend,
|
||||
LBID: plan.LBID,
|
||||
Name: plan.Name,
|
||||
ID: plan.ID,
|
||||
Timeouts: plan.Timeouts,
|
||||
GUID: types.StringValue(recordItemFrontendBind.GUID),
|
||||
Port: plan.Port,
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattens.LBFrontendBindResource", map[string]any{"name": plan.Name.ValueString()})
|
||||
return nil
|
||||
}
|
||||
125
internal/service/cloudbroker/lb/input_check.go
Normal file
125
internal/service/cloudbroker/lb/input_check.go
Normal file
@@ -0,0 +1,125 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/ic"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
)
|
||||
|
||||
// resourceLBInputChecks checks if rg_id, extnet_id and vins_id are valid.
|
||||
func resourceLBInputChecks(ctx context.Context, plan *models.ResourceLBModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
extNetId := uint64(plan.ExtNetID.ValueInt64())
|
||||
vinsId := uint64(plan.VINSID.ValueInt64())
|
||||
|
||||
if extNetId == 0 && vinsId == 0 {
|
||||
diags.AddError(fmt.Sprintf("Unable to validate vins_id and extnet_id"), "vins_id and ext_net_id cannot be both in the value 0")
|
||||
return diags
|
||||
}
|
||||
|
||||
rgID := uint64(plan.RGID.ValueInt64())
|
||||
tflog.Info(ctx, "resourceLBInputChecks: exist resource rg", map[string]any{"rg_id": rgID})
|
||||
err := ic.ExistRG(ctx, rgID, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about rg with ID %v", rgID), err.Error())
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "resourceLBInputChecks: exist resource extNet", map[string]any{" extnet_id": extNetId})
|
||||
err = ic.ExistExtNetInLb(ctx, extNetId, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about extNet with ID %v", extNetId), err.Error())
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "resourceLBInputChecks: exist resource VINS", map[string]any{" vins_id": vinsId})
|
||||
err = ic.ExistVinsInLb(ctx, vinsId, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about VINS with ID %v", vinsId), err.Error())
|
||||
}
|
||||
|
||||
return diags
|
||||
}
|
||||
|
||||
// resourceLBFrontendBindInputChecks checks if lb_id and backend_name are valid.
|
||||
func resourceLBFrontendBindInputChecks(ctx context.Context, plan *models.ResourceLBFrontendBindModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
lbID := uint64(plan.LBID.ValueInt64())
|
||||
fName := plan.Frontend.ValueString()
|
||||
tflog.Info(ctx, "resourceLBFrontendBindInputChecks: exist resource lb", map[string]any{"lb_id": lbID})
|
||||
err := ic.ExistLB(ctx, lbID, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about lb with ID %v", lbID), err.Error())
|
||||
return diags
|
||||
}
|
||||
tflog.Info(ctx, "resourceLBFrontendInputChecks: exist resource lbFrontend", map[string]any{"name": fName})
|
||||
err = ic.ExistLBFrontend(ctx, lbID, fName, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about frontend with name %v", fName), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
return diags
|
||||
}
|
||||
|
||||
// resourceLBFrontendInputChecks checks if lb_id and backend_name are valid.
|
||||
func resourceLBFrontendInputChecks(ctx context.Context, plan *models.ResourceLBFrontendModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
lbID := uint64(plan.LBID.ValueInt64())
|
||||
bName := plan.Backend.ValueString()
|
||||
tflog.Info(ctx, "resourceLBFrontendInputChecks: exist resource lb", map[string]any{"lb_id": lbID})
|
||||
err := ic.ExistLB(ctx, lbID, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about lb with ID %v", lbID), err.Error())
|
||||
return diags
|
||||
}
|
||||
tflog.Info(ctx, "resourceLBFrontendInputChecks: exist resource lbBackend", map[string]any{"name": bName})
|
||||
err = ic.ExistLBBackend(ctx, lbID, bName, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about backend with name %v", bName), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
return diags
|
||||
}
|
||||
|
||||
// resourceLBBackendServerInputChecks checks if lb_id and backend_name are valid.
|
||||
func resourceLBBackendServerInputChecks(ctx context.Context, plan *models.ResourceLBBackendServerModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
lbID := uint64(plan.LBID.ValueInt64())
|
||||
bName := plan.Backend.ValueString()
|
||||
tflog.Info(ctx, "resourceLBBackendServerInputChecks: exist resource lb", map[string]any{"lb_id": lbID})
|
||||
err := ic.ExistLB(ctx, lbID, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about lb with ID %v", lbID), err.Error())
|
||||
} else {
|
||||
tflog.Info(ctx, "resourceLBBackendServerInputChecks: exist resource lbBackend", map[string]any{"name": bName})
|
||||
err = ic.ExistLBBackend(ctx, lbID, bName, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about backend with name %v", bName), err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
return diags
|
||||
}
|
||||
|
||||
// resourceLBBackendInputChecks checks if lb_id are valid.
|
||||
func resourceLBBackendInputChecks(ctx context.Context, plan *models.ResourceLBBackendModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
lbID := uint64(plan.LBID.ValueInt64())
|
||||
tflog.Info(ctx, "resourceLBBackendInputChecks: exist resource lb", map[string]any{"lb_id": lbID})
|
||||
err := ic.ExistLB(ctx, lbID, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about lb with ID %v", lbID), err.Error())
|
||||
}
|
||||
|
||||
return diags
|
||||
}
|
||||
147
internal/service/cloudbroker/lb/models/model_data_source_lb.go
Normal file
147
internal/service/cloudbroker/lb/models/model_data_source_lb.go
Normal file
@@ -0,0 +1,147 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type DataSourceLB struct {
|
||||
// required fields
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
LBID types.Int64 `tfsdk:"lb_id"`
|
||||
|
||||
// response fields
|
||||
HAMode types.Bool `tfsdk:"ha_mode"`
|
||||
ACL types.String `tfsdk:"acl"`
|
||||
BackendHAIP types.String `tfsdk:"backend_haip"`
|
||||
Backends types.List `tfsdk:"backends"`
|
||||
CKey types.String `tfsdk:"ckey"`
|
||||
Description types.String `tfsdk:"desc"`
|
||||
DPAPIUser types.String `tfsdk:"dp_api_user"`
|
||||
DPAPIPassword types.String `tfsdk:"dp_api_password"`
|
||||
ExtNetID types.Int64 `tfsdk:"extnet_id"`
|
||||
FrontendHAIP types.String `tfsdk:"frontend_haip"`
|
||||
Frontends types.List `tfsdk:"frontends"`
|
||||
GID types.Int64 `tfsdk:"gid"`
|
||||
GUID types.Int64 `tfsdk:"guid"`
|
||||
ID types.Int64 `tfsdk:"id"`
|
||||
ImageID types.Int64 `tfsdk:"image_id"`
|
||||
ManagerId types.Int64 `tfsdk:"manager_id"`
|
||||
ManagerType types.String `tfsdk:"manager_type"`
|
||||
Meta types.List `tfsdk:"meta"`
|
||||
Milestones types.Int64 `tfsdk:"milestones"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
PartK8s types.Bool `tfsdk:"part_k8s"`
|
||||
PrimaryNode types.Object `tfsdk:"primary_node"`
|
||||
RGID types.Int64 `tfsdk:"rg_id"`
|
||||
SecondaryNode types.Object `tfsdk:"secondary_node"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
TechStatus types.String `tfsdk:"tech_status"`
|
||||
UserManaged types.Bool `tfsdk:"user_managed"`
|
||||
VINSID types.Int64 `tfsdk:"vins_id"`
|
||||
}
|
||||
|
||||
type ItemBackendModel struct {
|
||||
Algorithm types.String `tfsdk:"algorithm"`
|
||||
GUID types.String `tfsdk:"guid"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
ServerDefaultSettings types.Object `tfsdk:"server_default_settings"`
|
||||
Servers types.List `tfsdk:"servers"`
|
||||
}
|
||||
|
||||
type ItemFrontendModel struct {
|
||||
Backend types.String `tfsdk:"backend"`
|
||||
Bindings types.List `tfsdk:"bindings"`
|
||||
GUID types.String `tfsdk:"guid"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
}
|
||||
|
||||
type RecordNodeModel struct {
|
||||
BackendIP types.String `tfsdk:"backend_ip"`
|
||||
ComputeID types.Int64 `tfsdk:"compute_id"`
|
||||
FrontendIP types.String `tfsdk:"frontend_ip"`
|
||||
GUID types.String `tfsdk:"guid"`
|
||||
MGMTIP types.String `tfsdk:"mgmt_ip"`
|
||||
NetworkID types.Int64 `tfsdk:"network_id"`
|
||||
}
|
||||
|
||||
type RecordServerSettingsModel struct {
|
||||
Inter types.Int64 `tfsdk:"inter"`
|
||||
GUID types.String `tfsdk:"guid"`
|
||||
DownInter types.Int64 `tfsdk:"downinter"`
|
||||
Rise types.Int64 `tfsdk:"rise"`
|
||||
Fall types.Int64 `tfsdk:"fall"`
|
||||
SlowStart types.Int64 `tfsdk:"slowstart"`
|
||||
MaxConn types.Int64 `tfsdk:"maxconn"`
|
||||
MaxQueue types.Int64 `tfsdk:"maxqueue"`
|
||||
Weight types.Int64 `tfsdk:"weight"`
|
||||
}
|
||||
|
||||
type RecordServerModel struct {
|
||||
Address types.String `tfsdk:"address"`
|
||||
Check types.String `tfsdk:"check"`
|
||||
GUID types.String `tfsdk:"guid"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Port types.Int64 `tfsdk:"port"`
|
||||
ServerSettings types.Object `tfsdk:"server_settings"`
|
||||
}
|
||||
|
||||
type ItemBindingModel struct {
|
||||
Address types.String `tfsdk:"address"`
|
||||
GUID types.String `tfsdk:"guid"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Port types.Int64 `tfsdk:"port"`
|
||||
}
|
||||
|
||||
var ItemNode = map[string]attr.Type{
|
||||
"backend_ip": types.StringType,
|
||||
"compute_id": types.Int64Type,
|
||||
"frontend_ip": types.StringType,
|
||||
"guid": types.StringType,
|
||||
"mgmt_ip": types.StringType,
|
||||
"network_id": types.Int64Type,
|
||||
}
|
||||
|
||||
var ItemBackend = map[string]attr.Type{
|
||||
"algorithm": types.StringType,
|
||||
"guid": types.StringType,
|
||||
"name": types.StringType,
|
||||
"server_default_settings": types.ObjectType{AttrTypes: ItemServerSettings},
|
||||
"servers": types.ListType{ElemType: types.ObjectType{AttrTypes: ItemServers}},
|
||||
}
|
||||
|
||||
var ItemFrontend = map[string]attr.Type{
|
||||
"backend": types.StringType,
|
||||
"bindings": types.ListType{ElemType: types.ObjectType{AttrTypes: ItemBindings}},
|
||||
"guid": types.StringType,
|
||||
"name": types.StringType,
|
||||
}
|
||||
|
||||
var ItemServers = map[string]attr.Type{
|
||||
"address": types.StringType,
|
||||
"check": types.StringType,
|
||||
"guid": types.StringType,
|
||||
"name": types.StringType,
|
||||
"port": types.Int64Type,
|
||||
"server_settings": types.ObjectType{AttrTypes: ItemServerSettings},
|
||||
}
|
||||
|
||||
var ItemServerSettings = map[string]attr.Type{
|
||||
"inter": types.Int64Type,
|
||||
"guid": types.StringType,
|
||||
"downinter": types.Int64Type,
|
||||
"rise": types.Int64Type,
|
||||
"fall": types.Int64Type,
|
||||
"slowstart": types.Int64Type,
|
||||
"maxconn": types.Int64Type,
|
||||
"maxqueue": types.Int64Type,
|
||||
"weight": types.Int64Type,
|
||||
}
|
||||
|
||||
var ItemBindings = map[string]attr.Type{
|
||||
"address": types.StringType,
|
||||
"name": types.StringType,
|
||||
"port": types.Int64Type,
|
||||
"guid": types.StringType,
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type DataSourceLBList struct {
|
||||
|
||||
// optional fields
|
||||
ByID types.Int64 `tfsdk:"by_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
AccountID types.Int64 `tfsdk:"account_id"`
|
||||
RgID types.Int64 `tfsdk:"rg_id"`
|
||||
TechStatus types.String `tfsdk:"tech_status"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
FrontIP types.String `tfsdk:"front_ip"`
|
||||
BackIP types.String `tfsdk:"back_ip"`
|
||||
IncludeDeleted types.Bool `tfsdk:"include_deleted"`
|
||||
SortBy types.String `tfsdk:"sort_by"`
|
||||
Page types.Int64 `tfsdk:"page"`
|
||||
Size types.Int64 `tfsdk:"size"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
|
||||
// response fields
|
||||
Id types.String `tfsdk:"id"`
|
||||
Items []ItemsLBListModel `tfsdk:"items"`
|
||||
EntryCount types.Int64 `tfsdk:"entry_count"`
|
||||
}
|
||||
|
||||
type ItemsLBListModel struct {
|
||||
HAMode types.Bool `tfsdk:"ha_mode"`
|
||||
ACL types.String `tfsdk:"acl"`
|
||||
BackendHAIP types.String `tfsdk:"backend_haip"`
|
||||
Backends types.List `tfsdk:"backends"`
|
||||
CreatedBy types.String `tfsdk:"created_by"`
|
||||
CreatedTime types.Int64 `tfsdk:"created_time"`
|
||||
DeletedBy types.String `tfsdk:"deleted_by"`
|
||||
DeletedTime types.Int64 `tfsdk:"deleted_time"`
|
||||
Description types.String `tfsdk:"desc"`
|
||||
DPAPIUser types.String `tfsdk:"dp_api_user"`
|
||||
DPAPIPassword types.String `tfsdk:"dp_api_password"`
|
||||
ExtNetID types.Int64 `tfsdk:"extnet_id"`
|
||||
FrontendHAIP types.String `tfsdk:"frontend_haip"`
|
||||
Frontends types.List `tfsdk:"frontends"`
|
||||
GID types.Int64 `tfsdk:"gid"`
|
||||
GUID types.Int64 `tfsdk:"guid"`
|
||||
LBID types.Int64 `tfsdk:"lb_id"`
|
||||
ManagerId types.Int64 `tfsdk:"manager_id"`
|
||||
ManagerType types.String `tfsdk:"manager_type"`
|
||||
Milestones types.Int64 `tfsdk:"milestones"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
PartK8s types.Bool `tfsdk:"part_k8s"`
|
||||
PrimaryNode types.Object `tfsdk:"primary_node"`
|
||||
RGName types.String `tfsdk:"rg_name"`
|
||||
RGID types.Int64 `tfsdk:"rg_id"`
|
||||
SecondaryNode types.Object `tfsdk:"secondary_node"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
TechStatus types.String `tfsdk:"tech_status"`
|
||||
UpdatedBy types.String `tfsdk:"updated_by"`
|
||||
UpdatedTime types.Int64 `tfsdk:"updated_time"`
|
||||
UserManaged types.Bool `tfsdk:"user_managed"`
|
||||
VINSID types.Int64 `tfsdk:"vins_id"`
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type DataSourceLBListDeleted struct {
|
||||
|
||||
// optional fields
|
||||
ByID types.Int64 `tfsdk:"by_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
AccountID types.Int64 `tfsdk:"account_id"`
|
||||
RgID types.Int64 `tfsdk:"rg_id"`
|
||||
TechStatus types.String `tfsdk:"tech_status"`
|
||||
FrontIP types.String `tfsdk:"front_ip"`
|
||||
BackIP types.String `tfsdk:"back_ip"`
|
||||
SortBy types.String `tfsdk:"sort_by"`
|
||||
Page types.Int64 `tfsdk:"page"`
|
||||
Size types.Int64 `tfsdk:"size"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
|
||||
// response fields
|
||||
Id types.String `tfsdk:"id"`
|
||||
Items []ItemsLBListDeletedModel `tfsdk:"items"`
|
||||
EntryCount types.Int64 `tfsdk:"entry_count"`
|
||||
}
|
||||
|
||||
type ItemsLBListDeletedModel struct {
|
||||
HAMode types.Bool `tfsdk:"ha_mode"`
|
||||
ACL types.String `tfsdk:"acl"`
|
||||
BackendHAIP types.String `tfsdk:"backend_haip"`
|
||||
Backends types.List `tfsdk:"backends"`
|
||||
CreatedBy types.String `tfsdk:"created_by"`
|
||||
CreatedTime types.Int64 `tfsdk:"created_time"`
|
||||
DeletedBy types.String `tfsdk:"deleted_by"`
|
||||
DeletedTime types.Int64 `tfsdk:"deleted_time"`
|
||||
Description types.String `tfsdk:"desc"`
|
||||
DPAPIUser types.String `tfsdk:"dp_api_user"`
|
||||
DPAPIPassword types.String `tfsdk:"dp_api_password"`
|
||||
ExtNetID types.Int64 `tfsdk:"extnet_id"`
|
||||
FrontendHAIP types.String `tfsdk:"frontend_haip"`
|
||||
Frontends types.List `tfsdk:"frontends"`
|
||||
GID types.Int64 `tfsdk:"gid"`
|
||||
GUID types.Int64 `tfsdk:"guid"`
|
||||
LBID types.Int64 `tfsdk:"lb_id"`
|
||||
ManagerId types.Int64 `tfsdk:"manager_id"`
|
||||
ManagerType types.String `tfsdk:"manager_type"`
|
||||
Milestones types.Int64 `tfsdk:"milestones"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
PartK8s types.Bool `tfsdk:"part_k8s"`
|
||||
PrimaryNode types.Object `tfsdk:"primary_node"`
|
||||
RGName types.String `tfsdk:"rg_name"`
|
||||
RGID types.Int64 `tfsdk:"rg_id"`
|
||||
SecondaryNode types.Object `tfsdk:"secondary_node"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
TechStatus types.String `tfsdk:"tech_status"`
|
||||
UpdatedBy types.String `tfsdk:"updated_by"`
|
||||
UpdatedTime types.Int64 `tfsdk:"updated_time"`
|
||||
UserManaged types.Bool `tfsdk:"user_managed"`
|
||||
VINSID types.Int64 `tfsdk:"vins_id"`
|
||||
}
|
||||
52
internal/service/cloudbroker/lb/models/model_resource_lb.go
Normal file
52
internal/service/cloudbroker/lb/models/model_resource_lb.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type ResourceLBModel struct {
|
||||
// required fields
|
||||
RGID types.Int64 `tfsdk:"rg_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
ExtNetID types.Int64 `tfsdk:"extnet_id"`
|
||||
VINSID types.Int64 `tfsdk:"vins_id"`
|
||||
Start types.Bool `tfsdk:"start"`
|
||||
|
||||
// optional fields
|
||||
HAMode types.Bool `tfsdk:"ha_mode"`
|
||||
ACL types.String `tfsdk:"acl"`
|
||||
Description types.String `tfsdk:"desc"`
|
||||
Enable types.Bool `tfsdk:"enable"`
|
||||
Restart types.Bool `tfsdk:"restart"`
|
||||
ConfigReset types.Bool `tfsdk:"config_reset"`
|
||||
Permanently types.Bool `tfsdk:"permanently"`
|
||||
Restore types.Bool `tfsdk:"restore"`
|
||||
Safe types.Bool `tfsdk:"safe"`
|
||||
SysctlParams types.List `tfsdk:"sysctl_params"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
|
||||
// response fields
|
||||
BackendHAIP types.String `tfsdk:"backend_haip"`
|
||||
Backends types.List `tfsdk:"backends"`
|
||||
CKey types.String `tfsdk:"ckey"`
|
||||
DPAPIUser types.String `tfsdk:"dp_api_user"`
|
||||
DPAPIPassword types.String `tfsdk:"dp_api_password"`
|
||||
FrontendHAIP types.String `tfsdk:"frontend_haip"`
|
||||
Frontends types.List `tfsdk:"frontends"`
|
||||
GID types.Int64 `tfsdk:"gid"`
|
||||
GUID types.Int64 `tfsdk:"guid"`
|
||||
ID types.String `tfsdk:"id"`
|
||||
ImageID types.Int64 `tfsdk:"image_id"`
|
||||
LBID types.Int64 `tfsdk:"lb_id"`
|
||||
ManagerId types.Int64 `tfsdk:"manager_id"`
|
||||
ManagerType types.String `tfsdk:"manager_type"`
|
||||
Meta types.List `tfsdk:"meta"`
|
||||
Milestones types.Int64 `tfsdk:"milestones"`
|
||||
PartK8s types.Bool `tfsdk:"part_k8s"`
|
||||
PrimaryNode types.Object `tfsdk:"primary_node"`
|
||||
SecondaryNode types.Object `tfsdk:"secondary_node"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
TechStatus types.String `tfsdk:"tech_status"`
|
||||
UserManaged types.Bool `tfsdk:"user_managed"`
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type ResourceLBBackendModel struct {
|
||||
Algorithm types.String `tfsdk:"algorithm"`
|
||||
LBID types.Int64 `tfsdk:"lb_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
ID types.String `tfsdk:"id"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
GUID types.String `tfsdk:"guid"`
|
||||
Inter types.Int64 `tfsdk:"inter"`
|
||||
DownInter types.Int64 `tfsdk:"downinter"`
|
||||
Rise types.Int64 `tfsdk:"rise"`
|
||||
Fall types.Int64 `tfsdk:"fall"`
|
||||
SlowStart types.Int64 `tfsdk:"slowstart"`
|
||||
MaxConn types.Int64 `tfsdk:"maxconn"`
|
||||
MaxQueue types.Int64 `tfsdk:"maxqueue"`
|
||||
Weight types.Int64 `tfsdk:"weight"`
|
||||
Servers types.List `tfsdk:"servers"`
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type ResourceLBBackendServerModel struct {
|
||||
LBID types.Int64 `tfsdk:"lb_id"`
|
||||
Backend types.String `tfsdk:"backend_name"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Address types.String `tfsdk:"address"`
|
||||
Port types.Int64 `tfsdk:"port"`
|
||||
Check types.String `tfsdk:"check"`
|
||||
Inter types.Int64 `tfsdk:"inter"`
|
||||
GUID types.String `tfsdk:"guid"`
|
||||
DownInter types.Int64 `tfsdk:"downinter"`
|
||||
Rise types.Int64 `tfsdk:"rise"`
|
||||
Fall types.Int64 `tfsdk:"fall"`
|
||||
SlowStart types.Int64 `tfsdk:"slowstart"`
|
||||
MaxConn types.Int64 `tfsdk:"maxconn"`
|
||||
MaxQueue types.Int64 `tfsdk:"maxqueue"`
|
||||
Weight types.Int64 `tfsdk:"weight"`
|
||||
ID types.String `tfsdk:"id"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type ResourceLBFrontendModel struct {
|
||||
Backend types.String `tfsdk:"backend_name"`
|
||||
Bindings types.List `tfsdk:"bindings"`
|
||||
LBID types.Int64 `tfsdk:"lb_id"`
|
||||
GUID types.String `tfsdk:"guid"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
ID types.String `tfsdk:"id"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type ResourceLBFrontendBindModel struct {
|
||||
LBID types.Int64 `tfsdk:"lb_id"`
|
||||
Frontend types.String `tfsdk:"frontend_name"`
|
||||
Address types.String `tfsdk:"address"`
|
||||
GUID types.String `tfsdk:"guid"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Port types.Int64 `tfsdk:"port"`
|
||||
ID types.String `tfsdk:"id"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
}
|
||||
359
internal/service/cloudbroker/lb/resource_lb.go
Normal file
359
internal/service/cloudbroker/lb/resource_lb.go
Normal file
@@ -0,0 +1,359 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"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/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/schemas"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/utilities"
|
||||
)
|
||||
|
||||
var (
|
||||
_ resource.Resource = &resourceLB{}
|
||||
_ resource.ResourceWithImportState = &resourceLB{}
|
||||
)
|
||||
|
||||
// NewResourceLB is a helper function to simplify the provider implementation.
|
||||
func NewResourceLB() resource.Resource {
|
||||
return &resourceLB{}
|
||||
}
|
||||
|
||||
// resourceLB is the resource implementation.
|
||||
type resourceLB struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (r *resourceLB) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
||||
// Get plan to create lb
|
||||
var plan models.ResourceLBModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Create resourceLB: Error receiving the plan")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Create resourceLB: start creating", map[string]any{"name": plan.Name.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
createTimeout, diags := plan.Timeouts.Create(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Create resourceLB: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Create resourceLB: set timeouts successfully", map[string]any{
|
||||
"name": plan.Name.ValueString(),
|
||||
"createTimeout": createTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, createTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Check if input values are valid in the platform
|
||||
tflog.Info(ctx, "Create resourceLB: starting input checks", map[string]any{"name": plan.Name.ValueString()})
|
||||
resp.Diagnostics.Append(resourceLBInputChecks(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Create resourceLB: Error input checks")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Create resourceLB: input checks successful", map[string]any{"name": plan.Name.ValueString()})
|
||||
|
||||
// Make create request and get response for creation
|
||||
lbId, diags := utilities.CreateResourceLB(ctx, &plan, r.client)
|
||||
if diags.HasError() {
|
||||
resp.Diagnostics.Append(diags...)
|
||||
tflog.Error(ctx, "Create resourceLB: Error response for create resource LB")
|
||||
return
|
||||
}
|
||||
plan.ID = types.StringValue(strconv.Itoa(int(lbId)))
|
||||
|
||||
// additional settings after lb creation: in case of failures, warnings are added to resp.Diagnostics,
|
||||
// because additional settings failure is not critical. If errors were added instead of warnings, terraform
|
||||
// framework would mark resource as tainted and delete it, which would be unwanted behaviour.
|
||||
|
||||
// enable or disable lb, warnings added to resp.Diagnostics in case of failure.
|
||||
if !plan.Enable.IsNull() { // Enable is optional
|
||||
diags := utilities.LBEnableDisable(ctx, &plan, r.client)
|
||||
for _, d := range diags {
|
||||
if d.Severity() == diag.SeverityError {
|
||||
resp.Diagnostics.AddWarning(d.Summary(), d.Detail())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Create resourceLB: resource creation is completed", map[string]any{"id": lbId})
|
||||
|
||||
// Map response body to schema and populate Computed attribute values
|
||||
resp.Diagnostics.Append(flattens.LBResource(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
// Set state to fully populated data
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resourceLB) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
|
||||
// Get current state
|
||||
var state models.ResourceLBModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceLB: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read resourceLB: got state successfully", map[string]any{"ID": state.ID.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceLB: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read resourceLB: set timeouts successfully", map[string]any{
|
||||
"ID": state.ID.ValueString(),
|
||||
"readTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Read status lb and if it is necessary to restore it
|
||||
resp.Diagnostics.Append(utilities.LBReadStatus(ctx, &state, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Error read status or restore")
|
||||
return
|
||||
}
|
||||
|
||||
// Overwrite items with refreshed state
|
||||
resp.Diagnostics.Append(flattens.LBResource(ctx, &state, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceLB: Error flatten")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceLB: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read resourceLB")
|
||||
}
|
||||
|
||||
func (r *resourceLB) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
|
||||
// Retrieve values from plan
|
||||
var plan models.ResourceLBModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLB: Error receiving the plan")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceLB: got plan successfully", map[string]any{"ID": plan.ID.ValueString()})
|
||||
|
||||
// Retrieve values from state
|
||||
var state models.ResourceLBModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLB: Error receiving the state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceLB: got state successfully", map[string]any{"ID": plan.ID.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
updateTimeout, diags := plan.Timeouts.Update(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceLB: set timeouts successfully", map[string]any{
|
||||
"ID": state.ID.ValueString(),
|
||||
"updateTimeout": updateTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, updateTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Checking for values in the platform
|
||||
tflog.Info(ctx, "Update resourceLB: starting input checks", map[string]any{"ID": plan.ID.ValueString()})
|
||||
resp.Diagnostics.Append(resourceLBInputChecks(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLB: Error input checks")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceLB: input checks successful", map[string]any{"ID": plan.ID.ValueString()})
|
||||
|
||||
// Read status lb and if it is necessary to restore it
|
||||
resp.Diagnostics.Append(utilities.LBReadStatus(ctx, &state, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Error read status or restore")
|
||||
return
|
||||
}
|
||||
|
||||
// Update ha mode lb
|
||||
if !plan.HAMode.Equal(state.HAMode) && plan.HAMode.ValueBool() {
|
||||
resp.Diagnostics.Append(utilities.LBUpdateHaMode(ctx, &state, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLB: Error update ha mode")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Update sysctl LB params
|
||||
if !plan.SysctlParams.Equal(state.SysctlParams) {
|
||||
resp.Diagnostics.Append(utilities.LBUpdateSysctlParams(ctx, &plan, &state, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLB: Error update sysctl LB params")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
plan.ID = types.StringValue(strconv.Itoa(int(state.LBID.ValueInt64())))
|
||||
|
||||
// Enable/disable LB
|
||||
if !plan.Enable.Equal(state.Enable) {
|
||||
resp.Diagnostics.Append(utilities.LBEnableDisable(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLB: Error enable/disable LB")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Start/stop LB
|
||||
if !plan.Start.Equal(state.Start) {
|
||||
resp.Diagnostics.Append(utilities.LBStartStop(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLB: Error start/stop LB")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Update description LB
|
||||
if !plan.Description.IsUnknown() && !plan.Description.Equal(state.Description) {
|
||||
resp.Diagnostics.Append(utilities.LBUpdateDescription(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLB: Error update LB description")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Restart LB
|
||||
if !plan.Restart.Equal(state.Restart) && plan.Restart.ValueBool() {
|
||||
resp.Diagnostics.Append(utilities.LBRestart(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLB: Error update LB description")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Config reset
|
||||
if !plan.ConfigReset.Equal(state.Restart) && plan.ConfigReset.ValueBool() {
|
||||
resp.Diagnostics.Append(utilities.LBConfigReset(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLB: Error update LB description")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Update resourceLB: resource update is completed", map[string]any{"ID": plan.ID.ValueString()})
|
||||
|
||||
// Map response body to schema and populate Computed attribute values
|
||||
resp.Diagnostics.Append(flattens.LBResource(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
// Set state to fully populated data
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resourceLB) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
|
||||
// Get current state
|
||||
var state models.ResourceLBModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Delete resourceLB: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Delete resourceLB: got state successfully", map[string]any{"ID": state.ID.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Delete(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Delete resourceLB: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Delete resourceLB: set timeouts successfully", map[string]any{
|
||||
"id": state.ID.ValueString(),
|
||||
"deleteTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
var permanently bool
|
||||
if state.Permanently.IsNull() {
|
||||
permanently = true
|
||||
} else {
|
||||
permanently = state.Permanently.ValueBool()
|
||||
}
|
||||
|
||||
// Delete existing lb
|
||||
delReq := lb.DeleteRequest{
|
||||
LBID: uint64(state.LBID.ValueInt64()),
|
||||
Permanently: permanently,
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Delete resourceLB: calling cloudbroker().LB().Delete", map[string]any{
|
||||
"ID": state.ID.ValueString(),
|
||||
"req": delReq,
|
||||
})
|
||||
_, err := r.client.CloudBroker().LB().Delete(ctx, delReq)
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError("Delete resourceLB: Error deleting", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End delete resource lb ", map[string]any{"id": state.ID.ValueString()})
|
||||
}
|
||||
|
||||
func (r *resourceLB) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaResourceLB(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx, timeouts.Opts{Create: true, Read: true, Update: true, Delete: true}),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resourceLB) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_lb"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the resource.
|
||||
func (r *resourceLB) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure resourceLB")
|
||||
r.client = client.Resource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure resourceLB successfully")
|
||||
}
|
||||
|
||||
func (r *resourceLB) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
|
||||
// Retrieve import ID and save to id attribute
|
||||
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
|
||||
}
|
||||
267
internal/service/cloudbroker/lb/resource_lb_backend.go
Normal file
267
internal/service/cloudbroker/lb/resource_lb_backend.go
Normal file
@@ -0,0 +1,267 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
|
||||
"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/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/schemas"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/utilities"
|
||||
)
|
||||
|
||||
var (
|
||||
_ resource.Resource = &resourceLBBackend{}
|
||||
_ resource.ResourceWithImportState = &resourceLBBackend{}
|
||||
)
|
||||
|
||||
// NewResourceLBBackend is a helper function to simplify the provider implementation.
|
||||
func NewResourceLBBackend() resource.Resource {
|
||||
return &resourceLBBackend{}
|
||||
}
|
||||
|
||||
// resourceLBBackend is the resource implementation.
|
||||
type resourceLBBackend struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (r *resourceLBBackend) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
||||
// Get plan to create lb backend
|
||||
var plan models.ResourceLBBackendModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Create resourceLBBackend: Error receiving the plan")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Create resourceLBBackend: start creating", map[string]any{"name": plan.Name.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
createTimeout, diags := plan.Timeouts.Create(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Create resourceLBBackend: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Create resourceLBBackend: set timeouts successfully", map[string]any{
|
||||
"name": plan.Name.ValueString(),
|
||||
"createTimeout": createTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, createTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Check if input values are valid in the platform
|
||||
tflog.Info(ctx, "Create resourceLBBackend: starting input checks", map[string]any{"name": plan.Name.ValueString()})
|
||||
resp.Diagnostics.Append(resourceLBBackendInputChecks(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Create resourceLBBackend: Error input checks")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Create resourceLBBackend: input checks successful", map[string]any{"name": plan.Name.ValueString()})
|
||||
|
||||
// Make create request and get response for creation
|
||||
diags = utilities.CreateResourceLBBackend(ctx, &plan, r.client)
|
||||
if diags.HasError() {
|
||||
resp.Diagnostics.Append(diags...)
|
||||
tflog.Error(ctx, "Create resourceLBBackend: Error response for create resource LBBackend")
|
||||
return
|
||||
}
|
||||
|
||||
plan.ID = types.StringValue(strconv.Itoa(int(plan.LBID.ValueInt64())) + "#" + plan.Name.ValueString())
|
||||
|
||||
tflog.Info(ctx, "Create resourceLBBackend: resource creation is completed", map[string]any{"name": plan.Name.ValueString()})
|
||||
|
||||
// Map response body to schema and populate Computed attribute values
|
||||
resp.Diagnostics.Append(flattens.LBBackendResource(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
// Set state to fully populated data
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resourceLBBackend) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
|
||||
// Get current state
|
||||
var state models.ResourceLBBackendModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceLBBackend: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read resourceLBBackend: got state successfully", map[string]any{"ID": state.ID.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceLBBackend: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read resourceLBBackend: set timeouts successfully", map[string]any{
|
||||
"ID": state.ID.ValueString(),
|
||||
"readTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Overwrite items with refreshed state
|
||||
resp.Diagnostics.Append(flattens.LBBackendResource(ctx, &state, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceLBBackend: Error flatten")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceLBBackend: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read resourceLBBackend")
|
||||
}
|
||||
|
||||
func (r *resourceLBBackend) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
|
||||
// Retrieve values from plan
|
||||
var plan models.ResourceLBBackendModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLBBackend: Error receiving the plan")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceLBBackend: got plan successfully", map[string]any{"ID": plan.ID.ValueString()})
|
||||
|
||||
// Retrieve values from state
|
||||
var state models.ResourceLBBackendModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLBBackend: Error receiving the state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceLBBackend: got state successfully", map[string]any{"ID": plan.ID.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
updateTimeout, diags := plan.Timeouts.Update(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceLBBackend: set timeouts successfully", map[string]any{
|
||||
"ID": state.ID.ValueString(),
|
||||
"updateTimeout": updateTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, updateTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Checking for values in the platform
|
||||
tflog.Info(ctx, "Update resourceLBBackend: starting input checks", map[string]any{"ID": plan.ID.ValueString()})
|
||||
resp.Diagnostics.Append(resourceLBBackendInputChecks(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLBBackend: Error input checks")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceLBBackend: input checks successful", map[string]any{"ID": plan.ID.ValueString()})
|
||||
|
||||
// Check and update resource
|
||||
resp.Diagnostics.Append(utilities.UpdateLBBackend(ctx, &plan, &state, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLBBackend: Error editing lb backend")
|
||||
return
|
||||
}
|
||||
|
||||
plan.ID = types.StringValue(strconv.Itoa(int(plan.LBID.ValueInt64())) + "#" + plan.Name.ValueString())
|
||||
tflog.Info(ctx, "Update resourceLBBackend: resource update is completed", map[string]any{"ID": plan.ID.ValueString()})
|
||||
|
||||
// Map response body to schema and populate Computed attribute values
|
||||
resp.Diagnostics.Append(flattens.LBBackendResource(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
// Set state to fully populated data
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resourceLBBackend) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
|
||||
// Get current state
|
||||
var state models.ResourceLBBackendModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Delete resourceLBBackend: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Delete resourceLBBackend: got state successfully", map[string]any{"ID": state.ID.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Delete(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Delete resourceLBBackend: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Delete resourceLBBackend: set timeouts successfully", map[string]any{
|
||||
"id": state.ID.ValueString(),
|
||||
"deleteTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Delete existing lb backend
|
||||
delReq := lb.BackendDeleteRequest{
|
||||
LBID: uint64(state.LBID.ValueInt64()),
|
||||
BackendName: state.Name.ValueString(),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Delete resourceLBBackend: calling cloudbroker().LB().BackendDelete", map[string]any{
|
||||
"ID": state.ID.ValueString(),
|
||||
"req": delReq,
|
||||
})
|
||||
_, err := r.client.CloudBroker().LB().BackendDelete(ctx, delReq)
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError("Delete resourceLBBackend: Error deleting", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End delete resource lb backend", map[string]any{"id": state.ID.ValueString()})
|
||||
}
|
||||
|
||||
func (r *resourceLBBackend) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaResourceLBBackend(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx, timeouts.Opts{Create: true, Read: true, Update: true, Delete: true}),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resourceLBBackend) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_lb_backend"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the resource.
|
||||
func (r *resourceLBBackend) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure resourceLBBackend")
|
||||
r.client = client.Resource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure resourceLBBackend successfully")
|
||||
}
|
||||
|
||||
func (r *resourceLBBackend) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
|
||||
// Retrieve import ID and save to id attribute
|
||||
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
|
||||
}
|
||||
268
internal/service/cloudbroker/lb/resource_lb_backend_server.go
Normal file
268
internal/service/cloudbroker/lb/resource_lb_backend_server.go
Normal file
@@ -0,0 +1,268 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
|
||||
"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/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/schemas"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/utilities"
|
||||
)
|
||||
|
||||
var (
|
||||
_ resource.Resource = &resourceLBBackendServer{}
|
||||
_ resource.ResourceWithImportState = &resourceLBBackendServer{}
|
||||
)
|
||||
|
||||
// NewResourceLBBackendServer is a helper function to simplify the provider implementation.
|
||||
func NewResourceLBBackendServer() resource.Resource {
|
||||
return &resourceLBBackendServer{}
|
||||
}
|
||||
|
||||
// resourceLBBackendServer is the resource implementation.
|
||||
type resourceLBBackendServer struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (r *resourceLBBackendServer) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
||||
// Get plan to create lb backend server
|
||||
var plan models.ResourceLBBackendServerModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Create resourceLBBackendServer: Error receiving the plan")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Create resourceLBBackendServer: start creating", map[string]any{"name": plan.Name.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
createTimeout, diags := plan.Timeouts.Create(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Create resourceLBBackendServer: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Create resourceLBBackendServer: set timeouts successfully", map[string]any{
|
||||
"name": plan.Name.ValueString(),
|
||||
"createTimeout": createTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, createTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Check if input values are valid in the platform
|
||||
tflog.Info(ctx, "Create resourceLBBackendServer: starting input checks", map[string]any{"name": plan.Name.ValueString()})
|
||||
resp.Diagnostics.Append(resourceLBBackendServerInputChecks(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Create resourceLBBackendServer: Error input checks")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Create resourceLBBackendServer: input checks successful", map[string]any{"name": plan.Name.ValueString()})
|
||||
|
||||
// Make create request and get response for creation
|
||||
diags = utilities.CreateResourceLBBackendServer(ctx, &plan, r.client)
|
||||
if diags.HasError() {
|
||||
resp.Diagnostics.Append(diags...)
|
||||
tflog.Error(ctx, "Create resourceLBBackendServer: Error response for create resource LBBackendServer")
|
||||
return
|
||||
}
|
||||
|
||||
plan.ID = types.StringValue(strconv.Itoa(int(plan.LBID.ValueInt64())) + "#" + plan.Backend.ValueString() + "#" + plan.Name.ValueString())
|
||||
|
||||
tflog.Info(ctx, "Create resourceLBBackendServer: resource creation is completed", map[string]any{"name": plan.Name.ValueString()})
|
||||
|
||||
// Map response body to schema and populate Computed attribute values
|
||||
resp.Diagnostics.Append(flattens.LBBackendServerResource(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
// Set state to fully populated data
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resourceLBBackendServer) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
|
||||
// Get current state
|
||||
var state models.ResourceLBBackendServerModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceLBBackendServer: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read resourceLBBackendServer: got state successfully", map[string]any{"ID": state.ID.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceLBBackendServer: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read resourceLBBackendServer: set timeouts successfully", map[string]any{
|
||||
"ID": state.ID.ValueString(),
|
||||
"readTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Overwrite items with refreshed state
|
||||
resp.Diagnostics.Append(flattens.LBBackendServerResource(ctx, &state, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceLBBackendServer: Error flatten")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceLBBackendServer: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read resourceLBBackendServer")
|
||||
}
|
||||
|
||||
func (r *resourceLBBackendServer) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
|
||||
// Retrieve values from plan
|
||||
var plan models.ResourceLBBackendServerModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLBBackendServer: Error receiving the plan")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceLBBackendServer: got plan successfully", map[string]any{"ID": plan.ID.ValueString()})
|
||||
|
||||
// Retrieve values from state
|
||||
var state models.ResourceLBBackendServerModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLBBackendServer: Error receiving the state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceLBBackendServer: got state successfully", map[string]any{"ID": plan.ID.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
updateTimeout, diags := plan.Timeouts.Update(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceLBBackendServer: set timeouts successfully", map[string]any{
|
||||
"ID": state.ID.ValueString(),
|
||||
"updateTimeout": updateTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, updateTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Checking for values in the platform
|
||||
tflog.Info(ctx, "Update resourceLBBackendServer: starting input checks", map[string]any{"ID": plan.ID.ValueString()})
|
||||
resp.Diagnostics.Append(resourceLBBackendServerInputChecks(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLBBackendServer: Error input checks")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceLBBackendServer: input checks successful", map[string]any{"ID": plan.ID.ValueString()})
|
||||
|
||||
// Check and update resource
|
||||
resp.Diagnostics.Append(utilities.UpdateLBBackendServer(ctx, &plan, &state, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLBBackendServer: Error editing lb backend server")
|
||||
return
|
||||
}
|
||||
|
||||
plan.ID = types.StringValue(strconv.Itoa(int(plan.LBID.ValueInt64())) + "#" + plan.Backend.ValueString() + "#" + plan.Name.ValueString())
|
||||
tflog.Info(ctx, "Update resourceLBBackendServer: resource update is completed", map[string]any{"ID": plan.ID.ValueString()})
|
||||
|
||||
// Map response body to schema and populate Computed attribute values
|
||||
resp.Diagnostics.Append(flattens.LBBackendServerResource(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
// Set state to fully populated data
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resourceLBBackendServer) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
|
||||
// Get current state
|
||||
var state models.ResourceLBBackendServerModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Delete resourceLBBackendServer: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Delete resourceLBBackendServer: got state successfully", map[string]any{"ID": state.ID.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Delete(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Delete resourceLBBackendServer: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Delete resourceLBBackendServer: set timeouts successfully", map[string]any{
|
||||
"id": state.ID.ValueString(),
|
||||
"deleteTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Delete existing lb backend server
|
||||
delReq := lb.BackendServerDeleteRequest{
|
||||
LBID: uint64(state.LBID.ValueInt64()),
|
||||
BackendName: state.Backend.ValueString(),
|
||||
ServerName: state.Name.ValueString(),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Delete resourceLBBackendServer: calling cloudbroker().LB().BackendServerDelete", map[string]any{
|
||||
"ID": state.ID.ValueString(),
|
||||
"req": delReq,
|
||||
})
|
||||
_, err := r.client.CloudBroker().LB().BackendServerDelete(ctx, delReq)
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError("Delete resourceLBBackendServer: Error deleting", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End delete resource lb backend server", map[string]any{"id": state.ID.ValueString()})
|
||||
}
|
||||
|
||||
func (r *resourceLBBackendServer) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaResourceLBBackendServer(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx, timeouts.Opts{Create: true, Read: true, Update: true, Delete: true}),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resourceLBBackendServer) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_lb_backend_server"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the resource.
|
||||
func (r *resourceLBBackendServer) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure resourceLBBackendServer")
|
||||
r.client = client.Resource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure resourceLBBackendServer successfully")
|
||||
}
|
||||
|
||||
func (r *resourceLBBackendServer) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
|
||||
// Retrieve import ID and save to id attribute
|
||||
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
|
||||
}
|
||||
208
internal/service/cloudbroker/lb/resource_lb_frontend.go
Normal file
208
internal/service/cloudbroker/lb/resource_lb_frontend.go
Normal file
@@ -0,0 +1,208 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
|
||||
"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/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/schemas"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/utilities"
|
||||
)
|
||||
|
||||
var (
|
||||
_ resource.Resource = &resourceLBFrontend{}
|
||||
_ resource.ResourceWithImportState = &resourceLBFrontend{}
|
||||
)
|
||||
|
||||
// NewResourceLBFrontend is a helper function to simplify the provider implementation.
|
||||
func NewResourceLBFrontend() resource.Resource {
|
||||
return &resourceLBFrontend{}
|
||||
}
|
||||
|
||||
// resourceLBFrontend is the resource implementation.
|
||||
type resourceLBFrontend struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (r *resourceLBFrontend) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
||||
// Get plan to create lb frontend
|
||||
var plan models.ResourceLBFrontendModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Create resourceLBFrontend: Error receiving the plan")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Create resourceLBFrontend: start creating", map[string]any{"name": plan.Name.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
createTimeout, diags := plan.Timeouts.Create(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Create resourceLBFrontend: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Create resourceLBFrontend: set timeouts successfully", map[string]any{
|
||||
"name": plan.Name.ValueString(),
|
||||
"createTimeout": createTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, createTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Check if input values are valid in the platform
|
||||
tflog.Info(ctx, "Create resourceLBFrontend: starting input checks", map[string]any{"name": plan.Name.ValueString()})
|
||||
resp.Diagnostics.Append(resourceLBFrontendInputChecks(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Create resourceLBFrontend: Error input checks")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Create resourceLBFrontend: input checks successful", map[string]any{"name": plan.Name.ValueString()})
|
||||
|
||||
// Make create request and get response for creation
|
||||
diags = utilities.CreateResourceLBFrontend(ctx, &plan, r.client)
|
||||
if diags.HasError() {
|
||||
resp.Diagnostics.Append(diags...)
|
||||
tflog.Error(ctx, "Create resourceLBFrontend: Error response for create resource lb frontend")
|
||||
return
|
||||
}
|
||||
|
||||
plan.ID = types.StringValue(strconv.Itoa(int(plan.LBID.ValueInt64())) + "#" + plan.Name.ValueString())
|
||||
|
||||
tflog.Info(ctx, "Create resourceLBFrontend: resource creation is completed", map[string]any{"name": plan.Name.ValueString()})
|
||||
|
||||
// Map response body to schema and populate Computed attribute values
|
||||
resp.Diagnostics.Append(flattens.LBFrontendResource(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
// Set state to fully populated data
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resourceLBFrontend) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
|
||||
// Get current state
|
||||
var state models.ResourceLBFrontendModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceLBFrontend: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read resourceLBFrontend: got state successfully", map[string]any{"ID": state.ID.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceLBFrontend: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read resourceLBFrontend: set timeouts successfully", map[string]any{
|
||||
"ID": state.ID.ValueString(),
|
||||
"readTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Overwrite items with refreshed state
|
||||
resp.Diagnostics.Append(flattens.LBFrontendResource(ctx, &state, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceLBFrontend: Error flatten")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceLBFrontend: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read resourceLBFrontend")
|
||||
}
|
||||
|
||||
func (r *resourceLBFrontend) Update(ctx context.Context, _ resource.UpdateRequest, resp *resource.UpdateResponse) {
|
||||
tflog.Error(ctx, "Update resourceLBFrontend: This resource cannot be updated")
|
||||
resp.Diagnostics.AddError("This resource cannot be updated", "")
|
||||
return
|
||||
}
|
||||
|
||||
func (r *resourceLBFrontend) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
|
||||
// Get current state
|
||||
var state models.ResourceLBFrontendModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Delete resourceLBFrontend: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Delete resourceLBFrontend: got state successfully", map[string]any{"ID": state.ID.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Delete(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Delete resourceLBFrontend: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Delete resourceLBFrontend: set timeouts successfully", map[string]any{
|
||||
"id": state.ID.ValueString(),
|
||||
"deleteTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Delete existing lb frontend
|
||||
delReq := lb.FrontendDeleteRequest{
|
||||
LBID: uint64(state.LBID.ValueInt64()),
|
||||
FrontendName: state.Name.ValueString(),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Delete resourceLBFrontend: calling cloudbroker().LB().FrontendDelete", map[string]any{
|
||||
"ID": state.ID.ValueString(),
|
||||
"req": delReq,
|
||||
})
|
||||
_, err := r.client.CloudBroker().LB().FrontendDelete(ctx, delReq)
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError("Delete resourceLBFrontend: Error deleting", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End delete resource lb frontend", map[string]any{"id": state.ID.ValueString()})
|
||||
}
|
||||
|
||||
func (r *resourceLBFrontend) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaResourceLBFrontend(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx, timeouts.Opts{Create: true, Read: true, Update: true, Delete: true}),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resourceLBFrontend) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_lb_frontend"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the resource.
|
||||
func (r *resourceLBFrontend) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure resourceLBFrontend")
|
||||
r.client = client.Resource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure resourceLBFrontend successfully")
|
||||
}
|
||||
|
||||
func (r *resourceLBFrontend) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
|
||||
// Retrieve import ID and save to id attribute
|
||||
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
|
||||
}
|
||||
268
internal/service/cloudbroker/lb/resource_lb_frontend_bind.go
Normal file
268
internal/service/cloudbroker/lb/resource_lb_frontend_bind.go
Normal file
@@ -0,0 +1,268 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
|
||||
"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/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/schemas"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/utilities"
|
||||
)
|
||||
|
||||
var (
|
||||
_ resource.Resource = &resourceLBFrontendBind{}
|
||||
_ resource.ResourceWithImportState = &resourceLBFrontendBind{}
|
||||
)
|
||||
|
||||
// NewResourceLBFrontendBind is a helper function to simplify the provider implementation.
|
||||
func NewResourceLBFrontendBind() resource.Resource {
|
||||
return &resourceLBFrontendBind{}
|
||||
}
|
||||
|
||||
// resourceLBFrontendBind is the resource implementation.
|
||||
type resourceLBFrontendBind struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (r *resourceLBFrontendBind) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
||||
// Get plan to create lb frontend bind
|
||||
var plan models.ResourceLBFrontendBindModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Create resourceLBFrontendBind: Error receiving the plan")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Create resourceLBFrontendBind: start creating", map[string]any{"name": plan.Name.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
createTimeout, diags := plan.Timeouts.Create(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Create resourceLBFrontendBind: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Create resourceLBFrontendBind: set timeouts successfully", map[string]any{
|
||||
"name": plan.Name.ValueString(),
|
||||
"createTimeout": createTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, createTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Check if input values are valid in the platform
|
||||
tflog.Info(ctx, "Create resourceLBFrontendBind: starting input checks", map[string]any{"name": plan.Name.ValueString()})
|
||||
resp.Diagnostics.Append(resourceLBFrontendBindInputChecks(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Create resourceLBFrontendBind: Error input checks")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Create resourceLBFrontendBind: input checks successful", map[string]any{"name": plan.Name.ValueString()})
|
||||
|
||||
// Make create request and get response for creation
|
||||
diags = utilities.CreateResourceLBFrontendBind(ctx, &plan, r.client)
|
||||
if diags.HasError() {
|
||||
resp.Diagnostics.Append(diags...)
|
||||
tflog.Error(ctx, "Create resourceLBFrontendBind: Error response for create resource flipgroup")
|
||||
return
|
||||
}
|
||||
|
||||
plan.ID = types.StringValue(strconv.Itoa(int(plan.LBID.ValueInt64())) + "#" + plan.Frontend.ValueString() + "#" + plan.Name.ValueString())
|
||||
|
||||
tflog.Info(ctx, "Create resourceLBFrontendBind: resource creation is completed", map[string]any{"name": plan.Name.ValueString()})
|
||||
|
||||
// Map response body to schema and populate Computed attribute values
|
||||
resp.Diagnostics.Append(flattens.LBFrontendBindResource(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
// Set state to fully populated data
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resourceLBFrontendBind) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
|
||||
// Get current state
|
||||
var state models.ResourceLBFrontendBindModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceLBFrontendBind: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read resourceLBFrontendBind: got state successfully", map[string]any{"ID": state.ID.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceLBFrontendBind: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read resourceLBFrontendBind: set timeouts successfully", map[string]any{
|
||||
"ID": state.ID.ValueString(),
|
||||
"readTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Overwrite items with refreshed state
|
||||
resp.Diagnostics.Append(flattens.LBFrontendBindResource(ctx, &state, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceLBFrontendBind: Error flatten")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read resourceLBFrontendBind: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read resourceLBFrontendBind")
|
||||
}
|
||||
|
||||
func (r *resourceLBFrontendBind) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
|
||||
// Retrieve values from plan
|
||||
var plan models.ResourceLBFrontendBindModel
|
||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLBFrontendBind: Error receiving the plan")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceLBFrontendBind: got plan successfully", map[string]any{"ID": plan.ID.ValueString()})
|
||||
|
||||
// Retrieve values from state
|
||||
var state models.ResourceLBFrontendBindModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLBFrontendBind: Error receiving the state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceLBFrontendBind: got state successfully", map[string]any{"ID": plan.ID.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
updateTimeout, diags := plan.Timeouts.Update(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceLBFrontendBind: set timeouts successfully", map[string]any{
|
||||
"ID": state.ID.ValueString(),
|
||||
"updateTimeout": updateTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, updateTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Checking for values in the platform
|
||||
tflog.Info(ctx, "Update resourceLBFrontendBind: starting input checks", map[string]any{"ID": plan.ID.ValueString()})
|
||||
resp.Diagnostics.Append(resourceLBFrontendBindInputChecks(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLBFrontendBind: Error input checks")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Update resourceLBFrontendBind: input checks successful", map[string]any{"ID": plan.ID.ValueString()})
|
||||
|
||||
// Check and update resource
|
||||
resp.Diagnostics.Append(utilities.UpdateLBFrontendBind(ctx, &plan, &state, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Update resourceLBFrontendBind: Error editing lb backend")
|
||||
return
|
||||
}
|
||||
|
||||
plan.ID = types.StringValue(strconv.Itoa(int(plan.LBID.ValueInt64())) + "#" + plan.Frontend.ValueString() + "#" + plan.Name.ValueString())
|
||||
tflog.Info(ctx, "Update resourceLBFrontendBind: resource update is completed", map[string]any{"ID": plan.ID.ValueString()})
|
||||
|
||||
// Map response body to schema and populate Computed attribute values
|
||||
resp.Diagnostics.Append(flattens.LBFrontendBindResource(ctx, &plan, r.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
// Set state to fully populated data
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resourceLBFrontendBind) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
|
||||
// Get current state
|
||||
var state models.ResourceLBFrontendBindModel
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Delete resourceLBFrontendBind: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Delete resourceLBFrontendBind: got state successfully", map[string]any{"ID": state.ID.ValueString()})
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Delete(ctx, constants.Timeout300s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Delete resourceLBFrontendBind: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Delete resourceLBFrontendBind: set timeouts successfully", map[string]any{
|
||||
"id": state.ID.ValueString(),
|
||||
"deleteTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Delete existing flipgroup
|
||||
delReq := lb.FrontendBindDeleteRequest{
|
||||
LBID: uint64(state.LBID.ValueInt64()),
|
||||
FrontendName: state.Frontend.ValueString(),
|
||||
BindingName: state.Name.ValueString(),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Delete resourceLBFrontendBind: calling cloudbroker().LB().FrontendBindDelete", map[string]any{
|
||||
"ID": state.ID.ValueString(),
|
||||
"req": delReq,
|
||||
})
|
||||
_, err := r.client.CloudBroker().LB().FrontendBindDelete(ctx, delReq)
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError("Delete resourceLBFrontendBind: Error deleting", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End delete resource lb frontend bind", map[string]any{"id": state.ID.ValueString()})
|
||||
}
|
||||
|
||||
func (r *resourceLBFrontendBind) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaResourceLBFrontendBind(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx, timeouts.Opts{Create: true, Read: true, Update: true, Delete: true}),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resourceLBFrontendBind) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_cb_lb_frontend_bind"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the resource.
|
||||
func (r *resourceLBFrontendBind) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure resourceLBFrontendBind")
|
||||
r.client = client.Resource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure resourceLBFrontendBind successfully")
|
||||
}
|
||||
|
||||
func (r *resourceLBFrontendBind) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
|
||||
// Retrieve import ID and save to id attribute
|
||||
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
|
||||
}
|
||||
270
internal/service/cloudbroker/lb/schemas/schema_data_source_lb.go
Normal file
270
internal/service/cloudbroker/lb/schemas/schema_data_source_lb.go
Normal file
@@ -0,0 +1,270 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceLB() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
"lb_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
},
|
||||
"ha_mode": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"acl": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"backend_haip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"backends": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"algorithm": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"server_default_settings": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"downinter": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"fall": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"inter": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"maxconn": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"maxqueue": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"rise": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"slowstart": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"weight": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"servers": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"address": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"check": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"port": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"server_settings": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"downinter": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"fall": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"inter": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"maxconn": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"maxqueue": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"rise": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"slowstart": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"weight": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"ckey": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"desc": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"dp_api_user": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"dp_api_password": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"extnet_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"frontend_haip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"frontends": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"backend": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"bindings": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"address": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"port": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"gid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"manager_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"manager_type": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"image_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"meta": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"milestones": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"part_k8s": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"primary_node": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"backend_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"compute_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"frontend_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"mgmt_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"network_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"rg_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"secondary_node": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"backend_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"compute_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"frontend_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"mgmt_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"network_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"tech_status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"user_managed": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"vins_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,341 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceLBList() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
// optional attributes
|
||||
"by_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find by id",
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find by name",
|
||||
},
|
||||
"account_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find by account ID",
|
||||
},
|
||||
"rg_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find by RG ID",
|
||||
},
|
||||
"tech_status": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find by tech status",
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find by status",
|
||||
},
|
||||
"front_ip": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find by frontend Ip",
|
||||
},
|
||||
"back_ip": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find by backend Ip",
|
||||
},
|
||||
"include_deleted": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
Description: "included deleted LBs. If using field 'status', then include_deleted will be ignored",
|
||||
},
|
||||
"sort_by": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "sort by one of supported fields, format +|-(field)",
|
||||
},
|
||||
"page": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "page number",
|
||||
},
|
||||
"size": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "size number",
|
||||
},
|
||||
|
||||
// computed attributes
|
||||
"id": schema.StringAttribute{
|
||||
Optional: true,
|
||||
},
|
||||
"items": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"ha_mode": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"acl": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"backend_haip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"backends": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"algorithm": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"server_default_settings": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"inter": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"downinter": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"rise": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"fall": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"slowstart": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"maxconn": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"maxqueue": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"weight": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"servers": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"address": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"check": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"port": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"server_settings": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"inter": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"downinter": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"rise": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"fall": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"slowstart": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"maxconn": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"maxqueue": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"weight": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"created_by": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"created_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_by": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"desc": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"dp_api_user": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"dp_api_password": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"extnet_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"frontend_haip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"frontends": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"backend": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"bindings": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"address": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"port": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"gid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"lb_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"manager_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"manager_type": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"milestones": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"part_k8s": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"primary_node": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"backend_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"compute_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"frontend_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"mgmt_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"network_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"rg_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"rg_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"secondary_node": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"backend_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"compute_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"frontend_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"mgmt_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"network_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"tech_status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"updated_by": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"updated_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"user_managed": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"vins_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,333 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceLBListDeleted() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
// optional attributes
|
||||
"by_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find by id",
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find by name",
|
||||
},
|
||||
"account_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find by account ID",
|
||||
},
|
||||
"rg_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find by RG ID",
|
||||
},
|
||||
"tech_status": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find by tech status",
|
||||
},
|
||||
"front_ip": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find by frontend Ip",
|
||||
},
|
||||
"back_ip": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find by backend Ip",
|
||||
},
|
||||
"sort_by": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "sort by one of supported fields, format +|-(field)",
|
||||
},
|
||||
"page": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "page number",
|
||||
},
|
||||
"size": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "size number",
|
||||
},
|
||||
|
||||
// computed attributes
|
||||
"id": schema.StringAttribute{
|
||||
Optional: true,
|
||||
},
|
||||
"items": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"ha_mode": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"acl": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"backend_haip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"backends": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"algorithm": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"server_default_settings": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"inter": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"downinter": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"rise": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"fall": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"slowstart": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"maxconn": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"maxqueue": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"weight": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"servers": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"address": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"check": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"port": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"server_settings": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"inter": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"downinter": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"rise": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"fall": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"slowstart": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"maxconn": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"maxqueue": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"weight": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"created_by": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"created_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_by": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"desc": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"dp_api_user": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"dp_api_password": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"extnet_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"frontend_haip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"frontends": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"backend": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"bindings": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"address": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"port": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"gid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"lb_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"manager_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"manager_type": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"milestones": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"part_k8s": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"primary_node": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"backend_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"compute_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"frontend_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"mgmt_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"network_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"rg_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"rg_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"secondary_node": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"backend_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"compute_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"frontend_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"mgmt_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"network_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"tech_status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"updated_by": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"updated_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"user_managed": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"vins_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
316
internal/service/cloudbroker/lb/schemas/schema_resource_lb.go
Normal file
316
internal/service/cloudbroker/lb/schemas/schema_resource_lb.go
Normal file
@@ -0,0 +1,316 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func MakeSchemaResourceLB() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
// required attributes
|
||||
"rg_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Required: true,
|
||||
},
|
||||
"extnet_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
},
|
||||
"vins_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
},
|
||||
"start": schema.BoolAttribute{
|
||||
Required: true,
|
||||
},
|
||||
|
||||
// optional attributes
|
||||
"ha_mode": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"desc": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"enable": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
},
|
||||
"restart": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
},
|
||||
"config_reset": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
},
|
||||
"permanently": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
},
|
||||
"restore": schema.BoolAttribute{
|
||||
Optional: true,
|
||||
},
|
||||
"safe": schema.BoolAttribute{
|
||||
// Default: true
|
||||
Optional: true,
|
||||
},
|
||||
"sysctl_params": schema.ListNestedAttribute{
|
||||
Optional: true,
|
||||
Description: "Custom sysctl values for Load Balancer instance. Applied on boot.",
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"key": schema.StringAttribute{
|
||||
Required: true,
|
||||
},
|
||||
"value": schema.StringAttribute{
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"acl": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"backend_haip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"backends": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"algorithm": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"server_default_settings": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"downinter": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"fall": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"inter": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"maxconn": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"maxqueue": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"rise": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"slowstart": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"weight": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"servers": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"address": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"check": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"port": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"server_settings": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"downinter": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"fall": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"inter": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"maxconn": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"maxqueue": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"rise": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"slowstart": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"weight": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"ckey": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"meta": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"dp_api_user": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"dp_api_password": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"frontend_haip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"frontends": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"backend": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"bindings": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"address": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"port": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"gid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
PlanModifiers: []planmodifier.String{
|
||||
stringplanmodifier.UseStateForUnknown(),
|
||||
},
|
||||
},
|
||||
"lb_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"manager_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"manager_type": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"image_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"milestones": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"part_k8s": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"primary_node": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"backend_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"compute_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"frontend_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"mgmt_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"network_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"secondary_node": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"backend_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"compute_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"frontend_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"mgmt_ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"network_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"tech_status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"user_managed": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
"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/schema/validator"
|
||||
)
|
||||
|
||||
func MakeSchemaResourceLBBackend() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
"lb_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Required: true,
|
||||
},
|
||||
"algorithm": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Validators: []validator.String{
|
||||
stringvalidator.OneOf("roundrobin", "static-rr", "leastconn"),
|
||||
},
|
||||
},
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
PlanModifiers: []planmodifier.String{
|
||||
stringplanmodifier.UseStateForUnknown(),
|
||||
},
|
||||
},
|
||||
"downinter": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"fall": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"inter": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"maxconn": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"maxqueue": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"rise": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"slowstart": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"weight": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"servers": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"address": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"check": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"port": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"server_settings": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"downinter": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"fall": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"inter": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"maxconn": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"maxqueue": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"rise": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"slowstart": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"weight": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
"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/schema/validator"
|
||||
)
|
||||
|
||||
func MakeSchemaResourceLBBackendServer() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
"lb_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
Description: "ID of the LB instance to backendCreate",
|
||||
},
|
||||
"backend_name": schema.StringAttribute{
|
||||
Required: true,
|
||||
Description: "Must be unique among all backends of this LB - name of the new backend to create",
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Required: true,
|
||||
Description: "Must be unique among all servers defined for this backend - name of the server definition to add.",
|
||||
},
|
||||
"address": schema.StringAttribute{
|
||||
Required: true,
|
||||
Description: "IP address of the server.",
|
||||
},
|
||||
"port": schema.Int64Attribute{
|
||||
Required: true,
|
||||
Description: "Port number on the server",
|
||||
},
|
||||
"check": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Optional: true,
|
||||
Validators: []validator.String{
|
||||
stringvalidator.OneOf("disabled", "enabled"),
|
||||
},
|
||||
Description: "set to disabled if this server should be used regardless of its state.",
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"downinter": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"fall": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"inter": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"maxconn": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"maxqueue": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"rise": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"slowstart": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"weight": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
PlanModifiers: []planmodifier.String{
|
||||
stringplanmodifier.UseStateForUnknown(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func MakeSchemaResourceLBFrontend() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
"lb_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
},
|
||||
"backend_name": schema.StringAttribute{
|
||||
Required: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Required: true,
|
||||
},
|
||||
"bindings": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"address": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"port": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
PlanModifiers: []planmodifier.String{
|
||||
stringplanmodifier.UseStateForUnknown(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func MakeSchemaResourceLBFrontendBind() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
"lb_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
},
|
||||
"frontend_name": schema.StringAttribute{
|
||||
Required: true,
|
||||
},
|
||||
"address": schema.StringAttribute{
|
||||
Required: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Required: true,
|
||||
},
|
||||
"port": schema.Int64Attribute{
|
||||
Required: true,
|
||||
},
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
PlanModifiers: []planmodifier.String{
|
||||
stringplanmodifier.UseStateForUnknown(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package utilities
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
|
||||
)
|
||||
|
||||
func LBDataSourceCheckPresence(ctx context.Context, lbId uint64, c *decort.DecortClient) (*lb.RecordLB, diag.Diagnostics) {
|
||||
tflog.Info(ctx, fmt.Sprintf("LBDataSourceCheckPresence: Get info about lb with ID - %v", lbId))
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
recordLB, err := c.CloudBroker().LB().Get(ctx, lb.GetRequest{LBID: lbId})
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about lb with ID %v", lbId), err.Error())
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "LBDataSourceCheckPresence: response from CloudBroker().LB().Get", map[string]any{"lb_id": lbId, "response": recordLB})
|
||||
|
||||
return recordLB, nil
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package utilities
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
)
|
||||
|
||||
func LBListDataSourceCheckPresence(ctx context.Context, plan *models.DataSourceLBList, c *decort.DecortClient) (*lb.ListLB, error) {
|
||||
|
||||
listLBReq := lb.ListRequest{}
|
||||
|
||||
if !plan.ByID.IsNull() {
|
||||
listLBReq.ByID = uint64(plan.ByID.ValueInt64())
|
||||
}
|
||||
if !plan.Name.IsNull() {
|
||||
listLBReq.Name = plan.Name.ValueString()
|
||||
}
|
||||
if !plan.AccountID.IsNull() {
|
||||
listLBReq.AccountID = uint64(plan.AccountID.ValueInt64())
|
||||
}
|
||||
if !plan.RgID.IsNull() {
|
||||
listLBReq.RGID = uint64(plan.RgID.ValueInt64())
|
||||
}
|
||||
if !plan.TechStatus.IsNull() {
|
||||
listLBReq.TechStatus = plan.TechStatus.ValueString()
|
||||
}
|
||||
if !plan.Status.IsNull() {
|
||||
listLBReq.Status = plan.Status.ValueString()
|
||||
}
|
||||
if !plan.FrontIP.IsNull() {
|
||||
listLBReq.FrontIP = plan.FrontIP.ValueString()
|
||||
}
|
||||
if !plan.BackIP.IsNull() {
|
||||
listLBReq.BackIP = plan.BackIP.ValueString()
|
||||
}
|
||||
if plan.Status.IsNull() && !plan.IncludeDeleted.IsNull() {
|
||||
listLBReq.IncludeDeleted = plan.IncludeDeleted.ValueBool()
|
||||
}
|
||||
if !plan.SortBy.IsNull() {
|
||||
listLBReq.SortBy = plan.SortBy.ValueString()
|
||||
}
|
||||
if !plan.Page.IsNull() {
|
||||
listLBReq.Page = uint64(plan.Page.ValueInt64())
|
||||
}
|
||||
if !plan.Size.IsNull() {
|
||||
listLBReq.Size = uint64(plan.Size.ValueInt64())
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "LBListDataSourceCheckPresence: before call CloudBroker().LB().List", map[string]any{"response": listLBReq})
|
||||
lbList, err := c.CloudBroker().LB().List(ctx, listLBReq)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get info about data source list lb with error: %w", err)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "LBListDataSourceCheckPresence: response from CloudBroker().LB().List", map[string]any{"response": lbList})
|
||||
|
||||
return lbList, err
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package utilities
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
)
|
||||
|
||||
func LBListDeletedDataSourceCheckPresence(ctx context.Context, plan *models.DataSourceLBListDeleted, c *decort.DecortClient) (*lb.ListLB, error) {
|
||||
|
||||
req := lb.ListDeletedRequest{}
|
||||
|
||||
if !plan.ByID.IsNull() {
|
||||
req.ByID = uint64(plan.ByID.ValueInt64())
|
||||
}
|
||||
if !plan.Name.IsNull() {
|
||||
req.Name = plan.Name.ValueString()
|
||||
}
|
||||
if !plan.AccountID.IsNull() {
|
||||
req.AccountID = uint64(plan.AccountID.ValueInt64())
|
||||
}
|
||||
if !plan.RgID.IsNull() {
|
||||
req.RGID = uint64(plan.RgID.ValueInt64())
|
||||
}
|
||||
if !plan.TechStatus.IsNull() {
|
||||
req.TechStatus = plan.TechStatus.ValueString()
|
||||
}
|
||||
if !plan.FrontIP.IsNull() {
|
||||
req.FrontIP = plan.FrontIP.ValueString()
|
||||
}
|
||||
if !plan.BackIP.IsNull() {
|
||||
req.BackIP = plan.BackIP.ValueString()
|
||||
}
|
||||
if !plan.SortBy.IsNull() {
|
||||
req.SortBy = plan.SortBy.ValueString()
|
||||
}
|
||||
if !plan.Page.IsNull() {
|
||||
req.Page = uint64(plan.Page.ValueInt64())
|
||||
}
|
||||
if !plan.Size.IsNull() {
|
||||
req.Size = uint64(plan.Size.ValueInt64())
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "LBListDeletedDataSourceCheckPresence: before call CloudBroker().LB().ListDeleted", map[string]any{"response": req})
|
||||
lbDelList, err := c.CloudBroker().LB().ListDeleted(ctx, req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get info about data source list lb with error: %w", err)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "LBListDeletedDataSourceCheckPresence: response from CloudBroker().LB().ListDeleted", map[string]any{"response": lbDelList})
|
||||
|
||||
return lbDelList, err
|
||||
}
|
||||
352
internal/service/cloudbroker/lb/utilities/utility_resource_lb.go
Normal file
352
internal/service/cloudbroker/lb/utilities/utility_resource_lb.go
Normal file
@@ -0,0 +1,352 @@
|
||||
package utilities
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/status"
|
||||
)
|
||||
|
||||
func CreateResourceLB(ctx context.Context, plan *models.ResourceLBModel, c *decort.DecortClient) (uint64, diag.Diagnostics) {
|
||||
tflog.Info(ctx, fmt.Sprintf("Start create ResourceLB: name %s", plan.Name.ValueString()))
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
createReq := lb.CreateRequest{
|
||||
Name: plan.Name.ValueString(),
|
||||
RGID: uint64(plan.RGID.ValueInt64()),
|
||||
ExtNetID: uint64(plan.ExtNetID.ValueInt64()),
|
||||
VINSID: uint64(plan.VINSID.ValueInt64()),
|
||||
Start: plan.Start.ValueBool(),
|
||||
}
|
||||
|
||||
if plan.HAMode.IsUnknown() { // HAMode is optional & computed
|
||||
createReq.HighlyAvailable = false
|
||||
} else {
|
||||
createReq.HighlyAvailable = plan.HAMode.ValueBool()
|
||||
}
|
||||
|
||||
if !plan.Description.IsNull() { // Description is optional & computed
|
||||
createReq.Description = plan.Description.ValueString()
|
||||
}
|
||||
|
||||
if !plan.SysctlParams.IsNull() {
|
||||
result := make([]map[string]interface{}, 0, len(plan.SysctlParams.Elements()))
|
||||
for _, val := range plan.SysctlParams.Elements() {
|
||||
objVal := val.(types.Object)
|
||||
valMap := objVal.Attributes()
|
||||
mapKey := valMap["key"].(types.String).ValueString()
|
||||
mapVal := valMap["value"].(types.String).ValueString()
|
||||
tempMap := make(map[string]interface{})
|
||||
tempMap[mapKey] = mapVal
|
||||
result = append(result, tempMap)
|
||||
}
|
||||
createReq.SysctlParams = result
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "CreateResourceLB: before call CloudBroker().LB().Create", map[string]any{"req": createReq})
|
||||
|
||||
lbId, err := c.CloudBroker().LB().Create(ctx, createReq)
|
||||
if err != nil {
|
||||
diags.AddError("CreateResourceLB: unable to create LB", err.Error())
|
||||
return 0, diags
|
||||
}
|
||||
tflog.Info(ctx, "CreateResourceLB: LB created", map[string]any{"lb_id": lbId, "name": plan.Name.ValueString()})
|
||||
|
||||
return lbId, nil
|
||||
}
|
||||
|
||||
func LBResourceCheckPresence(ctx context.Context, plan *models.ResourceLBModel, c *decort.DecortClient) (*lb.RecordLB, diag.Diagnostics) {
|
||||
tflog.Info(ctx, fmt.Sprintf("LBCheckPresence: Get info about LB with ID - %v", plan.ID.ValueString()))
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
lbId, err := strconv.ParseUint(plan.ID.ValueString(), 10, 64)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot parsed ID lb from state", err.Error())
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
lbItem, err := c.CloudBroker().LB().Get(ctx, lb.GetRequest{LBID: lbId})
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about lb with ID %v", lbId), err.Error())
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
return lbItem, nil
|
||||
}
|
||||
|
||||
func LBEnableDisable(ctx context.Context, plan *models.ResourceLBModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "EnableDisable lb with ID", map[string]any{"lb_id": plan.ID.ValueString()})
|
||||
diags := diag.Diagnostics{}
|
||||
lbId, err := strconv.ParseUint(plan.ID.ValueString(), 10, 64)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot parsed ID lb from state", err.Error())
|
||||
return diags
|
||||
}
|
||||
if plan.Enable.IsNull() || plan.Enable.ValueBool() {
|
||||
tflog.Info(ctx, "Enable lb with ID", map[string]any{"lb_id": plan.ID.ValueString()})
|
||||
_, err := c.CloudBroker().LB().Enable(ctx, lb.EnableRequest{LBID: lbId})
|
||||
if err != nil {
|
||||
diags.AddError("EnableDisableLB: error to enable LB", err.Error())
|
||||
return diags
|
||||
}
|
||||
} else {
|
||||
tflog.Info(ctx, "Disable lb with ID", map[string]any{"lb_id": plan.ID.ValueString()})
|
||||
_, err := c.CloudBroker().LB().Disable(ctx, lb.DisableRequest{LBID: lbId})
|
||||
if err != nil {
|
||||
diags.AddError("EnableDisableLB: error to disable LB", err.Error())
|
||||
return diags
|
||||
}
|
||||
}
|
||||
return diags
|
||||
}
|
||||
|
||||
func LBReadStatus(ctx context.Context, plan *models.ResourceLBModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Read status lb with ID", map[string]any{"lb_id": plan.ID.ValueString()})
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
lbId, err := strconv.ParseUint(plan.ID.ValueString(), 10, 64)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot parsed ID lb from state", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
lbItem, err := c.CloudBroker().LB().Get(ctx, lb.GetRequest{LBID: lbId})
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about lb with ID %v", lbItem), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
switch lbItem.Status {
|
||||
case status.Modeled:
|
||||
diags.AddError("Error:", fmt.Sprintf("The lb is in status: %s, please, contact support for more information", lbItem.Status))
|
||||
return diags
|
||||
case status.Deleted:
|
||||
if plan.Restore.ValueBool() || plan.Restore.IsNull() {
|
||||
diags = LBRestore(ctx, plan, c)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, "Error restore lb", map[string]any{"lb_id": plan.ID.ValueString()})
|
||||
return diags
|
||||
}
|
||||
} else {
|
||||
diags.AddError("LB in status Deleted:", "please clean state, or restore lb")
|
||||
return diags
|
||||
}
|
||||
if plan.Enable.ValueBool() || plan.Enable.IsNull() {
|
||||
diags = LBEnableDisable(ctx, plan, c)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, "Error enable/disable lb", map[string]any{"lb_id": plan.ID.ValueString()})
|
||||
return diags
|
||||
}
|
||||
if plan.Start.ValueBool() || plan.Start.IsNull() {
|
||||
diags = LBStartStop(ctx, plan, c)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, "Error start/stop lb", map[string]any{"lb_id": plan.ID.ValueString()})
|
||||
return diags
|
||||
}
|
||||
}
|
||||
}
|
||||
case status.Destroying:
|
||||
diags.AddError("Error:", fmt.Sprintf("The lb is in progress with status: %s", lbItem.Status))
|
||||
return diags
|
||||
case status.Destroyed:
|
||||
diags.AddError("Error:", "The resource cannot be updated because it has been destroyed")
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Read status lb successfully", map[string]any{"lb_id": plan.ID.ValueString()})
|
||||
return diags
|
||||
}
|
||||
|
||||
func LBRestore(ctx context.Context, plan *models.ResourceLBModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Restore lb with ID", map[string]any{"lb_id": plan.ID.ValueString()})
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
lbId, err := strconv.ParseUint(plan.ID.ValueString(), 10, 64)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot parsed ID lb from state", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
_, err = c.CloudBroker().LB().Restore(ctx, lb.RestoreRequest{LBID: lbId})
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot restore lb with ID - %s", plan.ID.ValueString()), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Restore lb successfully", map[string]any{"lb_id": plan.ID.ValueString()})
|
||||
return diags
|
||||
}
|
||||
|
||||
func LBStartStop(ctx context.Context, plan *models.ResourceLBModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "StartStop lb with ID", map[string]any{"lb_id": plan.ID.ValueString()})
|
||||
diags := diag.Diagnostics{}
|
||||
lbId, err := strconv.ParseUint(plan.ID.ValueString(), 10, 64)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot parsed ID lb from state", err.Error())
|
||||
return diags
|
||||
}
|
||||
if plan.Enable.IsNull() || plan.Enable.ValueBool() {
|
||||
if plan.Start.ValueBool() || plan.Start.IsNull() {
|
||||
tflog.Info(ctx, "Start lb with ID", map[string]any{"lb_id": plan.ID.ValueString()})
|
||||
_, err := c.CloudBroker().LB().Start(ctx, lb.StartRequest{LBID: lbId})
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot start lb with ID - %s", plan.ID.ValueString()), err.Error())
|
||||
return diags
|
||||
}
|
||||
} else {
|
||||
tflog.Info(ctx, "Stop lb with ID", map[string]any{"lb_id": plan.ID.ValueString()})
|
||||
_, err := c.CloudBroker().LB().Stop(ctx, lb.StopRequest{LBID: lbId})
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot stop lb with ID - %s", plan.ID.ValueString()), err.Error())
|
||||
return diags
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return diags
|
||||
}
|
||||
|
||||
func LBUpdateHaMode(ctx context.Context, state *models.ResourceLBModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Update ha mode from lb with ID", map[string]any{"id": state.ID.ValueString()})
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
lbId, err := strconv.ParseUint(state.ID.ValueString(), 10, 64)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot parsed ID lb from state", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
_, err = c.CloudBroker().LB().HighlyAvailable(ctx, lb.HighlyAvailableRequest{LBID: lbId})
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot update ha mode from lb with ID - %s", state.ID.ValueString()), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Update ha mode from LB with ID successfully", map[string]any{"id": state.ID.ValueString()})
|
||||
|
||||
return diags
|
||||
}
|
||||
|
||||
func LBUpdateSysctlParams(ctx context.Context, plan *models.ResourceLBModel, state *models.ResourceLBModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Update sysctl parameters from LB with ID", map[string]any{"id": state.ID.ValueString()})
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
lbId, err := strconv.ParseUint(state.ID.ValueString(), 10, 64)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot parsed ID lb from state", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
sysctlParams := make([]map[string]interface{}, 0, len(plan.SysctlParams.Elements()))
|
||||
for _, val := range plan.SysctlParams.Elements() {
|
||||
objVal := val.(types.Object)
|
||||
valMap := objVal.Attributes()
|
||||
mapKey := valMap["key"].(types.String).ValueString()
|
||||
mapVal := valMap["value"].(types.String).ValueString()
|
||||
tempMap := make(map[string]interface{})
|
||||
tempMap[mapKey] = mapVal
|
||||
sysctlParams = append(sysctlParams, tempMap)
|
||||
}
|
||||
|
||||
req := lb.UpdateSysctParamsRequest{
|
||||
LBID: lbId,
|
||||
SysctlParams: sysctlParams,
|
||||
}
|
||||
|
||||
_, err = c.CloudBroker().LB().UpdateSysctlParams(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot update sysctl parameters from LB with ID - %s", state.ID.ValueString()), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Update sysctl parameters from LB with ID successfully", map[string]any{"id": state.ID.ValueString()})
|
||||
return diags
|
||||
}
|
||||
|
||||
func LBUpdateDescription(ctx context.Context, plan *models.ResourceLBModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Update description from lb with ID", map[string]any{"id": plan.ID.ValueString()})
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
lbId, err := strconv.ParseUint(plan.ID.ValueString(), 10, 64)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot parsed ID lb from state", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
_, err = c.CloudBroker().LB().Update(ctx, lb.UpdateRequest{LBID: lbId, Description: plan.Description.ValueString()})
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot update description from lb with ID - %s", plan.ID.ValueString()), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Update description from LB with ID successfully", map[string]any{"id": plan.ID.ValueString()})
|
||||
|
||||
return diags
|
||||
}
|
||||
|
||||
func LBRestart(ctx context.Context, plan *models.ResourceLBModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Restart lb with ID", map[string]any{"id": plan.ID.ValueString()})
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
lbId, err := strconv.ParseUint(plan.ID.ValueString(), 10, 64)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot parsed ID lb from state", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
req := lb.RestartRequest{
|
||||
LBID: lbId,
|
||||
Safe: false,
|
||||
}
|
||||
|
||||
if plan.Safe.ValueBool() || plan.Safe.IsNull() {
|
||||
req.Safe = true
|
||||
}
|
||||
|
||||
_, err = c.CloudBroker().LB().Restart(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot restart lb with ID - %s", plan.ID.ValueString()), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Restart LB with ID successfully", map[string]any{"id": plan.ID.ValueString()})
|
||||
|
||||
return diags
|
||||
}
|
||||
|
||||
func LBConfigReset(ctx context.Context, plan *models.ResourceLBModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Reset config from lb with ID", map[string]any{"id": plan.ID.ValueString()})
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
lbId, err := strconv.ParseUint(plan.ID.ValueString(), 10, 64)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot parsed ID lb from state", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
_, err = c.CloudBroker().LB().ConfigReset(ctx, lb.ConfigResetRequest{LBID: lbId})
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot reset config from lb with ID - %s", plan.ID.ValueString()), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Reset config from LB with ID successfully", map[string]any{"id": plan.ID.ValueString()})
|
||||
|
||||
return diags
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
package utilities
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
)
|
||||
|
||||
func CreateResourceLBBackend(ctx context.Context, plan *models.ResourceLBBackendModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, fmt.Sprintf("Start create ResourceLBBackend: backend_name %s", plan.Name.ValueString()))
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
createReq := lb.BackendCreateRequest{
|
||||
LBID: uint64(plan.LBID.ValueInt64()),
|
||||
BackendName: plan.Name.ValueString(),
|
||||
}
|
||||
|
||||
if !plan.Algorithm.IsUnknown() { // Algorithm is optional & computed
|
||||
createReq.Algorithm = plan.Algorithm.ValueString()
|
||||
}
|
||||
|
||||
if !plan.Inter.IsUnknown() { // Inter is optional & computed
|
||||
createReq.Inter = uint64(plan.Inter.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.DownInter.IsUnknown() { // DownInter is optional & computed
|
||||
createReq.DownInter = uint64(plan.DownInter.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.Rise.IsUnknown() { // Rise is optional & computed
|
||||
createReq.Rise = uint64(plan.Rise.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.Fall.IsUnknown() { // Fall is optional & computed
|
||||
createReq.Fall = uint64(plan.Fall.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.SlowStart.IsUnknown() { // SlowStart is optional & computed
|
||||
createReq.SlowStart = uint64(plan.SlowStart.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.MaxConn.IsUnknown() { // MaxConn is optional & computed
|
||||
createReq.MaxConn = uint64(plan.MaxConn.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.MaxQueue.IsUnknown() { // MaxQueue is optional & computed
|
||||
createReq.MaxQueue = uint64(plan.MaxQueue.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.Weight.IsUnknown() { // Weight is optional & computed
|
||||
createReq.Weight = uint64(plan.Weight.ValueInt64())
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "CreateResourceLBBackend: before call CloudBroker().LB().BackendCreate", map[string]any{"req": createReq})
|
||||
|
||||
resp, err := c.CloudBroker().LB().BackendCreate(ctx, createReq)
|
||||
if err != nil {
|
||||
diags.AddError("CreateResourceLBBackend: unable to create LB Backend", err.Error())
|
||||
return diags
|
||||
}
|
||||
tflog.Info(ctx, "CreateResourceLBBackend: LB Backend created", map[string]any{"responce": resp, "name": plan.Name.ValueString()})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func LBBackendResourceCheckPresence(ctx context.Context, plan *models.ResourceLBBackendModel, c *decort.DecortClient) (*lb.ItemBackend, diag.Diagnostics) {
|
||||
tflog.Info(ctx, fmt.Sprintf("LBBackendCheckPresence: Get info about LB Backend with ID - %v", plan.ID.ValueString()))
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
req := lb.GetRequest{}
|
||||
bName := plan.Name.ValueString()
|
||||
|
||||
if !plan.LBID.IsNull() {
|
||||
req.LBID = uint64(plan.LBID.ValueInt64())
|
||||
} else {
|
||||
parameters := strings.Split(plan.ID.ValueString(), "#")
|
||||
if len(parameters) != 2 {
|
||||
diags.AddError("LBBackendResourceCheckPresence: broken state id",
|
||||
fmt.Sprintf("state id expected: <lb_id>#<backend_name>, got: %v", plan.ID.ValueString()))
|
||||
return nil, diags
|
||||
}
|
||||
lbId, _ := strconv.ParseUint(parameters[0], 10, 64)
|
||||
req.LBID = lbId
|
||||
bName = parameters[1]
|
||||
}
|
||||
|
||||
lb, err := c.CloudBroker().LB().Get(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about lb with ID %v", req.LBID), err.Error())
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
backends := lb.Backends
|
||||
for _, b := range backends {
|
||||
if b.Name == bName {
|
||||
return &b, diags
|
||||
}
|
||||
}
|
||||
|
||||
diags.AddError(fmt.Sprintf("can not find backend with name: %s for lb: %d", bName, lb.ID), "")
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
func UpdateLBBackend(ctx context.Context, plan, state *models.ResourceLBBackendModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, fmt.Sprintf("UpdateLBBackend: Start edit lb backend with ID - %v", state.ID.ValueString()))
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
req := lb.BackendUpdateRequest{
|
||||
LBID: uint64(plan.LBID.ValueInt64()),
|
||||
BackendName: plan.Name.ValueString(),
|
||||
}
|
||||
|
||||
if !plan.Algorithm.IsUnknown() {
|
||||
req.Algorithm = plan.Algorithm.ValueString()
|
||||
}
|
||||
|
||||
if !plan.Inter.IsUnknown() {
|
||||
req.Inter = uint64(plan.Inter.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.DownInter.IsUnknown() {
|
||||
req.DownInter = uint64(plan.DownInter.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.Rise.IsUnknown() {
|
||||
req.Rise = uint64(plan.Rise.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.Fall.IsUnknown() {
|
||||
req.Fall = uint64(plan.Fall.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.SlowStart.IsUnknown() {
|
||||
req.SlowStart = uint64(plan.SlowStart.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.MaxConn.IsUnknown() {
|
||||
req.MaxConn = uint64(plan.MaxConn.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.MaxQueue.IsUnknown() {
|
||||
req.MaxQueue = uint64(plan.MaxQueue.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.Weight.IsUnknown() {
|
||||
req.Weight = uint64(plan.Weight.ValueInt64())
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().LB().BackendUpdate(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddError("UpdateLBBackend: cannot edit lb backend", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, fmt.Sprintf("UpdateLBBackend: Finish edit lb backend with name - %v", req.BackendName))
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package utilities
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
)
|
||||
|
||||
func CreateResourceLBBackendServer(ctx context.Context, plan *models.ResourceLBBackendServerModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, fmt.Sprintf("Start create ResourceLBBackendServer: name %s", plan.Name.ValueString()))
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
createReq := lb.BackendServerAddRequest{
|
||||
LBID: uint64(plan.LBID.ValueInt64()),
|
||||
BackendName: plan.Backend.ValueString(),
|
||||
ServerName: plan.Name.ValueString(),
|
||||
Address: plan.Address.ValueString(),
|
||||
Port: uint64(plan.Port.ValueInt64()),
|
||||
}
|
||||
|
||||
if !plan.Check.IsUnknown() { // Check is optional & computed
|
||||
createReq.Check = plan.Check.ValueString()
|
||||
}
|
||||
|
||||
if !plan.Inter.IsUnknown() { // Inter is optional & computed
|
||||
createReq.Inter = uint64(plan.Inter.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.DownInter.IsUnknown() { // DownInter is optional & computed
|
||||
createReq.DownInter = uint64(plan.DownInter.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.Rise.IsUnknown() { // Rise is optional & computed
|
||||
createReq.Rise = uint64(plan.Rise.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.Fall.IsUnknown() { // Fall is optional & computed
|
||||
createReq.Fall = uint64(plan.Fall.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.SlowStart.IsUnknown() { // SlowStart is optional & computed
|
||||
createReq.SlowStart = uint64(plan.SlowStart.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.MaxConn.IsUnknown() { // MaxConn is optional & computed
|
||||
createReq.MaxConn = uint64(plan.MaxConn.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.MaxQueue.IsUnknown() { // MaxQueue is optional & computed
|
||||
createReq.MaxQueue = uint64(plan.MaxQueue.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.Weight.IsUnknown() { // Weight is optional & computed
|
||||
createReq.Weight = uint64(plan.Weight.ValueInt64())
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "ResourceLBBackendServer: before call CloudBroker().LB().BackendServerAdd", map[string]any{"req": createReq})
|
||||
|
||||
resp, err := c.CloudBroker().LB().BackendServerAdd(ctx, createReq)
|
||||
if err != nil {
|
||||
diags.AddError("ResourceLBBackendServer: unable to create LB Backend Server", err.Error())
|
||||
return diags
|
||||
}
|
||||
tflog.Info(ctx, "ResourceLBBackendServer: LB Backend Server created", map[string]any{"responce": resp, "name": plan.Name.ValueString()})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func LBBackendServerResourceCheckPresence(ctx context.Context, plan *models.ResourceLBBackendServerModel, c *decort.DecortClient) (*lb.ItemServer, diag.Diagnostics) {
|
||||
tflog.Info(ctx, fmt.Sprintf("LBBackendServerCheckPresence: Get info about LB Backend Server with ID - %v", plan.ID.ValueString()))
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
req := lb.GetRequest{}
|
||||
bName := plan.Backend.ValueString()
|
||||
sName := plan.Name.ValueString()
|
||||
|
||||
if !plan.LBID.IsNull() {
|
||||
req.LBID = uint64(plan.LBID.ValueInt64())
|
||||
} else {
|
||||
parameters := strings.Split(plan.ID.ValueString(), "#")
|
||||
if len(parameters) != 3 {
|
||||
diags.AddError("LBBackendServerResourceCheckPresence: broken state id",
|
||||
fmt.Sprintf("state id expected: <lb_id>#<backend_name>#<server_name>, got: %v", plan.ID.ValueString()))
|
||||
return nil, diags
|
||||
}
|
||||
lbId, _ := strconv.ParseUint(parameters[0], 10, 64)
|
||||
req.LBID = lbId
|
||||
bName = parameters[1]
|
||||
sName = parameters[2]
|
||||
}
|
||||
|
||||
lbItem, err := c.CloudBroker().LB().Get(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about lb with ID %v", req.LBID), err.Error())
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
backend := &lb.ItemBackend{}
|
||||
backends := lbItem.Backends
|
||||
for i, b := range backends {
|
||||
if b.Name == bName {
|
||||
backend = &backends[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
if backend.Name == "" {
|
||||
diags.AddError(fmt.Sprintf("can not find backend with name: %s for lb: %d", bName, lbItem.ID), "")
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
for _, s := range backend.Servers {
|
||||
if s.Name == sName {
|
||||
return &s, nil
|
||||
}
|
||||
}
|
||||
|
||||
diags.AddError(fmt.Sprintf("can not find server with name: %s for backend: %s for lb: %d", sName, bName, lbItem.ID), "")
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
func UpdateLBBackendServer(ctx context.Context, plan, state *models.ResourceLBBackendServerModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, fmt.Sprintf("UpdateLBBackendServer: Start edit lb backend server with ID - %v", state.ID.ValueString()))
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
req := lb.BackendServerUpdateRequest{
|
||||
LBID: uint64(plan.LBID.ValueInt64()),
|
||||
BackendName: plan.Backend.ValueString(),
|
||||
ServerName: plan.Name.ValueString(),
|
||||
Address: plan.Address.ValueString(),
|
||||
Port: uint64(plan.Port.ValueInt64()),
|
||||
}
|
||||
|
||||
if !plan.Check.IsUnknown() {
|
||||
req.Check = plan.Check.ValueString()
|
||||
}
|
||||
|
||||
if !plan.Inter.IsUnknown() {
|
||||
req.Inter = uint64(plan.Inter.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.DownInter.IsUnknown() {
|
||||
req.DownInter = uint64(plan.DownInter.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.Rise.IsUnknown() {
|
||||
req.Rise = uint64(plan.Rise.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.Fall.IsUnknown() {
|
||||
req.Fall = uint64(plan.Fall.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.SlowStart.IsUnknown() {
|
||||
req.SlowStart = uint64(plan.SlowStart.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.MaxConn.IsUnknown() {
|
||||
req.MaxConn = uint64(plan.MaxConn.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.MaxQueue.IsUnknown() {
|
||||
req.MaxQueue = uint64(plan.MaxQueue.ValueInt64())
|
||||
}
|
||||
|
||||
if !plan.Weight.IsUnknown() {
|
||||
req.Weight = uint64(plan.Weight.ValueInt64())
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().LB().BackendServerUpdate(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddError("UpdateLBBackendServer: cannot edit lb backend server", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, fmt.Sprintf("UpdateLBBackendServer: Finish edit lb backend server with name - %v", req.BackendName))
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package utilities
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
)
|
||||
|
||||
func CreateResourceLBFrontend(ctx context.Context, plan *models.ResourceLBFrontendModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, fmt.Sprintf("Start create ResourceLBFrontend: frontend_name %s", plan.Name.ValueString()))
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
createReq := lb.FrontendCreateRequest{
|
||||
LBID: uint64(plan.LBID.ValueInt64()),
|
||||
BackendName: plan.Backend.ValueString(),
|
||||
FrontendName: plan.Name.ValueString(),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "ResourceLBFrontend: before call CloudBroker().LB().FrontendCreate", map[string]any{"req": createReq})
|
||||
|
||||
resp, err := c.CloudBroker().LB().FrontendCreate(ctx, createReq)
|
||||
if err != nil {
|
||||
diags.AddError("ResourceLBFrontend: unable to create LB Frontend", err.Error())
|
||||
return diags
|
||||
}
|
||||
tflog.Info(ctx, "ResourceLBFrontend: LB Frontend created", map[string]any{"responce": resp, "name": plan.Name.ValueString()})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func LBFrontendResourceCheckPresence(ctx context.Context, plan *models.ResourceLBFrontendModel, c *decort.DecortClient) (*lb.ItemFrontend, diag.Diagnostics) {
|
||||
tflog.Info(ctx, fmt.Sprintf("LBFrontendCheckPresence: Get info about LB Frontend with ID - %v", plan.ID.ValueString()))
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
req := lb.GetRequest{}
|
||||
fName := plan.Name.ValueString()
|
||||
|
||||
if !plan.LBID.IsNull() {
|
||||
req.LBID = uint64(plan.LBID.ValueInt64())
|
||||
} else {
|
||||
parameters := strings.Split(plan.ID.ValueString(), "#")
|
||||
if len(parameters) != 2 {
|
||||
diags.AddError("LBFrontendResourceCheckPresence: broken state id",
|
||||
fmt.Sprintf("state id expected: <lb_id>#<frontend_name>, got: %v", plan.ID.ValueString()))
|
||||
return nil, diags
|
||||
}
|
||||
lbId, _ := strconv.ParseUint(parameters[0], 10, 64)
|
||||
req.LBID = lbId
|
||||
fName = parameters[1]
|
||||
}
|
||||
|
||||
lb, err := c.CloudBroker().LB().Get(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about lb with ID %v", req.LBID), err.Error())
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
frontends := lb.Frontends
|
||||
for _, f := range frontends {
|
||||
if f.Name == fName {
|
||||
return &f, diags
|
||||
}
|
||||
}
|
||||
|
||||
diags.AddError(fmt.Sprintf("can not find frontend with name: %s for lb: %d", fName, lb.ID), "")
|
||||
return nil, diags
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package utilities
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/lb/models"
|
||||
)
|
||||
|
||||
func CreateResourceLBFrontendBind(ctx context.Context, plan *models.ResourceLBFrontendBindModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, fmt.Sprintf("Start create ResourceLBFrontendBind: frontend_name %s", plan.Name.ValueString()))
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
createReq := lb.FrontendBindRequest{
|
||||
LBID: uint64(plan.LBID.ValueInt64()),
|
||||
FrontendName: plan.Frontend.ValueString(),
|
||||
BindingName: plan.Name.ValueString(),
|
||||
BindingAddress: plan.Address.ValueString(),
|
||||
BindingPort: uint64(plan.Port.ValueInt64()),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "ResourceLBFrontendBind: before call CloudBroker().LB().FrontendBind", map[string]any{"req": createReq})
|
||||
|
||||
resp, err := c.CloudBroker().LB().FrontendBind(ctx, createReq)
|
||||
if err != nil {
|
||||
diags.AddError("ResourceLBFrontendBind: unable to create LB Frontend Bind", err.Error())
|
||||
return diags
|
||||
}
|
||||
tflog.Info(ctx, "ResourceLBFrontendBind: LB Frontend Bind created", map[string]any{"responce": resp, "name": plan.Name.ValueString()})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func LBFrontendBindResourceCheckPresence(ctx context.Context, plan *models.ResourceLBFrontendBindModel, c *decort.DecortClient) (*lb.ItemBinding, diag.Diagnostics) {
|
||||
tflog.Info(ctx, fmt.Sprintf("LBFrontendBindCheckPresence: Get info about LB Frontend Bind with ID - %v", plan.ID.ValueString()))
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
req := lb.GetRequest{}
|
||||
fName := plan.Frontend.ValueString()
|
||||
bName := plan.Name.ValueString()
|
||||
|
||||
if !plan.LBID.IsNull() {
|
||||
req.LBID = uint64(plan.LBID.ValueInt64())
|
||||
} else {
|
||||
parameters := strings.Split(plan.ID.ValueString(), "#")
|
||||
if len(parameters) != 3 {
|
||||
diags.AddError("LBFrontendResourceCheckPresence: broken state id",
|
||||
fmt.Sprintf("state id expected: <lb_id>#<frontend_name>#<backend_name>, got: %v", plan.ID.ValueString()))
|
||||
return nil, diags
|
||||
}
|
||||
lbId, _ := strconv.ParseUint(parameters[0], 10, 64)
|
||||
req.LBID = lbId
|
||||
fName = parameters[1]
|
||||
bName = parameters[2]
|
||||
}
|
||||
|
||||
lbItem, err := c.CloudBroker().LB().Get(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about lb with ID %v", req.LBID), err.Error())
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
frontend := &lb.ItemFrontend{}
|
||||
frontends := lbItem.Frontends
|
||||
for i, f := range frontends {
|
||||
if f.Name == fName {
|
||||
frontend = &frontends[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
if frontend.Name == "" {
|
||||
diags.AddError(fmt.Sprintf("can not find frontend with name: %s for lb: %d", fName, lbItem.ID), "")
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
for _, b := range frontend.Bindings {
|
||||
if b.Name == bName {
|
||||
return &b, nil
|
||||
}
|
||||
}
|
||||
|
||||
diags.AddError(fmt.Sprintf("can not find bind with name: %s for frontend: %s for lb: %d", bName, fName, lbItem.ID), "")
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
func UpdateLBFrontendBind(ctx context.Context, plan, state *models.ResourceLBFrontendBindModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, fmt.Sprintf("UpdateLBFrontendBind: Start edit lb frontend bind with ID - %v", state.ID.ValueString()))
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
req := lb.FrontendBindUpdateRequest{
|
||||
LBID: uint64(plan.LBID.ValueInt64()),
|
||||
FrontendName: plan.Frontend.ValueString(),
|
||||
BindingName: plan.Name.ValueString(),
|
||||
BindingAddress: plan.Address.ValueString(),
|
||||
BindingPort: uint64(plan.Port.ValueInt64()),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().LB().FrontendBindUpdate(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddError("UpdateLBFrontendBind: cannot edit lb frontend bind", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, fmt.Sprintf("UpdateLBFrontendBind: Finish edit lb frontend bind with name - %v", req.BindingName))
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user