This commit is contained in:
asteam
2024-12-04 13:18:58 +03:00
parent 003e4d656e
commit 76ea459b3d
417 changed files with 30051 additions and 975 deletions

View File

@@ -60,31 +60,34 @@ func DataSourceK8s(ctx context.Context, state *models.RecordK8SDataSourceModel,
id := uuid.New()
*state = models.RecordK8SDataSourceModel{
K8SID: state.K8SID,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
ACL: flattenACLDataSource(ctx, &cluster.ACL),
AccountID: types.Int64Value(int64(cluster.AccountID)),
AccountName: types.StringValue(cluster.AccountName),
BServiceID: types.Int64Value(int64(cluster.BServiceID)),
K8CI: types.Int64Value(int64(cluster.CIID)),
CreatedBy: types.StringValue(cluster.CreatedBy),
CreatedTime: types.Int64Value(int64(cluster.CreatedTime)),
DeletedBy: types.StringValue(cluster.DeletedBy),
DeletedTime: types.Int64Value(int64(cluster.DeletedTime)),
K8CIName: types.StringValue(cluster.K8CIName),
Masters: flattenMasterGroup(ctx, &cluster.K8SGroups.Masters, masterComputeList),
Workers: flattenK8sGroup(ctx, &cluster.K8SGroups.Workers, workersComputeList),
LBID: types.Int64Value(int64(cluster.LBID)),
Name: types.StringValue(cluster.Name),
NetworkPlugin: types.StringValue(cluster.NetworkPlugin),
RGID: types.Int64Value(int64(cluster.RGID)),
RGName: types.StringValue(cluster.RGName),
Status: types.StringValue(cluster.Status),
TechStatus: types.StringValue(cluster.TechStatus),
UpdatedBy: types.StringValue(cluster.UpdatedBy),
UpdatedTime: types.Int64Value(int64(cluster.UpdatedTime)),
VinsId: types.Int64Value(int64(k8sList.Data[0].VINSID)),
K8SID: state.K8SID,
Timeouts: state.Timeouts,
Id: types.StringValue(id.String()),
ACL: flattenACLDataSource(ctx, &cluster.ACL),
AccountID: types.Int64Value(int64(cluster.AccountID)),
AccountName: types.StringValue(cluster.AccountName),
K8SAddressVIP: flattenAddressVIP(ctx, cluster.AddressVIP),
BServiceID: types.Int64Value(int64(cluster.BServiceID)),
K8CI: types.Int64Value(int64(cluster.CIID)),
CreatedBy: types.StringValue(cluster.CreatedBy),
CreatedTime: types.Int64Value(int64(cluster.CreatedTime)),
DeletedBy: types.StringValue(cluster.DeletedBy),
DeletedTime: types.Int64Value(int64(cluster.DeletedTime)),
ExtnetOnly: types.BoolValue(cluster.ExtnetOnly),
HighlyAvailableLB: types.BoolValue(cluster.HighlyAvailableLB),
K8CIName: types.StringValue(cluster.K8CIName),
Masters: flattenMasterGroup(ctx, &cluster.K8SGroups.Masters, masterComputeList),
Workers: flattenK8sGroup(ctx, &cluster.K8SGroups.Workers, workersComputeList),
LBID: types.Int64Value(int64(cluster.LBID)),
Name: types.StringValue(cluster.Name),
NetworkPlugin: types.StringValue(cluster.NetworkPlugin),
RGID: types.Int64Value(int64(cluster.RGID)),
RGName: types.StringValue(cluster.RGName),
Status: types.StringValue(cluster.Status),
TechStatus: types.StringValue(cluster.TechStatus),
UpdatedBy: types.StringValue(cluster.UpdatedBy),
UpdatedTime: types.Int64Value(int64(cluster.UpdatedTime)),
VinsId: types.Int64Value(int64(k8sList.Data[0].VINSID)),
}
if cluster.LBID != 0 {
@@ -106,6 +109,18 @@ func DataSourceK8s(ctx context.Context, state *models.RecordK8SDataSourceModel,
return nil
}
func flattenAddressVIP(ctx context.Context, addressedVip k8s.K8SAddressVIP) *models.K8SAddressVIP {
tflog.Info(ctx, "Start flattenAddressVIP")
res := models.K8SAddressVIP{
BackendIP: types.StringValue(addressedVip.BackendIP),
FrontendIP: types.StringValue(addressedVip.FrontendIP),
}
tflog.Info(ctx, "End flattenAddressVIP")
return &res
}
func flattenMasterGroup(ctx context.Context, mastersGroup *k8s.MasterGroup, masters []*compute.RecordCompute) *models.MasterGroupDataSourceModel {
tflog.Info(ctx, "Start flattenMasterGroup")

View File

@@ -7,6 +7,7 @@ import (
"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/cloudapi/compute"
@@ -67,6 +68,7 @@ func K8SCPResource(ctx context.Context, plan *models.ResourceK8SCPModel, c *deco
Description: plan.Description,
ExtNetOnly: plan.ExtNetOnly,
OidcCertificate: plan.OidcCertificate,
Chipset: plan.Chipset,
Start: plan.Start,
Enabled: plan.Enabled,
Permanently: plan.Permanently,
@@ -90,6 +92,7 @@ func K8SCPResource(ctx context.Context, plan *models.ResourceK8SCPModel, c *deco
CreatedTime: types.Int64Value(int64(cluster.CreatedTime)),
DeletedBy: types.StringValue(cluster.DeletedBy),
DeletedTime: types.Int64Value(int64(cluster.DeletedTime)),
K8SAddressVIP: flattenK8SAddressVIP(ctx, cluster.AddressVIP),
K8SID: types.Int64Value(int64(cluster.ID)),
K8CIName: types.StringValue(cluster.K8CIName),
LBID: types.Int64Value(int64(cluster.LBID)),
@@ -126,6 +129,23 @@ func K8SCPResource(ctx context.Context, plan *models.ResourceK8SCPModel, c *deco
return nil
}
func flattenK8SAddressVIP(ctx context.Context, addressedVip k8s.K8SAddressVIP) basetypes.ObjectValue {
tflog.Info(ctx, "Start flattenAddressVIP")
temp := models.AddressVIPModel{
BackendIP: types.StringValue(addressedVip.BackendIP),
FrontendIP: types.StringValue(addressedVip.FrontendIP),
}
res, err := types.ObjectValueFrom(ctx, models.AddressVIP, temp)
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenK8SAddressVIP struct to obj", err))
}
tflog.Info(ctx, "End flattenAddressVIP")
return res
}
func flattenDetailedInfo(ctx context.Context, di *k8s.ListDetailedInfo, computes []*compute.RecordCompute) types.List {
tflog.Info(ctx, "Start flattenDetailedInfo")

View File

@@ -48,6 +48,8 @@ func K8SWGResource(ctx context.Context, plan *models.ResourceK8SWGModel, c *deco
WorkerSEPPool: plan.WorkerSEPPool,
CloudInit: plan.CloudInit,
Timeouts: plan.Timeouts,
Chipset: plan.Chipset,
WorkerChipset: plan.WorkerChipset,
Id: types.StringValue(strconv.Itoa(int(wg.ID))),
WorkerGroupId: types.Int64Value(int64(wg.ID)),
LastUpdated: plan.LastUpdated,

View File

@@ -10,32 +10,40 @@ type RecordK8SDataSourceModel struct {
K8SID types.Int64 `tfsdk:"k8s_id"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
// response fields
Id types.String `tfsdk:"id"`
ACL *RecordACLDataSourceModel `tfsdk:"acl"`
AccountID types.Int64 `tfsdk:"account_id"`
AccountName types.String `tfsdk:"account_name"`
BServiceID types.Int64 `tfsdk:"bservice_id"`
K8CI types.Int64 `tfsdk:"k8sci_id"`
CreatedBy types.String `tfsdk:"created_by"`
CreatedTime types.Int64 `tfsdk:"created_time"`
DeletedBy types.String `tfsdk:"deleted_by"`
DeletedTime types.Int64 `tfsdk:"deleted_time"`
ExtNetID types.Int64 `tfsdk:"extnet_id"`
K8CIName types.String `tfsdk:"k8sci_name"`
Masters *MasterGroupDataSourceModel `tfsdk:"masters"`
Workers []ItemK8SGroupDataSourceModel `tfsdk:"workers"`
LBID types.Int64 `tfsdk:"lb_id"`
LBIP types.String `tfsdk:"lb_ip"`
Name types.String `tfsdk:"name"`
NetworkPlugin types.String `tfsdk:"network_plugin"`
RGID types.Int64 `tfsdk:"rg_id"`
RGName types.String `tfsdk:"rg_name"`
Status types.String `tfsdk:"status"`
TechStatus types.String `tfsdk:"tech_status"`
UpdatedBy types.String `tfsdk:"updated_by"`
UpdatedTime types.Int64 `tfsdk:"updated_time"`
Kubeconfig types.String `tfsdk:"kubeconfig"`
VinsId types.Int64 `tfsdk:"vins_id"`
Id types.String `tfsdk:"id"`
ACL *RecordACLDataSourceModel `tfsdk:"acl"`
AccountID types.Int64 `tfsdk:"account_id"`
AccountName types.String `tfsdk:"account_name"`
BServiceID types.Int64 `tfsdk:"bservice_id"`
K8CI types.Int64 `tfsdk:"k8sci_id"`
CreatedBy types.String `tfsdk:"created_by"`
CreatedTime types.Int64 `tfsdk:"created_time"`
DeletedBy types.String `tfsdk:"deleted_by"`
ExtnetOnly types.Bool `tfsdk:"extnet_only"`
HighlyAvailableLB types.Bool `tfsdk:"ha_mode"`
K8SAddressVIP *K8SAddressVIP `tfsdk:"address_vip"`
DeletedTime types.Int64 `tfsdk:"deleted_time"`
ExtNetID types.Int64 `tfsdk:"extnet_id"`
K8CIName types.String `tfsdk:"k8sci_name"`
Masters *MasterGroupDataSourceModel `tfsdk:"masters"`
Workers []ItemK8SGroupDataSourceModel `tfsdk:"workers"`
LBID types.Int64 `tfsdk:"lb_id"`
LBIP types.String `tfsdk:"lb_ip"`
Name types.String `tfsdk:"name"`
NetworkPlugin types.String `tfsdk:"network_plugin"`
RGID types.Int64 `tfsdk:"rg_id"`
RGName types.String `tfsdk:"rg_name"`
Status types.String `tfsdk:"status"`
TechStatus types.String `tfsdk:"tech_status"`
UpdatedBy types.String `tfsdk:"updated_by"`
UpdatedTime types.Int64 `tfsdk:"updated_time"`
Kubeconfig types.String `tfsdk:"kubeconfig"`
VinsId types.Int64 `tfsdk:"vins_id"`
}
type K8SAddressVIP struct {
BackendIP types.String `tfsdk:"backend_ip"`
FrontendIP types.String `tfsdk:"frontend_ip"`
}
type RecordACLDataSourceModel struct {

View File

@@ -16,6 +16,7 @@ type ResourceK8SCPModel struct {
SEPPool types.String `tfsdk:"sep_pool"`
Num types.Int64 `tfsdk:"num"`
CPU types.Int64 `tfsdk:"cpu"`
Chipset types.String `tfsdk:"chipset"`
RAM types.Int64 `tfsdk:"ram"`
Disk types.Int64 `tfsdk:"disk"`
ExtNetID types.Int64 `tfsdk:"extnet_id"`
@@ -51,6 +52,7 @@ type ResourceK8SCPModel struct {
DeletedTime types.Int64 `tfsdk:"deleted_time"`
K8SID types.Int64 `tfsdk:"k8s_id"`
K8CIName types.String `tfsdk:"k8s_ci_name"`
K8SAddressVIP types.Object `tfsdk:"address_vip"`
LBID types.Int64 `tfsdk:"lb_id"`
LBIP types.String `tfsdk:"lb_ip"`
MasterGroupId types.Int64 `tfsdk:"master_group_id"`
@@ -63,6 +65,11 @@ type ResourceK8SCPModel struct {
Kubeconfig types.String `tfsdk:"kubeconfig"`
}
type AddressVIPModel struct {
BackendIP types.String `tfsdk:"backend_ip"`
FrontendIP types.String `tfsdk:"frontend_ip"`
}
type RecordACLModel struct {
AccountACL types.List `tfsdk:"account_acl"`
K8SACL types.List `tfsdk:"k8s_acl"`
@@ -93,6 +100,11 @@ type ItemInterfacesModel struct {
IpAddress types.String `tfsdk:"ip_address"`
}
var AddressVIP map[string]attr.Type = map[string]attr.Type{
"backend_ip": types.StringType,
"frontend_ip": types.StringType,
}
var ItemInterfaces map[string]attr.Type = map[string]attr.Type{
"def_gw": types.StringType,
"ip_address": types.StringType,

View File

@@ -11,8 +11,10 @@ type ResourceK8SWGModel struct {
K8SID types.Int64 `tfsdk:"k8s_id"`
Name types.String `tfsdk:"name"`
Num types.Int64 `tfsdk:"num"`
WorkerChipset types.String `tfsdk:"worker_chipset"`
CPU types.Int64 `tfsdk:"cpu"`
RAM types.Int64 `tfsdk:"ram"`
Chipset types.String `tfsdk:"chipset"`
Disk types.Int64 `tfsdk:"disk"`
Annotations types.List `tfsdk:"annotations"`
Labels types.List `tfsdk:"labels"`

View File

@@ -122,6 +122,23 @@ func MakeSchemaDataSourceK8S() map[string]schema.Attribute {
"extnet_id": schema.Int64Attribute{
Computed: true,
},
"extnet_only": schema.BoolAttribute{
Computed: true,
},
"ha_mode": schema.BoolAttribute{
Computed: true,
},
"address_vip": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"backend_ip": schema.StringAttribute{
Computed: true,
},
"frontend_ip": schema.StringAttribute{
Computed: true,
},
},
},
"k8sci_name": schema.StringAttribute{
Computed: true,
},

View File

@@ -126,7 +126,14 @@ func MakeSchemaResourceK8SCP() map[string]schema.Attribute {
},
"oidc_cert": schema.StringAttribute{
Optional: true,
Description: "insert ssl certificate in x509 pem format",
Description: "Insert ssl certificate in x509 pem format",
},
"chipset": schema.StringAttribute{
Optional: true,
Description: "Type of the emulated system",
Validators: []validator.String{
stringvalidator.OneOfCaseInsensitive("Q35", "i440fx"),
},
},
"lb_sysctl_params": schema.ListNestedAttribute{
Optional: true,
@@ -302,6 +309,17 @@ func MakeSchemaResourceK8SCP() map[string]schema.Attribute {
"account_name": schema.StringAttribute{
Computed: true,
},
"address_vip": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"backend_ip": schema.StringAttribute{
Computed: true,
},
"frontend_ip": schema.StringAttribute{
Computed: true,
},
},
},
"bservice_id": schema.Int64Attribute{
Computed: true,
},

View File

@@ -1,6 +1,7 @@
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/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
@@ -28,11 +29,25 @@ func MakeSchemaResourceK8SWG() map[string]schema.Attribute {
Computed: true,
Description: "Number of worker nodes to create.",
},
"worker_chipset": schema.StringAttribute{
Optional: true,
Description: "Type of the emulated system of worker nodes",
Validators: []validator.String{
stringvalidator.OneOfCaseInsensitive("Q35", "i440fx"),
},
},
"cpu": schema.Int64Attribute{
Optional: true,
Computed: true,
Description: "Worker node CPU count.",
},
"chipset": schema.StringAttribute{
Optional: true,
Description: "Type of the emulated system of work group",
Validators: []validator.String{
stringvalidator.OneOfCaseInsensitive("Q35", "i440fx"),
},
},
"ram": schema.Int64Attribute{
Optional: true,
Computed: true,

View File

@@ -100,6 +100,10 @@ func CreateRequestResourceK8CP(ctx context.Context, plan *models.ResourceK8SCPMo
req.OidcCertificate = plan.OidcCertificate.ValueString()
}
if !plan.Chipset.IsNull() {
req.Chipset = plan.Chipset.ValueString()
}
if !plan.Description.IsNull() {
req.Description = plan.Description.ValueString()
}
@@ -427,7 +431,7 @@ func K8SCPDeleteMaster(ctx context.Context, plan *models.ResourceK8SCPModel, sta
diags := diag.Diagnostics{}
deleteMasterComp := make([]string, 0)
deleteMasterComp := make([]uint64, 0)
for i, val := range state.DetailedInfo.Elements() {
if i == 2 {
@@ -437,15 +441,16 @@ func K8SCPDeleteMaster(ctx context.Context, plan *models.ResourceK8SCPModel, sta
if err != nil {
tflog.Error(ctx, fmt.Sprint("Error flattenDetailedInfo struct to obj", err), map[string]any{"k8s_id": plan.Id.ValueString()})
}
id := obj.Attributes()["compute_id"]
id := obj.Attributes()["compute_id"].(types.Int64).ValueInt64()
deleteMasterComp = append(deleteMasterComp, id.String())
deleteMasterComp = append(deleteMasterComp, uint64(id))
}
req := k8s.DeleteMasterFromGroupRequest{
K8SID: uint64(state.K8SID.ValueInt64()),
MasterGroupID: uint64(state.MasterGroupId.ValueInt64()),
MasterIDs: deleteMasterComp,
//TODO fix it
//MasterIDs: deleteMasterComp,
}
_, err := c.CloudAPI().K8S().DeleteMasterFromGroup(ctx, req)

View File

@@ -13,6 +13,7 @@ import (
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8s"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/tasks"
"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/k8s/models"
)
@@ -76,6 +77,9 @@ func CreateRequestResourceK8WG(ctx context.Context, plan *models.ResourceK8SWGMo
if !plan.CloudInit.IsNull() {
req.UserData = plan.CloudInit.ValueString()
}
if !plan.Chipset.IsNull() {
req.Chipset = plan.Chipset.ValueString()
}
tflog.Info(ctx, "End CreateRequestResourceK8WG", map[string]any{"name": plan.Name.ValueString()})
return req
@@ -87,14 +91,44 @@ func ResourceK8SWGCreate(ctx context.Context, plan *models.ResourceK8SWGModel, c
diags := diag.Diagnostics{}
// Make request and get response
wgId, err := c.CloudAPI().K8S().WorkersGroupAdd(ctx, CreateRequestResourceK8WG(ctx, plan))
resp, err := c.CloudAPI().K8S().WorkersGroupAdd(ctx, CreateRequestResourceK8WG(ctx, plan))
if err != nil {
tflog.Error(ctx, "Error response for create k8s_wg")
diags.AddError("Unable to Create K8SWG", err.Error())
return diags
}
plan.Id = types.StringValue(strconv.Itoa(int(wgId)))
taskReq := tasks.GetRequest{
AuditID: strings.Trim(resp, `"`),
}
for {
task, err := c.CloudAPI().Tasks().Get(ctx, taskReq)
if err != nil {
diags.AddError("The audit cannot be found", err.Error())
return diags
}
tflog.Info(ctx, fmt.Sprintf("ResourceK8SWGCreate instance creating - %s", task.Stage))
if task.Completed {
if task.Error != "" {
diags.AddError("Cannot create k8s wg instance:", task.Error)
return diags
}
result, err := task.Result.ID()
if err != nil {
diags.AddError("Cannot get wg ID:", err.Error())
return diags
}
plan.Id = types.StringValue(strconv.Itoa(result))
plan.LastUpdated = types.StringValue(time.Now().Format(time.RFC850))
break
}
time.Sleep(time.Second * 20)
}
plan.LastUpdated = types.StringValue(time.Now().Format(time.RFC850))
wg, k8sId, err := K8SWGResourceCheckPresence(ctx, plan, c)
@@ -185,6 +219,7 @@ func K8SWGUpdateNumWorkers(ctx context.Context, plan, state *models.ResourceK8SW
K8SID: k8sId,
WorkersGroupID: wg.ID,
Num: uint64(newNum) - wg.Num,
Chipset: plan.WorkerChipset.ValueString(),
}
tflog.Info(ctx, "Add workers in wg with id", map[string]any{"wg_id": state.WorkerGroupId.ValueInt64(), "k8s_id": state.K8SID.ValueInt64()})