parent
003e4d656e
commit
76ea459b3d
@ -0,0 +1,47 @@
|
||||
---
|
||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
||||
page_title: "dynamix_audit Data Source - terraform-provider-dynamix"
|
||||
subcategory: ""
|
||||
description: |-
|
||||
|
||||
---
|
||||
|
||||
# dynamix_audit (Data Source)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- schema generated by tfplugindocs -->
|
||||
## Schema
|
||||
|
||||
### Required
|
||||
|
||||
- `audit_guid` (String)
|
||||
|
||||
### Optional
|
||||
|
||||
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
|
||||
|
||||
### Read-Only
|
||||
|
||||
- `args` (String)
|
||||
- `call` (String)
|
||||
- `guid` (String)
|
||||
- `id` (String) The ID of this resource.
|
||||
- `kwargs` (String)
|
||||
- `remote_addr` (String)
|
||||
- `responsetime` (Number)
|
||||
- `result` (String)
|
||||
- `status_code` (Number)
|
||||
- `tags` (String)
|
||||
- `timestamp` (Number)
|
||||
- `timestamp_end` (Number)
|
||||
- `user` (String)
|
||||
|
||||
<a id="nestedblock--timeouts"></a>
|
||||
### Nested Schema for `timeouts`
|
||||
|
||||
Optional:
|
||||
|
||||
- `read` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).
|
@ -0,0 +1,47 @@
|
||||
---
|
||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
||||
page_title: "dynamix_dpdknet Data Source - terraform-provider-dynamix"
|
||||
subcategory: ""
|
||||
description: |-
|
||||
|
||||
---
|
||||
|
||||
# dynamix_dpdknet (Data Source)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- schema generated by tfplugindocs -->
|
||||
## Schema
|
||||
|
||||
### Required
|
||||
|
||||
- `dpdk_id` (Number)
|
||||
|
||||
### Optional
|
||||
|
||||
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
|
||||
|
||||
### Read-Only
|
||||
|
||||
- `account_access` (List of Number)
|
||||
- `compute_ids` (List of Number)
|
||||
- `created_time` (Number)
|
||||
- `desc` (String)
|
||||
- `gid` (Number)
|
||||
- `guid` (Number)
|
||||
- `id` (String) The ID of this resource.
|
||||
- `name` (String)
|
||||
- `ovs_bridge` (String)
|
||||
- `rg_access` (List of Number)
|
||||
- `status` (String)
|
||||
- `updated_time` (Number)
|
||||
- `vlan_id` (Number)
|
||||
|
||||
<a id="nestedblock--timeouts"></a>
|
||||
### Nested Schema for `timeouts`
|
||||
|
||||
Optional:
|
||||
|
||||
- `read` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).
|
@ -0,0 +1,65 @@
|
||||
---
|
||||
# generated by https://github.com/hashicorp/terraform-plugin-docs
|
||||
page_title: "dynamix_dpdknet_list Data Source - terraform-provider-dynamix"
|
||||
subcategory: ""
|
||||
description: |-
|
||||
|
||||
---
|
||||
|
||||
# dynamix_dpdknet_list (Data Source)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- schema generated by tfplugindocs -->
|
||||
## Schema
|
||||
|
||||
### Optional
|
||||
|
||||
- `by_id` (Number)
|
||||
- `compute_ids` (List of Number)
|
||||
- `desc` (String)
|
||||
- `gid` (Number)
|
||||
- `name` (String)
|
||||
- `page` (Number)
|
||||
- `size` (Number)
|
||||
- `sort_by` (String)
|
||||
- `status` (String)
|
||||
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
|
||||
|
||||
### Read-Only
|
||||
|
||||
- `entry_count` (Number)
|
||||
- `id` (String) The ID of this resource.
|
||||
- `items` (Attributes List) (see [below for nested schema](#nestedatt--items))
|
||||
|
||||
<a id="nestedblock--timeouts"></a>
|
||||
### Nested Schema for `timeouts`
|
||||
|
||||
Optional:
|
||||
|
||||
- `read` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).
|
||||
|
||||
|
||||
<a id="nestedatt--items"></a>
|
||||
### Nested Schema for `items`
|
||||
|
||||
Required:
|
||||
|
||||
- `dpdk_id` (Number)
|
||||
|
||||
Read-Only:
|
||||
|
||||
- `account_access` (List of Number)
|
||||
- `compute_ids` (List of Number)
|
||||
- `created_time` (Number)
|
||||
- `desc` (String)
|
||||
- `gid` (Number)
|
||||
- `guid` (Number)
|
||||
- `name` (String)
|
||||
- `ovs_bridge` (String)
|
||||
- `rg_access` (List of Number)
|
||||
- `status` (String)
|
||||
- `updated_time` (Number)
|
||||
- `vlan_id` (Number)
|
@ -0,0 +1,91 @@
|
||||
package audit
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/audit/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/audit/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/audit/schemas"
|
||||
)
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ datasource.DataSource = &dataSourceAudit{}
|
||||
)
|
||||
|
||||
func NewDataSourceAudit() datasource.DataSource {
|
||||
return &dataSourceAudit{}
|
||||
}
|
||||
|
||||
// dataSourceAudit is the data source implementation.
|
||||
type dataSourceAudit struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceAudit) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.DataSourceAudit
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAudit: Error get state")
|
||||
return
|
||||
}
|
||||
auditGuid := state.AuditGuid.ValueString()
|
||||
tflog.Info(ctx, "Read dataSourceAudit: got state successfully", map[string]any{"audit_guid": auditGuid})
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout180s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAudit: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceAudit: set timeouts successfully", map[string]any{
|
||||
"audit_guid": auditGuid,
|
||||
"readTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Map response body to schema
|
||||
resp.Diagnostics.Append(flattens.AuditDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAudit: Error flatten")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceAudit: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceAudit", map[string]any{"audit_guid": auditGuid})
|
||||
}
|
||||
|
||||
func (d *dataSourceAudit) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceAudit(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceAudit) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_audit"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceAudit) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceAudit")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceAudit successfully")
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package flattens
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/audit/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/audit/utilities"
|
||||
)
|
||||
|
||||
func AuditDataSource(ctx context.Context, state *models.DataSourceAudit, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.AuditDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
auditGuid := state.AuditGuid.ValueString()
|
||||
|
||||
recordAudit, diags := utilities.AuditDataSourceCheckPresence(ctx, auditGuid, c)
|
||||
if diags.HasError() {
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.AuditDataSource: before flatten", map[string]any{"audit_guid": auditGuid})
|
||||
|
||||
*state = models.DataSourceAudit{
|
||||
AuditGuid: state.AuditGuid,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Arguments: types.StringValue(recordAudit.Arguments),
|
||||
Call: types.StringValue(recordAudit.Call),
|
||||
GUID: types.StringValue(recordAudit.GUID),
|
||||
ID: types.StringValue(recordAudit.GUID),
|
||||
Kwargs: types.StringValue(recordAudit.Kwargs),
|
||||
RemoteAddr: types.StringValue(recordAudit.RemoteAddr),
|
||||
ResponseTime: types.Float64Value(recordAudit.ResponseTime),
|
||||
Result: types.StringValue(recordAudit.Result),
|
||||
StatusCode: types.Int64Value(int64(recordAudit.StatusCode)),
|
||||
Tags: types.StringValue(recordAudit.Tags),
|
||||
Timestamp: types.Float64Value(recordAudit.Timestamp),
|
||||
TimestampEnd: types.Float64Value(recordAudit.TimestampEnd),
|
||||
User: types.StringValue(recordAudit.User),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattens.AuditDataSource", map[string]any{"audit_guid": auditGuid})
|
||||
return nil
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type DataSourceAudit struct {
|
||||
//required field
|
||||
AuditGuid types.String `tfsdk:"audit_guid"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
|
||||
//response field
|
||||
Arguments types.String `tfsdk:"args"`
|
||||
Call types.String `tfsdk:"call"`
|
||||
GUID types.String `tfsdk:"guid"`
|
||||
ID types.String `tfsdk:"id"`
|
||||
Kwargs types.String `tfsdk:"kwargs"`
|
||||
RemoteAddr types.String `tfsdk:"remote_addr"`
|
||||
ResponseTime types.Float64 `tfsdk:"responsetime"`
|
||||
Result types.String `tfsdk:"result"`
|
||||
StatusCode types.Int64 `tfsdk:"status_code"`
|
||||
Tags types.String `tfsdk:"tags"`
|
||||
Timestamp types.Float64 `tfsdk:"timestamp"`
|
||||
TimestampEnd types.Float64 `tfsdk:"timestamp_end"`
|
||||
User types.String `tfsdk:"user"`
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceAudit() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
"audit_guid": schema.StringAttribute{
|
||||
Required: true,
|
||||
},
|
||||
"args": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"call": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"kwargs": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"remote_addr": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"responsetime": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"result": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"status_code": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"tags": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"timestamp": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"timestamp_end": schema.Float64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"user": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
@ -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/cloudapi/audit"
|
||||
)
|
||||
|
||||
func AuditDataSourceCheckPresence(ctx context.Context, auditGuid string, c *decort.DecortClient) (*audit.RecordAudit, diag.Diagnostics) {
|
||||
tflog.Info(ctx, fmt.Sprintf("AuditDataSourceCheckPresence: Get info about audit with ID - %v", auditGuid))
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
recordAudit, err := c.CloudAPI().Audit().Get(ctx, audit.GetRequest{AuditGuid: auditGuid})
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about audit with ID %v", auditGuid), err.Error())
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "AuditDataSourceCheckPresence: response from CloudBroker().Audit().Get", map[string]any{"audit_guid": auditGuid, "response": recordAudit})
|
||||
|
||||
return recordAudit, nil
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package dpdknet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/dpdknet/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/dpdknet/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/dpdknet/schemas"
|
||||
)
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ datasource.DataSource = &dataSourceDPDK{}
|
||||
)
|
||||
|
||||
func NewDataSourceDPDK() datasource.DataSource {
|
||||
return &dataSourceDPDK{}
|
||||
}
|
||||
|
||||
// dataSourceDPDK is the data source implementation.
|
||||
type dataSourceDPDK struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceDPDK) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.DataSourceDPDKModel
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceDPDK: Error get state")
|
||||
return
|
||||
}
|
||||
dpdkId := uint64(state.DPDKID.ValueInt64())
|
||||
tflog.Info(ctx, "Read dataSourceDPDK: got state successfully", map[string]any{"dpdk_id": dpdkId})
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout180s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceDPDK: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceDPDK: set timeouts successfully", map[string]any{
|
||||
"dpdk_id": dpdkId,
|
||||
"readTimeout": readTimeout})
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, readTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Map response body to schema
|
||||
resp.Diagnostics.Append(flattens.DPDKDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceDPDK: Error flatten")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceDPDK: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceDPDK", map[string]any{"dpdk_id": dpdkId})
|
||||
}
|
||||
|
||||
func (d *dataSourceDPDK) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceDPDK(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceDPDK) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_dpdknet"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceDPDK) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceDPDK")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceDPDK successfully")
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package dpdknet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/dpdknet/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/dpdknet/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/dpdknet/schemas"
|
||||
)
|
||||
|
||||
// Ensure the implementation satisfies the expected interfaces.
|
||||
var (
|
||||
_ datasource.DataSource = &dataSourceDPDKList{}
|
||||
)
|
||||
|
||||
func NewDataSourceDPDKList() datasource.DataSource {
|
||||
return &dataSourceDPDKList{}
|
||||
}
|
||||
|
||||
// dataSourceDPDKList is the data source implementation.
|
||||
type dataSourceDPDKList struct {
|
||||
client *decort.DecortClient
|
||||
}
|
||||
|
||||
func (d *dataSourceDPDKList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
// Read Terraform configuration data into the model
|
||||
var state models.DataSourceDPDKListModel
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceDPDKList: Error get state")
|
||||
return
|
||||
}
|
||||
|
||||
// Set timeouts
|
||||
readTimeout, diags := state.Timeouts.Read(ctx, constants.Timeout180s)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceDPDKList: Error set timeout")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "Read dataSourceDPDKList: 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.DPDKListDataSource(ctx, &state, d.client)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceDPDKList: Error flatten")
|
||||
return
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
tflog.Error(ctx, "Read dataSourceDPDKList: Error set state")
|
||||
return
|
||||
}
|
||||
tflog.Info(ctx, "End read dataSourceDPDKList")
|
||||
}
|
||||
|
||||
func (d *dataSourceDPDKList) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Attributes: schemas.MakeSchemaDataSourceDPDKList(),
|
||||
Blocks: map[string]schema.Block{
|
||||
"timeouts": timeouts.Block(ctx),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dataSourceDPDKList) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_dpdknet_list"
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *dataSourceDPDKList) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
|
||||
tflog.Info(ctx, "Get Configure dataSourceDPDKList")
|
||||
d.client = client.DataSource(ctx, &req, resp)
|
||||
tflog.Info(ctx, "Getting Configure dataSourceDPDKList successfully")
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
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/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/dpdknet/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/dpdknet/utilities"
|
||||
)
|
||||
|
||||
func DPDKDataSource(ctx context.Context, state *models.DataSourceDPDKModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.DPDKDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
dpdkId := uint64(state.DPDKID.ValueInt64())
|
||||
|
||||
recordDPDK, diags := utilities.DPDKDataSourceCheckPresence(ctx, dpdkId, c)
|
||||
if diags.HasError() {
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.DPDKDataSource: before flatten", map[string]any{"dpdk_id": dpdkId})
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceDPDKModel{
|
||||
DPDKID: state.DPDKID,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
AccountAccess: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, recordDPDK.AccountAccess),
|
||||
CreatedTime: types.Int64Value(int64(recordDPDK.CreatedTime)),
|
||||
Desc: types.StringValue(recordDPDK.Description),
|
||||
GID: types.Int64Value(int64(recordDPDK.GID)),
|
||||
GUID: types.Int64Value(int64(recordDPDK.GUID)),
|
||||
Name: types.StringValue(recordDPDK.Name),
|
||||
RGAccess: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, recordDPDK.RGAccess),
|
||||
Status: types.StringValue(recordDPDK.Status),
|
||||
OVSBridge: types.StringValue(recordDPDK.OVSBridge),
|
||||
VlanID: types.Int64Value(int64(recordDPDK.VlanID)),
|
||||
ComputeIDs: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, recordDPDK.ComputeIDs),
|
||||
UpdatedTime: types.Int64Value(int64(recordDPDK.UpdatedTime)),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "End flattens.DPDKDataSource", map[string]any{"dpdk_id": dpdkId})
|
||||
return nil
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
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/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/dpdknet/models"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/dpdknet/utilities"
|
||||
)
|
||||
|
||||
func DPDKListDataSource(ctx context.Context, state *models.DataSourceDPDKListModel, c *decort.DecortClient) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start flattens.DPDKListDataSource")
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
dpdkList, err := utilities.DPDKListDataSourceCheckPresence(ctx, state, c)
|
||||
if err != nil {
|
||||
diags.AddError("Cannot get info about list DPDK", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "flattens.DPDKListDataSource: before flatten")
|
||||
|
||||
id := uuid.New()
|
||||
*state = models.DataSourceDPDKListModel{
|
||||
ByID: state.ByID,
|
||||
GID: state.GID,
|
||||
Name: state.Name,
|
||||
Desc: state.Desc,
|
||||
Status: state.Status,
|
||||
ComputeIDs: state.ComputeIDs,
|
||||
SortBy: state.SortBy,
|
||||
Page: state.Page,
|
||||
Size: state.Size,
|
||||
Timeouts: state.Timeouts,
|
||||
|
||||
Id: types.StringValue(id.String()),
|
||||
}
|
||||
|
||||
items := make([]models.ItemDPDKListModel, 0, len(dpdkList.Data))
|
||||
for _, dpdkItem := range dpdkList.Data {
|
||||
|
||||
item := models.ItemDPDKListModel{
|
||||
AccountAccess: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, dpdkItem.AccountAccess),
|
||||
CreatedTime: types.Int64Value(int64(dpdkItem.CreatedTime)),
|
||||
Desc: types.StringValue(dpdkItem.Description),
|
||||
DPDKID: types.Int64Value(int64(dpdkItem.ID)),
|
||||
GID: types.Int64Value(int64(dpdkItem.GID)),
|
||||
GUID: types.Int64Value(int64(dpdkItem.GUID)),
|
||||
Name: types.StringValue(dpdkItem.Name),
|
||||
RGAccess: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, dpdkItem.RGAccess),
|
||||
Status: types.StringValue(dpdkItem.Status),
|
||||
OVSBridge: types.StringValue(dpdkItem.OVSBridge),
|
||||
VlanID: types.Int64Value(int64(dpdkItem.VlanID)),
|
||||
ComputeIDs: flattens.FlattenSimpleTypeToList(ctx, types.Int64Type, dpdkItem.ComputeIDs),
|
||||
UpdatedTime: types.Int64Value(int64(dpdkItem.UpdatedTime)),
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
state.Items = items
|
||||
state.EntryCount = types.Int64Value(int64(dpdkList.EntryCount))
|
||||
|
||||
tflog.Info(ctx, "End flattens.DPDKListDataSource")
|
||||
return nil
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type DataSourceDPDKModel struct {
|
||||
//required field
|
||||
DPDKID types.Int64 `tfsdk:"dpdk_id"`
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
|
||||
//response field
|
||||
AccountAccess types.List `tfsdk:"account_access"`
|
||||
CreatedTime types.Int64 `tfsdk:"created_time"`
|
||||
Desc types.String `tfsdk:"desc"`
|
||||
GID types.Int64 `tfsdk:"gid"`
|
||||
GUID types.Int64 `tfsdk:"guid"`
|
||||
Id types.String `tfsdk:"id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
RGAccess types.List `tfsdk:"rg_access"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
OVSBridge types.String `tfsdk:"ovs_bridge"`
|
||||
VlanID types.Int64 `tfsdk:"vlan_id"`
|
||||
ComputeIDs types.List `tfsdk:"compute_ids"`
|
||||
UpdatedTime types.Int64 `tfsdk:"updated_time"`
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
type DataSourceDPDKListModel struct {
|
||||
Timeouts timeouts.Value `tfsdk:"timeouts"`
|
||||
|
||||
// optional attributes
|
||||
ByID types.Int64 `tfsdk:"by_id"`
|
||||
GID types.Int64 `tfsdk:"gid"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Desc types.String `tfsdk:"desc"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
ComputeIDs types.List `tfsdk:"compute_ids"`
|
||||
SortBy types.String `tfsdk:"sort_by"`
|
||||
Page types.Int64 `tfsdk:"page"`
|
||||
Size types.Int64 `tfsdk:"size"`
|
||||
|
||||
// computed attributes
|
||||
Id types.String `tfsdk:"id"`
|
||||
Items []ItemDPDKListModel `tfsdk:"items"`
|
||||
EntryCount types.Int64 `tfsdk:"entry_count"`
|
||||
}
|
||||
|
||||
type ItemDPDKListModel struct {
|
||||
DPDKID types.Int64 `tfsdk:"dpdk_id"`
|
||||
AccountAccess types.List `tfsdk:"account_access"`
|
||||
CreatedTime types.Int64 `tfsdk:"created_time"`
|
||||
Desc types.String `tfsdk:"desc"`
|
||||
GID types.Int64 `tfsdk:"gid"`
|
||||
GUID types.Int64 `tfsdk:"guid"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
RGAccess types.List `tfsdk:"rg_access"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
OVSBridge types.String `tfsdk:"ovs_bridge"`
|
||||
VlanID types.Int64 `tfsdk:"vlan_id"`
|
||||
ComputeIDs types.List `tfsdk:"compute_ids"`
|
||||
UpdatedTime types.Int64 `tfsdk:"updated_time"`
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceDPDK() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
"dpdk_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
},
|
||||
"account_access": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.Int64Type,
|
||||
},
|
||||
"created_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"desc": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"gid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"rg_access": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.Int64Type,
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ovs_bridge": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"vlan_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"compute_ids": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.Int64Type,
|
||||
},
|
||||
"updated_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package schemas
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
func MakeSchemaDataSourceDPDKList() map[string]schema.Attribute {
|
||||
return map[string]schema.Attribute{
|
||||
// optional attributes
|
||||
"by_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
},
|
||||
"gid": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Optional: true,
|
||||
},
|
||||
"desc": schema.StringAttribute{
|
||||
Optional: true,
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Optional: true,
|
||||
},
|
||||
"compute_ids": schema.ListAttribute{
|
||||
Optional: true,
|
||||
ElementType: types.Int64Type,
|
||||
},
|
||||
"sort_by": schema.StringAttribute{
|
||||
Optional: true,
|
||||
},
|
||||
"page": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
},
|
||||
"size": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
},
|
||||
|
||||
// computed attributes
|
||||
"id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"items": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"dpdk_id": schema.Int64Attribute{
|
||||
Required: true,
|
||||
},
|
||||
"account_access": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.Int64Type,
|
||||
},
|
||||
"created_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"desc": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"gid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"guid": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"rg_access": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.Int64Type,
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"ovs_bridge": schema.StringAttribute{
|
||||
Computed: true,
|
||||
},
|
||||
"vlan_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
"compute_ids": schema.ListAttribute{
|
||||
Computed: true,
|
||||
ElementType: types.Int64Type,
|
||||
},
|
||||
"updated_time": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
@ -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/cloudapi/dpdknet"
|
||||
)
|
||||
|
||||
func DPDKDataSourceCheckPresence(ctx context.Context, dpdkId uint64, c *decort.DecortClient) (*dpdknet.RecordDPDKNet, diag.Diagnostics) {
|
||||
tflog.Info(ctx, fmt.Sprintf("DPDKDataSourceCheckPresence: Get info about DPDK net with ID - %d", dpdkId))
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
recordDPDK, err := c.CloudAPI().DPDKNet().Get(ctx, dpdknet.GetRequest{DPDKID: dpdkId})
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot get info about DPDK net with ID %d", dpdkId), err.Error())
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "DPDKDataSourceCheckPresence: response from CloudBroker().DPDKNet().Get", map[string]any{"dpdk_id": dpdkId, "response": recordDPDK})
|
||||
|
||||
return recordDPDK, nil
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package utilities
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/dpdknet"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/dpdknet/models"
|
||||
)
|
||||
|
||||
func DPDKListDataSourceCheckPresence(ctx context.Context, plan *models.DataSourceDPDKListModel, c *decort.DecortClient) (*dpdknet.ListDPDKNet, error) {
|
||||
tflog.Info(ctx, fmt.Sprintf("DPDKListDataSourceCheckPresence: Get DPDK list info"))
|
||||
|
||||
listDPDKReq := dpdknet.ListRequest{}
|
||||
|
||||
if !plan.ByID.IsNull() {
|
||||
listDPDKReq.ByID = uint64(plan.ByID.ValueInt64())
|
||||
}
|
||||
if !plan.GID.IsNull() {
|
||||
listDPDKReq.GID = uint64(plan.GID.ValueInt64())
|
||||
}
|
||||
if !plan.Name.IsNull() {
|
||||
listDPDKReq.Name = plan.Name.ValueString()
|
||||
}
|
||||
if !plan.Desc.IsNull() {
|
||||
listDPDKReq.Description = plan.Desc.ValueString()
|
||||
}
|
||||
if !plan.Status.IsNull() {
|
||||
listDPDKReq.Status = plan.Status.ValueString()
|
||||
}
|
||||
if !plan.ComputeIDs.IsNull() {
|
||||
computeIDs := make([]uint64, 0, len(plan.ComputeIDs.Elements()))
|
||||
diags := plan.ComputeIDs.ElementsAs(ctx, &computeIDs, false)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, "DPDKListDataSourceCheckPresence: cannot populate computeIDs with plan.ComputeIDs List elements")
|
||||
return nil, fmt.Errorf("cannot populate computeIDs with plan.ComputeIDs List elements")
|
||||
}
|
||||
listDPDKReq.ComputeIDs = computeIDs
|
||||
}
|
||||
if !plan.SortBy.IsNull() {
|
||||
listDPDKReq.SortBy = plan.SortBy.ValueString()
|
||||
}
|
||||
if !plan.Page.IsNull() {
|
||||
listDPDKReq.Page = uint64(plan.Page.ValueInt64())
|
||||
}
|
||||
if !plan.Size.IsNull() {
|
||||
listDPDKReq.Size = uint64(plan.Size.ValueInt64())
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "DPDKListDataSourceCheckPresence: before call CloudAPI().DPDKNet().List", map[string]any{"response": listDPDKReq})
|
||||
dpdkList, err := c.CloudAPI().DPDKNet().List(ctx, listDPDKReq)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get info about data source list DPDK net with error: %w", err)
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "DPDKListDataSourceCheckPresence: response from CloudAPI().DPDKNet().List", map[string]any{"response": dpdkList})
|
||||
|
||||
return dpdkList, err
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue