1.0.0
This commit is contained in:
91
internal/service/cloudapi/extnet/data_source_extnet.go
Normal file
91
internal/service/cloudapi/extnet/data_source_extnet.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package extnet
|
||||
|
||||
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/cloudapi/extnet/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/extnet/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/extnet/schemas"
|
||||
)
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ datasource.DataSource = &dataSourceExtNet{}
|
||||
)
|
||||
|
||||
func NewDataSourceExtNet() datasource.DataSource {
|
||||
return &dataSourceExtNet{}
|
||||
}
|
||||
|
||||
// dataSourceExtNet is the data source implementation.
|
||||
type dataSourceExtNet struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceExtNet) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.DataSourceExtNetModel
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceExtNet: Error get state")
|
||||
return
|
||||
}
|
||||
extnetId := uint64(state.NetID.ValueInt64())
|
||||
tflog.Info(ctx, "Read dataSourceExtNet: got state successfully", map[string]any{"extnet_id": extnetId})
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout30s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceExtNet: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceExtNet: set timeouts successfully", map[string]any{
|
||||
"extnet_id": extnetId,
|
||||
"readTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Map response body to schema
|
||||
resp.Diagnostics.Append(flattens.ExtNetDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceExtNet: Error flatten data source extnet")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceExtNet: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceExtNet", map[string]any{"extnet_id": extnetId})
|
||||
}
|
||||
|
||||
func (d *dataSourceExtNet) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceExtNet(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceExtNet) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_extnet"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceExtNet) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceExtNet")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceExtNet successfully")
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package extnet
|
||||
|
||||
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/cloudapi/extnet/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/extnet/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/extnet/schemas"
|
||||
)
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ datasource.DataSource = &dataSourceExtNetComputesList{}
|
||||
)
|
||||
|
||||
func NewDataSourceExtNetComputesList() datasource.DataSource {
|
||||
return &dataSourceExtNetComputesList{}
|
||||
}
|
||||
|
||||
// dataSourceExtNetComputesList is the data source implementation.
|
||||
type dataSourceExtNetComputesList struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceExtNetComputesList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.DataSourceExtNetComputesListModel
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceExtNetComputesList: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceExtNetComputesList: got state successfully")
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout30s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceExtNetComputesList: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceExtNetComputesList: set timeouts successfully", map[string]any{
|
||||
"account_id": state.AccountID.ValueInt64(),
|
||||
"readTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Map response body to schema
|
||||
resp.Diagnostics.Append(flattens.ExtNetComputesListDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceExtNetComputesList: Error flatten data source extnet")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceExtNetComputesList: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceExtNetComputesList")
|
||||
}
|
||||
|
||||
func (d *dataSourceExtNetComputesList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceExtNetComputesList(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceExtNetComputesList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_extnet_computes_list"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceExtNetComputesList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceExtNetComputesList")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceExtNetComputesList successfully")
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package extnet
|
||||
|
||||
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/cloudapi/extnet/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/extnet/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/extnet/schemas"
|
||||
)
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ datasource.DataSource = &dataSourceExtNetDefault{}
|
||||
)
|
||||
|
||||
func NewDataSourceExtNetDefault() datasource.DataSource {
|
||||
return &dataSourceExtNetDefault{}
|
||||
}
|
||||
|
||||
// dataSourceExtNetDefault is the data source implementation.
|
||||
type dataSourceExtNetDefault struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceExtNetDefault) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.DataSourceExtNetDefaultModel
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceExtNetDefault: Error get state")
|
||||
return
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Read dataSourceExtNetDefault: got state successfully")
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout30s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceExtNetDefault: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceExtNetDefault: set timeouts successfully")
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Map response body to schema
|
||||
resp.Diagnostics.Append(flattens.ExtNetDefaultDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceExtNetDefault: Error flatten data source extnet")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceExtNetDefault: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceExtNetDefault")
|
||||
}
|
||||
|
||||
func (d *dataSourceExtNetDefault) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceExtNetDefault(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceExtNetDefault) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_extnet_default"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceExtNetDefault) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceExtNetDefault")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceExtNetDefault successfully")
|
||||
}
|
||||
88
internal/service/cloudapi/extnet/data_source_extnet_list.go
Normal file
88
internal/service/cloudapi/extnet/data_source_extnet_list.go
Normal file
@@ -0,0 +1,88 @@
|
||||
package extnet
|
||||
|
||||
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/cloudapi/extnet/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/extnet/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/extnet/schemas"
|
||||
)
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ datasource.DataSource = &dataSourceExtNetList{}
|
||||
)
|
||||
|
||||
func NewDataSourceExtNetList() datasource.DataSource {
|
||||
return &dataSourceExtNetList{}
|
||||
}
|
||||
|
||||
// dataSourceExtNet is the data source implementation.
|
||||
type dataSourceExtNetList struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceExtNetList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.DataSourceExtNetListModel
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceExtNetList: Error get state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceExtNetList: got state successfully")
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout30s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceExtNetList: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceExtNetList: 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.ExtNetListDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceExtNetList: Error flatten data source extnet")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceExtNetList: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceExtNetList")
|
||||
}
|
||||
|
||||
func (d *dataSourceExtNetList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceExtNetList(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceExtNetList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_extnet_list"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceExtNetList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceExtNetList")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceExtNetList successfully")
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"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/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/extnet/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/extnet/utilities"
|
||||
)
|
||||
|
||||
// ExtNetDataSource flattens data source for extnet.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func ExtNetDataSource(ctx context.Context, state *models.DataSourceExtNetModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.ExtNetDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
netId := uint64(state.NetID.ValueInt64())
|
||||
|
||||
recordExtNet, err := utilities.ExtNetCheckPresence(ctx, netId, c)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about extnet with ID %v", netId), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.ExtNetDataSource: before flatten", map[string]any{"net_id": netId, "recordExtNet": recordExtNet})
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceExtNetModel{
|
||||
NetID: state.NetID,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
CKey: types.StringValue(recordExtNet.CKey),
|
||||
Meta: flattens.Meta(ctx, recordExtNet.Meta),
|
||||
Default: types.BoolValue(recordExtNet.Default),
|
||||
DefaultQOS: &models.QOSModel{
|
||||
EBurst: types.Int64Value(int64(recordExtNet.DefaultQOS.EBurst)),
|
||||
ERate: types.Int64Value(int64(recordExtNet.DefaultQOS.ERate)),
|
||||
GUID: types.StringValue(recordExtNet.DefaultQOS.GUID),
|
||||
InBurst: types.Int64Value(int64(recordExtNet.DefaultQOS.InBurst)),
|
||||
InRate: types.Int64Value(int64(recordExtNet.DefaultQOS.InRate)),
|
||||
},
|
||||
Description: types.StringValue(recordExtNet.Description),
|
||||
FreeIPs: types.Int64Value(int64(recordExtNet.FreeIPs)),
|
||||
Gateway: types.StringValue(recordExtNet.Gateway),
|
||||
GID: types.Int64Value(int64(recordExtNet.GID)),
|
||||
GUID: types.Int64Value(int64(recordExtNet.GUID)),
|
||||
IPCIDR: types.StringValue(recordExtNet.IPCIDR),
|
||||
Milestones: types.Int64Value(int64(recordExtNet.Milestones)),
|
||||
NetName: types.StringValue(recordExtNet.Name),
|
||||
Network: types.StringValue(recordExtNet.Network),
|
||||
NetworkID: types.Int64Value(int64(recordExtNet.NetworkID)),
|
||||
PreReservationsNum: types.Int64Value(int64(recordExtNet.PreReservationsNum)),
|
||||
Prefix: types.Int64Value(int64(recordExtNet.Prefix)),
|
||||
PriVNFDevID: types.Int64Value(int64(recordExtNet.PriVNFDevID)),
|
||||
Status: types.StringValue(recordExtNet.Status),
|
||||
VLANID: types.Int64Value(int64(recordExtNet.VLANID)),
|
||||
VNFs: &models.VNFsModel{
|
||||
DHCP: types.Int64Value(int64(recordExtNet.VNFs.DHCP)),
|
||||
},
|
||||
}
|
||||
|
||||
reservations := make([]models.ItemReservationModel, 0, len(recordExtNet.Reservations))
|
||||
for _, item := range recordExtNet.Reservations {
|
||||
r := models.ItemReservationModel{
|
||||
ClientType: types.StringValue(item.ClientType),
|
||||
Description: types.StringValue(item.Description),
|
||||
DomainName: types.StringValue(item.DomainName),
|
||||
Hostname: types.StringValue(item.Hostname),
|
||||
IP: types.StringValue(item.IP),
|
||||
MAC: types.StringValue(item.MAC),
|
||||
Type: types.StringValue(item.Type),
|
||||
VMID: types.Int64Value(int64(item.VMID)),
|
||||
}
|
||||
reservations = append(reservations, r)
|
||||
}
|
||||
state.Reservations = reservations
|
||||
|
||||
excluded := make([]models.ExcludedModel, 0, len(recordExtNet.Excluded))
|
||||
for _, item := range recordExtNet.Excluded {
|
||||
e := models.ExcludedModel{
|
||||
ClientType: types.StringValue(item.ClientType),
|
||||
DomainName: types.StringValue(item.DomainName),
|
||||
HostName: types.StringValue(item.HostName),
|
||||
IP: types.StringValue(item.IP),
|
||||
MAC: types.StringValue(item.MAC),
|
||||
Type: types.StringValue(item.Type),
|
||||
VMID: types.Int64Value(int64(item.VMID)),
|
||||
}
|
||||
excluded = append(excluded, e)
|
||||
}
|
||||
state.Excluded = excluded
|
||||
|
||||
var diagsItem diag.Diagnostics
|
||||
state.CheckIPs, diagsItem = types.ListValueFrom(ctx, types.StringType, recordExtNet.CheckIPs)
|
||||
if diagsItem.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.ExtNetDataSource: cannot flatten recordExtNet.CheckIPs to state.CheckIPs", diags))
|
||||
}
|
||||
state.DNS, diagsItem = types.ListValueFrom(ctx, types.StringType, recordExtNet.DNS)
|
||||
if diagsItem.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.ExtNetDataSource: cannot flatten recordExtNet.DNS to state.DNS", diags))
|
||||
}
|
||||
state.SharedWith, diagsItem = types.ListValueFrom(ctx, types.Int64Type, recordExtNet.SharedWith)
|
||||
if diagsItem.HasError() {
|
||||
tflog.Error(ctx, fmt.Sprint("flattens.ExtNetDataSource: cannot flatten recordExtNet.SharedWith to state.SharedWith", diags))
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.ExtNetDataSource: after flatten", map[string]any{"net_id": state.Id.ValueString()})
|
||||
|
||||
tflog.Info(ctx, "End flattens.ExtNetDataSource", map[string]any{"net_id": state.Id.ValueString()})
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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/cloudapi/extnet/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/extnet/utilities"
|
||||
)
|
||||
|
||||
// ExtNetComputesListDataSource flattens data source for extnet computes list.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func ExtNetComputesListDataSource(ctx context.Context, state *models.DataSourceExtNetComputesListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.ExtNetComputesListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
compsList, err := utilities.ExtNetComputesListCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about extnet list", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.ExtNetComputesListDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceExtNetComputesListModel{
|
||||
AccountID: state.AccountID,
|
||||
RGID: state.RGID,
|
||||
ComputeID: state.ComputeID,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
SortBy: state.SortBy,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
EntryCount: types.Int64Value(int64(compsList.EntryCount)),
|
||||
}
|
||||
|
||||
items := make([]models.ItemComputeModel, 0, len(compsList.Data))
|
||||
for _, item := range compsList.Data {
|
||||
i := models.ItemComputeModel{
|
||||
AccountID: types.Int64Value(int64(item.AccountID)),
|
||||
AccountName: types.StringValue(item.AccountName),
|
||||
ID: types.Int64Value(int64(item.ID)),
|
||||
Name: types.StringValue(item.Name),
|
||||
RGID: types.Int64Value(int64(item.RGID)),
|
||||
RGName: types.StringValue(item.RGName),
|
||||
}
|
||||
|
||||
extnets := make([]models.ItemComputeExtNetModel, 0, len(item.ExtNets))
|
||||
for _, en := range item.ExtNets {
|
||||
e := models.ItemComputeExtNetModel{
|
||||
NetId: types.Int64Value(int64(en.ID)),
|
||||
IpAddr: types.StringValue(en.IPAddr),
|
||||
IPCIDR: types.StringValue(en.IPCIDR),
|
||||
Name: types.StringValue(en.Name),
|
||||
}
|
||||
extnets = append(extnets, e)
|
||||
}
|
||||
i.ExtNets = extnets
|
||||
items = append(items, i)
|
||||
}
|
||||
|
||||
state.Items = items
|
||||
|
||||
tflog.Info(ctx, "flattens.ExtNetComputesListDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.ExtNetComputesListDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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/cloudapi/extnet/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/extnet/utilities"
|
||||
)
|
||||
|
||||
// ExtNetDefaultDataSource flattens data source for extnet default.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func ExtNetDefaultDataSource(ctx context.Context, state *models.DataSourceExtNetDefaultModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.ExtNetDefaultDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
netId, err := utilities.ExtNetDefaultCheckPresence(ctx, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about default extnet ID %v", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.ExtNetDefaultDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceExtNetDefaultModel{
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
NetId: types.Int64Value(int64(netId)),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.ExtNetDefaultDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.ExtNetDefaultDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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/cloudapi/extnet/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/extnet/utilities"
|
||||
)
|
||||
|
||||
// ExtNetListDataSource flattens data source for extnet list.
|
||||
// Return error in case data source is not found on the platform.
|
||||
// Flatten errors are added to tflog.
|
||||
func ExtNetListDataSource(ctx context.Context, state *models.DataSourceExtNetListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.ExtNetListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
extNetList, err := utilities.ExtNetListCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about extnet list", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.ExtNetListDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceExtNetListModel{
|
||||
AccountID: state.AccountID,
|
||||
ByID: state.ByID,
|
||||
Name: state.Name,
|
||||
Network: state.Network,
|
||||
VLANID: state.VLANID,
|
||||
VNFDevID: state.VNFDevID,
|
||||
Status: state.Status,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
SortBy: state.SortBy,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
EntryCount: types.Int64Value(int64(extNetList.EntryCount)),
|
||||
}
|
||||
|
||||
items := make([]models.ItemExtNetModel, 0, len(extNetList.Data))
|
||||
for _, item := range extNetList.Data {
|
||||
i := models.ItemExtNetModel{
|
||||
ID: types.Int64Value(int64(item.ID)),
|
||||
IPCIDR: types.StringValue(item.IPCIDR),
|
||||
Name: types.StringValue(item.Name),
|
||||
Status: types.StringValue(item.Status),
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
state.Items = items
|
||||
|
||||
tflog.Info(ctx, "flattens.ExtNetListDataSource: after flatten")
|
||||
|
||||
tflog.Info(ctx, "End flattens.ExtNetListDataSource")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
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 DataSourceExtNetModel struct {
|
||||
// request fields
|
||||
NetID types.Int64 `tfsdk:"net_id"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
|
||||
// response fields
|
||||
Id types.String `tfsdk:"id"`
|
||||
CKey types.String `tfsdk:"ckey"`
|
||||
Meta types.List `tfsdk:"meta"`
|
||||
CheckIPs types.List `tfsdk:"check_ips"`
|
||||
Default types.Bool `tfsdk:"default"`
|
||||
DefaultQOS *QOSModel `tfsdk:"default_qos"`
|
||||
Description types.String `tfsdk:"desc"`
|
||||
DNS types.List `tfsdk:"dns"`
|
||||
Excluded []ExcludedModel `tfsdk:"excluded"`
|
||||
FreeIPs types.Int64 `tfsdk:"free_ips"`
|
||||
Gateway types.String `tfsdk:"gateway"`
|
||||
GID types.Int64 `tfsdk:"gid"`
|
||||
GUID types.Int64 `tfsdk:"guid"`
|
||||
IPCIDR types.String `tfsdk:"ipcidr"`
|
||||
Milestones types.Int64 `tfsdk:"milestones"`
|
||||
NetName types.String `tfsdk:"net_name"`
|
||||
Network types.String `tfsdk:"network"`
|
||||
NetworkID types.Int64 `tfsdk:"network_id"`
|
||||
PreReservationsNum types.Int64 `tfsdk:"pre_reservations_num"`
|
||||
Prefix types.Int64 `tfsdk:"prefix"`
|
||||
PriVNFDevID types.Int64 `tfsdk:"pri_vnf_dev_id"`
|
||||
Reservations []ItemReservationModel `tfsdk:"reservations"`
|
||||
SharedWith types.List `tfsdk:"shared_with"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
VLANID types.Int64 `tfsdk:"vlan_id"`
|
||||
VNFs *VNFsModel `tfsdk:"vnfs"`
|
||||
}
|
||||
|
||||
type VNFsModel struct {
|
||||
DHCP types.Int64 `tfsdk:"dhcp"`
|
||||
}
|
||||
|
||||
type ExcludedModel struct {
|
||||
ClientType types.String `tfsdk:"client_type"`
|
||||
DomainName types.String `tfsdk:"domainname"`
|
||||
HostName types.String `tfsdk:"hostname"`
|
||||
IP types.String `tfsdk:"ip"`
|
||||
MAC types.String `tfsdk:"mac"`
|
||||
Type types.String `tfsdk:"type"`
|
||||
VMID types.Int64 `tfsdk:"vm_id"`
|
||||
}
|
||||
|
||||
type QOSModel struct {
|
||||
EBurst types.Int64 `tfsdk:"e_burst"`
|
||||
ERate types.Int64 `tfsdk:"e_rate"`
|
||||
GUID types.String `tfsdk:"guid"`
|
||||
InBurst types.Int64 `tfsdk:"in_burst"`
|
||||
InRate types.Int64 `tfsdk:"in_rate"`
|
||||
}
|
||||
|
||||
type ItemReservationModel struct {
|
||||
ClientType types.String `tfsdk:"client_type"`
|
||||
Description types.String `tfsdk:"desc"`
|
||||
DomainName types.String `tfsdk:"domainname"`
|
||||
Hostname types.String `tfsdk:"hostname"`
|
||||
IP types.String `tfsdk:"ip"`
|
||||
MAC types.String `tfsdk:"mac"`
|
||||
Type types.String `tfsdk:"type"`
|
||||
VMID types.Int64 `tfsdk:"vm_id"`
|
||||
}
|
||||
|
||||
var ItemExcluded = map[string]attr.Type{
|
||||
"client_type": types.StringType,
|
||||
"mac": types.StringType,
|
||||
"ip": types.StringType,
|
||||
"type": types.StringType,
|
||||
"vm_id": types.Int64Type,
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type DataSourceExtNetComputesListModel struct {
|
||||
// required fields
|
||||
AccountID types.Int64 `tfsdk:"account_id"`
|
||||
|
||||
// optional fields
|
||||
RGID types.Int64 `tfsdk:"rg_id"`
|
||||
ComputeID types.Int64 `tfsdk:"compute_id"`
|
||||
Page types.Int64 `tfsdk:"page"`
|
||||
Size types.Int64 `tfsdk:"size"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
SortBy types.String `tfsdk:"sort_by"`
|
||||
|
||||
// response fields
|
||||
Id types.String `tfsdk:"id"`
|
||||
Items []ItemComputeModel `tfsdk:"items"`
|
||||
EntryCount types.Int64 `tfsdk:"entry_count"`
|
||||
}
|
||||
|
||||
type ItemComputeModel struct {
|
||||
AccountID types.Int64 `tfsdk:"account_id"`
|
||||
AccountName types.String `tfsdk:"account_name"`
|
||||
ExtNets []ItemComputeExtNetModel `tfsdk:"extnets"`
|
||||
ID types.Int64 `tfsdk:"id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
RGID types.Int64 `tfsdk:"rg_id"`
|
||||
RGName types.String `tfsdk:"rg_name"`
|
||||
}
|
||||
|
||||
type ItemComputeExtNetModel struct {
|
||||
NetId types.Int64 `tfsdk:"net_id"`
|
||||
IpAddr types.String `tfsdk:"ipaddr"`
|
||||
IPCIDR types.String `tfsdk:"ipcidr"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type DataSourceExtNetDefaultModel struct {
|
||||
// request fields
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
|
||||
// response fields
|
||||
Id types.String `tfsdk:"id"`
|
||||
NetId types.Int64 `tfsdk:"net_id"`
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type DataSourceExtNetListModel struct {
|
||||
// optional fields
|
||||
AccountID types.Int64 `tfsdk:"account_id"`
|
||||
ByID types.Int64 `tfsdk:"by_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Network types.String `tfsdk:"network"`
|
||||
VLANID types.Int64 `tfsdk:"vlan_id"`
|
||||
VNFDevID types.Int64 `tfsdk:"vnfdev_id"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
Page types.Int64 `tfsdk:"page"`
|
||||
Size types.Int64 `tfsdk:"size"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
SortBy types.String `tfsdk:"sort_by"`
|
||||
|
||||
// response fields
|
||||
Id types.String `tfsdk:"id"`
|
||||
Items []ItemExtNetModel `tfsdk:"items"`
|
||||
EntryCount types.Int64 `tfsdk:"entry_count"`
|
||||
}
|
||||
|
||||
type ItemExtNetModel struct {
|
||||
ID types.Int64 `tfsdk:"net_id"`
|
||||
IPCIDR types.String `tfsdk:"ipcidr"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceExtNet() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
// required attributes
|
||||
"net_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
Description: "ext net id",
|
||||
},
|
||||
|
||||
// computed attributes
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ckey": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"meta": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"check_ips": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"default": schema.BoolAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"default_qos": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"e_rate": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"e_burst": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"in_burst": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"in_rate": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"desc": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"dns": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.StringType,
|
||||
},
|
||||
"excluded": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"client_type": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"mac": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"type": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"vm_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"free_ips": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"gateway": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"gid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ipcidr": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"milestones": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"net_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"network": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"network_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"pre_reservations_num": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"prefix": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"pri_vnf_dev_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"reservations": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"client_type": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"domainname": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"hostname": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"desc": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ip": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"mac": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"type": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"vm_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"shared_with": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.Int64Type,
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"vlan_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"vnfs": schema.SingleNestedAttribute{
|
||||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"dhcp": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceExtNetComputesList() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
// required attributes
|
||||
"account_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
Description: "find by account id",
|
||||
},
|
||||
|
||||
// optional attributes
|
||||
"rg_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find by rg id",
|
||||
},
|
||||
"compute_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find by compute id",
|
||||
},
|
||||
"page": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "page number",
|
||||
},
|
||||
"size": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "page size",
|
||||
},
|
||||
"sort_by": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "sort by one of supported fields, format +|-(field)",
|
||||
},
|
||||
|
||||
// computed attributes
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"items": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"account_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"account_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"extnets": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"net_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ipaddr": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ipcidr": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"rg_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"rg_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceExtNetDefault() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
// computed attributes
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"net_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceExtNetList() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
// optional attributes
|
||||
"account_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find by account id",
|
||||
},
|
||||
"by_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find by id",
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find by name",
|
||||
},
|
||||
"network": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find by network ip address",
|
||||
},
|
||||
"vlan_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find by vlan id",
|
||||
},
|
||||
"vnfdev_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "find by vnfdevices id",
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "find by status",
|
||||
},
|
||||
"page": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "page number",
|
||||
},
|
||||
"size": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Description: "page size",
|
||||
},
|
||||
"sort_by": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Description: "sort by one of supported fields, format +|-(field)",
|
||||
},
|
||||
|
||||
// computed attributes
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"items": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"net_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ipcidr": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
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/cloudapi/extnet"
|
||||
)
|
||||
|
||||
func ExtNetCheckPresence(ctx context.Context, netId uint64, c *decort.DecortClient) (*extnet.RecordExtNet, error) {
|
||||
tflog.Info(ctx, fmt.Sprintf("Get info about extnet with ID - %v", netId))
|
||||
|
||||
recordExtNet, err := c.CloudAPI().ExtNet().Get(ctx, extnet.GetRequest{NetID: netId})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get info about extnet with error: %w", err)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "ExtNetCheckPresence: response from CloudAPI().ExtNet().Get", map[string]any{"net_id": netId, "response": recordExtNet})
|
||||
|
||||
return recordExtNet, err
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package utilities
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/extnet/models"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/extnet"
|
||||
)
|
||||
|
||||
func ExtNetComputesListCheckPresence(ctx context.Context, plan *models.DataSourceExtNetComputesListModel, c *decort.DecortClient) (*extnet.ListExtNetComputes, error) {
|
||||
tflog.Info(ctx, "ExtNetComputesListCheckPresence: Get info about extnet list")
|
||||
|
||||
listCompReq := extnet.ListComputesRequest{
|
||||
AccountID: uint64(plan.AccountID.ValueInt64()),
|
||||
}
|
||||
|
||||
if !plan.RGID.IsNull() {
|
||||
listCompReq.RGID = uint64(plan.RGID.ValueInt64())
|
||||
}
|
||||
if !plan.ComputeID.IsNull() {
|
||||
listCompReq.ComputeID = uint64(plan.ComputeID.ValueInt64())
|
||||
}
|
||||
if !plan.Page.IsNull() {
|
||||
listCompReq.Page = uint64(plan.Page.ValueInt64())
|
||||
}
|
||||
if !plan.Size.IsNull() {
|
||||
listCompReq.Size = uint64(plan.Size.ValueInt64())
|
||||
}
|
||||
if !plan.SortBy.IsNull() {
|
||||
listCompReq.SortBy = plan.SortBy.ValueString()
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "ExtNetComputesListCheckPresence: before call CloudAPI().ExtNet().ListComputes", map[string]any{"req": listCompReq})
|
||||
compList, err := c.CloudAPI().ExtNet().ListComputes(ctx, listCompReq)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get info about extnet list computes with error: %w", err)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "ExtNetComputesListCheckPresence: response from CloudAPI().ExtNet().ListComputes", map[string]any{"response": compList})
|
||||
|
||||
return compList, err
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package utilities
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
)
|
||||
|
||||
func ExtNetDefaultCheckPresence(ctx context.Context, c *decort.DecortClient) (uint64, error) {
|
||||
tflog.Info(ctx, "ExtNetDefaultCheckPresence: Get info about default extnet with ID - %v")
|
||||
|
||||
netId, err := c.CloudAPI().ExtNet().GetDefault(ctx)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("ExtNetDefaultCheckPresence: cannot get info about extnet with error: %w", err)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "ExtNetDefaultCheckPresence: response from CloudAPI().ExtNet().GetDefault", map[string]any{"response": netId})
|
||||
|
||||
return netId, err
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package utilities
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/extnet/models"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/extnet"
|
||||
)
|
||||
|
||||
func ExtNetListCheckPresence(ctx context.Context, plan *models.DataSourceExtNetListModel, c *decort.DecortClient) (*extnet.ListExtNets, error) {
|
||||
tflog.Info(ctx, "ExtNetListCheckPresence: Get info about extnet list")
|
||||
|
||||
extnetListReq := extnet.ListRequest{}
|
||||
|
||||
if !plan.AccountID.IsNull() {
|
||||
extnetListReq.AccountID = uint64(plan.AccountID.ValueInt64())
|
||||
}
|
||||
if !plan.ByID.IsNull() {
|
||||
extnetListReq.ByID = uint64(plan.ByID.ValueInt64())
|
||||
}
|
||||
if !plan.Name.IsNull() {
|
||||
extnetListReq.Name = plan.Name.ValueString()
|
||||
}
|
||||
if !plan.Network.IsNull() {
|
||||
extnetListReq.Network = plan.Network.ValueString()
|
||||
}
|
||||
if !plan.VLANID.IsNull() {
|
||||
extnetListReq.VLANID = uint64(plan.VLANID.ValueInt64())
|
||||
}
|
||||
if !plan.VNFDevID.IsNull() {
|
||||
extnetListReq.VNFDevID = uint64(plan.VNFDevID.ValueInt64())
|
||||
}
|
||||
if !plan.Status.IsNull() {
|
||||
extnetListReq.Status = plan.Status.ValueString()
|
||||
}
|
||||
if !plan.Page.IsNull() {
|
||||
extnetListReq.Page = uint64(plan.Page.ValueInt64())
|
||||
}
|
||||
if !plan.Size.IsNull() {
|
||||
extnetListReq.Size = uint64(plan.Size.ValueInt64())
|
||||
}
|
||||
if !plan.SortBy.IsNull() {
|
||||
extnetListReq.SortBy = plan.SortBy.ValueString()
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "ExtNetListCheckPresence: before call CloudAPI().ExtNet().List", map[string]any{"req": extnetListReq})
|
||||
extNetList, err := c.CloudAPI().ExtNet().List(ctx, extnetListReq)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get info about extnet with error: %w", err)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "ExtNetListCheckPresence: response from CloudAPI().ExtNet().List", map[string]any{"response": extNetList})
|
||||
|
||||
return extNetList, err
|
||||
}
|
||||
Reference in New Issue
Block a user