This commit is contained in:
asteam
2024-08-23 16:55:50 +03:00
parent 6f40af6a5f
commit 003e4d656e
524 changed files with 43376 additions and 432 deletions

View File

@@ -0,0 +1,91 @@
package vins
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/vins/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceVINS{}
)
func NewDataSourceVINS() datasource.DataSource {
return &dataSourceVINS{}
}
// dataSourceVINS is the data source implementation.
type dataSourceVINS struct {
client *decort.DecortClient
}
func (d *dataSourceVINS) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.DataSourceVINSModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINS: Error get state")
return
}
vinsID := uint64(state.VinsID.ValueInt64())
tflog.Info(ctx, "Read dataSourceVINS: got state successfully", map[string]any{"vins_id": vinsID})
// Set timeouts
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout30s)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINS: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceVINS: set timeouts successfully", map[string]any{
"vins_id": vinsID,
"readTimeout": readTimeout})
ctx, cancel := context.WithTimeout(ctx, readTimeout)
defer cancel()
// Map response body to schema
resp.Diagnostics.Append(flattens.VINSDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINS: Error flatten")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINS: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceVINS", map[string]any{"vins_id": vinsID})
}
func (d *dataSourceVINS) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceVINS(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceVINS) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_cb_vins"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceVINS) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceVINS")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceVINS successfully")
}

View File

@@ -0,0 +1,91 @@
package vins
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/vins/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceVINSAudits{}
)
func NewDataSourceVINSAudits() datasource.DataSource {
return &dataSourceVINSAudits{}
}
// dataSourceVINSAudits is the data source implementation.
type dataSourceVINSAudits struct {
client *decort.DecortClient
}
func (d *dataSourceVINSAudits) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.DataSourceVINSAuditsModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSAudits: Error get state")
return
}
vinsID := uint64(state.VinsID.ValueInt64())
tflog.Info(ctx, "Read dataSourceVINSAudits: got state successfully", map[string]any{"vins_id": vinsID})
// Set timeouts
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout30s)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSAudits: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceVINSAudits: set timeouts successfully", map[string]any{
"vins_id": vinsID,
"readTimeout": readTimeout})
ctx, cancel := context.WithTimeout(ctx, readTimeout)
defer cancel()
// Map response body to schema
resp.Diagnostics.Append(flattens.VINSAuditsDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSAudits: Error flatten")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSAudits: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceVINSAudits", map[string]any{"vins_id": vinsID})
}
func (d *dataSourceVINSAudits) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceVINSAudits(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceVINSAudits) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_cb_vins_audits"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceVINSAudits) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceVINSAudits")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceVINSAudits successfully")
}

View File

@@ -0,0 +1,91 @@
package vins
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/vins/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceVINSExtNetList{}
)
func NewDataSourceVINSExtNetList() datasource.DataSource {
return &dataSourceVINSExtNetList{}
}
// dataSourceVINSExtNetList is the data source implementation.
type dataSourceVINSExtNetList struct {
client *decort.DecortClient
}
func (d *dataSourceVINSExtNetList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.DataSourceVINSExtNetListModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSExtNetList: Error get state")
return
}
vinsID := uint64(state.VinsID.ValueInt64())
tflog.Info(ctx, "Read dataSourceVINSExtNetList: got state successfully", map[string]any{"vins_id": vinsID})
// Set timeouts
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout30s)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSExtNetList: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceVINSExtNetList: set timeouts successfully", map[string]any{
"vins_id": vinsID,
"readTimeout": readTimeout})
ctx, cancel := context.WithTimeout(ctx, readTimeout)
defer cancel()
// Map response body to schema
resp.Diagnostics.Append(flattens.VINSExtNetListDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSExtNetList: Error flatten")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSExtNetList: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceVINSExtNetList", map[string]any{"vins_id": vinsID})
}
func (d *dataSourceVINSExtNetList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceVINSExtNetList(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceVINSExtNetList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_cb_vins_ext_net_list"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceVINSExtNetList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceVINSExtNetList")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceVINSExtNetList successfully")
}

View File

@@ -0,0 +1,91 @@
package vins
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/vins/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceVINSIPList{}
)
func NewDataSourceVINSIPList() datasource.DataSource {
return &dataSourceVINSIPList{}
}
// dataSourceVINSIPList is the data source implementation.
type dataSourceVINSIPList struct {
client *decort.DecortClient
}
func (d *dataSourceVINSIPList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.DataSourceVINSIPListModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSIPList: Error get state")
return
}
vinsID := uint64(state.VinsID.ValueInt64())
tflog.Info(ctx, "Read dataSourceVINSIPList: got state successfully", map[string]any{"vins_id": vinsID})
// Set timeouts
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout30s)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSIPList: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceVINSIPList: set timeouts successfully", map[string]any{
"vins_id": vinsID,
"readTimeout": readTimeout})
ctx, cancel := context.WithTimeout(ctx, readTimeout)
defer cancel()
// Map response body to schema
resp.Diagnostics.Append(flattens.VINSIPListDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSIPList: Error flatten")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSIPList: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceVINSIPList", map[string]any{"vins_id": vinsID})
}
func (d *dataSourceVINSIPList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceVINSIPList(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceVINSIPList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_cb_vins_ip_list"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceVINSIPList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceVINSIPList")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceVINSIPList successfully")
}

View File

@@ -0,0 +1,88 @@
package vins
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/vins/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceVINSList{}
)
func NewDataSourceVINSList() datasource.DataSource {
return &dataSourceVINSList{}
}
// dataSourceVINSList is the data source implementation.
type dataSourceVINSList struct {
client *decort.DecortClient
}
func (d *dataSourceVINSList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.DataSourceVINSListModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSList: Error get state")
return
}
tflog.Info(ctx, "Read dataSourceVINSList: 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 dataSourceVINSList: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceVINSList: 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.VINSListDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSList: Error flatten")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSList: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceVINSList")
}
func (d *dataSourceVINSList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceVINSList(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceVINSList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_cb_vins_list"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceVINSList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceVINSList")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceVINSList successfully")
}

View File

@@ -0,0 +1,88 @@
package vins
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/vins/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceVINSListDeleted{}
)
func NewDataSourceVINSListDeleted() datasource.DataSource {
return &dataSourceVINSListDeleted{}
}
// dataSourceVINSListDeleted is the data source implementation.
type dataSourceVINSListDeleted struct {
client *decort.DecortClient
}
func (d *dataSourceVINSListDeleted) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.DataSourceVINSListDeletedModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSListDeleted: Error get state")
return
}
tflog.Info(ctx, "Read dataSourceVINSListDeleted: 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 dataSourceVINSListDeleted: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceVINSListDeleted: 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.VINSListDeletedDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSListDeleted: Error flatten")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSListDeleted: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceVINSListDeleted")
}
func (d *dataSourceVINSListDeleted) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceVINSListDeleted(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceVINSListDeleted) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_cb_vins_list_deleted"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceVINSListDeleted) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceVINSListDeleted")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceVINSListDeleted successfully")
}

View File

@@ -0,0 +1,89 @@
package vins
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/vins/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceVINSNATRuleList{}
)
func NewDataSourceVINSNATRuleList() datasource.DataSource {
return &dataSourceVINSNATRuleList{}
}
// dataSourceVINSNATRuleList is the data source implementation.
type dataSourceVINSNATRuleList struct {
client *decort.DecortClient
}
func (d *dataSourceVINSNATRuleList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.DataSourceVINSNATRuleListModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSNATRuleList: Error get state")
return
}
tflog.Info(ctx, "Read dataSourceVINSNATRuleList: 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 dataSourceVINSNATRuleList: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceVINSNATRuleList: 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.VINSNATRuleListDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSNATRuleList: Error flatten")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSNATRuleList: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceVINSNATRuleList")
}
func (d *dataSourceVINSNATRuleList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceVINSNATRuleList(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceVINSNATRuleList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_cb_vins_nat_rule_list"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceVINSNATRuleList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceVINSNATRuleList")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceVINSNATRuleList successfully")
tflog.Info(ctx, "Getting Configure dataSourceVINSNATRuleList successfully")
}

View File

@@ -0,0 +1,88 @@
package vins
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/vins/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceVINSStaticRoute{}
)
func NewDataSourceVINSStaticRoute() datasource.DataSource {
return &dataSourceVINSStaticRoute{}
}
// dataSourceVINSStaticRoute is the data source implementation.
type dataSourceVINSStaticRoute struct {
client *decort.DecortClient
}
func (d *dataSourceVINSStaticRoute) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.DataSourceVINSStaticRouteModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSStaticRoute: Error get state")
return
}
tflog.Info(ctx, "Read dataSourceVINSStaticRoute: 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 dataSourceVINSStaticRoute: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceVINSStaticRoute: 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.VINSStaticRouteDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSStaticRoute: Error flatten")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSStaticRoute: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceVINSStaticRoute")
}
func (d *dataSourceVINSStaticRoute) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceVINSStaticRoute(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceVINSStaticRoute) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_cb_vins_static_route"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceVINSStaticRoute) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceVINSStaticRoute")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceVINSStaticRoute successfully")
}

View File

@@ -0,0 +1,88 @@
package vins
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/vins/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/schemas"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &dataSourceVINSStaticRouteList{}
)
func NewDataSourceVINSStaticRouteList() datasource.DataSource {
return &dataSourceVINSStaticRouteList{}
}
// dataSourceVINSStaticRouteList is the data source implementation.
type dataSourceVINSStaticRouteList struct {
client *decort.DecortClient
}
func (d *dataSourceVINSStaticRouteList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
// Read Terraform configuration data into the model
var state models.DataSourceVINSStaticRouteListModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSStaticRouteList: Error get state")
return
}
tflog.Info(ctx, "Read dataSourceVINSStaticRouteList: 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 dataSourceVINSStaticRouteList: Error set timeout")
return
}
tflog.Info(ctx, "Read dataSourceVINSStaticRouteList: 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.VINSStaticRouteListDataSource(ctx, &state, d.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSStaticRouteList: Error flatten")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read dataSourceVINSStaticRouteList: Error set state")
return
}
tflog.Info(ctx, "End read dataSourceVINSStaticRouteList")
}
func (d *dataSourceVINSStaticRouteList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaDataSourceVINSStaticRouteList(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx),
},
}
}
func (d *dataSourceVINSStaticRouteList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_cb_vins_static_route_list"
}
// Configure adds the provider configured client to the data source.
func (d *dataSourceVINSStaticRouteList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure dataSourceVINSStaticRouteList")
d.client = client.DataSource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure dataSourceVINSStaticRouteList successfully")
}

View File

@@ -0,0 +1,585 @@
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/decort-golang-sdk/pkg/cloudbroker/vins"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/utilities"
)
// VINSDataSource flattens data source for vins.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func VINSDataSource(ctx context.Context, state *models.DataSourceVINSModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.VINSDataSource")
diags := diag.Diagnostics{}
vinsId := uint64(state.VinsID.ValueInt64())
recordVins, diags := utilities.VINSDataSourceCheckPresence(ctx, vinsId, c)
if diags.HasError() {
return diags
}
tflog.Info(ctx, "flattens.VINSDataSource: before flatten", map[string]any{"vins_id": vinsId})
id := uuid.New()
*state = models.DataSourceVINSModel{
VinsID: state.VinsID,
Reason: state.Reason,
Timeouts: state.Timeouts,
VNFDev: flattenVNFDev(ctx, &recordVins.VNFDev),
AccountID: types.Int64Value(int64(recordVins.AccountID)),
AccountName: types.StringValue(recordVins.AccountName),
CreatedBy: types.StringValue(recordVins.CreatedBy),
CreatedTime: types.Int64Value(int64(recordVins.CreatedTime)),
DefaultGW: types.StringValue(recordVins.DefaultGW),
DefaultQOS: flattenQOS(ctx, &recordVins.DefaultQOS),
DeletedBy: types.StringValue(recordVins.DeletedBy),
DeletedTime: types.Int64Value(int64(recordVins.DeletedTime)),
Description: types.StringValue(recordVins.Description),
GID: types.Int64Value(int64(recordVins.GID)),
GUID: types.Int64Value(int64(recordVins.GUID)),
Id: types.StringValue(id.String()),
LockStatus: types.StringValue(recordVins.LockStatus),
ManagerID: types.Int64Value(int64(recordVins.ManagerID)),
ManagerType: types.StringValue(recordVins.ManagerType),
Milestones: types.Int64Value(int64(recordVins.Milestones)),
Name: types.StringValue(recordVins.Name),
NetMask: types.Int64Value(int64(recordVins.NetMask)),
Network: types.StringValue(recordVins.Network),
PreReservationsNum: types.Int64Value(int64(recordVins.PreReservationsNum)),
Redundant: types.BoolValue(recordVins.Redundant),
RGID: types.Int64Value(int64(recordVins.RGID)),
RGName: types.StringValue(recordVins.RGName),
SecVNFDevID: types.Int64Value(int64(recordVins.SecVNFDevID)),
Status: types.StringValue(recordVins.Status),
UpdatedBy: types.StringValue(recordVins.UpdatedBy),
UpdatedTime: types.Int64Value(int64(recordVins.UpdatedTime)),
UserManaged: types.BoolValue(recordVins.UserManaged),
VNFs: flattenVNFs(ctx, &recordVins.VNFs),
VXLANID: types.Int64Value(int64(recordVins.VXLANID)),
}
tflog.Info(ctx, "flattens.VINSDataSource: after flatten", map[string]any{"vins_id": state.Id.ValueString()})
tflog.Info(ctx, "End flattens.VINSDataSource", map[string]any{"vins_id": state.Id.ValueString()})
return nil
}
// flattenVNFDev flattens vnfdev.
// Flatten errors are added to tflog.
func flattenVNFDev(ctx context.Context, vnfdev *vins.VNFDev) types.Object {
tflog.Info(ctx, "Start flattenVNFDev")
temp := models.RecordVNFDevModel{
CKey: types.StringValue(vnfdev.CKey),
AccountID: types.Int64Value(int64(vnfdev.AccountID)),
Capabilities: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &vnfdev.Capabilities),
Config: flattenVNFDevConfig(ctx, &vnfdev.Config),
ConfigSaved: types.BoolValue(vnfdev.ConfigSaved),
CustomPreConfig: types.BoolValue(vnfdev.CustomPreConfig),
Description: types.StringValue(vnfdev.Description),
GID: types.Int64Value(int64(vnfdev.GID)),
GUID: types.Int64Value(int64(vnfdev.GUID)),
ID: types.Int64Value(int64(vnfdev.ID)),
Interfaces: flattenInterfaces(ctx, &vnfdev.Interfaces),
LockStatus: types.StringValue(vnfdev.LockStatus),
Meta: flattens.FlattenSimpleTypeToList(ctx, types.StringType, &vnfdev.Meta),
Milestones: types.Int64Value(int64(vnfdev.Milestones)),
Name: types.StringValue(vnfdev.Name),
Status: types.StringValue(vnfdev.Status),
TechStatus: types.StringValue(vnfdev.TechStatus),
Type: types.StringValue(vnfdev.Type),
VINS: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, &vnfdev.VINS),
}
res, err := types.ObjectValueFrom(ctx, models.ItemVNFDev, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenVNFDev struct to obj", err))
}
tflog.Info(ctx, "End flattenVNFDev")
return res
}
// flattenVNFDevConfig flattens config.
// Flatten errors are added to tflog.
func flattenVNFDevConfig(ctx context.Context, config *vins.Config) types.Object {
tflog.Info(ctx, "Start flattenVNFDevConfig")
temp := models.RecordVNFConfigModel{
MGMT: flattenMgmtVNFConfig(ctx, &config.MGMT),
Resources: flattenResourcesVNFConfig(ctx, &config.Resources),
}
res, err := types.ObjectValueFrom(ctx, models.ItemVNFConfig, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenVNFDevConfig struct to obj", err))
}
tflog.Info(ctx, "End flattenVNFDevConfig")
return res
}
// flattenMgmtVNFConfig flattens mgmt.
// Flatten errors are added to tflog.
func flattenMgmtVNFConfig(ctx context.Context, mgmt *vins.MGMT) types.Object {
tflog.Info(ctx, "Start flattenMgmtVNFConfig")
temp := models.RecordMGMTModel{
IPAddress: types.StringValue(mgmt.IPAddress),
Password: types.StringValue(mgmt.Password),
SSHKey: types.StringValue(mgmt.SSHKey),
User: types.StringValue(mgmt.User),
}
res, err := types.ObjectValueFrom(ctx, models.ItemMgmt, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenMgmtVNFConfig struct to obj", err))
}
tflog.Info(ctx, "End flattenMgmtVNFConfig")
return res
}
// flattenResourcesVNFConfig flattens resources.
// Flatten errors are added to tflog.
func flattenResourcesVNFConfig(ctx context.Context, resources *vins.Resources) types.Object {
tflog.Info(ctx, "Start flattenResourcesVNFConfig")
temp := models.RecordResourcesModel{
CPU: types.Int64Value(int64(resources.CPU)),
RAM: types.Int64Value(int64(resources.RAM)),
StackID: types.Int64Value(int64(resources.StackID)),
UUID: types.StringValue(resources.UUID),
}
res, err := types.ObjectValueFrom(ctx, models.ItemResources, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenResourcesVNFConfig struct to obj", err))
}
tflog.Info(ctx, "End flattenResourcesVNFConfig")
return res
}
// flattenInterfaces flattens interfaces.
// Flatten errors are added to tflog.
func flattenInterfaces(ctx context.Context, items *vins.ListInterfaces) types.List {
tflog.Info(ctx, "Start flattenInterfaces")
diags := diag.Diagnostics{}
tempSlice := make([]types.Object, 0, len(*items))
for _, item := range *items {
temp := models.VNFInterfaceModel{
ConnID: types.Int64Value(int64(item.ConnID)),
ConnType: types.StringValue(item.ConnType),
DefGW: types.StringValue(item.DefGW),
Enabled: types.BoolValue(item.Enabled),
FLIPGroupID: types.Int64Value(int64(item.FLIPGroupID)),
GUID: types.StringValue(item.GUID),
IPAddress: types.StringValue(item.IPAddress),
ListenSSH: types.BoolValue(item.ListenSSH),
MAC: types.StringValue(item.MAC),
Name: types.StringValue(item.Name),
NetID: types.Int64Value(int64(item.NetID)),
NetMask: types.Int64Value(int64(item.NetMask)),
NetType: types.StringValue(item.NetType),
NodeID: types.Int64Value(int64(item.NodeID)),
PCISlot: types.Int64Value(int64(item.PCISlot)),
QOS: flattenQOS(ctx, &item.QOS),
Target: types.StringValue(item.Target),
Type: types.StringValue(item.Type),
}
temp.VNFs, diags = types.ListValueFrom(ctx, types.Int64Type, item.VNFs)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("flattens.flattenInterfaces: cannot flatten item.VNFs to temp.VNFs", diags))
}
obj, err := types.ObjectValueFrom(ctx, models.ItemInterface, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenInterfaces struct to obj", err))
}
tempSlice = append(tempSlice, obj)
}
res, err := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemInterface}, tempSlice)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenInterfaces", err))
}
tflog.Info(ctx, "End flattenInterfaces")
return res
}
// flattenQOS flattens QOS.
// Flatten errors are added to tflog.
func flattenQOS(ctx context.Context, qos *vins.QOS) types.Object {
tflog.Info(ctx, "Start flattenQOS")
temp := models.QOSModel{
ERate: types.Int64Value(int64(qos.ERate)),
GUID: types.StringValue(qos.GUID),
InBurst: types.Int64Value(int64(qos.InBurst)),
InRate: types.Int64Value(int64(qos.InRate)),
}
res, err := types.ObjectValueFrom(ctx, models.ItemQOS, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenQOS struct to obj", err))
}
tflog.Info(ctx, "End flattenQOS")
return res
}
// flattenVNFs flattens vnfs.
func flattenVNFs(ctx context.Context, vnfs *vins.RecordVNFs) types.Object {
tflog.Info(ctx, "Start flattenVNFs")
temp := models.RecordVNFsModel{
DHCP: flattenDHCP(ctx, &vnfs.DHCP),
GW: flattenGW(ctx, &vnfs.GW),
NAT: flattenNAT(ctx, &vnfs.NAT),
}
res, err := types.ObjectValueFrom(ctx, models.ItemVNFs, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenVNFs struct to obj", err))
}
tflog.Info(ctx, "End flattenVNFs")
return res
}
// flattenDHCP flattens dhcp.
// Flatten errors are added to tflog.
func flattenDHCP(ctx context.Context, dhcp *vins.RecordDHCP) types.Object {
tflog.Info(ctx, "Start flattenDHCP")
temp := models.RecordDHCPModel{
CKey: types.StringValue(dhcp.CKey),
AccountID: types.Int64Value(int64(dhcp.AccountID)),
Config: flattenDHCPConfig(ctx, &dhcp.Config),
CreatedTime: types.Int64Value(int64(dhcp.CreatedTime)),
Devices: flattenDevices(ctx, &dhcp.Devices),
GID: types.Int64Value(int64(dhcp.GID)),
GUID: types.Int64Value(int64(dhcp.GUID)),
DHCPID: types.Int64Value(int64(dhcp.ID)),
LockStatus: types.StringValue(dhcp.LockStatus),
Milestones: types.Int64Value(int64(dhcp.Milestones)),
OwnerID: types.Int64Value(int64(dhcp.OwnerID)),
OwnerType: types.StringValue(dhcp.OwnerType),
PureVirtual: types.BoolValue(dhcp.PureVirtual),
Routes: flattenRoutes(ctx, &dhcp.Routes),
Status: types.StringValue(dhcp.Status),
TechStatus: types.StringValue(dhcp.TechStatus),
Type: types.StringValue(dhcp.Type),
}
res, diags := types.ObjectValueFrom(ctx, models.ItemDHCP, temp)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenDHCP struct to obj", diags))
}
tflog.Info(ctx, "End flattenDHCP")
return res
}
// flattenDHCPConfig flattens dhcp config.
// Flatten errors are added to tflog.
func flattenDHCPConfig(ctx context.Context, config *vins.VNFsConfig) types.Object {
tflog.Info(ctx, "Start flattenDHCPConfig")
diags := diag.Diagnostics{}
temp := models.RecordDHCPConfigModel{
DefaultGW: types.StringValue(config.DefaultGW),
IPEnd: types.StringValue(config.IPEnd),
IPStart: types.StringValue(config.IPStart),
Lease: types.Int64Value(int64(config.Lease)),
NetMask: types.Int64Value(int64(config.NetMask)),
Network: types.StringValue(config.Network),
Reservations: flattenReservations(ctx, &config.Reservations),
}
temp.DNS, diags = types.ListValueFrom(ctx, types.StringType, config.DNS)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("flattens.flattenDHCPConfig: cannot flatten config.DNS to temp.DNS", diags))
}
res, diags := types.ObjectValueFrom(ctx, models.ItemDHCPConfig, temp)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("Error flattenDHCPConfig struct to obj", diags))
}
tflog.Info(ctx, "End flattenDHCPConfig")
return res
}
// flattenReservations flattens dhcp config reservations.
// Flatten errors are added to tflog.
func flattenReservations(ctx context.Context, items *vins.ListReservations) types.List {
tflog.Info(ctx, "Start flattenReservations")
tempSlice := make([]types.Object, 0, len(*items))
for _, item := range *items {
temp := models.ReservationModel{
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)),
}
obj, diags := types.ObjectValueFrom(ctx, models.ItemReservations, temp)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("Error flattenReservations struct to obj", diags))
}
tempSlice = append(tempSlice, obj)
}
res, diags := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemReservations}, tempSlice)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("Error flattenReservations", diags))
}
tflog.Info(ctx, "End flattenReservations")
return res
}
// flattenDevices flattens devices.
// Flatten errors are added to tflog.
func flattenDevices(ctx context.Context, devices *vins.Devices) types.Object {
tflog.Info(ctx, "Start flattenDevices")
temp := models.DevicesModel{
Primary: flattenPrimaryDevices(ctx, &devices.Primary),
}
res, diags := types.ObjectValueFrom(ctx, models.ItemDevices, temp)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("Error flattenDevices struct to obj", diags))
}
tflog.Info(ctx, "End flattenDevices")
return res
}
// flattenPrimaryDevices flattens primary devices.
// Flatten errors are added to tflog.
func flattenPrimaryDevices(ctx context.Context, primary *vins.Primary) types.Object {
tflog.Info(ctx, "Start flattenPrimaryDevices")
temp := models.PrimaryDevicesModel{
DevID: types.Int64Value(int64(primary.DevID)),
IFace01: types.StringValue(primary.IFace01),
IFace02: types.StringValue(primary.IFace02),
}
res, diags := types.ObjectValueFrom(ctx, models.ItemPrimaryDevices, temp)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("Error flattenPrimaryDevices struct to obj", diags))
}
tflog.Info(ctx, "End flattenPrimaryDevices")
return res
}
// flattenRoutes flattens routes.
// Flatten errors are added to tflog.
func flattenRoutes(ctx context.Context, items *vins.ListRoutes) types.List {
tflog.Info(ctx, "Start flattenRoutes")
diags := diag.Diagnostics{}
tempSlice := make([]types.Object, 0, len(*items))
for _, item := range *items {
temp := models.RoutesModel{
Destination: types.StringValue(item.Destination),
Gateway: types.StringValue(item.Gateway),
GUID: types.StringValue(item.GUID),
RouteID: types.Int64Value(int64(item.ID)),
Netmask: types.StringValue(item.Netmask),
}
temp.ComputeIds, diags = types.ListValueFrom(ctx, types.Int64Type, item.ComputeIds)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("flattens.flattenRoutes: cannot flatten item.ComputeIds to temp.ComputeIds", diags))
}
obj, diags := types.ObjectValueFrom(ctx, models.ItemRoute, temp)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("Error flattenRoutes struct to obj", diags))
}
tempSlice = append(tempSlice, obj)
}
res, diags := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemRoute}, tempSlice)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("Error flattenRoutes", diags))
}
tflog.Info(ctx, "End flattenRoutes")
return res
}
// flattenGW flattens gw.
// Flatten errors are added to tflog.
func flattenGW(ctx context.Context, gw *vins.RecordGW) types.Object {
tflog.Info(ctx, "Start flattenGW")
diags := diag.Diagnostics{}
temp := models.RecordGWModel{
CKey: types.StringValue(gw.CKey),
AccountID: types.Int64Value(int64(gw.AccountID)),
Config: flattenGWConfig(ctx, &gw.Config),
CreatedTime: types.Int64Value(int64(gw.CreatedTime)),
Devices: flattenDevices(ctx, &gw.Devices),
GID: types.Int64Value(int64(gw.GID)),
GUID: types.Int64Value(int64(gw.GUID)),
GWID: types.Int64Value(int64(gw.ID)),
LockStatus: types.StringValue(gw.LockStatus),
Milestones: types.Int64Value(int64(gw.Milestones)),
OwnerID: types.Int64Value(int64(gw.OwnerID)),
OwnerType: types.StringValue(gw.OwnerType),
PureVirtual: types.BoolValue(gw.PureVirtual),
Routes: flattenRoutes(ctx, &gw.Routes),
Status: types.StringValue(gw.Status),
TechStatus: types.StringValue(gw.TechStatus),
Type: types.StringValue(gw.Type),
}
res, diags := types.ObjectValueFrom(ctx, models.ItemGW, temp)
if diags != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenGW struct to obj", diags))
}
tflog.Info(ctx, "End flattenGW")
return res
}
// flattenGWConfig flattens gw config.
// Flatten errors are added to tflog.
func flattenGWConfig(ctx context.Context, config *vins.GWConfig) types.Object {
tflog.Info(ctx, "Start flattenGWConfig")
diags := diag.Diagnostics{}
temp := models.RecordGWConfigModel{
DefaultGW: types.StringValue(config.DefaultGW),
ExtNetID: types.Int64Value(int64(config.ExtNetID)),
ExtNetIP: types.StringValue(config.ExtNetIP),
ExtNetMask: types.Int64Value(int64(config.ExtNetMask)),
QOS: flattenQOS(ctx, &config.QOS),
}
res, diags := types.ObjectValueFrom(ctx, models.ItemGWConfig, temp)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("Error flattenGWConfig struct to obj", diags))
}
tflog.Info(ctx, "End flattenGWConfig")
return res
}
// flattenNAT flattens nat.
// Flatten errors are added to tflog.
func flattenNAT(ctx context.Context, nat *vins.RecordNAT) types.Object {
tflog.Info(ctx, "Start flattenNAT")
temp := models.RecordNATModel{
CKey: types.StringValue(nat.CKey),
AccountID: types.Int64Value(int64(nat.AccountID)),
Config: flattenNATConfig(ctx, &nat.Config),
CreatedTime: types.Int64Value(int64(nat.CreatedTime)),
Devices: flattenDevices(ctx, &nat.Devices),
GID: types.Int64Value(int64(nat.GID)),
GUID: types.Int64Value(int64(nat.GUID)),
NatID: types.Int64Value(int64(nat.ID)),
LockStatus: types.StringValue(nat.LockStatus),
Milestones: types.Int64Value(int64(nat.Milestones)),
OwnerID: types.Int64Value(int64(nat.OwnerID)),
OwnerType: types.StringValue(nat.OwnerType),
PureVirtual: types.BoolValue(nat.PureVirtual),
Routes: flattenRoutes(ctx, &nat.Routes),
Status: types.StringValue(nat.Status),
TechStatus: types.StringValue(nat.TechStatus),
Type: types.StringValue(nat.Type),
}
res, diags := types.ObjectValueFrom(ctx, models.ItemNAT, temp)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("Error flattenNAT struct to obj", diags))
}
tflog.Info(ctx, "End flattenNAT")
return res
}
// flattenRules flattens nat rules.
// Flatten errors are added to tflog.
func flattenRules(ctx context.Context, items *vins.ListNATRule) types.List {
tflog.Info(ctx, "Start flattenRules")
tempSlice := make([]types.Object, 0, len(*items))
for _, item := range *items {
temp := models.NATRuleModel{
RuleID: types.Int64Value(int64(item.ID)),
LocalIP: types.StringValue(item.LocalIP),
LocalPort: types.Int64Value(int64(item.LocalPort)),
Protocol: types.StringValue(item.Protocol),
PublicPortEnd: types.Int64Value(int64(item.PublicPortEnd)),
PublicPortStart: types.Int64Value(int64(item.PublicPortStart)),
VMID: types.Int64Value(int64(item.VMID)),
VMName: types.StringValue(item.VMName),
}
obj, diags := types.ObjectValueFrom(ctx, models.ItemNATRule, temp)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("Error flattenRules struct to obj", diags))
}
tempSlice = append(tempSlice, obj)
}
res, diags := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemNATRule}, tempSlice)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("Error flattenRules", diags))
}
tflog.Info(ctx, "End flattenRules")
return res
}
// flattenNATConfig flattens nat config.
// Flatten errors are added to tflog.
func flattenNATConfig(ctx context.Context, config *vins.NATConfig) types.Object {
tflog.Info(ctx, "Start flattenNATConfig")
diags := diag.Diagnostics{}
temp := models.NATConfigModel{
NetMask: types.Int64Value(int64(config.NetMask)),
Network: types.StringValue(config.Network),
Rules: flattenRules(ctx, &config.Rules),
}
res, diags := types.ObjectValueFrom(ctx, models.ItemNATConfig, temp)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("Error flattenNATConfig struct to obj", diags))
}
tflog.Info(ctx, "End flattenNATConfig")
return res
}

View File

@@ -0,0 +1,55 @@
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/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/utilities"
)
// VINSAuditsDataSource flattens data source for vins audits.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func VINSAuditsDataSource(ctx context.Context, state *models.DataSourceVINSAuditsModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.VINSAuditsDataSource")
diags := diag.Diagnostics{}
vinsId := uint64(state.VinsID.ValueInt64())
audits, diags := utilities.VINSAuditsDataSourceCheckPresence(ctx, vinsId, c)
if diags.HasError() {
return diags
}
tflog.Info(ctx, "flattens.VINSAuditsDataSource: before flatten", map[string]any{"vins_id": vinsId})
id := uuid.New()
*state = models.DataSourceVINSAuditsModel{
VinsID: state.VinsID,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
}
items := make([]models.ItemAuditModel, 0, len(*audits))
for _, item := range *audits {
a := models.ItemAuditModel{
Call: types.StringValue(item.Call),
ResponseTime: types.Float64Value(item.ResponseTime),
StatusCode: types.Int64Value(int64(item.StatusCode)),
Timestamp: types.Float64Value(item.Timestamp),
User: types.StringValue(item.User),
}
items = append(items, a)
}
state.Items = items
tflog.Info(ctx, "End flattens.VINSAuditsDataSource", map[string]any{"vins_id": state.Id.ValueString()})
return nil
}

View File

@@ -0,0 +1,57 @@
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/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/utilities"
)
// VINSExtNetListDataSource flattens data source for vins ext net list.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func VINSExtNetListDataSource(ctx context.Context, state *models.DataSourceVINSExtNetListModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.VINSExtNetListDataSource")
diags := diag.Diagnostics{}
vinsId := uint64(state.VinsID.ValueInt64())
extnetList, diags := utilities.VINSExtNetListDataSourceCheckPresence(ctx, vinsId, c)
if diags.HasError() {
return diags
}
tflog.Info(ctx, "flattens.VINSExtNetListDataSource: before flatten", map[string]any{"vins_id": vinsId})
id := uuid.New()
*state = models.DataSourceVINSExtNetListModel{
VinsID: state.VinsID,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
EntryCount: types.Int64Value(int64(extnetList.EntryCount)),
}
items := make([]models.ItemExtNetVinsModel, 0, len(extnetList.Data))
for _, item := range extnetList.Data {
en := models.ItemExtNetVinsModel{
DefaultGW: types.StringValue(item.DefaultGW),
ExtNetID: types.Int64Value(int64(item.ExtNetID)),
IP: types.StringValue(item.IP),
PrefixLen: types.Int64Value(int64(item.PrefixLen)),
Status: types.StringValue(item.Status),
TechStatus: types.StringValue(item.TechStatus),
}
items = append(items, en)
}
state.Items = items
tflog.Info(ctx, "End flattens.VINSExtNetListDataSource", map[string]any{"vins_id": state.Id.ValueString()})
return nil
}

View File

@@ -0,0 +1,58 @@
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/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/utilities"
)
// VINSIPListDataSource flattens data source for vins ip list.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func VINSIPListDataSource(ctx context.Context, state *models.DataSourceVINSIPListModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.VINSIPListDataSource")
diags := diag.Diagnostics{}
vinsId := uint64(state.VinsID.ValueInt64())
ipList, diags := utilities.VINSIPListDataSourceCheckPresence(ctx, vinsId, c)
if diags.HasError() {
return diags
}
tflog.Info(ctx, "flattens.VINSIPListDataSource: before flatten", map[string]any{"vins_id": vinsId})
id := uuid.New()
*state = models.DataSourceVINSIPListModel{
VinsID: state.VinsID,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
EntryCount: types.Int64Value(int64(ipList.EntryCount)),
}
items := make([]models.ItemIPVinsModel, 0, len(ipList.Data))
for _, item := range ipList.Data {
ip := models.ItemIPVinsModel{
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)),
}
items = append(items, ip)
}
state.Items = items
tflog.Info(ctx, "End flattens.VINSIPListDataSource", map[string]any{"vins_id": state.Id.ValueString()})
return nil
}

View File

@@ -0,0 +1,117 @@
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/decort-golang-sdk/pkg/cloudbroker/vins"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/utilities"
)
// VINSListDataSource flattens data source for vins list.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func VINSListDataSource(ctx context.Context, state *models.DataSourceVINSListModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.VINSListDataSource")
diags := diag.Diagnostics{}
vinsList, diags := utilities.VINSListDataSourceCheckPresence(ctx, state, c)
if diags.HasError() {
return diags
}
tflog.Info(ctx, "flattens.VINSListDataSource: before flatten")
id := uuid.New()
*state = models.DataSourceVINSListModel{
ByID: state.ByID,
Name: state.Name,
AccountID: state.AccountID,
RGID: state.RGID,
ExtIP: state.ExtIP,
VNFDevID: state.VNFDevID,
IncludeDeleted: state.IncludeDeleted,
SortBy: state.SortBy,
Page: state.Page,
Size: state.Size,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
EntryCount: types.Int64Value(int64(vinsList.EntryCount)),
}
items := make([]models.ItemVinsModel, 0, len(vinsList.Data))
for _, item := range vinsList.Data {
v := models.ItemVinsModel{
AccountID: types.Int64Value(int64(item.AccountID)),
AccountName: types.StringValue(item.AccountName),
CreatedBy: types.StringValue(item.CreatedBy),
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
DefaultGW: types.StringValue(item.DefaultGW),
DefaultQOS: flattenQOS(ctx, &item.DefaultQOS),
DeletedBy: types.StringValue(item.DeletedBy),
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
Description: types.StringValue(item.Description),
ExternalIP: types.StringValue(item.ExternalIP),
ExtnetID: types.Int64Value(int64(item.ExtnetId)),
FreeIPs: types.Int64Value(int64(item.FreeIPs)),
GID: types.Int64Value(int64(item.GID)),
GUID: types.Int64Value(int64(item.GUID)),
ID: types.Int64Value(int64(item.ID)),
LockStatus: types.StringValue(item.LockStatus),
ManagerID: types.Int64Value(int64(item.ManagerID)),
ManagerType: types.StringValue(item.ManagerType),
Milestones: types.Int64Value(int64(item.Milestones)),
Name: types.StringValue(item.Name),
Netmask: types.Int64Value(int64(item.NetMask)),
Network: types.StringValue(item.Network),
PreReservationsNum: types.Int64Value(int64(item.PreReservationsNum)),
PriVNFDevID: types.Int64Value(int64(item.PriVNFDevID)),
Redundant: types.BoolValue(item.Redundant),
RGID: types.Int64Value(int64(item.RGID)),
RGName: types.StringValue(item.RGName),
SecVNFDefID: types.Int64Value(int64(item.SecVNFDevID)),
Status: types.StringValue(item.Status),
UpdatedBy: types.StringValue(item.UpdatedBy),
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
UserManaged: types.BoolValue(item.UserManaged),
VNFs: flattenListVNFs(ctx, &item.VNFs),
VXLANID: types.Int64Value(int64(item.VXLANID)),
}
items = append(items, v)
}
state.Items = items
tflog.Info(ctx, "End flattens.VINSListDataSource")
return nil
}
// flattenListVNFs flattens ItemListVNFs.
// Flatten errors are added to tflog.
func flattenListVNFs(ctx context.Context, iv *vins.ItemVNFs) types.Object {
tflog.Info(ctx, "Start flattenListVNFs")
temp := models.ListVNFsModel{
DHCP: types.Int64Value(int64(iv.DHCP)),
DNS: types.Int64Value(int64(iv.DNS)),
FW: types.Int64Value(int64(iv.FW)),
GW: types.Int64Value(int64(iv.GW)),
NAT: types.Int64Value(int64(iv.NAT)),
VPN: types.Int64Value(int64(iv.VPN)),
}
res, err := types.ObjectValueFrom(ctx, models.ItemListVNFs, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenListVNFs struct to obj", err))
}
tflog.Info(ctx, "End flattenListVNFs")
return res
}

View File

@@ -0,0 +1,88 @@
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/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/utilities"
)
// VINSListDeletedDataSource flattens data source for vins list deleted.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func VINSListDeletedDataSource(ctx context.Context, state *models.DataSourceVINSListDeletedModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.VINSListDeletedDataSource")
diags := diag.Diagnostics{}
vinsList, diags := utilities.VINSListDeletedDataSourceCheckPresence(ctx, state, c)
if diags.HasError() {
return diags
}
tflog.Info(ctx, "flattens.VINSListDeletedDataSource: before flatten")
id := uuid.New()
*state = models.DataSourceVINSListDeletedModel{
ByID: state.ByID,
Name: state.Name,
AccountID: state.AccountID,
RGID: state.RGID,
ExtIP: state.ExtIP,
SortBy: state.SortBy,
Page: state.Page,
Size: state.Size,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
EntryCount: types.Int64Value(int64(vinsList.EntryCount)),
}
items := make([]models.ItemVinsDeletedModel, 0, len(vinsList.Data))
for _, item := range vinsList.Data {
v := models.ItemVinsDeletedModel{
AccountID: types.Int64Value(int64(item.AccountID)),
AccountName: types.StringValue(item.AccountName),
CreatedBy: types.StringValue(item.CreatedBy),
CreatedTime: types.Int64Value(int64(item.CreatedTime)),
DefaultGW: types.StringValue(item.DefaultGW),
DefaultQOS: flattenQOS(ctx, &item.DefaultQOS),
DeletedBy: types.StringValue(item.DeletedBy),
DeletedTime: types.Int64Value(int64(item.DeletedTime)),
Description: types.StringValue(item.Description),
ExternalIP: types.StringValue(item.ExternalIP),
GID: types.Int64Value(int64(item.GID)),
GUID: types.Int64Value(int64(item.GUID)),
ID: types.Int64Value(int64(item.ID)),
LockStatus: types.StringValue(item.LockStatus),
ManagerID: types.Int64Value(int64(item.ManagerID)),
ManagerType: types.StringValue(item.ManagerType),
Milestones: types.Int64Value(int64(item.Milestones)),
Name: types.StringValue(item.Name),
Netmask: types.Int64Value(int64(item.NetMask)),
Network: types.StringValue(item.Network),
PreReservationsNum: types.Int64Value(int64(item.PreReservationsNum)),
PriVNFDevID: types.Int64Value(int64(item.PriVNFDevID)),
Redundant: types.BoolValue(item.Redundant),
RGID: types.Int64Value(int64(item.RGID)),
RGName: types.StringValue(item.RGName),
SecVNFDefID: types.Int64Value(int64(item.SecVNFDevID)),
Status: types.StringValue(item.Status),
UpdatedBy: types.StringValue(item.UpdatedBy),
UpdatedTime: types.Int64Value(int64(item.UpdatedTime)),
UserManaged: types.BoolValue(item.UserManaged),
VNFs: flattenListVNFs(ctx, &item.VNFs),
VXLANID: types.Int64Value(int64(item.VXLANID)),
}
items = append(items, v)
}
state.Items = items
tflog.Info(ctx, "End flattens.VINSListDeletedDataSource")
return nil
}

View File

@@ -0,0 +1,58 @@
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/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/utilities"
)
// VINSNATRuleListDataSource flattens data source for vins nat rule list.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func VINSNATRuleListDataSource(ctx context.Context, state *models.DataSourceVINSNATRuleListModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.VINSNATRuleListDataSource")
diags := diag.Diagnostics{}
natRulesList, diags := utilities.VINSNATRuleListDataSourceCheckPresence(ctx, state, c)
if diags.HasError() {
return diags
}
tflog.Info(ctx, "flattens.VINSNATRuleListDataSource: before flatten")
id := uuid.New()
*state = models.DataSourceVINSNATRuleListModel{
VinsID: state.VinsID,
Reason: state.Reason,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
EntryCount: types.Int64Value(int64(natRulesList.EntryCount)),
}
items := make([]models.ItemVINSNATRuleModel, 0, len(natRulesList.Data))
for _, item := range natRulesList.Data {
v := models.ItemVINSNATRuleModel{
ID: types.Int64Value(int64(item.ID)),
LocalIP: types.StringValue(item.LocalIP),
LocalPort: types.Int64Value(int64(item.LocalPort)),
Protocol: types.StringValue(item.Protocol),
PublicPortEnd: types.Int64Value(int64(item.PublicPortEnd)),
PublicPortStart: types.Int64Value(int64(item.PublicPortStart)),
VMID: types.Int64Value(int64(item.VMID)),
VMName: types.StringValue(item.VMName),
}
items = append(items, v)
}
state.Items = items
tflog.Info(ctx, "End flattens.VINSNATRuleListDataSource")
return nil
}

View File

@@ -0,0 +1,51 @@
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/service/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/utilities"
)
// VINSStaticRouteDataSource flattens data source for vins static route.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func VINSStaticRouteDataSource(ctx context.Context, state *models.DataSourceVINSStaticRouteModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.VINSStaticRouteDataSource")
diags := diag.Diagnostics{}
route, diags := utilities.VINSStaticRouteDataSourceCheckPresence(ctx, uint64(state.VinsID.ValueInt64()), uint64(state.RouteID.ValueInt64()), c)
if diags.HasError() {
return diags
}
tflog.Info(ctx, "flattens.VINSStaticRouteDataSource: before flatten")
id := uuid.New()
*state = models.DataSourceVINSStaticRouteModel{
VinsID: state.VinsID,
RouteID: state.RouteID,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
Destination: types.StringValue(route.Destination),
Gateway: types.StringValue(route.Gateway),
GUID: types.StringValue(route.GUID),
Netmask: types.StringValue(route.Netmask),
}
state.ComputeIds, diags = types.ListValueFrom(ctx, types.Int64Type, route.ComputeIds)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("Error flattens.VINSStaticRouteDataSource: cannot flatten route.ComputeIds to state.ComputeIds", diags))
}
tflog.Info(ctx, "End flattens.VINSStaticRouteDataSource")
return nil
}

View File

@@ -0,0 +1,63 @@
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/service/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/utilities"
)
// VINSStaticRouteListDataSource flattens data source for vins static route list.
// Return error in case data source is not found on the platform.
// Flatten errors are added to tflog.
func VINSStaticRouteListDataSource(ctx context.Context, state *models.DataSourceVINSStaticRouteListModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.VINSStaticRouteListDataSource")
diags := diag.Diagnostics{}
vinsId := uint64(state.VinsID.ValueInt64())
routesList, diags := utilities.VINSStaticRouteListDataSourceCheckPresence(ctx, vinsId, c)
if diags.HasError() {
return diags
}
tflog.Info(ctx, "flattens.VINSStaticRouteListDataSource: before flatten")
id := uuid.New()
*state = models.DataSourceVINSStaticRouteListModel{
VinsID: state.VinsID,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
EntryCount: types.Int64Value(int64(routesList.EntryCount)),
}
items := make([]models.ItemVinsStaticRouteModel, 0, len(routesList.Data))
for _, item := range routesList.Data {
v := models.ItemVinsStaticRouteModel{
Destination: types.StringValue(item.Destination),
Gateway: types.StringValue(item.Gateway),
GUID: types.StringValue(item.GUID),
ID: types.Int64Value(int64(item.ID)),
Netmask: types.StringValue(item.Netmask),
}
v.ComputeIds, diags = types.ListValueFrom(ctx, types.Int64Type, item.ComputeIds)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("Error flattens.VINSStaticRouteListDataSource: cannot flatten item.ComputeIds to v.ComputeIds", diags))
}
items = append(items, v)
}
state.Items = items
tflog.Info(ctx, "End flattens.VINSStaticRouteListDataSource")
return nil
}

View File

@@ -0,0 +1,161 @@
package flattens
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/vins"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/utilities"
)
// VINSResource flattens resource for vins.
// Return error in case resource is not found on the platform.
// Flatten errors are added to tflog.
func VINSResource(ctx context.Context, plan *models.ResourceVINSModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.VINSResource")
diags := diag.Diagnostics{}
vinsId, err := strconv.ParseUint(plan.Id.ValueString(), 10, 64)
if err != nil {
diags.AddError("Cannot parse vins ID from state", err.Error())
return diags
}
recordVins, diags := utilities.VINSResourceCheckPresence(ctx, vinsId, c)
if diags.HasError() {
return diags
}
tflog.Info(ctx, "flattens.VINSResource: before flatten", map[string]any{"vins_id": vinsId})
*plan = models.ResourceVINSModel{
Name: types.StringValue(recordVins.Name),
RGID: plan.RGID,
AccountID: plan.AccountID,
IPCIDR: plan.IPCIDR,
PreReservationsNum: plan.PreReservationsNum,
Description: plan.Description,
GID: plan.GID,
DNS: plan.DNS,
Enable: plan.Enable,
Permanently: plan.Permanently,
Force: plan.Force,
Restore: plan.Restore,
VnfdevRestart: plan.VnfdevRestart,
VnfdevRedeploy: plan.VnfdevRedeploy,
ExtNet: plan.ExtNet,
IP: plan.IP,
NatRule: plan.NatRule,
Timeouts: plan.Timeouts,
VinsID: types.Int64Value(int64(vinsId)),
Id: types.StringValue(strconv.Itoa(int(recordVins.ID))),
LastUpdated: plan.LastUpdated,
VNFDev: flattenVNFDev(ctx, &recordVins.VNFDev),
AccountName: types.StringValue(recordVins.AccountName),
CreatedBy: types.StringValue(recordVins.CreatedBy),
CreatedTime: types.Int64Value(int64(recordVins.CreatedTime)),
DefaultGW: types.StringValue(recordVins.DefaultGW),
DefaultQOS: flattenQOS(ctx, &recordVins.DefaultQOS),
DeletedBy: types.StringValue(recordVins.DeletedBy),
DeletedTime: types.Int64Value(int64(recordVins.DeletedTime)),
GUID: types.Int64Value(int64(recordVins.GUID)),
LockStatus: types.StringValue(recordVins.LockStatus),
ManagerID: types.Int64Value(int64(recordVins.ManagerID)),
ManagerType: types.StringValue(recordVins.ManagerType),
Milestones: types.Int64Value(int64(recordVins.Milestones)),
NetMask: types.Int64Value(int64(recordVins.NetMask)),
Network: types.StringValue(recordVins.Network),
Redundant: types.BoolValue(recordVins.Redundant),
RGName: types.StringValue(recordVins.RGName),
SecVNFDevID: types.Int64Value(int64(recordVins.SecVNFDevID)),
Status: types.StringValue(recordVins.Status),
UpdatedBy: types.StringValue(recordVins.UpdatedBy),
UpdatedTime: types.Int64Value(int64(recordVins.UpdatedTime)),
UserManaged: types.BoolValue(recordVins.UserManaged),
VNFs: flattenVNFs(ctx, &recordVins.VNFs),
VXLANID: types.Int64Value(int64(recordVins.VXLANID)),
}
if plan.RGID.IsUnknown() {
plan.RGID = types.Int64Value(int64(recordVins.RGID))
}
if plan.AccountID.IsUnknown() {
plan.AccountID = types.Int64Value(int64(recordVins.AccountID))
}
if plan.GID.IsUnknown() {
plan.GID = types.Int64Value(int64(recordVins.GID))
}
if plan.PreReservationsNum.IsUnknown() {
plan.PreReservationsNum = types.Int64Value(int64(recordVins.PreReservationsNum))
}
if plan.Description.IsUnknown() {
plan.Description = types.StringValue(recordVins.Description)
}
if plan.DNS.IsNull() {
plan.DNS = types.SetNull(types.StringType)
}
if !plan.NatRule.IsNull() {
plan.NatRule = flattenNatRule(ctx, plan, &recordVins.VNFs.NAT.Config.Rules)
}
tflog.Info(ctx, "flattens.VINSResource: after flatten", map[string]any{"vins_id": plan.Id.ValueString()})
tflog.Info(ctx, "End flattens.VINSResource", map[string]any{"vins_id": plan.Id.ValueString()})
return nil
}
// flattenNatRule flattens nat rule parameters:
// - rule_id (computed),
// - int_port, ext_port_end, proto (optional & computed).
// Flatten errors are added to tflog.
func flattenNatRule(ctx context.Context, plan *models.ResourceVINSModel, rules *vins.ListNATRule) types.List {
tflog.Info(ctx, "Start flattenRuleIdInNatRule")
diags := diag.Diagnostics{}
itemsNatRulePlan := make([]models.NatRuleResourceModel, 0, len(plan.NatRule.Elements()))
diags.Append(plan.NatRule.ElementsAs(ctx, &itemsNatRulePlan, false)...)
if diags.HasError() {
tflog.Error(ctx, "flattenRuleIdInNatRule: cannot populate itemsNatRulePlan with plan.NatRule list elements")
}
for i, natRule := range itemsNatRulePlan {
ruleFromPlatform := natRule.GetNatRule(*rules)
if ruleFromPlatform == nil {
tflog.Error(ctx, fmt.Sprintf("flattenRuleIdInNatRule: rule_id can not be flatten for natRule %v because such nat_rule does not exist", natRule))
continue
}
itemsNatRulePlan[i].RuleID = types.Int64Value(int64(ruleFromPlatform.ID))
if itemsNatRulePlan[i].IntPort.ValueInt64() == 0 {
itemsNatRulePlan[i].IntPort = types.Int64Value(int64(ruleFromPlatform.LocalPort))
}
if itemsNatRulePlan[i].ExtPortEnd.ValueInt64() == 0 {
itemsNatRulePlan[i].ExtPortEnd = types.Int64Value(int64(ruleFromPlatform.PublicPortEnd))
}
if itemsNatRulePlan[i].Proto.ValueString() == "" {
itemsNatRulePlan[i].Proto = types.StringValue(ruleFromPlatform.Protocol)
}
}
res, err := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: models.ItemNatRuleResource}, itemsNatRulePlan)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenRuleIdInNatRule", err))
}
tflog.Info(ctx, "End flattenRuleIdInNatRule")
return res
}

View File

@@ -0,0 +1,68 @@
package flattens
import (
"context"
"fmt"
"time"
"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/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/utilities"
)
// VINSStaticRouteResource flattens resource for vins static route.
// Return error in case resource is not found on the platform.
// Flatten errors are added to tflog.
func VINSStaticRouteResource(ctx context.Context, plan *models.ResourceVINSStaticRouteModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start flattens.VINSStaticRouteResource")
vinsId, routeId, diags := utilities.GetVinsIDAndRouteID(ctx, plan)
if diags.HasError() {
return diags
}
recordRoute, diags := utilities.VINSStaticRouteResourceCheckPresence(ctx, vinsId, routeId, c)
if diags.HasError() {
return diags
}
tflog.Info(ctx, "flattens.VINSStaticRouteResource: before flatten", map[string]any{"id": plan.Id.ValueString()})
*plan = models.ResourceVINSStaticRouteModel{
VinsID: types.Int64Value(int64(vinsId)),
Destination: types.StringValue(recordRoute.Destination),
Netmask: types.StringValue(recordRoute.Netmask),
Gateway: types.StringValue(recordRoute.Gateway),
Timeouts: plan.Timeouts,
RouteID: types.Int64Value(int64(routeId)),
ComputeIDs: plan.ComputeIDs,
Id: plan.Id,
LastUpdated: plan.LastUpdated,
GUID: types.StringValue(recordRoute.GUID),
}
if plan.ComputeIDs.IsUnknown() {
plan.ComputeIDs, diags = types.ListValueFrom(ctx, types.Int64Type, recordRoute.ComputeIds)
if diags.HasError() {
tflog.Error(ctx, fmt.Sprint("Error VINSStaticRouteResource: cannot flatten recordRoute.ComputeIds to plan.ComputeIDs", diags))
}
}
if plan.Id.IsUnknown() {
plan.Id = types.StringValue(fmt.Sprintf("%d#%d", vinsId, routeId))
}
if plan.LastUpdated.IsUnknown() {
plan.LastUpdated = types.StringValue(time.Now().Format(time.RFC850))
}
tflog.Info(ctx, "flattens.VINSStaticRouteResource: after flatten", map[string]any{"id": plan.Id.ValueString()})
tflog.Info(ctx, "End flattens.VINSStaticRouteResource", map[string]any{"id": plan.Id.ValueString()})
return nil
}

View File

@@ -0,0 +1,91 @@
package vins
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"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/vins/models"
)
// resourceVINSInputChecks checks if user provided rg_id, account_id, ext_net_id and gid are valid.
// It also checks that either rg_id or account_id is specified.
func resourceVINSInputChecks(ctx context.Context, plan *models.ResourceVINSModel, c *decort.DecortClient) diag.Diagnostics {
diags := diag.Diagnostics{}
if plan.RGID.IsUnknown() && plan.AccountID.IsUnknown() {
tflog.Error(ctx, "resourceVINSInputChecks: Error providing rg_id or account_id")
diags.AddError(fmt.Sprintf("Unable to validate rg_id and account_id"), "Either accountId or resource group ID should be specified")
return diags
}
if !plan.RGID.IsUnknown() && !plan.AccountID.IsUnknown() {
tflog.Error(ctx, "resourceVINSInputChecks: Error providing rg_id and account_id at the same time")
diags.AddError(fmt.Sprintf("Unable to validate rg_id and account_id"), "Either rg_id or account_id must be provided")
return diags
}
if !plan.RGID.IsUnknown() { // RGID is optional & computed
rgId := uint64(plan.RGID.ValueInt64())
tflog.Info(ctx, "resourceVINSInputChecks: exist resource group", 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())
}
}
if !plan.ExtNet.IsNull() { // ExtNet is optional
var extnetPlan models.ExtNetModel
tflog.Info(ctx, "resourceVINSInputChecks: new extnet specified", map[string]any{"name": plan.Name.ValueString()})
diags.Append(plan.ExtNet.As(ctx, &extnetPlan, basetypes.ObjectAsOptions{UnhandledNullAsEmpty: true})...)
if diags.HasError() {
tflog.Error(ctx, "resourceVINSInputChecks: cannot populate extnet with plan.ExtNet object element")
return diags
}
extnetId := int(extnetPlan.ExtNetID.ValueInt64())
tflog.Info(ctx, "resourceVINSInputChecks: exist ext_net check", map[string]any{"ext_net_id": extnetId})
err := ic.ExistExtNetInVins(ctx, extnetId, c)
if err != nil {
diags.AddError(fmt.Sprintf("Cannot get info about ext net with ID %v", extnetId), err.Error())
}
}
if !plan.AccountID.IsUnknown() { // AccountID is optional & computed
accountId := uint64(plan.AccountID.ValueInt64())
tflog.Info(ctx, "resourceVINSInputChecks: exist account check", map[string]any{"account_id": accountId})
err := ic.ExistAccount(ctx, accountId, c)
if err != nil {
diags.AddError(fmt.Sprintf("Cannot get info about account with ID %v", accountId), err.Error())
}
}
if !plan.GID.IsUnknown() { // GID is optional & computed
gid := uint64(plan.GID.ValueInt64())
tflog.Info(ctx, "resourceVINSInputChecks: exist gid check", map[string]any{"gid": gid})
err := ic.ExistGID(ctx, gid, c)
if err != nil {
diags.AddError(fmt.Sprintf("Cannot get info about gid with ID %v", gid), err.Error())
}
}
return diags
}
// resourceVINSStaticRouteInputChecks checks if user provided vins_id is valid.
func resourceVINSStaticRouteInputChecks(ctx context.Context, plan *models.ResourceVINSStaticRouteModel, c *decort.DecortClient) diag.Diagnostics {
diags := diag.Diagnostics{}
vinsId := uint64(plan.VinsID.ValueInt64())
tflog.Info(ctx, "resourceVINSStaticRouteInputChecks: exist vins", map[string]any{"vins_id": vinsId})
err := ic.ExistVins(ctx, vinsId, c)
if err != nil {
diags.AddError(fmt.Sprintf("Cannot get info about vins with ID %v", vinsId), err.Error())
}
return diags
}

View File

@@ -0,0 +1,454 @@
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"
)
// models
type DataSourceVINSModel struct {
// request fields
VinsID types.Int64 `tfsdk:"vins_id"`
Reason types.String `tfsdk:"reason"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
Id types.String `tfsdk:"id"`
VNFDev types.Object `tfsdk:"vnf_dev"`
AccountID types.Int64 `tfsdk:"account_id"`
AccountName types.String `tfsdk:"account_name"`
CreatedBy types.String `tfsdk:"created_by"`
CreatedTime types.Int64 `tfsdk:"created_time"`
DefaultGW types.String `tfsdk:"default_gw"`
DefaultQOS types.Object `tfsdk:"default_qos"`
DeletedBy types.String `tfsdk:"deleted_by"`
DeletedTime types.Int64 `tfsdk:"deleted_time"`
Description types.String `tfsdk:"description"`
GID types.Int64 `tfsdk:"gid"`
GUID types.Int64 `tfsdk:"guid"`
LockStatus types.String `tfsdk:"lock_status"`
ManagerID types.Int64 `tfsdk:"manager_id"`
ManagerType types.String `tfsdk:"manager_type"`
Milestones types.Int64 `tfsdk:"milestones"`
Name types.String `tfsdk:"name"`
NetMask types.Int64 `tfsdk:"netmask"`
Network types.String `tfsdk:"network"`
PreReservationsNum types.Int64 `tfsdk:"pre_reservations_num"`
Redundant types.Bool `tfsdk:"redundant"`
RGID types.Int64 `tfsdk:"rg_id"`
RGName types.String `tfsdk:"rg_name"`
SecVNFDevID types.Int64 `tfsdk:"sec_vnf_dev_id"`
Status types.String `tfsdk:"status"`
UpdatedBy types.String `tfsdk:"updated_by"`
UpdatedTime types.Int64 `tfsdk:"updated_time"`
UserManaged types.Bool `tfsdk:"user_managed"`
VNFs types.Object `tfsdk:"vnfs"`
VXLANID types.Int64 `tfsdk:"vxlan_id"`
}
type RecordVNFDevModel struct {
CKey types.String `tfsdk:"ckey"`
AccountID types.Int64 `tfsdk:"account_id"`
Capabilities types.List `tfsdk:"capabilities"`
Config types.Object `tfsdk:"config"`
ConfigSaved types.Bool `tfsdk:"config_saved"`
CustomPreConfig types.Bool `tfsdk:"custom_precfg"`
Description types.String `tfsdk:"description"`
GID types.Int64 `tfsdk:"gid"`
GUID types.Int64 `tfsdk:"guid"`
ID types.Int64 `tfsdk:"id"`
Interfaces types.List `tfsdk:"interfaces"`
LockStatus types.String `tfsdk:"lock_status"`
Meta types.List `tfsdk:"meta"`
Milestones types.Int64 `tfsdk:"milestones"`
Name types.String `tfsdk:"name"`
Status types.String `tfsdk:"status"`
TechStatus types.String `tfsdk:"tech_status"`
Type types.String `tfsdk:"type"`
VINS types.List `tfsdk:"vins"`
}
type RecordVNFConfigModel struct {
MGMT types.Object `tfsdk:"mgmt"`
Resources types.Object `tfsdk:"resources"`
}
type RecordMGMTModel struct {
IPAddress types.String `tfsdk:"ip_addr"`
Password types.String `tfsdk:"password"`
SSHKey types.String `tfsdk:"ssh_key"`
User types.String `tfsdk:"user"`
}
type RecordResourcesModel struct {
CPU types.Int64 `tfsdk:"cpu"`
RAM types.Int64 `tfsdk:"ram"`
StackID types.Int64 `tfsdk:"stack_id"`
UUID types.String `tfsdk:"uuid"`
}
type VNFInterfaceModel struct {
ConnID types.Int64 `tfsdk:"conn_id"`
ConnType types.String `tfsdk:"conn_type"`
DefGW types.String `tfsdk:"def_gw"`
Enabled types.Bool `tfsdk:"enabled"`
FLIPGroupID types.Int64 `tfsdk:"flipgroup_id"`
GUID types.String `tfsdk:"guid"`
IPAddress types.String `tfsdk:"ip_address"`
ListenSSH types.Bool `tfsdk:"listen_ssh"`
MAC types.String `tfsdk:"mac"`
Name types.String `tfsdk:"name"`
NetID types.Int64 `tfsdk:"net_id"`
NetMask types.Int64 `tfsdk:"net_mask"`
NetType types.String `tfsdk:"net_type"`
NodeID types.Int64 `tfsdk:"node_id"`
PCISlot types.Int64 `tfsdk:"pci_slot"`
QOS types.Object `tfsdk:"qos"`
Target types.String `tfsdk:"target"`
Type types.String `tfsdk:"type"`
VNFs types.List `tfsdk:"vnfs"`
}
type QOSModel struct {
ERate types.Int64 `tfsdk:"e_rate"`
GUID types.String `tfsdk:"guid"`
InBurst types.Int64 `tfsdk:"in_burst"`
InRate types.Int64 `tfsdk:"in_rate"`
}
type RecordVNFsModel struct {
DHCP types.Object `tfsdk:"dhcp"`
GW types.Object `tfsdk:"gw"`
NAT types.Object `tfsdk:"nat"`
}
type RecordDHCPModel struct {
CKey types.String `tfsdk:"ckey"`
AccountID types.Int64 `tfsdk:"account_id"`
Config types.Object `tfsdk:"config"`
CreatedTime types.Int64 `tfsdk:"created_time"`
Devices types.Object `tfsdk:"devices"`
GID types.Int64 `tfsdk:"gid"`
GUID types.Int64 `tfsdk:"guid"`
DHCPID types.Int64 `tfsdk:"dhcp_id"`
LockStatus types.String `tfsdk:"lock_status"`
Milestones types.Int64 `tfsdk:"milestones"`
OwnerID types.Int64 `tfsdk:"owner_id"`
OwnerType types.String `tfsdk:"owner_type"`
PureVirtual types.Bool `tfsdk:"pure_virtual"`
Routes types.List `tfsdk:"routes"`
Status types.String `tfsdk:"status"`
TechStatus types.String `tfsdk:"tech_status"`
Type types.String `tfsdk:"type"`
}
type RoutesModel struct {
ComputeIds types.List `tfsdk:"compute_ids"`
Destination types.String `tfsdk:"destination"`
Gateway types.String `tfsdk:"gateway"`
GUID types.String `tfsdk:"guid"`
RouteID types.Int64 `tfsdk:"route_id"`
Netmask types.String `tfsdk:"netmask"`
}
type DevicesModel struct {
Primary types.Object `tfsdk:"primary"`
}
type PrimaryDevicesModel struct {
DevID types.Int64 `tfsdk:"dev_id"`
IFace01 types.String `tfsdk:"iface01"`
IFace02 types.String `tfsdk:"iface02"`
}
type RecordDHCPConfigModel struct {
DefaultGW types.String `tfsdk:"default_gw"`
DNS types.List `tfsdk:"dns"`
IPEnd types.String `tfsdk:"ip_end"`
IPStart types.String `tfsdk:"ip_start"`
Lease types.Int64 `tfsdk:"lease"`
NetMask types.Int64 `tfsdk:"netmask"`
Network types.String `tfsdk:"network"`
Reservations types.List `tfsdk:"reservations"`
}
type ReservationModel 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"`
}
type RecordNATModel struct {
CKey types.String `tfsdk:"ckey"`
AccountID types.Int64 `tfsdk:"account_id"`
Config types.Object `tfsdk:"config"`
CreatedTime types.Int64 `tfsdk:"created_time"`
Devices types.Object `tfsdk:"devices"`
GID types.Int64 `tfsdk:"gid"`
GUID types.Int64 `tfsdk:"guid"`
NatID types.Int64 `tfsdk:"nat_id"`
LockStatus types.String `tfsdk:"lock_status"`
Milestones types.Int64 `tfsdk:"milestones"`
OwnerID types.Int64 `tfsdk:"owner_id"`
OwnerType types.String `tfsdk:"owner_type"`
PureVirtual types.Bool `tfsdk:"pure_virtual"`
Routes types.List `tfsdk:"routes"`
Status types.String `tfsdk:"status"`
TechStatus types.String `tfsdk:"tech_status"`
Type types.String `tfsdk:"type"`
}
type NATConfigModel struct {
NetMask types.Int64 `tfsdk:"net_mask"`
Network types.String `tfsdk:"network"`
Rules types.List `tfsdk:"rules"`
}
type NATRuleModel struct {
RuleID types.Int64 `tfsdk:"rule_id"`
LocalIP types.String `tfsdk:"local_ip"`
LocalPort types.Int64 `tfsdk:"local_port"`
Protocol types.String `tfsdk:"protocol"`
PublicPortEnd types.Int64 `tfsdk:"public_port_end"`
PublicPortStart types.Int64 `tfsdk:"public_port_start"`
VMID types.Int64 `tfsdk:"vm_id"`
VMName types.String `tfsdk:"vm_name"`
}
type RecordGWModel struct {
CKey types.String `tfsdk:"ckey"`
AccountID types.Int64 `tfsdk:"account_id"`
Config types.Object `tfsdk:"config"`
CreatedTime types.Int64 `tfsdk:"created_time"`
Devices types.Object `tfsdk:"devices"`
GID types.Int64 `tfsdk:"gid"`
GUID types.Int64 `tfsdk:"guid"`
GWID types.Int64 `tfsdk:"gw_id"`
LockStatus types.String `tfsdk:"lock_status"`
Milestones types.Int64 `tfsdk:"milestones"`
OwnerID types.Int64 `tfsdk:"owner_id"`
OwnerType types.String `tfsdk:"owner_type"`
PureVirtual types.Bool `tfsdk:"pure_virtual"`
Routes types.List `tfsdk:"routes"`
Status types.String `tfsdk:"status"`
TechStatus types.String `tfsdk:"tech_status"`
Type types.String `tfsdk:"type"`
}
type RecordGWConfigModel struct {
DefaultGW types.String `tfsdk:"default_gw"`
ExtNetID types.Int64 `tfsdk:"ext_net_id"`
ExtNetIP types.String `tfsdk:"ext_net_ip"`
ExtNetMask types.Int64 `tfsdk:"ext_netmask"`
QOS types.Object `tfsdk:"qos"`
}
// variables for models
var ItemVNFDev = map[string]attr.Type{
"ckey": types.StringType,
"account_id": types.Int64Type,
"capabilities": types.ListType{ElemType: types.StringType},
"config": types.ObjectType{AttrTypes: ItemVNFConfig},
"config_saved": types.BoolType,
"custom_precfg": types.BoolType,
"description": types.StringType,
"gid": types.Int64Type,
"guid": types.Int64Type,
"id": types.Int64Type,
"interfaces": types.ListType{ElemType: types.ObjectType{AttrTypes: ItemInterface}},
"lock_status": types.StringType,
"meta": types.ListType{ElemType: types.StringType},
"milestones": types.Int64Type,
"name": types.StringType,
"status": types.StringType,
"tech_status": types.StringType,
"type": types.StringType,
"vins": types.ListType{ElemType: types.Int64Type},
}
var ItemInterface = map[string]attr.Type{
"conn_id": types.Int64Type,
"conn_type": types.StringType,
"def_gw": types.StringType,
"enabled": types.BoolType,
"flipgroup_id": types.Int64Type,
"guid": types.StringType,
"ip_address": types.StringType,
"listen_ssh": types.BoolType,
"mac": types.StringType,
"name": types.StringType,
"net_id": types.Int64Type,
"net_mask": types.Int64Type,
"net_type": types.StringType,
"node_id": types.Int64Type,
"pci_slot": types.Int64Type,
"qos": types.ObjectType{AttrTypes: ItemQOS},
"target": types.StringType,
"type": types.StringType,
"vnfs": types.ListType{ElemType: types.Int64Type},
}
var ItemQOS = map[string]attr.Type{
"e_rate": types.Int64Type,
"guid": types.StringType,
"in_burst": types.Int64Type,
"in_rate": types.Int64Type,
}
var ItemVNFConfig = map[string]attr.Type{
"mgmt": types.ObjectType{AttrTypes: ItemMgmt},
"resources": types.ObjectType{AttrTypes: ItemResources},
}
var ItemMgmt = map[string]attr.Type{
"ip_addr": types.StringType,
"password": types.StringType,
"ssh_key": types.StringType,
"user": types.StringType,
}
var ItemResources = map[string]attr.Type{
"cpu": types.Int64Type,
"ram": types.Int64Type,
"stack_id": types.Int64Type,
"uuid": types.StringType,
}
var ItemVNFs = map[string]attr.Type{
"dhcp": types.ObjectType{AttrTypes: ItemDHCP},
"gw": types.ObjectType{AttrTypes: ItemGW},
"nat": types.ObjectType{AttrTypes: ItemNAT},
}
var ItemDHCP = map[string]attr.Type{
"ckey": types.StringType,
"account_id": types.Int64Type,
"config": types.ObjectType{AttrTypes: ItemDHCPConfig},
"created_time": types.Int64Type,
"devices": types.ObjectType{AttrTypes: ItemDevices},
"gid": types.Int64Type,
"guid": types.Int64Type,
"dhcp_id": types.Int64Type,
"lock_status": types.StringType,
"milestones": types.Int64Type,
"owner_id": types.Int64Type,
"owner_type": types.StringType,
"pure_virtual": types.BoolType,
"routes": types.ListType{ElemType: types.ObjectType{AttrTypes: ItemRoute}},
"status": types.StringType,
"tech_status": types.StringType,
"type": types.StringType,
}
var ItemRoute = map[string]attr.Type{
"compute_ids": types.ListType{ElemType: types.Int64Type},
"destination": types.StringType,
"gateway": types.StringType,
"guid": types.StringType,
"route_id": types.Int64Type,
"netmask": types.StringType,
}
var ItemDevices = map[string]attr.Type{
"primary": types.ObjectType{AttrTypes: ItemPrimaryDevices},
}
var ItemPrimaryDevices = map[string]attr.Type{
"dev_id": types.Int64Type,
"iface01": types.StringType,
"iface02": types.StringType,
}
var ItemDHCPConfig = map[string]attr.Type{
"default_gw": types.StringType,
"dns": types.ListType{ElemType: types.StringType},
"ip_end": types.StringType,
"ip_start": types.StringType,
"lease": types.Int64Type,
"netmask": types.Int64Type,
"network": types.StringType,
"reservations": types.ListType{ElemType: types.ObjectType{AttrTypes: ItemReservations}},
}
var ItemReservations = map[string]attr.Type{
"client_type": types.StringType,
"desc": types.StringType,
"domainname": types.StringType,
"hostname": types.StringType,
"ip": types.StringType,
"mac": types.StringType,
"type": types.StringType,
"vm_id": types.Int64Type,
}
var ItemGW = map[string]attr.Type{
"ckey": types.StringType,
"account_id": types.Int64Type,
"config": types.ObjectType{AttrTypes: ItemGWConfig},
"created_time": types.Int64Type,
"devices": types.ObjectType{AttrTypes: ItemDevices},
"gid": types.Int64Type,
"guid": types.Int64Type,
"gw_id": types.Int64Type,
"lock_status": types.StringType,
"milestones": types.Int64Type,
"owner_id": types.Int64Type,
"owner_type": types.StringType,
"pure_virtual": types.BoolType,
"routes": types.ListType{ElemType: types.ObjectType{AttrTypes: ItemRoute}},
"status": types.StringType,
"tech_status": types.StringType,
"type": types.StringType,
}
var ItemGWConfig = map[string]attr.Type{
"default_gw": types.StringType,
"ext_net_id": types.Int64Type,
"ext_net_ip": types.StringType,
"ext_netmask": types.Int64Type,
"qos": types.ObjectType{AttrTypes: ItemQOS},
}
var ItemNAT = map[string]attr.Type{
"ckey": types.StringType,
"account_id": types.Int64Type,
"config": types.ObjectType{AttrTypes: ItemNATConfig},
"created_time": types.Int64Type,
"devices": types.ObjectType{AttrTypes: ItemDevices},
"gid": types.Int64Type,
"guid": types.Int64Type,
"nat_id": types.Int64Type,
"lock_status": types.StringType,
"milestones": types.Int64Type,
"owner_id": types.Int64Type,
"owner_type": types.StringType,
"pure_virtual": types.BoolType,
"routes": types.ListType{ElemType: types.ObjectType{AttrTypes: ItemRoute}},
"status": types.StringType,
"tech_status": types.StringType,
"type": types.StringType,
}
var ItemNATConfig = map[string]attr.Type{
"net_mask": types.Int64Type,
"network": types.StringType,
"rules": types.ListType{ElemType: types.ObjectType{AttrTypes: ItemNATRule}},
}
var ItemNATRule = map[string]attr.Type{
"rule_id": types.Int64Type,
"local_ip": types.StringType,
"local_port": types.Int64Type,
"protocol": types.StringType,
"public_port_end": types.Int64Type,
"public_port_start": types.Int64Type,
"vm_id": types.Int64Type,
"vm_name": types.StringType,
}

View File

@@ -0,0 +1,24 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type DataSourceVINSAuditsModel struct {
// request fields
VinsID types.Int64 `tfsdk:"vins_id"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
Id types.String `tfsdk:"id"`
Items []ItemAuditModel `tfsdk:"items"`
}
type ItemAuditModel struct {
Call types.String `tfsdk:"call"`
ResponseTime types.Float64 `tfsdk:"response_time"`
StatusCode types.Int64 `tfsdk:"statuscode"`
Timestamp types.Float64 `tfsdk:"timestamp"`
User types.String `tfsdk:"user"`
}

View File

@@ -0,0 +1,26 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type DataSourceVINSExtNetListModel struct {
// request fields
VinsID types.Int64 `tfsdk:"vins_id"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
Id types.String `tfsdk:"id"`
Items []ItemExtNetVinsModel `tfsdk:"items"`
EntryCount types.Int64 `tfsdk:"entry_count"`
}
type ItemExtNetVinsModel struct {
DefaultGW types.String `tfsdk:"default_gw"`
ExtNetID types.Int64 `tfsdk:"ext_net_id"`
IP types.String `tfsdk:"ip"`
PrefixLen types.Int64 `tfsdk:"prefix_len"`
Status types.String `tfsdk:"status"`
TechStatus types.String `tfsdk:"tech_status"`
}

View File

@@ -0,0 +1,27 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type DataSourceVINSIPListModel struct {
// request fields
VinsID types.Int64 `tfsdk:"vins_id"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
Id types.String `tfsdk:"id"`
Items []ItemIPVinsModel `tfsdk:"items"`
EntryCount types.Int64 `tfsdk:"entry_count"`
}
type ItemIPVinsModel struct {
ClientType types.String `tfsdk:"client_type"`
DomainName types.String `tfsdk:"domain_name"`
Hostname types.String `tfsdk:"host_name"`
IP types.String `tfsdk:"ip"`
MAC types.String `tfsdk:"mac"`
Type types.String `tfsdk:"type"`
VMID types.Int64 `tfsdk:"vm_id"`
}

View File

@@ -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 DataSourceVINSListModel struct {
// request fields
ByID types.Int64 `tfsdk:"by_id"`
Name types.String `tfsdk:"name"`
AccountID types.Int64 `tfsdk:"account_id"`
RGID types.Int64 `tfsdk:"rg_id"`
ExtIP types.String `tfsdk:"ext_ip"`
VNFDevID types.Int64 `tfsdk:"vnfdev_id"`
IncludeDeleted types.Bool `tfsdk:"include_deleted"`
Page types.Int64 `tfsdk:"page"`
SortBy types.String `tfsdk:"sort_by"`
Size types.Int64 `tfsdk:"size"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
Id types.String `tfsdk:"id"`
Items []ItemVinsModel `tfsdk:"items"`
EntryCount types.Int64 `tfsdk:"entry_count"`
}
type ItemVinsModel struct {
AccountID types.Int64 `tfsdk:"account_id"`
AccountName types.String `tfsdk:"account_name"`
CreatedBy types.String `tfsdk:"created_by"`
CreatedTime types.Int64 `tfsdk:"created_time"`
DefaultGW types.String `tfsdk:"default_gw"`
DefaultQOS types.Object `tfsdk:"default_qos"`
DeletedBy types.String `tfsdk:"deleted_by"`
DeletedTime types.Int64 `tfsdk:"deleted_time"`
Description types.String `tfsdk:"description"`
ExternalIP types.String `tfsdk:"external_ip"`
ExtnetID types.Int64 `tfsdk:"extnet_id"`
FreeIPs types.Int64 `tfsdk:"free_ips"`
GID types.Int64 `tfsdk:"gid"`
GUID types.Int64 `tfsdk:"guid"`
ID types.Int64 `tfsdk:"vins_id"`
LockStatus types.String `tfsdk:"lock_status"`
ManagerID types.Int64 `tfsdk:"manager_id"`
ManagerType types.String `tfsdk:"manager_type"`
Milestones types.Int64 `tfsdk:"milestones"`
Name types.String `tfsdk:"name"`
Netmask types.Int64 `tfsdk:"netmask"`
Network types.String `tfsdk:"network"`
PreReservationsNum types.Int64 `tfsdk:"pre_reservations_num"`
PriVNFDevID types.Int64 `tfsdk:"pri_vnf_dev_id"`
Redundant types.Bool `tfsdk:"redundant"`
RGID types.Int64 `tfsdk:"rg_id"`
RGName types.String `tfsdk:"rg_name"`
SecVNFDefID types.Int64 `tfsdk:"sec_vnf_dev_id"`
Status types.String `tfsdk:"status"`
UpdatedBy types.String `tfsdk:"updated_by"`
UpdatedTime types.Int64 `tfsdk:"updated_time"`
UserManaged types.Bool `tfsdk:"user_managed"`
VNFs types.Object `tfsdk:"vnfs"`
VXLANID types.Int64 `tfsdk:"vxlan_id"`
}
type ListVNFsModel struct {
DHCP types.Int64 `tfsdk:"dhcp"`
DNS types.Int64 `tfsdk:"dns"`
FW types.Int64 `tfsdk:"fw"`
GW types.Int64 `tfsdk:"gw"`
NAT types.Int64 `tfsdk:"nat"`
VPN types.Int64 `tfsdk:"vpn"`
}
var ItemListVNFs = map[string]attr.Type{
"dhcp": types.Int64Type,
"dns": types.Int64Type,
"fw": types.Int64Type,
"gw": types.Int64Type,
"nat": types.Int64Type,
"vpn": types.Int64Type,
}

View File

@@ -0,0 +1,59 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type DataSourceVINSListDeletedModel struct {
// request fields
ByID types.Int64 `tfsdk:"by_id"`
Name types.String `tfsdk:"name"`
AccountID types.Int64 `tfsdk:"account_id"`
RGID types.Int64 `tfsdk:"rg_id"`
ExtIP types.String `tfsdk:"ext_ip"`
Page types.Int64 `tfsdk:"page"`
SortBy types.String `tfsdk:"sort_by"`
Size types.Int64 `tfsdk:"size"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
Id types.String `tfsdk:"id"`
Items []ItemVinsDeletedModel `tfsdk:"items"`
EntryCount types.Int64 `tfsdk:"entry_count"`
}
type ItemVinsDeletedModel struct {
AccountID types.Int64 `tfsdk:"account_id"`
AccountName types.String `tfsdk:"account_name"`
CreatedBy types.String `tfsdk:"created_by"`
CreatedTime types.Int64 `tfsdk:"created_time"`
DefaultGW types.String `tfsdk:"default_gw"`
DefaultQOS types.Object `tfsdk:"default_qos"`
DeletedBy types.String `tfsdk:"deleted_by"`
DeletedTime types.Int64 `tfsdk:"deleted_time"`
Description types.String `tfsdk:"description"`
ExternalIP types.String `tfsdk:"external_ip"`
GID types.Int64 `tfsdk:"gid"`
GUID types.Int64 `tfsdk:"guid"`
ID types.Int64 `tfsdk:"vins_id"`
LockStatus types.String `tfsdk:"lock_status"`
ManagerID types.Int64 `tfsdk:"manager_id"`
ManagerType types.String `tfsdk:"manager_type"`
Milestones types.Int64 `tfsdk:"milestones"`
Name types.String `tfsdk:"name"`
Netmask types.Int64 `tfsdk:"netmask"`
Network types.String `tfsdk:"network"`
PreReservationsNum types.Int64 `tfsdk:"pre_reservations_num"`
PriVNFDevID types.Int64 `tfsdk:"pri_vnf_dev_id"`
Redundant types.Bool `tfsdk:"redundant"`
RGID types.Int64 `tfsdk:"rg_id"`
RGName types.String `tfsdk:"rg_name"`
SecVNFDefID types.Int64 `tfsdk:"sec_vnf_dev_id"`
Status types.String `tfsdk:"status"`
UpdatedBy types.String `tfsdk:"updated_by"`
UpdatedTime types.Int64 `tfsdk:"updated_time"`
UserManaged types.Bool `tfsdk:"user_managed"`
VNFs types.Object `tfsdk:"vnfs"`
VXLANID types.Int64 `tfsdk:"vxlan_id"`
}

View File

@@ -0,0 +1,29 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type DataSourceVINSNATRuleListModel struct {
// request fields
VinsID types.Int64 `tfsdk:"vins_id"`
Reason types.String `tfsdk:"reason"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
Id types.String `tfsdk:"id"`
Items []ItemVINSNATRuleModel `tfsdk:"items"`
EntryCount types.Int64 `tfsdk:"entry_count"`
}
type ItemVINSNATRuleModel struct {
ID types.Int64 `tfsdk:"id"`
LocalIP types.String `tfsdk:"local_ip"`
LocalPort types.Int64 `tfsdk:"local_port"`
Protocol types.String `tfsdk:"protocol"`
PublicPortEnd types.Int64 `tfsdk:"public_port_end"`
PublicPortStart types.Int64 `tfsdk:"public_port_start"`
VMID types.Int64 `tfsdk:"vm_id"`
VMName types.String `tfsdk:"vm_name"`
}

View File

@@ -0,0 +1,21 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type DataSourceVINSStaticRouteModel struct {
// request fields
VinsID types.Int64 `tfsdk:"vins_id"`
RouteID types.Int64 `tfsdk:"route_id"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
Id types.String `tfsdk:"id"`
ComputeIds types.List `tfsdk:"compute_ids"`
Destination types.String `tfsdk:"destination"`
Gateway types.String `tfsdk:"gateway"`
GUID types.String `tfsdk:"guid"`
Netmask types.String `tfsdk:"netmask"`
}

View File

@@ -0,0 +1,26 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type DataSourceVINSStaticRouteListModel struct {
// request fields
VinsID types.Int64 `tfsdk:"vins_id"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
Id types.String `tfsdk:"id"`
Items []ItemVinsStaticRouteModel `tfsdk:"items"`
EntryCount types.Int64 `tfsdk:"entry_count"`
}
type ItemVinsStaticRouteModel struct {
ComputeIds types.List `tfsdk:"compute_ids"`
Destination types.String `tfsdk:"destination"`
Gateway types.String `tfsdk:"gateway"`
GUID types.String `tfsdk:"guid"`
ID types.Int64 `tfsdk:"route_id"`
Netmask types.String `tfsdk:"netmask"`
}

View File

@@ -0,0 +1,131 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
)
type ResourceVINSModel struct {
// required fields
Name types.String `tfsdk:"name"`
RGID types.Int64 `tfsdk:"rg_id"`
AccountID types.Int64 `tfsdk:"account_id"`
// optional fields
IPCIDR types.String `tfsdk:"ipcidr"`
PreReservationsNum types.Int64 `tfsdk:"pre_reservations_num"`
Description types.String `tfsdk:"description"`
GID types.Int64 `tfsdk:"gid"`
DNS types.Set `tfsdk:"dns"`
Enable types.Bool `tfsdk:"enable"`
Permanently types.Bool `tfsdk:"permanently"`
Force types.Bool `tfsdk:"force"`
Restore types.Bool `tfsdk:"restore"`
VnfdevStart types.Bool `tfsdk:"vnfdev_start"`
VnfdevReset types.Bool `tfsdk:"vnfdev_reset"`
VnfdevRestart types.Bool `tfsdk:"vnfdev_restart"`
VnfdevRedeploy types.Bool `tfsdk:"vnfdev_redeploy"`
DefaultQOS types.Object `tfsdk:"default_qos"`
ExtNet types.Object `tfsdk:"ext_net"`
IP types.List `tfsdk:"ip"`
NatRule types.List `tfsdk:"nat_rule"`
Reason types.String `tfsdk:"reason"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
VinsID types.Int64 `tfsdk:"vins_id"`
Id types.String `tfsdk:"id"`
LastUpdated types.String `tfsdk:"last_updated"`
VNFDev types.Object `tfsdk:"vnf_dev"`
AccountName types.String `tfsdk:"account_name"`
CreatedBy types.String `tfsdk:"created_by"`
CreatedTime types.Int64 `tfsdk:"created_time"`
DefaultGW types.String `tfsdk:"default_gw"`
DeletedBy types.String `tfsdk:"deleted_by"`
DeletedTime types.Int64 `tfsdk:"deleted_time"`
GUID types.Int64 `tfsdk:"guid"`
LockStatus types.String `tfsdk:"lock_status"`
ManagerID types.Int64 `tfsdk:"manager_id"`
ManagerType types.String `tfsdk:"manager_type"`
Milestones types.Int64 `tfsdk:"milestones"`
NetMask types.Int64 `tfsdk:"net_mask"`
Network types.String `tfsdk:"network"`
Redundant types.Bool `tfsdk:"redundant"`
RGName types.String `tfsdk:"rg_name"`
SecVNFDevID types.Int64 `tfsdk:"sec_vnf_dev_id"`
Status types.String `tfsdk:"status"`
UpdatedBy types.String `tfsdk:"updated_by"`
UpdatedTime types.Int64 `tfsdk:"updated_time"`
UserManaged types.Bool `tfsdk:"user_managed"`
VNFs types.Object `tfsdk:"vnfs"`
VXLANID types.Int64 `tfsdk:"vxlan_id"`
}
type ExtNetModel struct {
ExtNetID types.Int64 `tfsdk:"ext_net_id"`
ExtNetIP types.String `tfsdk:"ext_net_ip"`
}
type IPModel struct {
Type types.String `tfsdk:"type"`
IPAddr types.String `tfsdk:"ip_addr"`
MacAddr types.String `tfsdk:"mac_addr"`
ComputeID types.Int64 `tfsdk:"compute_id"`
Reason types.String `tfsdk:"reason"`
}
type NatRuleResourceModel struct {
IntIP types.String `tfsdk:"int_ip"`
IntPort types.Int64 `tfsdk:"int_port"`
ExtPortStart types.Int64 `tfsdk:"ext_port_start"`
ExtPortEnd types.Int64 `tfsdk:"ext_port_end"`
Proto types.String `tfsdk:"proto"`
RuleID types.Int64 `tfsdk:"rule_id"`
Reason types.String `tfsdk:"reason"`
}
var ItemNatRuleResource = map[string]attr.Type{
"int_ip": types.StringType,
"int_port": types.Int64Type,
"ext_port_start": types.Int64Type,
"ext_port_end": types.Int64Type,
"proto": types.StringType,
"rule_id": types.Int64Type,
}
// Contains returns true if NatRuleResourceModel contains n as an element. Otherwise it returns false.
func (n *NatRuleResourceModel) Contains(natRuleList []NatRuleResourceModel) bool {
for _, natRuleElem := range natRuleList {
if n.IntIP.Equal(natRuleElem.IntIP) &&
n.IntPort.Equal(natRuleElem.IntPort) &&
n.ExtPortStart.Equal(natRuleElem.ExtPortStart) {
return true
}
}
return false
}
// GetNatRule returns nat_rule from the platform equivalent to NatRuleResourceModel. If the rule doesn't exist it returns nil.
func (n *NatRuleResourceModel) GetNatRule(rules vins.ListNATRule) *vins.ItemNATRule {
for _, rule := range rules {
if n.IntIP.Equal(types.StringValue(rule.LocalIP)) &&
n.ExtPortStart.Equal(types.Int64Value(int64(rule.PublicPortStart))) {
return &rule
}
}
return nil
}
// Contains returns true if IPModel contains i as an element. Otherwise it returns false.
func (i *IPModel) Contains(ipList []IPModel) bool {
for _, ipElem := range ipList {
if i.IPAddr.Equal(ipElem.IPAddr) {
return true
}
}
return false
}

View File

@@ -0,0 +1,24 @@
package models
import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type ResourceVINSStaticRouteModel struct {
// required fields
VinsID types.Int64 `tfsdk:"vins_id"`
Destination types.String `tfsdk:"destination"`
Netmask types.String `tfsdk:"netmask"`
Gateway types.String `tfsdk:"gateway"`
// optional fields
RouteID types.Int64 `tfsdk:"route_id"`
ComputeIDs types.List `tfsdk:"compute_ids"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
Id types.String `tfsdk:"id"`
LastUpdated types.String `tfsdk:"last_updated"`
GUID types.String `tfsdk:"guid"`
}

View File

@@ -0,0 +1,424 @@
package vins
import (
"context"
"fmt"
"strconv"
"time"
"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/vins"
"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/vins/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/schemas"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/utilities"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ resource.Resource = &resourceVINS{}
_ resource.ResourceWithImportState = &resourceVINS{}
)
// NewResourceVINS is a helper function to simplify the provider implementation.
func NewResourceVINS() resource.Resource {
return &resourceVINS{}
}
// resourceVINS is the resource implementation.
type resourceVINS struct {
client *decort.DecortClient
}
// Create creates the resource and sets the initial Terraform state.
func (r *resourceVINS) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
// Get plan to create vins
var plan models.ResourceVINSModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Create resourceVINS: Error receiving the plan")
return
}
tflog.Info(ctx, "Create resourceVINS: got plan successfully", map[string]any{"name": plan.Name.ValueString()})
tflog.Info(ctx, "Create resourceVINS: start creating", map[string]any{"name": plan.Name.ValueString()})
// Set timeouts
createTimeout, diags := plan.Timeouts.Create(ctx, constants.Timeout20m)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Create resourceVINS: Error set timeout")
return
}
tflog.Info(ctx, "Create resourceVINS: 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 resourceVINS: starting input checks", map[string]any{"name": plan.Name.ValueString()})
resp.Diagnostics.Append(resourceVINSInputChecks(ctx, &plan, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Create resourceVINS: Error input checks")
return
}
tflog.Info(ctx, "Create resourceVINS: input checks successful", map[string]any{"name": plan.Name.ValueString()})
var vinsId uint64
// Make create request and get response for creation in RG
if !plan.RGID.IsUnknown() {
vinsId, diags = utilities.CreateInRGResourceVINS(ctx, &plan, r.client)
if diags.HasError() {
resp.Diagnostics.Append(diags...)
tflog.Error(ctx, "Create resourceVINS: Error response for create in RG of resource vins")
return
}
}
// Make create request and get response for creation in account
if !plan.AccountID.IsUnknown() {
vinsId, diags = utilities.CreateInAccountResourceVINS(ctx, &plan, r.client)
if diags.HasError() {
resp.Diagnostics.Append(diags...)
tflog.Error(ctx, "Create resourceVINS: Error response for create in account of resource vins")
return
}
}
plan.Id = types.StringValue(strconv.Itoa(int(vinsId)))
plan.LastUpdated = types.StringValue(time.Now().Format(time.RFC850))
tflog.Info(ctx, "Create resourceVINS: vins created", map[string]any{"vins_id": vinsId, "name": plan.Name.ValueString()})
// additional settings after vins 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.
// reserve ip for vins after creation, warnings added to resp.Diagnostics in case of failure.
if !plan.IP.IsNull() { // IP is optional
resp.Diagnostics.Append(utilities.IPCreateVINS(ctx, vinsId, &plan, r.client)...)
}
// add nat rules for vins after creation, warnings added to resp.Diagnostics in case of failure.
if !plan.NatRule.IsNull() { // NatRule is optional
resp.Diagnostics.Append(utilities.NATRuleCreateVINS(ctx, vinsId, &plan, r.client)...)
}
// update default qos for vins after creation, warnings added to resp.Diagnostics in case of failure.
if !plan.DefaultQOS.IsUnknown() { // DefaultQOS is optional && computed
resp.Diagnostics.Append(utilities.DefaultQosCreateVINS(ctx, vinsId, &plan, r.client)...)
}
tflog.Info(ctx, "Create resourceVINS: resource creation is completed", map[string]any{"vins_id": vinsId})
// Map response body to schema and populate Computed attribute values
resp.Diagnostics.Append(flattens.VINSResource(ctx, &plan, r.client)...)
if resp.Diagnostics.HasError() {
return
}
// Set data last update
plan.LastUpdated = types.StringValue(time.Now().Format(time.RFC850))
// Set state to fully populated data
resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
if resp.Diagnostics.HasError() {
return
}
}
// Read refreshes the Terraform state with the latest data.
func (r *resourceVINS) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
// Get current state
var state models.ResourceVINSModel
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read resourceVINS: Error get state")
return
}
tflog.Info(ctx, "Read resourceVINS: got state successfully", map[string]any{"vins_id": state.Id.ValueString()})
// Set timeouts
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout600s)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read resourceVINS: Error set timeout")
return
}
tflog.Info(ctx, "Read resourceVINS: set timeouts successfully", map[string]any{
"vins_id": state.Id.ValueString(),
"readTimeout": readTimeout})
ctx, cancel := context.WithTimeout(ctx, readTimeout)
defer cancel()
// read status
tflog.Info(ctx, "Read resourceVINS: before VINSReadStatus", map[string]any{"vins_id": state.Id.ValueString()})
resp.Diagnostics.Append(utilities.VINSReadStatus(ctx, &state, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read resourceVINS: Error reading status")
return
}
// Overwrite items with refreshed state
resp.Diagnostics.Append(flattens.VINSResource(ctx, &state, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read resourceVINS: Error flatten")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read resourceVINS: Error set state")
return
}
tflog.Info(ctx, "End read resourceVINS")
}
// Update updates the resource and sets the updated Terraform state on success.
func (r *resourceVINS) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
// Retrieve values from plan
var plan models.ResourceVINSModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceVINS: Error receiving the plan")
return
}
tflog.Info(ctx, "Update resourceVINS: got plan successfully", map[string]any{"vins_id": plan.Id.ValueString()})
// Retrieve values from state
var state models.ResourceVINSModel
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceVINS: Error receiving the state")
return
}
tflog.Info(ctx, "Update resourceVINS: got state successfully", map[string]any{"vins_id": state.Id.ValueString()})
// Set timeouts
updateTimeout, diags := plan.Timeouts.Update(ctx, constants.Timeout20m)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Error set timeout")
return
}
tflog.Info(ctx, "Update resourceVINS: set timeouts successfully", map[string]any{
"vins_id": state.Id.ValueString(),
"updateTimeout": updateTimeout})
ctx, cancel := context.WithTimeout(ctx, updateTimeout)
defer cancel()
// Checking for values in the platform
tflog.Info(ctx, "Update resourceVINS: starting input checks", map[string]any{"vins_id": plan.Id.ValueString()})
resp.Diagnostics.Append(resourceVINSInputChecks(ctx, &plan, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceVINS: Error input checks")
return
}
tflog.Info(ctx, "Update resourceVINS: input checks successful", map[string]any{"vins_id": state.Id.ValueString()})
vinsId, err := strconv.ParseUint(state.Id.ValueString(), 10, 64)
if err != nil {
resp.Diagnostics.AddError(fmt.Sprintf("Cannot parse vins ID %s from state", state.Id.ValueString()), err.Error())
return
}
// enable/disable vins if needed
if !plan.Enable.Equal(state.Enable) && !plan.Enable.IsNull() {
resp.Diagnostics.Append(utilities.EnableDisableUpdateVINS(ctx, vinsId, &plan, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceVINS: Error enabling/disabling vins")
return
}
}
// connect/disconnect extnet for vins if needed
if !plan.ExtNet.Equal(state.ExtNet) {
resp.Diagnostics.Append(utilities.ExtNetUpdateVINS(ctx, vinsId, &plan, &state, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceVINS: Error updating vins extnet")
return
}
}
// reserve/release ip for vins if needed
if !plan.IP.Equal(state.IP) {
resp.Diagnostics.Append(utilities.IPUpdateVINS(ctx, vinsId, &plan, &state, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceVINS: Error releasing/reserving vins ip")
return
}
}
// add/delete nat rules for vins if needed
if !plan.NatRule.Equal(state.NatRule) {
resp.Diagnostics.Append(utilities.NATRuleUpdateVINS(ctx, vinsId, &plan, &state, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceVINS: Error adding/deleting nat rules for vins")
return
}
}
// add/delete dns for vins if needed. Empty "dns" is allowed, it will update vnfs.dhcp.config.dns from current values to empty list
if !plan.DNS.IsNull() && !plan.DNS.Equal(state.DNS) {
resp.Diagnostics.Append(utilities.UpdateDNSlistVINS(ctx, vinsId, &plan, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceVINS: Error updating DNSList")
return
}
}
if !plan.DefaultQOS.IsUnknown() && !plan.DefaultQOS.Equal(state.DefaultQOS) {
resp.Diagnostics.Append(utilities.UpdateDefaultQosVINS(ctx, vinsId, &plan, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceVINS: Error updating DefaultQos")
return
}
}
// restart vnf_dev for vins if needed
if !plan.VnfdevRestart.Equal(state.VnfdevRestart) && !plan.VnfdevRestart.IsNull() {
resp.Diagnostics.Append(utilities.VnfdevRestartUpdateVINS(ctx, vinsId, &state, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceVINS: Unable to restart vnf_def for VINS")
return
}
}
// redeploy vnf_dev for vins if needed
if !plan.VnfdevRedeploy.Equal(state.VnfdevRedeploy) && !plan.VnfdevRedeploy.IsNull() {
resp.Diagnostics.Append(utilities.VnfdevRedeployUpdateVINS(ctx, vinsId, &state, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceVINS: Unable to redeploy vnf_def for VINS")
return
}
}
// reset vnf_dev for vins if needed
if !plan.VnfdevReset.Equal(state.VnfdevReset) && !plan.VnfdevReset.IsNull() {
resp.Diagnostics.Append(utilities.VnfdevResetUpdateVINS(ctx, vinsId, &state, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceVINS: Unable to reset vnf_def for VINS")
return
}
}
// start/stop vnf_dev for vins if needed
if !plan.VnfdevStart.Equal(state.VnfdevStart) && !plan.VnfdevStart.IsNull() {
resp.Diagnostics.Append(utilities.VnfdevStartStopUpdateVINS(ctx, vinsId, &state, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceVINS: Unable to start/stop vnf_def for VINS")
return
}
}
tflog.Info(ctx, "Update resourceVINS: resource update is completed", map[string]any{"vins_id": plan.Id.ValueString()})
// Map response body to schema and populate Computed attribute values
resp.Diagnostics.Append(flattens.VINSResource(ctx, &plan, r.client)...)
if resp.Diagnostics.HasError() {
return
}
// Set data last update
plan.LastUpdated = types.StringValue(time.Now().Format(time.RFC850))
// Set state to fully populated data
resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
if resp.Diagnostics.HasError() {
return
}
}
// Delete deletes the resource and removes the Terraform state on success.
func (r *resourceVINS) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
// Get current state
var state models.ResourceVINSModel
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Delete resourceVINS: Error get state")
return
}
tflog.Info(ctx, "Delete resourceVINS: got state successfully", map[string]any{"vins_id": state.Id.ValueString()})
// Set timeouts
deleteTimeout, diags := state.Timeouts.Delete(ctx, constants.Timeout600s)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Delete resourceVINS: Error set timeout")
return
}
tflog.Info(ctx, "Delete resourceVINS: set timeouts successfully", map[string]any{
"vins_id": state.Id.ValueString(),
"deleteTimeout": deleteTimeout})
ctx, cancel := context.WithTimeout(ctx, deleteTimeout)
defer cancel()
// Delete existing vins
delReq := vins.DeleteRequest{
VINSID: uint64(state.VinsID.ValueInt64()),
}
if state.Force.IsNull() {
delReq.Force = true // default value
} else {
delReq.Force = state.Force.ValueBool()
}
if state.Permanently.IsNull() {
delReq.Permanently = true // default value
} else {
delReq.Permanently = state.Permanently.ValueBool()
}
tflog.Info(ctx, "Delete resourceVINS: calling cloudbroker().VINS().Delete", map[string]any{
"vins_id": state.Id.ValueString(),
"req": delReq,
})
_, err := r.client.CloudBroker().VINS().Delete(ctx, delReq)
if err != nil {
resp.Diagnostics.AddError("Delete resourceVINS: Error deleting", err.Error())
return
}
tflog.Info(ctx, "End delete resource vins", map[string]any{"vins_id": state.Id.ValueString()})
}
// Schema defines the schema for the resource.
func (r *resourceVINS) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaResourceVINS(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx, timeouts.Opts{Create: true, Read: true, Update: true, Delete: true}),
},
}
}
// Metadata returns the resource type name.
func (r *resourceVINS) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_cb_vins"
}
// Configure adds the provider configured client to the resource.
func (r *resourceVINS) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure resourceVINS")
r.client = client.Resource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure resourceVINS successfully")
}
func (r *resourceVINS) 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)
}

View File

@@ -0,0 +1,312 @@
package vins
import (
"context"
"fmt"
"time"
"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/vins"
"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/vins/flattens"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/schemas"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/utilities"
)
// Ensure the implementation satisfies the expected interfaces.
var (
_ resource.Resource = &resourceVINSStaticRoute{}
_ resource.ResourceWithImportState = &resourceVINSStaticRoute{}
)
// NewResourceVINSStaticRoute is a helper function to simplify the provider implementation.
func NewResourceVINSStaticRoute() resource.Resource {
return &resourceVINSStaticRoute{}
}
// resourceVINSStaticRoute is the resource implementation.
type resourceVINSStaticRoute struct {
client *decort.DecortClient
}
// Create creates the resource and sets the initial Terraform state.
func (r *resourceVINSStaticRoute) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
// Get plan to create vins
var plan models.ResourceVINSStaticRouteModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Create resourceVINSStaticRoute: Error receiving the plan")
return
}
tflog.Info(ctx, "Create resourceVINSStaticRoute: got plan successfully", map[string]any{"id": plan.Id.ValueString()})
tflog.Info(ctx, "Create resourceVINSStaticRoute: start creating", map[string]any{"id": plan.Id.ValueString()})
// Set timeouts
createTimeout, diags := plan.Timeouts.Create(ctx, constants.Timeout20m)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Create resourceVINSStaticRoute: Error set timeout")
return
}
tflog.Info(ctx, "Create resourceVINSStaticRoute: set timeouts successfully", map[string]any{
"id": plan.Id.ValueString(),
"createTimeout": createTimeout})
ctx, cancel := context.WithTimeout(ctx, createTimeout)
defer cancel()
// Check if input values are valid in the platform
tflog.Info(ctx, "Create resourceVINSStaticRoute: starting input checks", map[string]any{"id": plan.Id.ValueString()})
resp.Diagnostics.Append(resourceVINSStaticRouteInputChecks(ctx, &plan, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Create resourceVINSStaticRoute: Error input checks")
return
}
tflog.Info(ctx, "Create resourceVINSStaticRoute: input checks successful", map[string]any{"id": plan.Id.ValueString()})
// Make create request and get response for vins static route creation
staticReq := vins.StaticRouteAddRequest{
VINSID: uint64(plan.VinsID.ValueInt64()),
Destination: plan.Destination.ValueString(),
Netmask: plan.Netmask.ValueString(),
Gateway: plan.Gateway.ValueString(),
}
if !plan.ComputeIDs.IsUnknown() {
computes := make([]uint64, 0, len(plan.ComputeIDs.Elements()))
diags = plan.ComputeIDs.ElementsAs(ctx, &computes, false)
if diags.HasError() {
resp.Diagnostics.Append(diags...)
tflog.Error(ctx, "Create resourceVINSStaticRoute: cannot populate computes with plan.ComputeIDs List elements")
return
}
staticReq.ComputeIds = computes
}
_, err := r.client.CloudBroker().VINS().StaticRouteAdd(ctx, staticReq)
if err != nil {
resp.Diagnostics.AddError("Create resourceVINSStaticRoute: Error adding static route to vins", err.Error())
return
}
routeId, diags := utilities.GetStaticRouteID(ctx, &plan, r.client)
if diags.HasError() {
resp.Diagnostics.Append(diags...)
tflog.Error(ctx, "Create resourceVINSStaticRoute: cannot get route id")
return
}
plan.Id = types.StringValue(fmt.Sprintf("%d#%d", plan.VinsID.ValueInt64(), routeId))
tflog.Info(ctx, "Create resourceVINSStaticRoute: resource creation is completed", map[string]any{"id": plan.Id.ValueString()})
// Map response body to schema and populate Computed attribute values
resp.Diagnostics.Append(flattens.VINSStaticRouteResource(ctx, &plan, r.client)...)
if resp.Diagnostics.HasError() {
return
}
plan.LastUpdated = types.StringValue(time.Now().Format(time.RFC850))
// Set state to fully populated data
resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
if resp.Diagnostics.HasError() {
return
}
}
// Read refreshes the Terraform state with the latest data.
func (r *resourceVINSStaticRoute) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
// Get current state
var state models.ResourceVINSStaticRouteModel
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read resourceVINSStaticRoute: Error get state")
return
}
tflog.Info(ctx, "Read resourceVINSStaticRoute: got state successfully", map[string]any{"vins_id": state.Id.ValueString()})
// Set timeouts
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout600s)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read resourceVINSStaticRoute: Error set timeout")
return
}
tflog.Info(ctx, "Read resourceVINSStaticRoute: set timeouts successfully", map[string]any{
"vins_id": state.Id.ValueString(),
"readTimeout": readTimeout})
ctx, cancel := context.WithTimeout(ctx, readTimeout)
defer cancel()
// Overwrite items with refreshed state
resp.Diagnostics.Append(flattens.VINSStaticRouteResource(ctx, &state, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read resourceVINSStaticRoute: Error flatten")
return
}
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Read resourceVINSStaticRoute: Error set state")
return
}
tflog.Info(ctx, "End read resourceVINSStaticRoute")
}
// Update updates the resource and sets the updated Terraform state on success.
func (r *resourceVINSStaticRoute) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
// Retrieve values from plan
var plan models.ResourceVINSStaticRouteModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceVINSStaticRoute: Error receiving the plan")
return
}
tflog.Info(ctx, "Update resourceVINSStaticRoute: got plan successfully", map[string]any{"id": plan.Id.ValueString()})
// Retrieve values from state
var state models.ResourceVINSStaticRouteModel
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceVINSStaticRoute: Error receiving the state")
return
}
tflog.Info(ctx, "Update resourceVINSStaticRoute: got state successfully", map[string]any{"id": state.Id.ValueString()})
// Set timeouts
updateTimeout, diags := plan.Timeouts.Update(ctx, constants.Timeout20m)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Error set timeout")
return
}
tflog.Info(ctx, "Update resourceVINSStaticRoute: 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 resourceVINSStaticRoute: starting input checks", map[string]any{"id": plan.Id.ValueString()})
resp.Diagnostics.Append(resourceVINSStaticRouteInputChecks(ctx, &plan, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceVINS: Error input checks")
return
}
tflog.Info(ctx, "Update resourceVINSStaticRoute: input checks successful", map[string]any{"id": state.Id.ValueString()})
// change compute_ids, if needed
if !plan.ComputeIDs.Equal(state.ComputeIDs) {
resp.Diagnostics.Append(utilities.UpdateComputeIDsVINSStaticRoute(ctx, &plan, &state, r.client)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Update resourceVINSStaticRoute: Error updating compute_ids")
return
}
}
tflog.Info(ctx, "Update resourceVINSStaticRoute: 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.VINSStaticRouteResource(ctx, &plan, r.client)...)
if resp.Diagnostics.HasError() {
return
}
// Set data last update
plan.LastUpdated = types.StringValue(time.Now().Format(time.RFC850))
// Set state to fully populated data
resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
if resp.Diagnostics.HasError() {
return
}
}
// Delete deletes the resource and removes the Terraform state on success.
func (r *resourceVINSStaticRoute) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
// Get current state
var state models.ResourceVINSStaticRouteModel
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Delete resourceVINSStaticRoute: Error get state")
return
}
tflog.Info(ctx, "Delete resourceVINSStaticRoute: got state successfully", map[string]any{"id": state.Id.ValueString()})
// Set timeouts
deleteTimeout, diags := state.Timeouts.Delete(ctx, constants.Timeout600s)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
tflog.Error(ctx, "Delete resourceVINSStaticRoute: Error set timeout")
return
}
tflog.Info(ctx, "Delete resourceVINSStaticRoute: set timeouts successfully", map[string]any{
"id": state.Id.ValueString(),
"deleteTimeout": deleteTimeout})
ctx, cancel := context.WithTimeout(ctx, deleteTimeout)
defer cancel()
vinsId, routeId, diags := utilities.GetVinsIDAndRouteID(ctx, &state)
if diags.HasError() {
resp.Diagnostics.Append(diags...)
return
}
// Delete static route
delReq := vins.StaticRouteDelRequest{
VINSID: vinsId,
RouteId: routeId,
}
tflog.Info(ctx, "Delete resourceVINSStaticRoute: calling cloudbroker().VINS().StaticRouteDel", map[string]any{
"id": state.Id.ValueString(),
"req": delReq,
})
_, err := r.client.CloudBroker().VINS().StaticRouteDel(ctx, delReq)
if err != nil {
resp.Diagnostics.AddError("Delete resourceVINSStaticRoute: Error deleting", err.Error())
return
}
tflog.Info(ctx, "End delete resourceVINSStaticRoute", map[string]any{"id": state.Id.ValueString()})
}
// Schema defines the schema for the resource.
func (r *resourceVINSStaticRoute) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: schemas.MakeSchemaResourceVINSStaticRoute(),
Blocks: map[string]schema.Block{
"timeouts": timeouts.Block(ctx, timeouts.Opts{Create: true, Read: true, Update: true, Delete: true}),
},
}
}
// Metadata returns the resource type name.
func (r *resourceVINSStaticRoute) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_cb_vins_static_route"
}
// Configure adds the provider configured client to the resource.
func (r *resourceVINSStaticRoute) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
tflog.Info(ctx, "Get Configure resourceVINSStaticRoute")
r.client = client.Resource(ctx, &req, resp)
tflog.Info(ctx, "Getting Configure resourceVINSStaticRoute successfully")
}
func (r *resourceVINSStaticRoute) 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)
}

View File

@@ -0,0 +1,717 @@
package schemas
import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)
func MakeSchemaDataSourceVINS() map[string]schema.Attribute {
return map[string]schema.Attribute{
// required attributes
"vins_id": schema.Int64Attribute{
Required: true,
Description: "Unique ID of the ViNS.",
},
// optional attributes
"reason": schema.StringAttribute{
Optional: true,
Description: "reason for action",
},
// computed attributes
"id": schema.StringAttribute{
Computed: true,
},
"vnf_dev": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"ckey": schema.StringAttribute{
Computed: true,
},
"account_id": schema.Int64Attribute{
Computed: true,
},
"capabilities": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
},
"config": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"mgmt": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"ip_addr": schema.StringAttribute{
Computed: true,
},
"password": schema.StringAttribute{
Computed: true,
},
"ssh_key": schema.StringAttribute{
Computed: true,
},
"user": schema.StringAttribute{
Computed: true,
},
},
},
"resources": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"cpu": schema.Int64Attribute{
Computed: true,
},
"ram": schema.Int64Attribute{
Computed: true,
},
"stack_id": schema.Int64Attribute{
Computed: true,
},
"uuid": schema.StringAttribute{
Computed: true,
},
},
},
},
},
"config_saved": schema.BoolAttribute{
Computed: true,
},
"custom_precfg": schema.BoolAttribute{
Computed: true,
},
"description": schema.StringAttribute{
Computed: true,
},
"gid": schema.Int64Attribute{
Computed: true,
},
"guid": schema.Int64Attribute{
Computed: true,
},
"id": schema.Int64Attribute{
Computed: true,
},
"interfaces": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"conn_id": schema.Int64Attribute{
Computed: true,
},
"conn_type": schema.StringAttribute{
Computed: true,
},
"def_gw": schema.StringAttribute{
Computed: true,
},
"enabled": schema.BoolAttribute{
Computed: true,
},
"flipgroup_id": schema.Int64Attribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"ip_address": schema.StringAttribute{
Computed: true,
},
"listen_ssh": schema.BoolAttribute{
Computed: true,
},
"mac": schema.StringAttribute{
Computed: true,
},
"name": schema.StringAttribute{
Computed: true,
},
"net_id": schema.Int64Attribute{
Computed: true,
},
"net_mask": schema.Int64Attribute{
Computed: true,
},
"net_type": schema.StringAttribute{
Computed: true,
},
"node_id": schema.Int64Attribute{
Computed: true,
},
"pci_slot": schema.Int64Attribute{
Computed: true,
},
"qos": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"e_rate": schema.Int64Attribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"in_burst": schema.Int64Attribute{
Computed: true,
},
"in_rate": schema.Int64Attribute{
Computed: true,
},
},
},
"target": schema.StringAttribute{
Computed: true,
},
"type": schema.StringAttribute{
Computed: true,
},
"vnfs": schema.ListAttribute{
Computed: true,
ElementType: types.Int64Type,
},
},
},
},
"lock_status": schema.StringAttribute{
Computed: true,
},
"meta": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
},
"milestones": schema.Int64Attribute{
Computed: true,
},
"name": schema.StringAttribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
"tech_status": schema.StringAttribute{
Computed: true,
},
"type": schema.StringAttribute{
Computed: true,
},
"vins": schema.ListAttribute{
Computed: true,
ElementType: types.Int64Type,
},
},
},
"account_id": schema.Int64Attribute{
Computed: true,
},
"account_name": schema.StringAttribute{
Computed: true,
},
"created_by": schema.StringAttribute{
Computed: true,
},
"created_time": schema.Int64Attribute{
Computed: true,
},
"default_gw": schema.StringAttribute{
Computed: true,
},
"default_qos": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"e_rate": schema.Int64Attribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"in_burst": schema.Int64Attribute{
Computed: true,
},
"in_rate": schema.Int64Attribute{
Computed: true,
},
},
},
"deleted_by": schema.StringAttribute{
Computed: true,
},
"deleted_time": schema.Int64Attribute{
Computed: true,
},
"description": schema.StringAttribute{
Computed: true,
},
"gid": schema.Int64Attribute{
Computed: true,
},
"guid": schema.Int64Attribute{
Computed: true,
},
"lock_status": schema.StringAttribute{
Computed: true,
},
"manager_id": schema.Int64Attribute{
Computed: true,
},
"manager_type": schema.StringAttribute{
Computed: true,
},
"milestones": schema.Int64Attribute{
Computed: true,
},
"name": schema.StringAttribute{
Computed: true,
},
"netmask": schema.Int64Attribute{
Computed: true,
},
"network": schema.StringAttribute{
Computed: true,
},
"pre_reservations_num": schema.Int64Attribute{
Computed: true,
},
"redundant": schema.BoolAttribute{
Computed: true,
},
"rg_id": schema.Int64Attribute{
Computed: true,
},
"rg_name": schema.StringAttribute{
Computed: true,
},
"sec_vnf_dev_id": schema.Int64Attribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
"updated_by": schema.StringAttribute{
Computed: true,
},
"updated_time": schema.Int64Attribute{
Computed: true,
},
"user_managed": schema.BoolAttribute{
Computed: true,
},
"vnfs": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"dhcp": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"ckey": schema.StringAttribute{
Computed: true,
},
"account_id": schema.Int64Attribute{
Computed: true,
},
"config": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"default_gw": schema.StringAttribute{
Computed: true,
},
"dns": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
},
"ip_end": schema.StringAttribute{
Computed: true,
},
"ip_start": schema.StringAttribute{
Computed: true,
},
"lease": schema.Int64Attribute{
Computed: true,
},
"netmask": schema.Int64Attribute{
Computed: true,
},
"network": schema.StringAttribute{
Computed: true,
},
"reservations": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"client_type": schema.StringAttribute{
Computed: true,
},
"desc": schema.StringAttribute{
Computed: true,
},
"domainname": schema.StringAttribute{
Computed: true,
},
"hostname": 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,
},
},
},
},
},
},
"created_time": schema.Int64Attribute{
Computed: true,
},
"devices": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"primary": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"dev_id": schema.Int64Attribute{
Computed: true,
},
"iface01": schema.StringAttribute{
Computed: true,
},
"iface02": schema.StringAttribute{
Computed: true,
},
},
},
},
},
"gid": schema.Int64Attribute{
Computed: true,
},
"guid": schema.Int64Attribute{
Computed: true,
},
"dhcp_id": schema.Int64Attribute{
Computed: true,
},
"lock_status": schema.StringAttribute{
Computed: true,
},
"milestones": schema.Int64Attribute{
Computed: true,
},
"owner_id": schema.Int64Attribute{
Computed: true,
},
"owner_type": schema.StringAttribute{
Computed: true,
},
"pure_virtual": schema.BoolAttribute{
Computed: true,
},
"routes": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"route_id": schema.Int64Attribute{
Computed: true,
},
"compute_ids": schema.ListAttribute{
Computed: true,
ElementType: types.Int64Type,
},
"destination": schema.StringAttribute{
Computed: true,
},
"gateway": schema.StringAttribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"netmask": schema.StringAttribute{
Computed: true,
},
},
},
},
"status": schema.StringAttribute{
Computed: true,
},
"tech_status": schema.StringAttribute{
Computed: true,
},
"type": schema.StringAttribute{
Computed: true,
},
},
},
"gw": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"ckey": schema.StringAttribute{
Computed: true,
},
"account_id": schema.Int64Attribute{
Computed: true,
},
"config": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"default_gw": schema.StringAttribute{
Computed: true,
},
"ext_net_id": schema.Int64Attribute{
Computed: true,
},
"ext_net_ip": schema.StringAttribute{
Computed: true,
},
"ext_netmask": schema.Int64Attribute{
Computed: true,
},
"qos": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"e_rate": schema.Int64Attribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"in_burst": schema.Int64Attribute{
Computed: true,
},
"in_rate": schema.Int64Attribute{
Computed: true,
},
},
},
},
},
"created_time": schema.Int64Attribute{
Computed: true,
},
"devices": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"primary": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"dev_id": schema.Int64Attribute{
Computed: true,
},
"iface01": schema.StringAttribute{
Computed: true,
},
"iface02": schema.StringAttribute{
Computed: true,
},
},
},
},
},
"gid": schema.Int64Attribute{
Computed: true,
},
"guid": schema.Int64Attribute{
Computed: true,
},
"gw_id": schema.Int64Attribute{
Computed: true,
},
"lock_status": schema.StringAttribute{
Computed: true,
},
"milestones": schema.Int64Attribute{
Computed: true,
},
"owner_id": schema.Int64Attribute{
Computed: true,
},
"owner_type": schema.StringAttribute{
Computed: true,
},
"pure_virtual": schema.BoolAttribute{
Computed: true,
},
"routes": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"compute_ids": schema.ListAttribute{
Computed: true,
ElementType: types.Int64Type,
},
"route_id": schema.Int64Attribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"destination": schema.StringAttribute{
Computed: true,
},
"netmask": schema.StringAttribute{
Computed: true,
},
"gateway": schema.StringAttribute{
Computed: true,
},
},
},
},
"status": schema.StringAttribute{
Computed: true,
},
"tech_status": schema.StringAttribute{
Computed: true,
},
"type": schema.StringAttribute{
Computed: true,
},
},
},
"nat": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"ckey": schema.StringAttribute{
Computed: true,
},
"account_id": schema.Int64Attribute{
Computed: true,
},
"config": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"net_mask": schema.Int64Attribute{
Computed: true,
},
"network": schema.StringAttribute{
Computed: true,
},
"rules": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"rule_id": schema.Int64Attribute{
Computed: true,
},
"local_ip": schema.StringAttribute{
Computed: true,
},
"local_port": schema.Int64Attribute{
Computed: true,
},
"protocol": schema.StringAttribute{
Computed: true,
},
"public_port_end": schema.Int64Attribute{
Computed: true,
},
"public_port_start": schema.Int64Attribute{
Computed: true,
},
"vm_id": schema.Int64Attribute{
Computed: true,
},
"vm_name": schema.StringAttribute{
Computed: true,
},
},
},
},
},
},
"created_time": schema.Int64Attribute{
Computed: true,
},
"devices": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"primary": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"dev_id": schema.Int64Attribute{
Computed: true,
},
"iface01": schema.StringAttribute{
Computed: true,
},
"iface02": schema.StringAttribute{
Computed: true,
},
},
},
},
},
"gid": schema.Int64Attribute{
Computed: true,
},
"guid": schema.Int64Attribute{
Computed: true,
},
"nat_id": schema.Int64Attribute{
Computed: true,
},
"lock_status": schema.StringAttribute{
Computed: true,
},
"milestones": schema.Int64Attribute{
Computed: true,
},
"owner_id": schema.Int64Attribute{
Computed: true,
},
"owner_type": schema.StringAttribute{
Computed: true,
},
"pure_virtual": schema.BoolAttribute{
Computed: true,
},
"routes": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"compute_ids": schema.ListAttribute{
Computed: true,
ElementType: types.Int64Type,
},
"route_id": schema.Int64Attribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"destination": schema.StringAttribute{
Computed: true,
},
"netmask": schema.StringAttribute{
Computed: true,
},
"gateway": schema.StringAttribute{
Computed: true,
},
},
},
},
"status": schema.StringAttribute{
Computed: true,
},
"tech_status": schema.StringAttribute{
Computed: true,
},
"type": schema.StringAttribute{
Computed: true,
},
},
},
},
},
"vxlan_id": schema.Int64Attribute{
Computed: true,
},
}
}

View File

@@ -0,0 +1,42 @@
package schemas
import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
)
func MakeSchemaDataSourceVINSAudits() map[string]schema.Attribute {
return map[string]schema.Attribute{
// required attributes
"vins_id": schema.Int64Attribute{
Required: true,
Description: "Unique ID of the ViNS.",
},
// computed attributes
"id": schema.StringAttribute{
Computed: true,
},
"items": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"call": schema.StringAttribute{
Computed: true,
},
"response_time": schema.Float64Attribute{
Computed: true,
},
"statuscode": schema.Int64Attribute{
Computed: true,
},
"timestamp": schema.Float64Attribute{
Computed: true,
},
"user": schema.StringAttribute{
Computed: true,
},
},
},
},
}
}

View File

@@ -0,0 +1,48 @@
package schemas
import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
)
func MakeSchemaDataSourceVINSExtNetList() map[string]schema.Attribute {
return map[string]schema.Attribute{
// required attributes
"vins_id": schema.Int64Attribute{
Required: true,
Description: "Unique ID of the ViNS.",
},
// computed attributes
"id": schema.StringAttribute{
Computed: true,
},
"items": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"default_gw": schema.StringAttribute{
Computed: true,
},
"ext_net_id": schema.Int64Attribute{
Computed: true,
},
"ip": schema.StringAttribute{
Computed: true,
},
"prefix_len": schema.Int64Attribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
"tech_status": schema.StringAttribute{
Computed: true,
},
},
},
},
"entry_count": schema.Int64Attribute{
Computed: true,
},
}
}

View File

@@ -0,0 +1,51 @@
package schemas
import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
)
func MakeSchemaDataSourceVINSIPList() map[string]schema.Attribute {
return map[string]schema.Attribute{
// required attributes
"vins_id": schema.Int64Attribute{
Required: true,
Description: "Unique ID of the ViNS",
},
// computed attributes
"id": schema.StringAttribute{
Computed: true,
},
"items": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"client_type": schema.StringAttribute{
Computed: true,
},
"domain_name": schema.StringAttribute{
Computed: true,
},
"host_name": 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,
},
},
},
},
"entry_count": schema.Int64Attribute{
Computed: true,
},
}
}

View File

@@ -0,0 +1,202 @@
package schemas
import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
)
func MakeSchemaDataSourceVINSList() map[string]schema.Attribute {
return map[string]schema.Attribute{
// optional attributes
"by_id": schema.Int64Attribute{
Optional: true,
Description: "Filter by ID",
},
"name": schema.StringAttribute{
Optional: true,
Description: "Filter by Name",
},
"account_id": schema.Int64Attribute{
Optional: true,
Description: "Filter by Account ID",
},
"rg_id": schema.Int64Attribute{
Optional: true,
Description: "Filter by RG ID",
},
"ext_ip": schema.StringAttribute{
Optional: true,
Description: "Filter by external IP address",
},
"vnfdev_id": schema.Int64Attribute{
Optional: true,
Description: "find by VNF Device id",
},
"include_deleted": schema.BoolAttribute{
Optional: true,
Description: "Include deleted computes",
},
"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: "Page size",
},
// 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,
},
"created_by": schema.StringAttribute{
Computed: true,
},
"created_time": schema.Int64Attribute{
Computed: true,
},
"default_gw": schema.StringAttribute{
Computed: true,
},
"default_qos": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"e_rate": schema.Int64Attribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"in_burst": schema.Int64Attribute{
Computed: true,
},
"in_rate": schema.Int64Attribute{
Computed: true,
},
},
},
"deleted_by": schema.StringAttribute{
Computed: true,
},
"deleted_time": schema.Int64Attribute{
Computed: true,
},
"description": schema.StringAttribute{
Computed: true,
},
"external_ip": schema.StringAttribute{
Computed: true,
},
"extnet_id": schema.Int64Attribute{
Computed: true,
},
"free_ips": schema.Int64Attribute{
Computed: true,
},
"gid": schema.Int64Attribute{
Computed: true,
},
"guid": schema.Int64Attribute{
Computed: true,
},
"vins_id": schema.Int64Attribute{
Computed: true,
},
"lock_status": schema.StringAttribute{
Computed: true,
},
"manager_id": schema.Int64Attribute{
Computed: true,
},
"manager_type": schema.StringAttribute{
Computed: true,
},
"milestones": schema.Int64Attribute{
Computed: true,
},
"name": schema.StringAttribute{
Computed: true,
},
"netmask": schema.Int64Attribute{
Computed: true,
},
"network": schema.StringAttribute{
Computed: true,
},
"pre_reservations_num": schema.Int64Attribute{
Computed: true,
},
"pri_vnf_dev_id": schema.Int64Attribute{
Computed: true,
},
"redundant": schema.BoolAttribute{
Computed: true,
},
"rg_id": schema.Int64Attribute{
Computed: true,
},
"rg_name": schema.StringAttribute{
Computed: true,
},
"sec_vnf_dev_id": schema.Int64Attribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
"updated_by": schema.StringAttribute{
Computed: true,
},
"updated_time": schema.Int64Attribute{
Computed: true,
},
"user_managed": schema.BoolAttribute{
Computed: true,
},
"vnfs": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"dhcp": schema.Int64Attribute{
Computed: true,
},
"dns": schema.Int64Attribute{
Computed: true,
},
"fw": schema.Int64Attribute{
Computed: true,
},
"gw": schema.Int64Attribute{
Computed: true,
},
"nat": schema.Int64Attribute{
Computed: true,
},
"vpn": schema.Int64Attribute{
Computed: true,
},
},
},
"vxlan_id": schema.Int64Attribute{
Computed: true,
},
},
},
},
"entry_count": schema.Int64Attribute{
Computed: true,
},
}
}

View File

@@ -0,0 +1,188 @@
package schemas
import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
)
func MakeSchemaDataSourceVINSListDeleted() map[string]schema.Attribute {
return map[string]schema.Attribute{
// optional attributes
"by_id": schema.Int64Attribute{
Optional: true,
Description: "Filter by ID",
},
"name": schema.StringAttribute{
Optional: true,
Description: "Filter by Name",
},
"account_id": schema.Int64Attribute{
Optional: true,
Description: "Filter by Account ID",
},
"rg_id": schema.Int64Attribute{
Optional: true,
Description: "Filter by RG ID",
},
"ext_ip": schema.StringAttribute{
Optional: true,
Description: "Filter by external IP address",
},
"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: "Page size",
},
// 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,
},
"created_by": schema.StringAttribute{
Computed: true,
},
"created_time": schema.Int64Attribute{
Computed: true,
},
"default_gw": schema.StringAttribute{
Computed: true,
},
"default_qos": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"e_rate": schema.Int64Attribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"in_burst": schema.Int64Attribute{
Computed: true,
},
"in_rate": schema.Int64Attribute{
Computed: true,
},
},
},
"deleted_by": schema.StringAttribute{
Computed: true,
},
"deleted_time": schema.Int64Attribute{
Computed: true,
},
"description": schema.StringAttribute{
Computed: true,
},
"external_ip": schema.StringAttribute{
Computed: true,
},
"gid": schema.Int64Attribute{
Computed: true,
},
"guid": schema.Int64Attribute{
Computed: true,
},
"vins_id": schema.Int64Attribute{
Computed: true,
},
"lock_status": schema.StringAttribute{
Computed: true,
},
"manager_id": schema.Int64Attribute{
Computed: true,
},
"manager_type": schema.StringAttribute{
Computed: true,
},
"milestones": schema.Int64Attribute{
Computed: true,
},
"name": schema.StringAttribute{
Computed: true,
},
"netmask": schema.Int64Attribute{
Computed: true,
},
"network": schema.StringAttribute{
Computed: true,
},
"pre_reservations_num": schema.Int64Attribute{
Computed: true,
},
"pri_vnf_dev_id": schema.Int64Attribute{
Computed: true,
},
"redundant": schema.BoolAttribute{
Computed: true,
},
"rg_id": schema.Int64Attribute{
Computed: true,
},
"rg_name": schema.StringAttribute{
Computed: true,
},
"sec_vnf_dev_id": schema.Int64Attribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
"updated_by": schema.StringAttribute{
Computed: true,
},
"updated_time": schema.Int64Attribute{
Computed: true,
},
"user_managed": schema.BoolAttribute{
Computed: true,
},
"vnfs": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"dhcp": schema.Int64Attribute{
Computed: true,
},
"dns": schema.Int64Attribute{
Computed: true,
},
"fw": schema.Int64Attribute{
Computed: true,
},
"gw": schema.Int64Attribute{
Computed: true,
},
"nat": schema.Int64Attribute{
Computed: true,
},
"vpn": schema.Int64Attribute{
Computed: true,
},
},
},
"vxlan_id": schema.Int64Attribute{
Computed: true,
},
},
},
},
"entry_count": schema.Int64Attribute{
Computed: true,
},
}
}

View File

@@ -0,0 +1,59 @@
package schemas
import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
)
func MakeSchemaDataSourceVINSNATRuleList() map[string]schema.Attribute {
return map[string]schema.Attribute{
// required attributes
"vins_id": schema.Int64Attribute{
Required: true,
Description: "VINS id",
},
// optional attributes
"reason": schema.StringAttribute{
Optional: true,
Description: "reason for action",
},
// computed attributes
"id": schema.StringAttribute{
Computed: true,
},
"items": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"id": schema.Int64Attribute{
Computed: true,
},
"local_ip": schema.StringAttribute{
Computed: true,
},
"local_port": schema.Int64Attribute{
Computed: true,
},
"protocol": schema.StringAttribute{
Computed: true,
},
"public_port_end": schema.Int64Attribute{
Computed: true,
},
"public_port_start": schema.Int64Attribute{
Computed: true,
},
"vm_id": schema.Int64Attribute{
Computed: true,
},
"vm_name": schema.StringAttribute{
Computed: true,
},
},
},
},
"entry_count": schema.Int64Attribute{
Computed: true,
},
}
}

View File

@@ -0,0 +1,41 @@
package schemas
import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)
func MakeSchemaDataSourceVINSStaticRoute() map[string]schema.Attribute {
return map[string]schema.Attribute{
// required attributes
"vins_id": schema.Int64Attribute{
Required: true,
Description: "vins ID",
},
"route_id": schema.Int64Attribute{
Required: true,
Description: "static route ID",
},
// computed attributes
"id": schema.StringAttribute{
Computed: true,
},
"compute_ids": schema.ListAttribute{
Computed: true,
ElementType: types.Int64Type,
},
"destination": schema.StringAttribute{
Computed: true,
},
"gateway": schema.StringAttribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"netmask": schema.StringAttribute{
Computed: true,
},
}
}

View File

@@ -0,0 +1,50 @@
package schemas
import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)
func MakeSchemaDataSourceVINSStaticRouteList() map[string]schema.Attribute {
return map[string]schema.Attribute{
// required attributes
"vins_id": schema.Int64Attribute{
Required: true,
Description: "vins ID",
},
// computed attributes
"id": schema.StringAttribute{
Computed: true,
},
"items": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"compute_ids": schema.ListAttribute{
Computed: true,
ElementType: types.Int64Type,
},
"destination": schema.StringAttribute{
Computed: true,
},
"gateway": schema.StringAttribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"netmask": schema.StringAttribute{
Computed: true,
},
"route_id": schema.Int64Attribute{
Computed: true,
},
},
},
},
"entry_count": schema.Int64Attribute{
Computed: true,
},
}
}

View File

@@ -0,0 +1,884 @@
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"
"github.com/hashicorp/terraform-plugin-framework/types"
)
func MakeSchemaResourceVINS() map[string]schema.Attribute {
return map[string]schema.Attribute{
// required attributes
"name": schema.StringAttribute{
Required: true,
Description: "vins name",
},
// optional attributes
"rg_id": schema.Int64Attribute{
Optional: true, // either rg_id or account_id must be specified
Computed: true,
Description: "resource group id, used for creating vins in resource group",
},
"account_id": schema.Int64Attribute{
Optional: true, // either rg_id or account_id must be specified
Computed: true,
Description: "account id, used for creating vins in account",
},
"ipcidr": schema.StringAttribute{
Optional: true,
Description: "private network IP CIDR, used for creating vins either in resource group or in account",
},
"pre_reservations_num": schema.Int64Attribute{
Optional: true,
Computed: true,
Description: "number of pre created reservations, used for creating vins either in resource group or in account",
// default is 32
},
"description": schema.StringAttribute{
Optional: true,
Computed: true,
Description: "description, used for creating vins either in resource group or in account",
// default is ""
},
"dns": schema.SetAttribute{
Optional: true,
ElementType: types.StringType,
Description: "list of DNS ip address",
},
"gid": schema.Int64Attribute{
Optional: true,
Computed: true,
Description: "grid (platform) ID, used for creating vins in account",
},
"enable": schema.BoolAttribute{
Optional: true,
Description: "flag to enable/disable vins",
// default is true
},
"permanently": schema.BoolAttribute{
Optional: true,
Description: "flag to delete vins permanently",
// default is false
},
"force": schema.BoolAttribute{
Optional: true,
Description: "flag to force delete of non-empty vins",
// default is false
},
"restore": schema.BoolAttribute{
Optional: true,
Description: "flag to restore vins",
// default is false
},
"vnfdev_start": schema.BoolAttribute{
Optional: true,
Description: "true to start vnfdev, false to stop vnfdev",
// default is false
},
"vnfdev_reset": schema.BoolAttribute{
Optional: true,
Description: "reset ViNS's primary vnf device",
// default is false
},
"vnfdev_restart": schema.BoolAttribute{
Optional: true,
Description: "flag to restart vnfdev",
// default is false
},
"vnfdev_redeploy": schema.BoolAttribute{
Optional: true,
Description: "flag to redeploy vnfdev",
// default is false
},
"reason": schema.StringAttribute{
Optional: true,
Description: "reason for action",
},
"ext_net": schema.SingleNestedAttribute{
Optional: true,
Description: "connect/disconnect vins to/from external network",
Attributes: map[string]schema.Attribute{
"ext_net_id": schema.Int64Attribute{
Optional: true,
Description: "external network ID",
// default is -1
},
"ext_net_ip": schema.StringAttribute{
Optional: true,
Description: "directly set IP address",
// default is ""
},
},
},
"ip": schema.ListNestedAttribute{
Optional: true,
Description: "ip reserve/release",
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"type": schema.StringAttribute{
Required: true,
Description: "type of the reservation",
Validators: []validator.String{
stringvalidator.OneOfCaseInsensitive("DHCP", "VIP", "EXCLUDED"), // case is ignored
},
},
"ip_addr": schema.StringAttribute{
Optional: true,
Description: "IP address to use. Non-empty string is required for type EXCLUDE. Ignored for types DHCP and VIP.",
},
"mac_addr": schema.StringAttribute{
Optional: true,
Description: "MAC address to associate with IP reservation. Ignored for type EXCLUDE, non-empty string is required for DHCP and VIP.",
},
"compute_id": schema.Int64Attribute{
Optional: true,
Description: "ID of the compute, associated with this reservation of type DHCP. Ignored for other types.",
},
"reason": schema.StringAttribute{
Optional: true,
},
},
},
},
"nat_rule": schema.ListNestedAttribute{
Optional: true,
Description: "create/delete NAT (port forwarding rule) on vins",
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"int_ip": schema.StringAttribute{
Required: true,
Description: "internal IP address to apply this rule to",
},
"int_port": schema.Int64Attribute{
Optional: true,
Computed: true,
Description: "internal IP port number to use for this rule",
},
"ext_port_start": schema.Int64Attribute{
Required: true,
Description: "external IP start port to use for this rule",
},
"ext_port_end": schema.Int64Attribute{
Optional: true,
Computed: true,
Description: "external IP end port to use for this rule",
},
"proto": schema.StringAttribute{
Optional: true,
Computed: true,
Description: "IP protocol type (tcp or udp)",
Validators: []validator.String{
stringvalidator.OneOf("tcp", "udp"), // case is not ignored
},
},
"rule_id": schema.Int64Attribute{
Computed: true,
Description: "rule id",
},
"reason": schema.StringAttribute{
Optional: true,
},
},
},
},
"default_qos": schema.SingleNestedAttribute{
Optional: true,
Computed: true,
Attributes: map[string]schema.Attribute{
"e_rate": schema.Int64Attribute{
Optional: true,
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"in_burst": schema.Int64Attribute{
Optional: true,
Computed: true,
},
"in_rate": schema.Int64Attribute{
Optional: true,
Computed: true,
},
},
},
// computed attributes
"id": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"vins_id": schema.Int64Attribute{
Computed: true,
Description: "Unique ID of the ViNS. If ViNS ID is specified, then ViNS name, rg_id and account_id are ignored.",
},
"last_updated": schema.StringAttribute{
Computed: true,
},
"vnf_dev": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"ckey": schema.StringAttribute{
Computed: true,
},
"account_id": schema.Int64Attribute{
Computed: true,
},
"capabilities": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
},
"config": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"mgmt": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"ip_addr": schema.StringAttribute{
Computed: true,
},
"password": schema.StringAttribute{
Computed: true,
},
"ssh_key": schema.StringAttribute{
Computed: true,
},
"user": schema.StringAttribute{
Computed: true,
},
},
},
"resources": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"cpu": schema.Int64Attribute{
Computed: true,
},
"ram": schema.Int64Attribute{
Computed: true,
},
"stack_id": schema.Int64Attribute{
Computed: true,
},
"uuid": schema.StringAttribute{
Computed: true,
},
},
},
},
},
"config_saved": schema.BoolAttribute{
Computed: true,
},
"custom_precfg": schema.BoolAttribute{
Computed: true,
},
"description": schema.StringAttribute{
Computed: true,
},
"id": schema.Int64Attribute{
Computed: true,
},
"gid": schema.Int64Attribute{
Computed: true,
},
"guid": schema.Int64Attribute{
Computed: true,
},
"interfaces": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"conn_id": schema.Int64Attribute{
Computed: true,
},
"conn_type": schema.StringAttribute{
Computed: true,
},
"def_gw": schema.StringAttribute{
Computed: true,
},
"enabled": schema.BoolAttribute{
Computed: true,
},
"flipgroup_id": schema.Int64Attribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"ip_address": schema.StringAttribute{
Computed: true,
},
"listen_ssh": schema.BoolAttribute{
Computed: true,
},
"mac": schema.StringAttribute{
Computed: true,
},
"name": schema.StringAttribute{
Computed: true,
},
"net_id": schema.Int64Attribute{
Computed: true,
},
"net_mask": schema.Int64Attribute{
Computed: true,
},
"net_type": schema.StringAttribute{
Computed: true,
},
"node_id": schema.Int64Attribute{
Computed: true,
},
"pci_slot": schema.Int64Attribute{
Computed: true,
},
"qos": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"e_rate": schema.Int64Attribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"in_burst": schema.Int64Attribute{
Computed: true,
},
"in_rate": schema.Int64Attribute{
Computed: true,
},
},
},
"target": schema.StringAttribute{
Computed: true,
},
"type": schema.StringAttribute{
Computed: true,
},
"vnfs": schema.ListAttribute{
Computed: true,
ElementType: types.Int64Type,
},
},
},
},
"lock_status": schema.StringAttribute{
Computed: true,
},
"meta": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
},
"milestones": schema.Int64Attribute{
Computed: true,
},
"name": schema.StringAttribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
"tech_status": schema.StringAttribute{
Computed: true,
},
"type": schema.StringAttribute{
Computed: true,
},
"vins": schema.ListAttribute{
Computed: true,
ElementType: types.Int64Type,
},
},
},
"account_name": schema.StringAttribute{
Computed: true,
},
"created_by": schema.StringAttribute{
Computed: true,
},
"created_time": schema.Int64Attribute{
Computed: true,
},
"default_gw": schema.StringAttribute{
Computed: true,
},
"deleted_by": schema.StringAttribute{
Computed: true,
},
"deleted_time": schema.Int64Attribute{
Computed: true,
},
"guid": schema.Int64Attribute{
Computed: true,
},
"lock_status": schema.StringAttribute{
Computed: true,
},
"manager_id": schema.Int64Attribute{
Computed: true,
},
"manager_type": schema.StringAttribute{
Computed: true,
},
"milestones": schema.Int64Attribute{
Computed: true,
},
"net_mask": schema.Int64Attribute{
Computed: true,
},
"network": schema.StringAttribute{
Computed: true,
},
"redundant": schema.BoolAttribute{
Computed: true,
},
"rg_name": schema.StringAttribute{
Computed: true,
},
"sec_vnf_dev_id": schema.Int64Attribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
"updated_by": schema.StringAttribute{
Computed: true,
},
"updated_time": schema.Int64Attribute{
Computed: true,
},
"user_managed": schema.BoolAttribute{
Computed: true,
},
"vnfs": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"dhcp": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"ckey": schema.StringAttribute{
Computed: true,
},
"account_id": schema.Int64Attribute{
Computed: true,
},
"config": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"default_gw": schema.StringAttribute{
Computed: true,
},
"dns": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
},
"ip_end": schema.StringAttribute{
Computed: true,
},
"ip_start": schema.StringAttribute{
Computed: true,
},
"lease": schema.Int64Attribute{
Computed: true,
},
"netmask": schema.Int64Attribute{
Computed: true,
},
"network": schema.StringAttribute{
Computed: true,
},
"reservations": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"client_type": schema.StringAttribute{
Computed: true,
},
"desc": schema.StringAttribute{
Computed: true,
},
"domainname": schema.StringAttribute{
Computed: true,
},
"hostname": 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,
},
},
},
},
},
},
"created_time": schema.Int64Attribute{
Computed: true,
},
"devices": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"primary": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"dev_id": schema.Int64Attribute{
Computed: true,
},
"iface01": schema.StringAttribute{
Computed: true,
},
"iface02": schema.StringAttribute{
Computed: true,
},
},
},
},
},
"gid": schema.Int64Attribute{
Computed: true,
},
"guid": schema.Int64Attribute{
Computed: true,
},
"dhcp_id": schema.Int64Attribute{
Computed: true,
},
"lock_status": schema.StringAttribute{
Computed: true,
},
"milestones": schema.Int64Attribute{
Computed: true,
},
"owner_id": schema.Int64Attribute{
Computed: true,
},
"owner_type": schema.StringAttribute{
Computed: true,
},
"pure_virtual": schema.BoolAttribute{
Computed: true,
},
"routes": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"route_id": schema.Int64Attribute{
Computed: true,
},
"compute_ids": schema.ListAttribute{
Computed: true,
ElementType: types.Int64Type,
},
"destination": schema.StringAttribute{
Computed: true,
},
"gateway": schema.StringAttribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"netmask": schema.StringAttribute{
Computed: true,
},
},
},
},
"status": schema.StringAttribute{
Computed: true,
},
"tech_status": schema.StringAttribute{
Computed: true,
},
"type": schema.StringAttribute{
Computed: true,
},
},
},
"gw": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"ckey": schema.StringAttribute{
Computed: true,
},
"account_id": schema.Int64Attribute{
Computed: true,
},
"config": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"default_gw": schema.StringAttribute{
Computed: true,
},
"ext_net_id": schema.Int64Attribute{
Computed: true,
},
"ext_net_ip": schema.StringAttribute{
Computed: true,
},
"ext_netmask": schema.Int64Attribute{
Computed: true,
},
"qos": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"e_rate": schema.Int64Attribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"in_burst": schema.Int64Attribute{
Computed: true,
},
"in_rate": schema.Int64Attribute{
Computed: true,
},
},
},
},
},
"created_time": schema.Int64Attribute{
Computed: true,
},
"devices": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"primary": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"dev_id": schema.Int64Attribute{
Computed: true,
},
"iface01": schema.StringAttribute{
Computed: true,
},
"iface02": schema.StringAttribute{
Computed: true,
},
},
},
},
},
"gid": schema.Int64Attribute{
Computed: true,
},
"guid": schema.Int64Attribute{
Computed: true,
},
"gw_id": schema.Int64Attribute{
Computed: true,
},
"lock_status": schema.StringAttribute{
Computed: true,
},
"milestones": schema.Int64Attribute{
Computed: true,
},
"owner_id": schema.Int64Attribute{
Computed: true,
},
"owner_type": schema.StringAttribute{
Computed: true,
},
"pure_virtual": schema.BoolAttribute{
Computed: true,
},
"routes": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"compute_ids": schema.ListAttribute{
Computed: true,
ElementType: types.Int64Type,
},
"route_id": schema.Int64Attribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"destination": schema.StringAttribute{
Computed: true,
},
"netmask": schema.StringAttribute{
Computed: true,
},
"gateway": schema.StringAttribute{
Computed: true,
},
},
},
},
"status": schema.StringAttribute{
Computed: true,
},
"tech_status": schema.StringAttribute{
Computed: true,
},
"type": schema.StringAttribute{
Computed: true,
},
},
},
"nat": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"ckey": schema.StringAttribute{
Computed: true,
},
"account_id": schema.Int64Attribute{
Computed: true,
},
"config": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"net_mask": schema.Int64Attribute{
Computed: true,
},
"network": schema.StringAttribute{
Computed: true,
},
"rules": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"rule_id": schema.Int64Attribute{
Computed: true,
},
"local_ip": schema.StringAttribute{
Computed: true,
},
"local_port": schema.Int64Attribute{
Computed: true,
},
"protocol": schema.StringAttribute{
Computed: true,
},
"public_port_end": schema.Int64Attribute{
Computed: true,
},
"public_port_start": schema.Int64Attribute{
Computed: true,
},
"vm_id": schema.Int64Attribute{
Computed: true,
},
"vm_name": schema.StringAttribute{
Computed: true,
},
},
},
},
},
},
"created_time": schema.Int64Attribute{
Computed: true,
},
"devices": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"primary": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"dev_id": schema.Int64Attribute{
Computed: true,
},
"iface01": schema.StringAttribute{
Computed: true,
},
"iface02": schema.StringAttribute{
Computed: true,
},
},
},
},
},
"gid": schema.Int64Attribute{
Computed: true,
},
"guid": schema.Int64Attribute{
Computed: true,
},
"nat_id": schema.Int64Attribute{
Computed: true,
},
"lock_status": schema.StringAttribute{
Computed: true,
},
"milestones": schema.Int64Attribute{
Computed: true,
},
"owner_id": schema.Int64Attribute{
Computed: true,
},
"owner_type": schema.StringAttribute{
Computed: true,
},
"pure_virtual": schema.BoolAttribute{
Computed: true,
},
"routes": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"compute_ids": schema.ListAttribute{
Computed: true,
ElementType: types.Int64Type,
},
"route_id": schema.Int64Attribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"destination": schema.StringAttribute{
Computed: true,
},
"netmask": schema.StringAttribute{
Computed: true,
},
"gateway": schema.StringAttribute{
Computed: true,
},
},
},
},
"status": schema.StringAttribute{
Computed: true,
},
"tech_status": schema.StringAttribute{
Computed: true,
},
"type": schema.StringAttribute{
Computed: true,
},
},
},
},
},
"vxlan_id": schema.Int64Attribute{
Computed: true,
},
}
}

View File

@@ -0,0 +1,51 @@
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 MakeSchemaResourceVINSStaticRoute() map[string]schema.Attribute {
return map[string]schema.Attribute{
// required attributes
"vins_id": schema.Int64Attribute{
Required: true,
Description: "Unique ID of the ViNS.",
},
"destination": schema.StringAttribute{
Required: true,
},
"netmask": schema.StringAttribute{
Required: true,
},
"gateway": schema.StringAttribute{
Required: true,
},
// optional attributes
"compute_ids": schema.ListAttribute{
Computed: true,
Optional: true,
ElementType: types.Int64Type,
},
// computed attributes
"id": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"last_updated": schema.StringAttribute{
Computed: true,
},
"guid": schema.StringAttribute{
Computed: true,
},
"route_id": schema.Int64Attribute{
Computed: true,
},
}
}

View File

@@ -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/vins"
)
func VINSDataSourceCheckPresence(ctx context.Context, vinsId uint64, c *decort.DecortClient) (*vins.RecordVINS, diag.Diagnostics) {
tflog.Info(ctx, fmt.Sprintf("VINSDataSourceCheckPresence: Get info about vins with ID - %v", vinsId))
diags := diag.Diagnostics{}
recordVINS, err := c.CloudBroker().VINS().Get(ctx, vins.GetRequest{VINSID: vinsId})
if err != nil {
diags.AddError(fmt.Sprintf("Cannot get info about vins with ID %v", vinsId), err.Error())
return nil, diags
}
tflog.Info(ctx, "VINSDataSourceCheckPresence: response from CloudBroker().VINS().Get", map[string]any{"vins_id": vinsId, "response": recordVINS})
return recordVINS, nil
}

View File

@@ -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/vins"
)
func VINSAuditsDataSourceCheckPresence(ctx context.Context, vinsId uint64, c *decort.DecortClient) (*vins.ListAudits, diag.Diagnostics) {
tflog.Info(ctx, fmt.Sprintf("VINSAuditsDataSourceCheckPresence: Get info about vins audit with vins ID - %v", vinsId))
diags := diag.Diagnostics{}
audits, err := c.CloudBroker().VINS().Audits(ctx, vins.AuditsRequest{VINSID: vinsId})
if err != nil {
diags.AddError(fmt.Sprintf("Cannot get info about audits for vins with ID %v", vinsId), err.Error())
return nil, diags
}
tflog.Info(ctx, "VINSAuditsDataSourceCheckPresence: successful response from CloudBroker().VINS().Audits", map[string]any{"vins_id": vinsId})
return &audits, nil
}

View File

@@ -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/vins"
)
func VINSExtNetListDataSourceCheckPresence(ctx context.Context, vinsId uint64, c *decort.DecortClient) (*vins.ListExtNets, diag.Diagnostics) {
tflog.Info(ctx, fmt.Sprintf("VINSExtNetListDataSourceCheckPresence: Get info about vins audit with vins ID - %v", vinsId))
diags := diag.Diagnostics{}
extnetList, err := c.CloudBroker().VINS().ExtNetList(ctx, vins.ExtNetListRequest{VINSID: vinsId})
if err != nil {
diags.AddError(fmt.Sprintf("Cannot get info about extnet list for vins with ID %v", vinsId), err.Error())
return nil, diags
}
tflog.Info(ctx, "VINSExtNetListDataSourceCheckPresence: successful response from CloudBroker().VINS().ExtNetList", map[string]any{"vins_id": vinsId})
return extnetList, nil
}

View File

@@ -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/vins"
)
func VINSIPListDataSourceCheckPresence(ctx context.Context, vinsId uint64, c *decort.DecortClient) (*vins.ListIPs, diag.Diagnostics) {
tflog.Info(ctx, fmt.Sprintf("VINSIPListDataSourceCheckPresence: Get info about vins audit with vins ID - %v", vinsId))
diags := diag.Diagnostics{}
ipList, err := c.CloudBroker().VINS().IPList(ctx, vins.IPListRequest{VINSID: vinsId})
if err != nil {
diags.AddError(fmt.Sprintf("Cannot get info about ip list for vins with ID %v", vinsId), err.Error())
return nil, diags
}
tflog.Info(ctx, "VINSIPListDataSourceCheckPresence: successful response from CloudBroker().VINS().IPList", map[string]any{"vins_id": vinsId})
return ipList, nil
}

View File

@@ -0,0 +1,59 @@
package utilities
import (
"context"
"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/vins"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/models"
)
func VINSListDataSourceCheckPresence(ctx context.Context, plan *models.DataSourceVINSListModel, c *decort.DecortClient) (*vins.ListVINS, diag.Diagnostics) {
tflog.Info(ctx, "VINSListDataSourceCheckPresence: Get info about vins list")
diags := diag.Diagnostics{}
listReq := vins.ListRequest{}
if !plan.ByID.IsNull() {
listReq.ByID = uint64(plan.ByID.ValueInt64())
}
if !plan.Name.IsNull() {
listReq.Name = plan.Name.ValueString()
}
if !plan.AccountID.IsNull() {
listReq.AccountID = uint64(plan.AccountID.ValueInt64())
}
if !plan.RGID.IsNull() {
listReq.RGID = uint64(plan.RGID.ValueInt64())
}
if !plan.ExtIP.IsNull() {
listReq.ExtIP = plan.ExtIP.ValueString()
}
if !plan.VNFDevID.IsNull() {
listReq.VNFDevID = uint64(plan.VNFDevID.ValueInt64())
}
if !plan.IncludeDeleted.IsNull() {
listReq.IncludeDeleted = plan.IncludeDeleted.ValueBool()
}
if !plan.SortBy.IsNull() {
listReq.SortBy = plan.SortBy.ValueString()
}
if !plan.Page.IsNull() {
listReq.Page = uint64(plan.Page.ValueInt64())
}
if !plan.Size.IsNull() {
listReq.Size = uint64(plan.Size.ValueInt64())
}
tflog.Info(ctx, "VINSListDataSourceCheckPresence: before call CloudBroker().VINS().List", map[string]any{"req": listReq})
list, err := c.CloudBroker().VINS().List(ctx, listReq)
if err != nil {
diags.AddError("Cannot get info about vins list", err.Error())
return nil, diags
}
tflog.Info(ctx, "VINSListDataSourceCheckPresence: successful response from CloudBroker().VINS().List")
return list, nil
}

View File

@@ -0,0 +1,53 @@
package utilities
import (
"context"
"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/vins"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/models"
)
func VINSListDeletedDataSourceCheckPresence(ctx context.Context, plan *models.DataSourceVINSListDeletedModel, c *decort.DecortClient) (*vins.ListVINS, diag.Diagnostics) {
tflog.Info(ctx, "VINSListDeletedDataSourceCheckPresence: Get info about vins list")
diags := diag.Diagnostics{}
listReq := vins.ListDeletedRequest{}
if !plan.ByID.IsNull() {
listReq.ByID = uint64(plan.ByID.ValueInt64())
}
if !plan.Name.IsNull() {
listReq.Name = plan.Name.ValueString()
}
if !plan.AccountID.IsNull() {
listReq.AccountID = uint64(plan.AccountID.ValueInt64())
}
if !plan.RGID.IsNull() {
listReq.RGID = uint64(plan.RGID.ValueInt64())
}
if !plan.ExtIP.IsNull() {
listReq.ExtIP = plan.ExtIP.ValueString()
}
if !plan.SortBy.IsNull() {
listReq.SortBy = plan.SortBy.ValueString()
}
if !plan.Page.IsNull() {
listReq.Page = uint64(plan.Page.ValueInt64())
}
if !plan.Size.IsNull() {
listReq.Size = uint64(plan.Size.ValueInt64())
}
tflog.Info(ctx, "VINSListDeletedDataSourceCheckPresence: before call CloudBroker().VINS().ListDeleted", map[string]any{"req": listReq})
list, err := c.CloudBroker().VINS().ListDeleted(ctx, listReq)
if err != nil {
diags.AddError("Cannot get info about vins deleted list", err.Error())
return nil, diags
}
tflog.Info(ctx, "VINSListDeletedDataSourceCheckPresence: successful response from CloudBroker().VINS().ListDeleted")
return list, nil
}

View File

@@ -0,0 +1,34 @@
package utilities
import (
"context"
"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/vins"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/models"
)
func VINSNATRuleListDataSourceCheckPresence(ctx context.Context, state *models.DataSourceVINSNATRuleListModel, c *decort.DecortClient) (*vins.ListNATRules, diag.Diagnostics) {
tflog.Info(ctx, "VINSNATRuleListDataSourceCheckPresence: Get info about vins nat rule list")
diags := diag.Diagnostics{}
req := vins.NATRuleListRequest{
VINSID: uint64(state.VinsID.ValueInt64()),
}
if !state.Reason.IsNull() {
req.Reason = state.Reason.ValueString()
}
natRuleList, err := c.CloudBroker().VINS().NATRuleList(ctx, req)
if err != nil {
diags.AddError("Cannot get info about vins nat rule list", err.Error())
return nil, diags
}
tflog.Info(ctx, "VINSNATRuleListDataSourceCheckPresence: successful response from CloudBroker().VINS().NATRuleList")
return natRuleList, nil
}

View File

@@ -0,0 +1,39 @@
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/vins"
)
func VINSStaticRouteDataSourceCheckPresence(ctx context.Context, vinsId, routeId uint64, c *decort.DecortClient) (*vins.ItemRoutes, diag.Diagnostics) {
tflog.Info(ctx, "VINSStaticRouteDataSourceCheckPresence: Get info about vins static route", map[string]any{
"vins_id": vinsId,
"route_id": routeId,
})
diags := diag.Diagnostics{}
routesList, err := c.CloudBroker().VINS().StaticRouteList(ctx, vins.StaticRouteListRequest{VINSID: vinsId})
if err != nil {
diags.AddError("Cannot get info about vins static route", err.Error())
return nil, diags
}
tflog.Info(ctx, "VINSStaticRouteDataSourceCheckPresence: successful response from CloudBroker().VINS().StaticRouteList")
staticRoute := &vins.ItemRoutes{}
for _, route := range routesList.Data {
if routeId == route.ID {
staticRoute = &route
return staticRoute, nil
}
}
diags.AddError("Static route not found",
fmt.Sprintf("Static route with id %d not found for vins with id %d", routeId, vinsId))
return nil, diags
}

View File

@@ -0,0 +1,25 @@
package utilities
import (
"context"
"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/vins"
)
func VINSStaticRouteListDataSourceCheckPresence(ctx context.Context, vinsId uint64, c *decort.DecortClient) (*vins.ListStaticRoutes, diag.Diagnostics) {
tflog.Info(ctx, "VINSStaticRouteListDataSourceCheckPresence: Get info about vins static route list")
diags := diag.Diagnostics{}
routesList, err := c.CloudBroker().VINS().StaticRouteList(ctx, vins.StaticRouteListRequest{VINSID: vinsId})
if err != nil {
diags.AddError("Cannot get info about vins static route list", err.Error())
return nil, diags
}
tflog.Info(ctx, "VINSStaticRouteListDataSourceCheckPresence: successful response from CloudBroker().VINS().StaticRouteList")
return routesList, nil
}

View File

@@ -0,0 +1,948 @@
package utilities
import (
"context"
"fmt"
"strconv"
"strings"
"time"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/hashicorp/terraform-plugin-log/tflog"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/models"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/status"
)
func VINSResourceCheckPresence(ctx context.Context, vinsId uint64, c *decort.DecortClient) (*vins.RecordVINS, diag.Diagnostics) {
tflog.Info(ctx, fmt.Sprintf("VINSResourceCheckPresence: Get info about vins with ID - %v", vinsId))
diags := diag.Diagnostics{}
recordVINS, err := c.CloudBroker().VINS().Get(ctx, vins.GetRequest{VINSID: vinsId})
if err != nil {
diags.AddError(fmt.Sprintf("Cannot get info about vins with ID %v", vinsId), err.Error())
return nil, diags
}
tflog.Info(ctx, "VINSResourceCheckPresence: response from CloudBroker().VINS().Get", map[string]any{"vins_id": vinsId, "response": recordVINS})
return recordVINS, nil
}
// CreateInRGResourceVINS creates vins in resource group based on plan.
// Returns vins_id for created vins and errors in case of failures.
func CreateInRGResourceVINS(ctx context.Context, plan *models.ResourceVINSModel, c *decort.DecortClient) (uint64, diag.Diagnostics) {
tflog.Info(ctx, fmt.Sprintf("Start CreateInRGResourceVINS: vins_name %s", plan.Name.ValueString()))
diags := diag.Diagnostics{}
createReq := vins.CreateInRGRequest{
Name: plan.Name.ValueString(),
RGID: uint64(plan.RGID.ValueInt64()),
}
if !plan.IPCIDR.IsNull() { // IPCIDR is optional
createReq.IPCIDR = plan.IPCIDR.ValueString()
}
if !plan.ExtNet.IsNull() { // ExtNet is optional
var extnetPlan models.ExtNetModel
tflog.Info(ctx, "CreateInRGResourceVINS: extnet specified", map[string]any{"name": plan.Name.ValueString()})
diags.Append(plan.ExtNet.As(ctx, &extnetPlan, basetypes.ObjectAsOptions{UnhandledNullAsEmpty: true})...)
if diags.HasError() {
tflog.Error(ctx, "CreateInRGResourceVINS: cannot populate extnet with plan.ExtNet object element")
return 0, diags
}
if extnetPlan.ExtNetID.IsNull() {
createReq.ExtNetID = -1 // default value
} else {
createReq.ExtNetID = extnetPlan.ExtNetID.ValueInt64()
}
if !extnetPlan.ExtNetIP.IsNull() {
createReq.ExtIP = extnetPlan.ExtNetIP.ValueString()
}
} else {
createReq.ExtNetID = -1 // default value
}
if !plan.Description.IsNull() { // Description is optional
createReq.Description = plan.Description.ValueString()
}
if plan.PreReservationsNum.IsUnknown() { // PreReservationsNum is optional & computed
createReq.PreReservationsNum = uint64(32) // default value
} else {
createReq.PreReservationsNum = uint64(plan.PreReservationsNum.ValueInt64())
}
if !plan.Reason.IsNull() {
createReq.Reason = plan.Reason.ValueString()
}
if !plan.DNS.IsNull() {
result := make([]string, 0, len(plan.DNS.Elements()))
for _, val := range plan.DNS.Elements() {
result = append(result, strings.Trim(val.String(), "\""))
}
createReq.DNSList = result
}
tflog.Info(ctx, "CreateInRGResourceVINS: before call CloudBroker().VINS().CreateInRG", map[string]any{"req": createReq})
vinsId, err := c.CloudBroker().VINS().CreateInRG(ctx, createReq)
if err != nil {
diags.AddError(
"Create resourceVINS: unable to Create VINS in RG",
err.Error(),
)
return 0, diags
}
tflog.Info(ctx, "CreateInRGResourceVINS: vins created", map[string]any{"vins_id": vinsId, "vins_name": plan.Name.ValueString()})
return vinsId, nil
}
// CreateInAccountResourceVINS creates vins in account based on plan.
// Returns vins_id for created vins and errors in case of failures.
func CreateInAccountResourceVINS(ctx context.Context, plan *models.ResourceVINSModel, c *decort.DecortClient) (uint64, diag.Diagnostics) {
tflog.Info(ctx, fmt.Sprintf("Start CreateInAccountResourceVINS: vins_name %s", plan.Name.ValueString()))
diags := diag.Diagnostics{}
createReq := vins.CreateInAccountRequest{
Name: plan.Name.ValueString(),
AccountID: uint64(plan.AccountID.ValueInt64()),
}
if !plan.GID.IsUnknown() { // IPCIDR is optional & computed
createReq.GID = uint64(plan.GID.ValueInt64())
}
if !plan.IPCIDR.IsNull() { // IPCIDR is optional
createReq.IPCIDR = plan.IPCIDR.ValueString()
}
if !plan.Description.IsNull() { // Description is optional
createReq.Description = plan.Description.ValueString()
}
if plan.PreReservationsNum.IsNull() { // PreReservationsNum is optional
createReq.PreReservationsNum = uint64(32) // default value
} else {
createReq.PreReservationsNum = uint64(plan.PreReservationsNum.ValueInt64())
}
if !plan.Reason.IsNull() {
createReq.Reason = plan.Reason.ValueString()
}
if !plan.DNS.IsNull() {
result := make([]string, 0, len(plan.DNS.Elements()))
for _, val := range plan.DNS.Elements() {
result = append(result, strings.Trim(val.String(), "\""))
}
createReq.DNSList = result
}
tflog.Info(ctx, "CreateInAccountResourceVINS: before call CloudBroker().VINS().CreateInAccount", map[string]any{"req": createReq})
vinsId, err := c.CloudBroker().VINS().CreateInAccount(ctx, createReq)
if err != nil {
diags.AddError(
"Create resourceVINS: unable to Create VINS in Account",
err.Error(),
)
return 0, diags
}
tflog.Info(ctx, "CreateInAccountResourceVINS: vins created", map[string]any{"vins_id": vinsId, "vins_name": plan.Name.ValueString()})
return vinsId, nil
}
// IPCreateVINS reserves ips that user specified in ip field for created resource.
// In case of failure returns warnings.
func IPCreateVINS(ctx context.Context, vinsId uint64, plan *models.ResourceVINSModel, c *decort.DecortClient) diag.Diagnostics {
diags := diag.Diagnostics{}
// plan.IP is not null as it was checked before call
ipPlan := make([]models.IPModel, 0, len(plan.IP.Elements()))
tflog.Info(ctx, "IPCreateVINS: new ip specified", map[string]any{"vins_id": vinsId})
diagsItem := plan.IP.ElementsAs(ctx, &ipPlan, true)
if diagsItem.HasError() {
tflog.Error(ctx, fmt.Sprintf("IPCreateVINS: cannot populate ipPlan with plan.IP list elements: %v", diagsItem))
diags.AddWarning("IPCreateVINS: Unable to read ip for vins",
fmt.Sprintf("%v", diagsItem))
return diags
}
for _, ip := range ipPlan {
ipReserveReq := vins.IPReserveRequest{
VINSID: vinsId,
Type: ip.Type.ValueString(),
}
if ip.IPAddr.ValueString() != "" {
ipReserveReq.IPAddr = ip.IPAddr.ValueString()
}
if ip.MacAddr.ValueString() != "" {
ipReserveReq.MAC = ip.MacAddr.ValueString()
}
if ip.ComputeID.ValueInt64() != 0 {
ipReserveReq.ComputeID = uint64(ip.ComputeID.ValueInt64())
}
if ip.Reason.ValueString() != "" {
ipReserveReq.Reason = ip.Reason.ValueString()
}
tflog.Info(ctx, "IPCreateVINS: before calling CloudBroker().VINS().IPReserve", map[string]any{
"vins_id": vinsId,
"ipReserveReq": ipReserveReq})
res, err := c.CloudBroker().VINS().IPReserve(ctx, ipReserveReq)
if err != nil {
diags.AddWarning("IPCreateVINS: Unable to reserve ip for vins",
err.Error())
}
tflog.Info(ctx, "IPCreateVINS: response from CloudBroker().VINS().IPReserve", map[string]any{
"vins_id": vinsId,
"response": res})
}
return diags
}
// IPUpdateVINS reserves/releases ips that user specified in ip field for updated resource.
// In case of failure returns errors.
func IPUpdateVINS(ctx context.Context, vinsId uint64, plan, state *models.ResourceVINSModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start IPUpdateVINS: new ip specified", map[string]any{"vins_id": vinsId})
diags := diag.Diagnostics{}
ipPlan := make([]models.IPModel, 0, len(plan.IP.Elements()))
tflog.Info(ctx, "IPUpdateVINS: new ip specified", map[string]any{"vins_id": vinsId})
diags.Append(plan.IP.ElementsAs(ctx, &ipPlan, true)...)
if diags.HasError() {
tflog.Error(ctx, "IPUpdateVINS: cannot populate ipPlan with plan.IP list elements")
return diags
}
ipState := make([]models.IPModel, 0, len(state.IP.Elements()))
tflog.Info(ctx, "IPUpdateVINS: new ip specified", map[string]any{"vins_id": vinsId})
diags.Append(state.IP.ElementsAs(ctx, &ipState, true)...)
if diags.HasError() {
tflog.Error(ctx, "IPUpdateVINS: cannot populate ipState with state.IP list elements")
return diags
}
// define ip to be released and release them
var deletedIP []models.IPModel
for _, ipStateElem := range ipState {
if !ipStateElem.Contains(ipPlan) {
deletedIP = append(deletedIP, ipStateElem)
}
}
if len(deletedIP) == 0 {
tflog.Info(ctx, "IPUpdateVINS: no ip needs to be release", map[string]any{"vins_id": plan.Id.ValueString()})
}
if len(deletedIP) > 0 {
tflog.Info(ctx, "IPUpdateVINS: ip needs to be released", map[string]any{
"vins_id": plan.Id.ValueString(),
"deletedIP": deletedIP})
for _, deletedIPItem := range deletedIP {
releaseIPReq := vins.IPReleaseRequest{
VINSID: vinsId,
IPAddr: deletedIPItem.IPAddr.ValueString(),
MAC: deletedIPItem.MacAddr.ValueString(),
}
tflog.Info(ctx, "IPUpdateVINS: before calling CloudBroker().VINS().IPRelese", map[string]any{"vins_id": plan.Id.ValueString(), "req": releaseIPReq})
res, err := c.CloudBroker().VINS().IPRelease(ctx, releaseIPReq)
tflog.Info(ctx, "IPUpdateVINS: response from CloudBroker().VINS().IPRelese", map[string]any{"vins_id": plan.Id.ValueString(), "response": res})
if err != nil {
diags.AddError(
"IPUpdateVINS: can not release ip for VINS",
err.Error())
}
}
}
// define ips to be reserved and reserve them
var addedIP []models.IPModel
for _, ipPlanElem := range ipPlan {
if !ipPlanElem.Contains(ipState) {
addedIP = append(addedIP, ipPlanElem)
}
}
if len(addedIP) == 0 {
tflog.Info(ctx, "IPUpdateVINS: no ip needs to be reserved", map[string]any{"vins_id": plan.Id.ValueString()})
}
if len(addedIP) > 0 {
tflog.Info(ctx, "IPUpdateVINS: ip needs to be reserved", map[string]any{
"vins_id": plan.Id.ValueString(),
"addedIP": addedIP})
for _, addedIPItem := range addedIP {
ipReserveReq := vins.IPReserveRequest{
VINSID: vinsId,
Type: addedIPItem.Type.ValueString(),
}
if addedIPItem.IPAddr.ValueString() != "" {
ipReserveReq.IPAddr = addedIPItem.IPAddr.ValueString()
}
if addedIPItem.MacAddr.ValueString() != "" {
ipReserveReq.MAC = addedIPItem.MacAddr.ValueString()
}
if addedIPItem.ComputeID.ValueInt64() != 0 {
ipReserveReq.ComputeID = uint64(addedIPItem.ComputeID.ValueInt64())
}
if addedIPItem.Reason.ValueString() != "" {
ipReserveReq.MAC = addedIPItem.Reason.ValueString()
}
tflog.Info(ctx, "IPUpdateVINS: before calling CloudBroker().VINS().IPReserve", map[string]any{
"vins_id": vinsId,
"ipReserveReq": ipReserveReq})
res, err := c.CloudBroker().VINS().IPReserve(ctx, ipReserveReq)
if err != nil {
diags.AddError("IPUpdateVINS: Unable to reserve ip for vins",
err.Error())
}
tflog.Info(ctx, "IPUpdateVINS: response from CloudBroker().VINS().IPReserve", map[string]any{
"vins_id": vinsId,
"response": res})
}
}
return diags
}
// ExtNetUpdateVINS updates ext_net_id and/or ext_net_ip that user specified in ext_net block for updated resource.
// In case of failure returns errors.
func ExtNetUpdateVINS(ctx context.Context, vinsId uint64, plan, state *models.ResourceVINSModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start ExtNetUpdateVINS: new ext_net specified", map[string]any{
"vins_id": vinsId,
})
diags := diag.Diagnostics{}
if !state.ExtNet.IsNull() {
disconReq := vins.ExtNetDisconnectRequest{
VINSID: vinsId,
}
tflog.Info(ctx, "ExtNetUpdateVINS: before calling CloudBroker().VINS().ExtNetDisconnect", map[string]any{"vins_id": plan.Id.ValueString(), "req": disconReq})
res, err := c.CloudBroker().VINS().ExtNetDisconnect(ctx, disconReq)
tflog.Info(ctx, "ExtNetUpdateVINS: response from CloudBroker().VINS().ExtNetDisconnect", map[string]any{"vins_id": plan.Id.ValueString(), "response": res})
if err != nil {
diags.AddError(
"ExtNetUpdateVINS: can not disconnect extnet for VINS",
err.Error())
}
}
if !plan.ExtNet.IsNull() {
var extnetPlan models.ExtNetModel
tflog.Info(ctx, "ExtNetUpdateVINS: new extnet specified", map[string]any{"name": plan.Name.ValueString()})
diags.Append(plan.ExtNet.As(ctx, &extnetPlan, basetypes.ObjectAsOptions{UnhandledNullAsEmpty: true})...)
if diags.HasError() {
tflog.Error(ctx, "ExtNetUpdateVINS: cannot populate extnet with plan.ExtNet object element")
return diags
}
conReq := vins.ExtNetConnectRequest{
VINSID: vinsId,
}
if !extnetPlan.ExtNetID.IsNull() {
conReq.NetID = uint64(extnetPlan.ExtNetID.ValueInt64())
}
if !extnetPlan.ExtNetIP.IsNull() {
conReq.IP = extnetPlan.ExtNetIP.ValueString()
}
tflog.Info(ctx, "ExtNetUpdateVINS: before calling CloudBroker().VINS().ExtNetConnect", map[string]any{"vins_id": plan.Id.ValueString(), "req": conReq})
res, err := c.CloudBroker().VINS().ExtNetConnect(ctx, conReq)
tflog.Info(ctx, "ExtNetUpdateVINS: response from CloudBroker().VINS().ExtNetConnect", map[string]any{"vins_id": plan.Id.ValueString(), "response": res})
if err != nil {
diags.AddError(
"ExtNetUpdateVINS: can not connect extnet to VINS",
err.Error())
}
}
return diags
}
// NATRuleCreateVINS adds nat rules that user specified in nat_rule field for created resource.
// In case of failure returns warnings.
func NATRuleCreateVINS(ctx context.Context, vinsId uint64, plan *models.ResourceVINSModel, c *decort.DecortClient) diag.Diagnostics {
diags := diag.Diagnostics{}
// plan.NatRule is not null as it was checked before call
natRulePlan := make([]models.NatRuleResourceModel, 0, len(plan.NatRule.Elements()))
tflog.Info(ctx, "NATRuleCreateVINS: new natRule specified", map[string]any{"vins_id": vinsId})
diagsItem := plan.NatRule.ElementsAs(ctx, &natRulePlan, false)
if diagsItem.HasError() {
tflog.Error(ctx, fmt.Sprintf("NATRuleCreateVINS: cannot populate natRulePlan with plan.NatRule list elements: %v", diagsItem))
diags.AddWarning("NATRuleCreateVINS: Unable to add nat rule for vins",
fmt.Sprintf("%v", diagsItem))
return diags
}
for _, nat := range natRulePlan {
natAddReq := vins.NATRuleAddRequest{
VINSID: vinsId,
IntIP: nat.IntIP.ValueString(),
IntPort: uint64(nat.IntPort.ValueInt64()),
ExtPortStart: uint64(nat.ExtPortStart.ValueInt64()),
}
if !nat.ExtPortEnd.IsUnknown() {
natAddReq.ExtPortEnd = uint64(nat.ExtPortEnd.ValueInt64())
}
if !nat.Proto.IsUnknown() {
natAddReq.Proto = nat.Proto.ValueString()
}
if !nat.Reason.IsNull() {
natAddReq.Reason = nat.Reason.ValueString()
}
tflog.Info(ctx, "NATRuleCreateVINS: before calling CloudBroker().VINS().NATRuleAdd", map[string]any{
"vins_id": vinsId,
"natAddReq": natAddReq})
res, err := c.CloudBroker().VINS().NATRuleAdd(ctx, natAddReq)
if err != nil {
diags.AddWarning("NATRuleCreateVINS: Unable to add nat rule for vins",
err.Error())
}
tflog.Info(ctx, "NATRuleCreateVINS: response from CloudBroker().VINS().NATRuleAdd", map[string]any{
"vins_id": vinsId,
"response": res})
}
return diags
}
// DefaultQosCreateVINS update qos that user specified in defaultQos field for created resource.
// In case of failure returns warnings.
func DefaultQosCreateVINS(ctx context.Context, vinsId uint64, plan *models.ResourceVINSModel, c *decort.DecortClient) diag.Diagnostics {
diags := diag.Diagnostics{}
// plan.DefaultQOS is not null as it was checked before call
var defaultQosPlan models.QOSModel
tflog.Info(ctx, "DefaultQosCreateVINS: defaultQos specified", map[string]any{"name": plan.Name.ValueString()})
diags.Append(plan.DefaultQOS.As(ctx, &defaultQosPlan, basetypes.ObjectAsOptions{UnhandledNullAsEmpty: true})...)
if diags.HasError() {
tflog.Error(ctx, "DefaultQosCreateVINS: cannot populate defaultQosPlan with plan.DefaultQOS object")
diags.AddWarning("DefaultQosCreateVINS: Unable to update defaultQos for vins",
fmt.Sprintf("cannot populate defaultQosPlan with plan.DefaultQOS object"))
return diags
}
qosReq := vins.DefaultQOSUpdateRequest{
VINSID: vinsId,
}
if !defaultQosPlan.InRate.IsUnknown() {
qosReq.IngressRate = uint64(defaultQosPlan.InRate.ValueInt64())
}
if !defaultQosPlan.InBurst.IsUnknown() {
qosReq.IngressBirst = uint64(defaultQosPlan.InBurst.ValueInt64())
}
if !defaultQosPlan.ERate.IsUnknown() {
qosReq.EgressRate = uint64(defaultQosPlan.ERate.ValueInt64())
}
tflog.Info(ctx, "DefaultQosCreateVINS: before calling CloudBroker().VINS().DefaultQOSUpdate", map[string]any{
"vins_id": vinsId,
"natAddReq": qosReq})
res, err := c.CloudBroker().VINS().DefaultQOSUpdate(ctx, qosReq)
if err != nil {
diags.AddWarning("DefaultQosCreateVINS: Unable to update defaultQos for vins",
err.Error())
}
tflog.Info(ctx, "DefaultQosCreateVINS: response from CloudBroker().VINS().DefaultQOSUpdate", map[string]any{
"vins_id": vinsId,
"response": res})
return diags
}
// NATRuleUpdateVINS adds/deleted nat rules that user specified in nat_rule field for updated resource.
// In case of failure returns errors.
func NATRuleUpdateVINS(ctx context.Context, vinsId uint64, plan, state *models.ResourceVINSModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start NATRuleUpdateVINS: new natRule specified", map[string]any{"vins_id": vinsId})
diags := diag.Diagnostics{}
itemsNatRulePlan := make([]models.NatRuleResourceModel, 0, len(plan.NatRule.Elements()))
diags.Append(plan.NatRule.ElementsAs(ctx, &itemsNatRulePlan, false)...)
if diags.HasError() {
tflog.Error(ctx, "NATRuleUpdateVINS: cannot populate natRulePlan with plan.NatRule list elements")
return diags
}
itemsNatRuleState := make([]models.NatRuleResourceModel, 0, len(state.NatRule.Elements()))
diags.Append(state.NatRule.ElementsAs(ctx, &itemsNatRuleState, false)...)
if diags.HasError() {
tflog.Error(ctx, "NATRuleUpdateVINS: cannot populate natRuleState with state.NatRule list elements")
return diags
}
// define nat rules to be deleted and delete them
var deletedNatRule []models.NatRuleResourceModel
for _, natRuleStateElem := range itemsNatRuleState {
if !natRuleStateElem.Contains(itemsNatRulePlan) {
deletedNatRule = append(deletedNatRule, natRuleStateElem)
}
}
if len(deletedNatRule) == 0 {
tflog.Info(ctx, "NATRuleUpdateVINS: no natRule needs to be deleted", map[string]any{"vins_id": plan.Id.ValueString()})
}
if len(deletedNatRule) > 0 {
tflog.Info(ctx, "NATRuleUpdateVINS: natRule needs to be deleted", map[string]any{
"vins_id": plan.Id.ValueString(),
"deletedNatRule": deletedNatRule})
for _, deletedNatRuleItem := range deletedNatRule {
deleteNATReq := vins.NATRuleDelRequest{
VINSID: vinsId,
RuleID: deletedNatRuleItem.RuleID.ValueInt64(),
}
if deletedNatRuleItem.Reason.ValueString() != "" {
deleteNATReq.Reason = deletedNatRuleItem.Reason.ValueString()
}
tflog.Info(ctx, "NATRuleUpdateVINS: before calling CloudBroker().VINS().NATRuleDel", map[string]any{"vins_id": plan.Id.ValueString(), "req": deleteNATReq})
res, err := c.CloudBroker().VINS().NATRuleDel(ctx, deleteNATReq)
tflog.Info(ctx, "NATRuleUpdateVINS: response from CloudBroker().VINS().NATRuleDel", map[string]any{"vins_id": plan.Id.ValueString(), "response": res})
if err != nil {
diags.AddError(
"NATRuleUpdateVINS: can not delete nat rule for VINS",
err.Error())
}
}
}
// define nat rules to be added and add them
var addedNatRules []models.NatRuleResourceModel
for _, natRulePlanElem := range itemsNatRulePlan {
if !natRulePlanElem.Contains(itemsNatRuleState) {
addedNatRules = append(addedNatRules, natRulePlanElem)
}
}
if len(addedNatRules) == 0 {
tflog.Info(ctx, "NATRuleUpdateVINS: no nat rule needs to be added", map[string]any{"vins_id": plan.Id.ValueString()})
}
if len(addedNatRules) > 0 {
tflog.Info(ctx, "NATRuleUpdateVINS: nat rule needs to be added", map[string]any{
"vins_id": plan.Id.ValueString(),
"addedNatRules": addedNatRules})
for _, addedNatRuleItem := range addedNatRules {
natAddReq := vins.NATRuleAddRequest{
VINSID: vinsId,
IntIP: addedNatRuleItem.IntIP.ValueString(),
IntPort: uint64(addedNatRuleItem.IntPort.ValueInt64()),
ExtPortStart: uint64(addedNatRuleItem.ExtPortStart.ValueInt64()),
}
if !addedNatRuleItem.ExtPortEnd.IsUnknown() {
natAddReq.ExtPortEnd = uint64(addedNatRuleItem.ExtPortEnd.ValueInt64())
}
if !addedNatRuleItem.Proto.IsUnknown() {
natAddReq.Proto = addedNatRuleItem.Proto.ValueString()
}
if !addedNatRuleItem.Reason.IsUnknown() {
natAddReq.Reason = addedNatRuleItem.Reason.ValueString()
}
tflog.Info(ctx, "NATRuleUpdateVINS: before calling CloudBroker().VINS().NATRuleAdd", map[string]any{
"vins_id": vinsId,
"natAddReq": natAddReq})
res, err := c.CloudBroker().VINS().NATRuleAdd(ctx, natAddReq)
if err != nil {
diags.AddError("NATRuleUpdateVINS: Unable to add nat rule for vins",
err.Error())
}
tflog.Info(ctx, "NATRuleUpdateVINS: response from CloudBroker().VINS().NATRuleAdd", map[string]any{
"vins_id": vinsId,
"response": res})
}
}
return diags
}
// VINSReadStatus loads vins resource by ids id, gets it current status. Performs restore and enable if needed for
// Deleted status.
// In case of failure returns errors.
func VINSReadStatus(ctx context.Context, state *models.ResourceVINSModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "VINSReadStatus: Read status vins with ID", map[string]any{"vins_id": state.Id.ValueString()})
diags := diag.Diagnostics{}
vinsId, err := strconv.ParseUint(state.Id.ValueString(), 10, 64)
if err != nil {
diags.AddError("VINSReadStatus: Cannot parse vins ID from state", err.Error())
return diags
}
recordVINS, diags := VINSResourceCheckPresence(ctx, vinsId, c)
if err != nil {
diags.AddError("VINSReadStatus: Unable to Read/Update VINS before status check", err.Error())
return diags
}
// check resource status
switch recordVINS.Status {
case status.Modeled:
diags.AddError(
"VINS is in status Modeled",
"please, contact support for more information",
)
return diags
case status.Deleted:
// attempt to restore vins
tflog.Info(ctx, "VINSReadStatus: vins with status.Deleted is being read or updated, attempt to restore it", map[string]any{
"vins_id": recordVINS.ID,
"status": recordVINS.Status})
if state.Restore.IsNull() || state.Restore.ValueBool() { // default true or user set-up true
diags.Append(RestoreVINS(ctx, vinsId, c)...)
if diags.HasError() {
tflog.Error(ctx, "VINSReadStatus: cannot restore vins")
return diags
}
tflog.Info(ctx, "VINSReadStatus: vins restored successfully", map[string]any{"vins_id": vinsId})
if state.Enable.IsNull() || state.Enable.ValueBool() {
diags.Append(EnableVINS(ctx, vinsId, c)...)
if diags.HasError() {
tflog.Error(ctx, "VINSReadStatus: cannot enable vins")
return diags
}
tflog.Info(ctx, "VINSReadStatus: vins enabled successfully", map[string]any{"vins_id": vinsId})
}
state.LastUpdated = types.StringValue(time.Now().Format(time.RFC850))
}
case status.Enabled:
if !state.Enable.ValueBool() && !state.Enable.IsNull() {
tflog.Info(ctx, "VINSReadStatus: vins with status.Enabled is being read or updated but should not be according to configuration (enable=false), attempt to disable it", map[string]any{
"vins_id": recordVINS.ID,
"status": recordVINS.Status})
diags.Append(DisableVINS(ctx, vinsId, c)...)
if diags.HasError() {
tflog.Error(ctx, "VINSReadStatus: cannot disable vins")
return diags
}
tflog.Info(ctx, "VINSReadStatus: vins disabled successfully", map[string]any{"vins_id": vinsId})
state.LastUpdated = types.StringValue(time.Now().Format(time.RFC850))
}
case status.Disabled:
if state.Enable.ValueBool() {
tflog.Info(ctx, "VINSReadStatus: vins with status.Disabled is being read or updated but should not be according to configuration (enable=true), attempt to enable it", map[string]any{
"vins_id": recordVINS.ID,
"status": recordVINS.Status})
diags.Append(EnableVINS(ctx, vinsId, c)...)
if diags.HasError() {
tflog.Error(ctx, "VINSReadStatus: cannot enable vins")
return diags
}
tflog.Info(ctx, "VINSReadStatus: vins enabled successfully", map[string]any{"vins_id": vinsId})
state.LastUpdated = types.StringValue(time.Now().Format(time.RFC850))
}
case status.Destroyed:
diags.AddError(
"VINSReadStatus: vins is in status Destroyed",
fmt.Sprintf("the resource with vins_id %d cannot be read or updated because it has been destroyed", vinsId),
)
return diags
}
return nil
}
// RestoreVINS performs vins Restore request.
// Returns error in case of failures.
func RestoreVINS(ctx context.Context, vinsId uint64, c *decort.DecortClient) diag.Diagnostics {
diags := diag.Diagnostics{}
tflog.Info(ctx, "RestoreVINS: before calling CloudBroker().VINS().Restore", map[string]any{"vinsId": vinsId, "req": vins.RestoreRequest{VINSID: vinsId}})
res, err := c.CloudBroker().VINS().Restore(ctx, vins.RestoreRequest{VINSID: vinsId})
if err != nil {
diags.AddError(
"RestoreVINS: cannot restore vins",
err.Error(),
)
return diags
}
tflog.Info(ctx, "RestoreVINS: response from CloudBroker().VINS().Restore", map[string]any{"vinsId": vinsId, "response": res})
return nil
}
// DisableVINS performs vins Disable request.
// Returns error in case of failures.
func DisableVINS(ctx context.Context, vinsId uint64, c *decort.DecortClient) diag.Diagnostics {
diags := diag.Diagnostics{}
tflog.Info(ctx, "DisableVINS: before calling CloudBroker().VINS().Disable", map[string]any{"vinsId": vinsId})
res, err := c.CloudBroker().VINS().Disable(ctx, vins.DisableRequest{VINSID: vinsId})
if err != nil {
diags.AddError(
"DisableVINS: cannot disable vins",
err.Error(),
)
return diags
}
tflog.Info(ctx, "DisableVINS: response from CloudBroker().VINS().Disable", map[string]any{"vinsId": vinsId, "response": res})
return nil
}
// EnableVINS performs vins Enable request.
// Returns error in case of failures.
func EnableVINS(ctx context.Context, vinsId uint64, c *decort.DecortClient) diag.Diagnostics {
diags := diag.Diagnostics{}
tflog.Info(ctx, "EnableVINS: before calling CloudBroker().VINS().Enable", map[string]any{"vinsId": vinsId})
res, err := c.CloudBroker().VINS().Enable(ctx, vins.EnableRequest{VINSID: vinsId})
if err != nil {
diags.AddError(
"EnableVINS: cannot enable vins",
err.Error(),
)
return diags
}
tflog.Info(ctx, "EnableVINS: response from CloudBroker().VINS().Enable", map[string]any{"vinsId": vinsId, "response": res})
return nil
}
// EnableDisableUpdateVINS performs vins Enable/disable request.
// Returns errors in case of failures.
func EnableDisableUpdateVINS(ctx context.Context, vinsId uint64, plan *models.ResourceVINSModel, c *decort.DecortClient) diag.Diagnostics {
diags := diag.Diagnostics{}
enable := plan.Enable.ValueBool()
tflog.Info(ctx, "Start EnableDisableUpdateVINS", map[string]any{"vinsId": vinsId, "enable": enable})
if enable {
diags.Append(EnableVINS(ctx, vinsId, c)...)
return diags
}
if !enable {
diags.Append(DisableVINS(ctx, vinsId, c)...)
return diags
}
return nil
}
// VnfdevRestartUpdateVINS restarts vnf_dev for vins.
// Returns error in case of failures.
func VnfdevRestartUpdateVINS(ctx context.Context, vinsId uint64, plan *models.ResourceVINSModel, c *decort.DecortClient) diag.Diagnostics {
diags := diag.Diagnostics{}
tflog.Info(ctx, "VnfdevRestartUpdateVINS: before calling CloudBroker().VINS().VNFDevRestart", map[string]any{"vinsId": vinsId})
req := vins.VNFDevRestartRequest{
VINSID: vinsId,
}
if !plan.Reason.IsNull() {
req.Reason = plan.Reason.ValueString()
}
res, err := c.CloudBroker().VINS().VNFDevRestart(ctx, req)
if err != nil {
diags.AddError(
"VnfdevRestartUpdateVINS: cannot restart vnf_dev for vins",
err.Error(),
)
return diags
}
tflog.Info(ctx, "VnfdevRestartUpdateVINS: response from CloudBroker().VINS().VNFDevRestart", map[string]any{"vinsId": vinsId, "response": res})
return nil
}
// VnfdevRedeployUpdateVINS redeploys vnf_dev for vins.
// Returns error in case of failures.
func VnfdevRedeployUpdateVINS(ctx context.Context, vinsId uint64, plan *models.ResourceVINSModel, c *decort.DecortClient) diag.Diagnostics {
diags := diag.Diagnostics{}
tflog.Info(ctx, "VnfdevRedeployUpdateVINS: before calling CloudBroker().VINS().VNFDevRedeploy", map[string]any{"vinsId": vinsId})
req := vins.VNFDevRedeployRequest{
VINSID: vinsId,
}
if !plan.Reason.IsNull() {
req.Reason = plan.Reason.ValueString()
}
res, err := c.CloudBroker().VINS().VNFDevRedeploy(ctx, req)
if err != nil {
diags.AddError(
"VnfdevRedeployUpdateVINS: cannot redeploy vnf_dev for vins",
err.Error(),
)
return diags
}
tflog.Info(ctx, "VnfdevRedeployUpdateVINS: response from CloudBroker().VINS().VNFDevRedeploy", map[string]any{"vinsId": vinsId, "response": res})
return nil
}
// VnfdevResetUpdateVINS reset vnf_dev for vins.
// Returns error in case of failures.
func VnfdevResetUpdateVINS(ctx context.Context, vinsId uint64, plan *models.ResourceVINSModel, c *decort.DecortClient) diag.Diagnostics {
diags := diag.Diagnostics{}
tflog.Info(ctx, "VnfdevResetUpdateVINS: before calling CloudBroker().VINS().VNFDevReset", map[string]any{"vinsId": vinsId})
req := vins.VNFDevResetRequest{
VINSID: vinsId,
}
if !plan.Reason.IsNull() {
req.Reason = plan.Reason.ValueString()
}
res, err := c.CloudBroker().VINS().VNFDevReset(ctx, req)
if err != nil {
diags.AddError(
"VnfdevResetUpdateVINS: cannot reset vnf_dev for vins",
err.Error(),
)
return diags
}
tflog.Info(ctx, "VnfdevResetUpdateVINS: response from CloudBroker().VINS().VNFDevReset", map[string]any{"vinsId": vinsId, "response": res})
return nil
}
// VnfdevStartStopUpdateVINS start/stop vnf_dev for vins.
// Returns error in case of failures.
func VnfdevStartStopUpdateVINS(ctx context.Context, vinsId uint64, plan *models.ResourceVINSModel, c *decort.DecortClient) diag.Diagnostics {
diags := diag.Diagnostics{}
if plan.VnfdevStart.ValueBool() {
req := vins.VNFDevStartRequest{
VINSID: vinsId,
}
if !plan.Reason.IsNull() {
req.Reason = plan.Reason.ValueString()
}
tflog.Info(ctx, "VnfdevResetUpdateVINS: before calling CloudBroker().VINS().VNFDevStart", map[string]any{"vinsId": vinsId})
res, err := c.CloudBroker().VINS().VNFDevStart(ctx, req)
if err != nil {
diags.AddError(
"VnfdevResetUpdateVINS: cannot start vnf_dev for vins",
err.Error(),
)
return diags
}
tflog.Info(ctx, "VnfdevResetUpdateVINS: response from CloudBroker().VINS().VNFDevStart", map[string]any{"vinsId": vinsId, "response": res})
return nil
}
req := vins.VNFDevStopRequest{
VINSID: vinsId,
}
if !plan.Reason.IsNull() {
req.Reason = plan.Reason.ValueString()
}
tflog.Info(ctx, "VnfdevResetUpdateVINS: before calling CloudBroker().VINS().VNFDevStop", map[string]any{"vinsId": vinsId})
res, err := c.CloudBroker().VINS().VNFDevStop(ctx, req)
if err != nil {
diags.AddError(
"VnfdevResetUpdateVINS: cannot start vnf_dev for vins",
err.Error(),
)
return diags
}
tflog.Info(ctx, "VnfdevResetUpdateVINS: response from CloudBroker().VINS().VNFDevStop", map[string]any{"vinsId": vinsId, "response": res})
return nil
}
// UpdateDNSlistVINS apply new DNS list in VINS
// Returns error in case of failures.
func UpdateDNSlistVINS(ctx context.Context, vinsId uint64, plan *models.ResourceVINSModel, c *decort.DecortClient) diag.Diagnostics {
diags := diag.Diagnostics{}
req := vins.DNSApplyRequest{
VINSID: vinsId,
}
dnsList := make([]string, 0, len(plan.DNS.Elements()))
for _, val := range plan.DNS.Elements() {
dnsList = append(dnsList, strings.Trim(val.String(), "\""))
}
req.DNSList = dnsList
tflog.Info(ctx, "UpdateDNSListVINS: before calling CloudBroker().VINS().DNSApply", map[string]any{"vinsId": vinsId})
res, err := c.CloudBroker().VINS().DNSApply(ctx, req)
if err != nil {
diags.AddError(
"UpdateDNSListVINS: cannot apply DNSList for vins",
err.Error(),
)
return diags
}
tflog.Info(ctx, "UpdateDNSListVINS: after calling CloudBroker().VINS().DNSApply", map[string]any{"vinsId": vinsId, "response": res})
return nil
}
// UpdateDefaultQosVINS update qos that user specified in defaultQos field for update resource.
// In case of failure returns error.
func UpdateDefaultQosVINS(ctx context.Context, vinsId uint64, plan *models.ResourceVINSModel, c *decort.DecortClient) diag.Diagnostics {
diags := diag.Diagnostics{}
// plan.DefaultQOS is not null as it was checked before call
var defaultQosPlan models.QOSModel
tflog.Info(ctx, "DefaultQosUpdateVINS: defaultQos specified", map[string]any{"name": plan.Name.ValueString()})
diags.Append(plan.DefaultQOS.As(ctx, &defaultQosPlan, basetypes.ObjectAsOptions{UnhandledNullAsEmpty: true})...)
if diags.HasError() {
tflog.Error(ctx, "DefaultQosUpdateVINS: cannot populate defaultQosPlan with plan.DefaultQOS object")
return diags
}
qosReq := vins.DefaultQOSUpdateRequest{
VINSID: vinsId,
}
if !defaultQosPlan.InRate.IsUnknown() {
qosReq.IngressRate = uint64(defaultQosPlan.InRate.ValueInt64())
}
if !defaultQosPlan.InBurst.IsUnknown() {
qosReq.IngressBirst = uint64(defaultQosPlan.InBurst.ValueInt64())
}
if !defaultQosPlan.ERate.IsUnknown() {
qosReq.EgressRate = uint64(defaultQosPlan.ERate.ValueInt64())
}
tflog.Info(ctx, "DefaultQosUpdateVINS: before calling CloudBroker().VINS().DefaultQOSUpdate", map[string]any{
"vins_id": vinsId,
"natAddReq": qosReq})
res, err := c.CloudBroker().VINS().DefaultQOSUpdate(ctx, qosReq)
if err != nil {
diags.AddError("DefaultQosUpdateVINS: Unable to update defaultQos for vins",
err.Error())
}
tflog.Info(ctx, "DefaultQosUpdateVINS: response from CloudBroker().VINS().DefaultQOSUpdate", map[string]any{
"vins_id": vinsId,
"response": res})
return diags
}

View File

@@ -0,0 +1,195 @@
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/vins"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudbroker/vins/models"
)
func VINSStaticRouteResourceCheckPresence(ctx context.Context, vinsId, routeId uint64, c *decort.DecortClient) (*vins.ItemRoutes, diag.Diagnostics) {
tflog.Info(ctx, "VINSStaticRouteResourceCheckPresence: Get info about vins static route")
diags := diag.Diagnostics{}
tflog.Info(ctx, "VINSStaticRouteResourceCheckPresence: before call to CloudBroker().VINS().StaticRouteList", map[string]any{"vins_id": vinsId, "route_id": routeId})
staticRouteList, err := c.CloudBroker().VINS().StaticRouteList(ctx, vins.StaticRouteListRequest{VINSID: vinsId})
if err != nil {
diags.AddError(
fmt.Sprintf("VINSStaticRouteResourceCheckPresence: Cannot get info about vins static route %v", vinsId),
err.Error())
return nil, diags
}
tflog.Info(ctx, "VINSStaticRouteResourceCheckPresence: response from CloudBroker().VINS().StaticRouteList", map[string]any{"vins_id": vinsId, "response": staticRouteList})
staticRoute := &vins.ItemRoutes{}
for _, route := range staticRouteList.Data {
if routeId == route.ID {
staticRoute = &route
return staticRoute, nil
}
}
diags.AddError(
"VINSStaticRouteResourceCheckPresence: static route not found",
fmt.Sprintf("static route not found for route_id=%d and vins_id=%d", routeId, vinsId))
return nil, diags
}
func GetVinsIDAndRouteID(ctx context.Context, plan *models.ResourceVINSStaticRouteModel) (uint64, uint64, diag.Diagnostics) {
tflog.Info(ctx, "Start GetVinsIDAndRouteID")
var err error
diags := diag.Diagnostics{}
vinsId := uint64(plan.VinsID.ValueInt64())
routeId := uint64(plan.RouteID.ValueInt64())
if plan.Id.ValueString() != "" {
vals := strings.Split(plan.Id.ValueString(), "#")
if len(vals) != 2 {
diags.AddError(
"GetVinsIDAndRouteID: broken state id",
fmt.Sprintf("state id expected: <vins_id>#<route_id>, got: %v", plan.Id.ValueString()))
return 0, 0, diags
}
vinsId, err = strconv.ParseUint(vals[0], 10, 64)
if err != nil {
diags.AddError("GetVinsIDAndRouteID: can not parse vinsId from state", err.Error())
return 0, 0, diags
}
routeId, err = strconv.ParseUint(vals[1], 10, 64)
if err != nil {
diags.AddError("GetVinsIDAndRouteID: can not parse routeId from state", err.Error())
return 0, 0, diags
}
}
return vinsId, routeId, nil
}
func GetStaticRouteID(ctx context.Context, plan *models.ResourceVINSStaticRouteModel, c *decort.DecortClient) (uint64, diag.Diagnostics) {
tflog.Info(ctx, "Start GetStaticRouteID")
diags := diag.Diagnostics{}
vinsId := uint64(plan.VinsID.ValueInt64())
tflog.Info(ctx, "GetStaticRouteID: before call to CloudBroker().VINS().StaticRouteList", map[string]any{"vins_id": vinsId})
staticRouteList, err := c.CloudBroker().VINS().StaticRouteList(ctx, vins.StaticRouteListRequest{VINSID: vinsId})
if err != nil {
diags.AddError(
fmt.Sprintf("GetStaticRouteID: Cannot get info about vins static routes %v", vinsId),
err.Error())
return 0, diags
}
tflog.Info(ctx, "GetStaticRouteID: response from CloudBroker().VINS().StaticRouteList", map[string]any{"vins_id": vinsId, "response": staticRouteList})
destination := plan.Destination.ValueString()
gateway := plan.Gateway.ValueString()
staticRoute := &vins.ItemRoutes{}
for _, route := range staticRouteList.Data {
if destination == route.Destination && gateway == route.Gateway {
staticRoute = &route
return staticRoute.ID, nil
}
}
diags.AddError(
"GetStaticRouteID: static route not found",
fmt.Sprintf("Static route (destination=%s, gateway=%s) not found for vins with vins_id=%d", destination, gateway, vinsId))
return 0, diags
}
func UpdateComputeIDsVINSStaticRoute(ctx context.Context, plan, state *models.ResourceVINSStaticRouteModel, c *decort.DecortClient) diag.Diagnostics {
tflog.Info(ctx, "Start UpdateComputeIDsVINSStaticRoute", map[string]any{"id": plan.Id.ValueString()})
vinsId, routeId, diags := GetVinsIDAndRouteID(ctx, plan)
if diags.HasError() {
return diags
}
computesPlan := make([]uint64, 0, len(plan.ComputeIDs.Elements()))
diags = plan.ComputeIDs.ElementsAs(ctx, &computesPlan, false)
if diags.HasError() {
tflog.Error(ctx, "UpdateComputeIDsVINSStaticRoute: cannot populate computes with plan.ComputeIDs List elements")
return diags
}
computesState := make([]uint64, 0, len(state.ComputeIDs.Elements()))
diags = state.ComputeIDs.ElementsAs(ctx, &computesState, false)
if diags.HasError() {
tflog.Error(ctx, "UpdateComputeIDsVINSStaticRoute: cannot populate computes with state.ComputeIDs List elements")
return diags
}
var deletedComputes []uint64
for _, comp := range computesState {
if !contains(comp, computesPlan) {
deletedComputes = append(deletedComputes, comp)
}
}
if len(deletedComputes) != 0 {
revokeReq := vins.StaticRouteAccessRevokeRequest{
VINSID: vinsId,
RouteId: routeId,
ComputeIds: deletedComputes,
}
tflog.Info(ctx, "UpdateComputeIDsVINSStaticRoute: before call to CloudBroker().VINS().StaticRouteAccessRevoke", map[string]any{"revokeReq": revokeReq})
_, err := c.CloudBroker().VINS().StaticRouteAccessRevoke(ctx, revokeReq)
if err != nil {
diags.AddError(
fmt.Sprintf("UpdateComputeIDsVINSStaticRoute: Cannot revoke static routes for vins with id %v", vinsId),
err.Error())
}
}
var addedComputes []uint64
for _, comp := range computesPlan {
if !contains(comp, computesState) {
addedComputes = append(addedComputes, comp)
}
}
if len(addedComputes) != 0 {
grantReq := vins.StaticRouteAccessGrantRequest{
VINSID: vinsId,
RouteId: routeId,
ComputeIds: addedComputes,
}
tflog.Info(ctx, "UpdateComputeIDsVINSStaticRoute: before call to CloudBroker().VINS().StaticRouteAccessGrant", map[string]any{"grantReq": grantReq})
_, err := c.CloudBroker().VINS().StaticRouteAccessGrant(ctx, grantReq)
if err != nil {
diags.AddError(
fmt.Sprintf("UpdateComputeIDsVINSStaticRoute: Cannot grant static routes for vins with id %v", vinsId),
err.Error())
}
}
return diags
}
// contains returns true if slice contains element. Otherwise it returns false.
func contains(element uint64, slice []uint64) bool {
for _, s := range slice {
if s == element {
return true
}
}
return false
}