This commit is contained in:
2023-07-26 13:32:39 +03:00
parent f731cf246f
commit 272e385318
167 changed files with 5194 additions and 890 deletions

View File

@@ -22,7 +22,6 @@ package controller
import (
"bytes"
"context"
"crypto/tls"
"fmt"
"io/ioutil"
@@ -30,7 +29,6 @@ import (
"net/url"
"strconv"
"strings"
"time"
// "time"
@@ -373,82 +371,3 @@ func (config *ControllerCfg) CloudBroker() *cloudbroker.CloudBroker {
client, _ := config.caller.(*decort.DecortClient)
return client.CloudBroker()
}
func (config *ControllerCfg) DecortAPICall(ctx context.Context, method string, api_name string, url_values *url.Values) (json_resp string, err error) { //nolint:unparam
// This is a convenience wrapper around standard HTTP request methods that is aware of the
// authorization mode for which the provider was initialized and compiles request accordingly.
if config.cc_client == nil {
// this should never happen if ClientConfig was properly called prior to decortAPICall
return "", fmt.Errorf("decortAPICall method called with unconfigured DECORT cloud controller HTTP client.")
}
// Example: to create api_params, one would generally do the following:
//
// data := []byte(`{"machineId": "2638"}`)
// api_params := bytes.NewBuffer(data))
//
// Or:
//
// params := url.Values{}
// params.Add("machineId", "2638")
// params.Add("username", "u")
// params.Add("password", "b")
// req, _ := http.NewRequest(method, url, strings.NewReader(params.Encode()))
//
if config.auth_mode_code == MODE_UNDEF {
return "", fmt.Errorf("decortAPICall method called for unknown authorization mode.")
}
if config.auth_mode_code == MODE_LEGACY {
url_values.Add("authkey", config.legacy_sid)
}
params_str := url_values.Encode()
req, err := http.NewRequest(method, config.controller_url+api_name, strings.NewReader(params_str))
if err != nil {
return "", err
}
req = req.WithContext(ctx)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Content-Length", strconv.Itoa(len(params_str)))
req.Header.Set("Accept", "application/json")
if config.auth_mode_code == MODE_OAUTH2 || config.auth_mode_code == MODE_JWT {
req.Header.Set("Authorization", fmt.Sprintf("bearer %s", config.jwt))
}
var resp *http.Response
var body []byte
for i := 0; i < 5; i++ {
resp, err = config.cc_client.Do(req)
if err != nil {
return "", err
}
body, err = ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
resp.Body.Close()
log.Debugf("decortAPICall: %s %s\n %s", method, api_name, body)
if resp.StatusCode == http.StatusOK {
return string(body), nil
} else {
if resp.StatusCode == http.StatusInternalServerError {
log.Warnf("got 500, retrying %d/5", i+1)
time.Sleep(time.Second * 5)
continue
}
return "", fmt.Errorf("decortAPICall: unexpected status code %d when calling API %q with request Body %q. Respone:\n%s",
resp.StatusCode, req.URL, params_str, body)
}
}
return "", fmt.Errorf("decortAPICall: unexpected status code %d when calling API %q with request Body %q. Respone:\n%s",
resp.StatusCode, req.URL, params_str, body)
}

View File

@@ -41,13 +41,13 @@ func UtilityLocationGetDefaultGridID(ctx context.Context, m interface{}) (int, e
return 0, err
}
if len(locList) == 0 {
if len(locList.Data) == 0 {
DefaultGridID = 0
return 0, fmt.Errorf("utilityLocationGetDefaultGridID: retrieved 0 length locations list")
}
DefaultGridID = int(locList[0].GID)
log.Debugf("utilityLocationGetDefaultGridID: default location GridID %d, name %s", DefaultGridID, locList[0].Name)
DefaultGridID = int(locList.Data[0].GID)
log.Debugf("utilityLocationGetDefaultGridID: default location GridID %d, name %s", DefaultGridID, locList.Data[0].Name)
return DefaultGridID, nil
}

View File

@@ -38,6 +38,7 @@ import (
cb_account "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/account"
cb_disks "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/disks"
cb_extnet "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/extnet"
cb_grid "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/grid"
cb_image "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/image"
cb_pcidevice "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/pcidevice"
@@ -65,6 +66,7 @@ func newDataSourcesMap() map[string]*schema.Resource {
"decort_k8s_wg": k8s.DataSourceK8sWg(),
"decort_k8s_wg_list": k8s.DataSourceK8sWgList(),
"decort_k8s_computes": k8s.DataSourceK8sComputes(),
"decort_k8ci_list": k8s.DataSourceK8CIList(),
"decort_vins": vins.DataSourceVins(),
"decort_vins_list": vins.DataSourceVinsList(),
"decort_vins_audits": vins.DataSourceVinsAudits(),
@@ -132,6 +134,9 @@ func newDataSourcesMap() map[string]*schema.Resource {
"decort_cb_account_rg_list": cb_account.DataSourceAccountRGList(),
"decort_cb_account_vins_list": cb_account.DataSourceAccountVinsList(),
"decort_cb_account_audits_list": cb_account.DataSourceAccountAuditsList(),
"decort_cb_extnet": cb_extnet.DataSourceExtnetCB(),
"decort_cb_extnet_list": cb_extnet.DataSourceExtnetListCB(),
"decort_cb_extnet_default": cb_extnet.DataSourceExtnetDefaultCB(),
"decort_cb_disk": cb_disks.DataSourceDisk(),
"decort_cb_disk_list": cb_disks.DataSourceDiskList(),
"decort_cb_image": cb_image.DataSourceImage(),

View File

@@ -37,6 +37,7 @@ import (
cb_account "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/account"
cb_disks "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/disks"
cb_extnet "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/extnet"
cb_image "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/image"
cb_k8s "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/k8s"
cb_kvmvm "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/kvmvm"
@@ -73,6 +74,7 @@ func newResourcesMap() map[string]*schema.Resource {
"decort_flipgroup": flipgroup.ResourceFlipgroup(),
"decort_cb_account": cb_account.ResourceAccount(),
"decort_cb_extnet": cb_extnet.ResourceExtnetCB(),
"decort_cb_disk": cb_disks.ResourceDisk(),
"decort_cb_image": cb_image.ResourceImage(),
"decort_cb_virtual_image": cb_image.ResourceVirtualImage(),

View File

@@ -41,6 +41,7 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
// TODO: resources (additional ds / additional request inside body (?))
func dataSourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
acc, err := utilityAccountCheckPresence(ctx, d, m)
if err != nil {
@@ -268,13 +269,13 @@ func dataSourceAccountSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"resources": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: resourcesSchemaMake(),
},
},
// "resources": {
// Type: schema.TypeList,
// Computed: true,
// Elem: &schema.Resource{
// Schema: resourcesSchemaMake(),
// },
// },
"ckey": {
Type: schema.TypeString,
Computed: true,

View File

@@ -42,9 +42,9 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func flattenAccountComputesList(acl account.ListComputes) []map[string]interface{} {
func flattenAccountComputesList(acl *account.ListComputes) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, acc := range acl {
for _, acc := range acl.Data {
temp := map[string]interface{}{
"account_id": acc.AccountID,
"account_name": acc.AccountName,
@@ -82,6 +82,7 @@ func dataSourceAccountComputesListRead(ctx context.Context, d *schema.ResourceDa
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenAccountComputesList(accountComputesList))
d.Set("entry_count", accountComputesList.EntryCount)
return nil
}
@@ -93,6 +94,56 @@ func dataSourceAccountComputesListSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "ID of the account",
},
"compute_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by compute ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by compute name",
},
"rg_name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by RG name",
},
"rg_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by RG ID",
},
"tech_status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by tech. status",
},
"ip_address": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by IP address",
},
"extnet_name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by extnet name",
},
"extnet_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by extnet ID",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "Page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "Page size",
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -182,6 +233,10 @@ func dataSourceAccountComputesListSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}

View File

@@ -50,10 +50,17 @@ func dataSourceAccountDeletedListRead(ctx context.Context, d *schema.ResourceDat
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenAccountList(accountDeletedList))
d.Set("entry_count", accountDeletedList.EntryCount)
return nil
}
func dataSourceAccountDeletedListSchemaMake() map[string]*schema.Schema {
temp := dataSourceAccountListSchemaMake()
delete(temp, "status")
return temp
}
func DataSourceAccountDeletedList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
@@ -65,6 +72,6 @@ func DataSourceAccountDeletedList() *schema.Resource {
Default: &constants.Timeout60s,
},
Schema: dataSourceAccountListSchemaMake(),
Schema: dataSourceAccountDeletedListSchemaMake(),
}
}

View File

@@ -41,9 +41,9 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func flattenAccountDisksList(adl account.ListDisks) []map[string]interface{} {
func flattenAccountDisksList(adl *account.ListDisks) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, ad := range adl {
for _, ad := range adl.Data {
temp := map[string]interface{}{
"disk_id": ad.ID,
"disk_name": ad.Name,
@@ -68,6 +68,7 @@ func dataSourceAccountDisksListRead(ctx context.Context, d *schema.ResourceData,
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenAccountDisksList(accountDisksList))
d.Set("entry_count", accountDisksList.EntryCount)
return nil
}
@@ -79,6 +80,36 @@ func dataSourceAccountDisksListSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "ID of the account",
},
"disk_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by disk ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by disk name",
},
"disk_max_size": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by disk max size",
},
"type": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by disk type",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "Page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "Page size",
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -116,6 +147,10 @@ func dataSourceAccountDisksListSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}

View File

@@ -42,9 +42,9 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func flattenAccountFlipGroupsList(afgl account.ListFLIPGroups) []map[string]interface{} {
func flattenAccountFlipGroupsList(afgl *account.ListFLIPGroups) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, afg := range afgl {
for _, afg := range afgl.Data {
temp := map[string]interface{}{
"account_id": afg.AccountID,
"client_type": afg.ClientType,
@@ -83,6 +83,7 @@ func dataSourceAccountFlipGroupsListRead(ctx context.Context, d *schema.Resource
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenAccountFlipGroupsList(accountFlipGroupsList))
d.Set("entry_count", accountFlipGroupsList.EntryCount)
return nil
}
@@ -94,6 +95,46 @@ func dataSourceAccountFlipGroupsListSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "ID of the account",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by name",
},
"vins_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ViNS ID",
},
"vins_name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by ViNS name",
},
"extnet_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by extnet ID",
},
"by_ip": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by IP",
},
"flipgroup_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by flipgroup ID",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "Page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "Page size",
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -187,6 +228,10 @@ func dataSourceAccountFlipGroupsListSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}

View File

@@ -42,9 +42,9 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func flattenAccountList(al account.ListAccounts) []map[string]interface{} {
func flattenAccountList(al *account.ListAccounts) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, acc := range al {
for _, acc := range al.Data {
temp := map[string]interface{}{
"acl": flattenRgAcl(acc.ACL),
"created_time": acc.CreatedTime,
@@ -84,12 +84,33 @@ func dataSourceAccountListRead(ctx context.Context, d *schema.ResourceData, m in
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenAccountList(accountList))
d.Set("entry_count", accountList.EntryCount)
return nil
}
func dataSourceAccountListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by name",
},
"acl": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by ACL",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by status",
},
"page": {
Type: schema.TypeInt,
Optional: true,
@@ -164,6 +185,10 @@ func dataSourceAccountListSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}

View File

@@ -42,9 +42,9 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func flattenAccountRGList(argl account.ListRG) []map[string]interface{} {
func flattenAccountRGList(argl *account.ListRG) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, arg := range argl {
for _, arg := range argl.Data {
temp := map[string]interface{}{
"computes": flattenAccRGComputes(arg.Computes),
"resources": flattenAccRGResources(arg.Resources),
@@ -125,6 +125,7 @@ func dataSourceAccountRGListRead(ctx context.Context, d *schema.ResourceData, m
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenAccountRGList(accountRGList))
d.Set("entry_count", accountRGList.EntryCount)
return nil
}
@@ -136,6 +137,41 @@ func dataSourceAccountRGListSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "ID of the account",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "Page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "Page size",
},
"rg_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by RG ID",
},
"vins_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ViNS ID",
},
"vm_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by VM ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by name",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by status",
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -311,6 +347,10 @@ func dataSourceAccountRGListSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}

View File

@@ -42,9 +42,9 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func flattenAccountTemplatesList(atl account.ListTemplates) []map[string]interface{} {
func flattenAccountTemplatesList(atl *account.ListTemplates) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, at := range atl {
for _, at := range atl.Data {
temp := map[string]interface{}{
"unc_path": at.UNCPath,
"account_id": at.AccountID,
@@ -83,6 +83,10 @@ func dataSourceAccountTemplatesListSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "ID of the account",
},
"include_deleted": {
Type: schema.TypeBool,
Optional: true,
},
"items": {
Type: schema.TypeList,
Computed: true,

View File

@@ -42,9 +42,9 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func flattenAccountVinsList(avl account.ListVINS) []map[string]interface{} {
func flattenAccountVinsList(avl *account.ListVINS) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, av := range avl {
for _, av := range avl.Data {
temp := map[string]interface{}{
"account_id": av.AccountID,
"account_name": av.AccountName,
@@ -79,6 +79,7 @@ func dataSourceAccountVinsListRead(ctx context.Context, d *schema.ResourceData,
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenAccountVinsList(accountVinsList))
d.Set("entry_count", accountVinsList.EntryCount)
return nil
}
@@ -90,6 +91,36 @@ func dataSourceAccountVinsListSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "ID of the account",
},
"vins_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ViNS ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by name",
},
"rg_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by RG ID",
},
"ext_ip": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by external IP",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "Page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "Page size",
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -167,6 +198,10 @@ func dataSourceAccountVinsListSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}

View File

@@ -7,7 +7,7 @@ import (
func flattenAccount(d *schema.ResourceData, acc account.RecordAccount) error {
d.Set("dc_location", acc.DCLocation)
d.Set("resources", flattenAccResources(acc.Resources))
// d.Set("resources", flattenAccResources(acc.Resources))
d.Set("ckey", acc.CKey)
d.Set("acl", flattenAccAcl(acc.ACL))
d.Set("company", acc.Company)
@@ -95,15 +95,15 @@ func flattenRgResourceLimits(rl account.ResourceLimits) []map[string]interface{}
}
func flattenAccResources(r account.Resources) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"current": flattenAccResource(r.Current),
"reserved": flattenAccResource(r.Reserved),
}
res = append(res, temp)
return res
}
// func flattenAccResources(r account.Resources) []map[string]interface{} {
// res := make([]map[string]interface{}, 0)
// temp := map[string]interface{}{
// "current": flattenAccResource(r.Current),
// "reserved": flattenAccResource(r.Reserved),
// }
// res = append(res, temp)
// return res
// }
func flattenAccountSeps(seps map[string]map[string]account.DiskUsage) []map[string]interface{} {
res := make([]map[string]interface{}, 0)

View File

@@ -47,129 +47,8 @@ import (
)
func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceAccountCreate")
c := m.(*controller.ControllerCfg)
req := account.CreateRequest{}
req.Name = d.Get("account_name").(string)
req.Username = d.Get("username").(string)
if emailaddress, ok := d.GetOk("emailaddress"); ok {
req.EmailAddress = emailaddress.(string)
}
if sendAccessEmails, ok := d.GetOk("send_access_emails"); ok {
req.SendAccessEmails = sendAccessEmails.(bool)
}
if resLimits, ok := d.GetOk("resource_limits"); ok {
resLimit := resLimits.([]interface{})[0]
resLimitConv := resLimit.(map[string]interface{})
if resLimitConv["cu_m"] != nil {
maxMemCap := int(resLimitConv["cu_m"].(float64))
if maxMemCap == 0 {
req.MaxMemoryCapacity = -1
} else {
req.MaxMemoryCapacity = int64(maxMemCap)
}
}
if resLimitConv["cu_d"] != nil {
maxDiskCap := int(resLimitConv["cu_d"].(float64))
if maxDiskCap == 0 {
req.MaxVDiskCapacity = -1
} else {
req.MaxVDiskCapacity = int64(maxDiskCap)
}
}
if resLimitConv["cu_c"] != nil {
maxCPUCap := int(resLimitConv["cu_c"].(float64))
if maxCPUCap == 0 {
req.MaxCPUCapacity = -1
} else {
req.MaxCPUCapacity = int64(maxCPUCap)
}
}
if resLimitConv["cu_i"] != nil {
maxNumPublicIP := int(resLimitConv["cu_i"].(float64))
if maxNumPublicIP == 0 {
req.MaxNumPublicIP = -1
} else {
req.MaxNumPublicIP = int64(maxNumPublicIP)
}
}
if resLimitConv["cu_np"] != nil {
maxNP := int(resLimitConv["cu_np"].(float64))
if maxNP == 0 {
req.MaxNetworkPeerTransfer = -1
} else {
req.MaxNetworkPeerTransfer = int64(maxNP)
}
}
if resLimitConv["gpu_units"] != nil {
gpuUnits := int(resLimitConv["gpu_units"].(float64))
if gpuUnits == 0 {
req.GPUUnits = -1
} else {
req.GPUUnits = int64(gpuUnits)
}
}
}
accountId, err := c.CloudAPI().Account().Create(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId(strconv.FormatUint(accountId, 10))
d.Set("account_id", accountId)
if enable, ok := d.GetOk("enable"); ok {
reqSwitch := account.DisableEnableRequest{
AccountID: accountId,
}
enable := enable.(bool)
if enable {
_, err := c.CloudAPI().Account().Enable(ctx, reqSwitch)
if err != nil {
return diag.FromErr(err)
} else {
_, err := c.CloudAPI().Account().Disable(ctx, reqSwitch)
if err != nil {
return diag.FromErr(err)
}
}
}
}
if users, ok := d.GetOk("users"); ok {
addedUsers := users.([]interface{})
if len(addedUsers) > 0 {
for _, user := range addedUsers {
userConv := user.(map[string]interface{})
req := account.AddUserRequest{
AccountID: accountId,
UserID: userConv["user_id"].(string),
AccessType: strings.ToUpper(userConv["access_type"].(string)),
}
_, err := c.CloudAPI().Account().AddUser(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
}
}
return resourceAccountRead(ctx, d, m)
return diag.Errorf(
"Only users with admin privileges are able to create accounts. Contact your platform administrator.\nUse 'terraform import decort_account.<NAME> <ID>' command to import existing account configuration")
}
func resourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
@@ -629,13 +508,13 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"resources": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: resourcesSchemaMake(),
},
},
// "resources": {
// Type: schema.TypeList,
// Computed: true,
// Elem: &schema.Resource{
// Schema: resourcesSchemaMake(),
// },
// },
"ckey": {
Type: schema.TypeString,
Computed: true,

View File

@@ -42,7 +42,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityAccountComputesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListComputes, error) {
func utilityAccountComputesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListComputes, error) {
c := m.(*controller.ControllerCfg)
var id uint64
@@ -52,6 +52,46 @@ func utilityAccountComputesListCheckPresence(ctx context.Context, d *schema.Reso
AccountID: id,
}
if compute_id, ok := d.GetOk("compute_id"); ok {
req.ComputeID = uint64(compute_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if rg_name, ok := d.GetOk("rg_name"); ok {
req.RGName = rg_name.(string)
}
if rg_id, ok := d.GetOk("rg_id"); ok {
req.RGID = uint64(rg_id.(int))
}
if tech_status, ok := d.GetOk("tech_status"); ok {
req.TechStatus = tech_status.(string)
}
if ip_address, ok := d.GetOk("ip_address"); ok {
req.IPAddress = ip_address.(string)
}
if extnet_name, ok := d.GetOk("extnet_name"); ok {
req.ExtNetName = extnet_name.(string)
}
if extnet_id, ok := d.GetOk("extnet_id"); ok {
req.ExtNetID = uint64(extnet_id.(int))
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
log.Debugf("utilityAccountComputesListCheckPresence: load account list")
accountComputesList, err := c.CloudAPI().Account().ListComputes(ctx, req)
if err != nil {

View File

@@ -42,23 +42,29 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityAccountDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListAccounts, error) {
func utilityAccountDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListAccounts, error) {
c := m.(*controller.ControllerCfg)
var (
pageVal uint64 = 0
sizeVal uint64 = 0
)
req := account.ListDeletedRequest{}
if page, ok := d.GetOk("page"); ok {
pageVal = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
sizeVal = uint64(size.(int))
req.Page = uint64(page.(int))
}
req := account.ListDeletedRequest{
Page: pageVal,
Size: sizeVal,
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if acl, ok := d.GetOk("acl"); ok {
req.ACL = acl.(string)
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
log.Debugf("utilityAccountDeletedListCheckPresence: load")

View File

@@ -41,7 +41,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityAccountDisksListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListDisks, error) {
func utilityAccountDisksListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListDisks, error) {
c := m.(*controller.ControllerCfg)
var id uint64
@@ -51,6 +51,30 @@ func utilityAccountDisksListCheckPresence(ctx context.Context, d *schema.Resourc
AccountID: id,
}
if disk_id, ok := d.GetOk("disk_id"); ok {
req.DiskID = uint64(disk_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if disk_max_size, ok := d.GetOk("disk_max_size"); ok {
req.DiskMaxSize = uint64(disk_max_size.(int))
}
if typeVal, ok := d.GetOk("type"); ok {
req.Type = typeVal.(string)
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
accountDisksList, err := c.CloudAPI().Account().ListDisks(ctx, req)
if err != nil {
return nil, err

View File

@@ -42,7 +42,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityAccountFlipGroupsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListFLIPGroups, error) {
func utilityAccountFlipGroupsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListFLIPGroups, error) {
c := m.(*controller.ControllerCfg)
var id uint64
@@ -52,6 +52,38 @@ func utilityAccountFlipGroupsListCheckPresence(ctx context.Context, d *schema.Re
AccountID: id,
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if vins_id, ok := d.GetOk("vins_id"); ok {
req.VINSID = uint64(vins_id.(int))
}
if vins_name, ok := d.GetOk("vins_name"); ok {
req.VINSName = vins_name.(string)
}
if extnet_id, ok := d.GetOk("extnet_id"); ok {
req.ExtNetID = uint64(extnet_id.(int))
}
if by_ip, ok := d.GetOk("by_ip"); ok {
req.ByIP = by_ip.(string)
}
if flipgroup_id, ok := d.GetOk("flipgroup_id"); ok {
req.FLIPGroupID = uint64(flipgroup_id.(int))
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
log.Debugf("utilityAccountFlipGroupsListCheckPresence")
accountFlipGroupsList, err := c.CloudAPI().Account().ListFLIPGroups(ctx, req)
if err != nil {

View File

@@ -42,23 +42,31 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityAccountListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListAccounts, error) {
func utilityAccountListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListAccounts, error) {
c := m.(*controller.ControllerCfg)
var (
pageVal uint64 = 0
sizeVal uint64 = 0
)
req := account.ListRequest{}
if page, ok := d.GetOk("page"); ok {
pageVal = uint64(page.(int))
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
sizeVal = uint64(size.(int))
req.Size = uint64(size.(int))
}
req := account.ListRequest{
Page: pageVal,
Size: sizeVal,
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if acl, ok := d.GetOk("acl"); ok {
req.ACL = acl.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
log.Debugf("utilityAccountListCheckPresence: load account list")

View File

@@ -42,7 +42,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityAccountRGListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListRG, error) {
func utilityAccountRGListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListRG, error) {
c := m.(*controller.ControllerCfg)
var id uint64
@@ -52,6 +52,34 @@ func utilityAccountRGListCheckPresence(ctx context.Context, d *schema.ResourceDa
AccountID: id,
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if rg_id, ok := d.GetOk("rg_id"); ok {
req.RGID = uint64(rg_id.(int))
}
if vins_id, ok := d.GetOk("vins_id"); ok {
req.VINSID = uint64(vins_id.(int))
}
if vm_id, ok := d.GetOk("vm_id"); ok {
req.VMID = uint64(vm_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
log.Debugf("utilityAccountRGListCheckPresence: load account list")
accountRGList, err := c.CloudAPI().Account().ListRG(ctx, req)
if err != nil {

View File

@@ -42,7 +42,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityAccountTemplatesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListTemplates, error) {
func utilityAccountTemplatesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListTemplates, error) {
c := m.(*controller.ControllerCfg)
var id uint64
@@ -52,6 +52,10 @@ func utilityAccountTemplatesListCheckPresence(ctx context.Context, d *schema.Res
AccountID: id,
}
if include_deleted, ok := d.GetOk("include_deleted"); ok {
req.IncludeDeleted = include_deleted.(bool)
}
log.Debugf("utilityAccountTemplatesListCheckPresence: load")
accountTemplatesList, err := c.CloudAPI().Account().ListTemplates(ctx, req)
if err != nil {

View File

@@ -42,7 +42,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityAccountVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListVINS, error) {
func utilityAccountVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListVINS, error) {
c := m.(*controller.ControllerCfg)
var id uint64
@@ -52,6 +52,30 @@ func utilityAccountVinsListCheckPresence(ctx context.Context, d *schema.Resource
AccountID: id,
}
if vins_id, ok := d.GetOk("vins_id"); ok {
req.VINSID = uint64(vins_id.(int))
}
if rg_id, ok := d.GetOk("rg_id"); ok {
req.RGID = uint64(rg_id.(int))
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if ext_ip, ok := d.GetOk("ext_ip"); ok {
req.ExtIP = ext_ip.(string)
}
log.Debugf("utilityAccountVinsListCheckPresence: load account list")
accountVinsList, err := c.CloudAPI().Account().ListVINS(ctx, req)
if err != nil {

View File

@@ -50,10 +50,24 @@ func dataSourceBasicServiceDeletedListRead(ctx context.Context, d *schema.Resour
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenBasicServiceList(basicServiceDeletedList))
d.Set("entry_count", basicServiceDeletedList.EntryCount)
return nil
}
func dataSourceBasicServiceDeletedListSchemaMake() map[string]*schema.Schema {
temp := dataSourceBasicServiceListSchemaMake()
delete(temp, "by_id")
delete(temp, "name")
delete(temp, "rg_name")
delete(temp, "status")
delete(temp, "tech_status")
delete(temp, "account_name")
return temp
}
func DataSourceBasicServiceDeletedList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
@@ -65,6 +79,6 @@ func DataSourceBasicServiceDeletedList() *schema.Resource {
Default: &constants.Timeout60s,
},
Schema: dataSourceBasicServiceListSchemaMake(),
Schema: dataSourceBasicServiceDeletedListSchemaMake(),
}
}

View File

@@ -42,9 +42,9 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func flattenBasicServiceList(bsl bservice.ListBasicServices) []map[string]interface{} {
func flattenBasicServiceList(bsl *bservice.ListBasicServices) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, bs := range bsl {
for _, bs := range bsl.Data {
temp := map[string]interface{}{
"account_id": bs.AccountID,
"account_name": bs.AccountName,
@@ -83,12 +83,43 @@ func dataSourceBasicServiceListRead(ctx context.Context, d *schema.ResourceData,
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenBasicServiceList(basicServiceList))
d.Set("entry_count", basicServiceList.EntryCount)
return nil
}
func dataSourceBasicServiceListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by bservice name",
},
"rg_name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by resource group name",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by status",
},
"tech_status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by tech status",
},
"account_name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by account name",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
@@ -208,6 +239,10 @@ func dataSourceBasicServiceListSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}

View File

@@ -20,5 +20,5 @@ func existRGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool
rgId := uint64(d.Get("rg_id").(int))
return len(rgList.FilterByID(rgId)) != 0, nil
return len(rgList.FilterByID(rgId).Data) != 0, nil
}

View File

@@ -42,9 +42,9 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityBasicServiceDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (bservice.ListBasicServices, error) {
func utilityBasicServiceDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*bservice.ListBasicServices, error) {
c := m.(*controller.ControllerCfg)
req := bservice.ListRequest{}
req := bservice.ListDeletedRequest{}
if accountId, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountId.(int))

View File

@@ -42,7 +42,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityBasicServiceListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (bservice.ListBasicServices, error) {
func utilityBasicServiceListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*bservice.ListBasicServices, error) {
c := m.(*controller.ControllerCfg)
req := bservice.ListRequest{}
@@ -59,6 +59,30 @@ func utilityBasicServiceListCheckPresence(ctx context.Context, d *schema.Resourc
req.Size = uint64(size.(int))
}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if rg_name, ok := d.GetOk("rg_name"); ok {
req.RGName = rg_name.(string)
}
if tech_status, ok := d.GetOk("tech_status"); ok {
req.TechStatus = tech_status.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if acc_name, ok := d.GetOk("account_name"); ok {
req.AccountName = acc_name.(string)
}
log.Debugf("utilityBasicServiceListCheckPresence")
basicServiceList, err := c.CloudAPI().BService().List(ctx, req)
if err != nil {

View File

@@ -50,12 +50,43 @@ func dataSourceDiskListRead(ctx context.Context, d *schema.ResourceData, m inter
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenDiskList(diskList))
d.Set("entry_count", diskList.EntryCount)
return nil
}
func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Find by name",
},
"account_name": {
Type: schema.TypeString,
Optional: true,
Description: "Find by account name",
},
"disk_max_size": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by max disk size",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Find by status",
},
"shared": {
Type: schema.TypeBool,
Optional: true,
Description: "Find by shared field",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
@@ -434,6 +465,10 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}

View File

@@ -38,12 +38,13 @@ import (
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/disks"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func flattenDiskListTypesDetailed(tld []interface{}) []map[string]interface{} {
func flattenDiskListTypesDetailed(tld *disks.ListTypes) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, typeListDetailed := range tld {
for _, typeListDetailed := range tld.Data {
toMap := typeListDetailed.(map[string]interface{})
temp := map[string]interface{}{
"pools": flattenListTypesDetailedPools(toMap["pools"].([]interface{})),

View File

@@ -50,6 +50,7 @@ func dataSourceDiskListUnattachedRead(ctx context.Context, d *schema.ResourceDat
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenDiskListUnattached(diskListUnattached))
d.Set("entry_count", diskListUnattached.EntryCount)
return nil
}
@@ -71,12 +72,46 @@ func DataSourceDiskListUnattached() *schema.Resource {
func dataSourceDiskListUnattachedSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by ID",
},
"account_name": {
Type: schema.TypeString,
Optional: true,
Description: "Find by account name",
},
"disk_max_size": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by max disk size",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Find by status",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
Description: "ID of the account the disks belong to",
},
"type": {
Type: schema.TypeString,
Optional: true,
Description: "type of the disks",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "Page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "Page size",
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -401,6 +436,10 @@ func dataSourceDiskListUnattachedSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}

View File

@@ -4,6 +4,7 @@ Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Tim Tkachev, <tvtkachev@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -42,7 +43,7 @@ import (
)
func dataSourceDiskListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
diskList, err := utilityDiskListCheckPresence(ctx, d, m)
diskList, err := utilityDiskListDeletedCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
@@ -50,10 +51,424 @@ func dataSourceDiskListDeletedRead(ctx context.Context, d *schema.ResourceData,
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenDiskList(diskList))
d.Set("entry_count", diskList.EntryCount)
return nil
}
func dataSourceDiskDeletedListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by disk ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by disk name",
},
"account_name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by account name",
},
"disk_max_size": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by max disk size",
},
"shared": {
Type: schema.TypeBool,
Optional: true,
Description: "Find shared disks",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
Description: "ID of the account the disks belong to",
},
"type": {
Type: schema.TypeString,
Optional: true,
Description: "type of the disks",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "Page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "Page size",
},
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"account_id": {
Type: schema.TypeInt,
Computed: true,
Description: "The unique ID of the subscriber-owner of the disk",
},
"account_name": {
Type: schema.TypeString,
Computed: true,
Description: "The name of the subscriber '(account') to whom this disk belongs",
},
"acl": {
Type: schema.TypeString,
Computed: true,
},
// "boot_partition": {
// Type: schema.TypeInt,
// Computed: true,
// Description: "Number of disk partitions",
// },
"computes": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_id": {
Type: schema.TypeString,
Computed: true,
},
"compute_name": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
Description: "Created time",
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
Description: "Deleted time",
},
"desc": {
Type: schema.TypeString,
Computed: true,
Description: "Description of disk",
},
"destruction_time": {
Type: schema.TypeInt,
Computed: true,
Description: "Time of final deletion",
},
"devicename": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the device",
},
// "disk_path": {
// Type: schema.TypeString,
// Computed: true,
// Description: "Disk path",
// },
"gid": {
Type: schema.TypeInt,
Computed: true,
Description: "ID of the grid (platform)",
},
// "guid": {
// Type: schema.TypeInt,
// Computed: true,
// Description: "Disk ID on the storage side",
// },
"disk_id": {
Type: schema.TypeInt,
Computed: true,
Description: "The unique ID of the subscriber-owner of the disk",
},
"image_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Image ID",
},
"images": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "IDs of images using the disk",
},
"iotune": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"read_bytes_sec": {
Type: schema.TypeInt,
Computed: true,
Description: "Number of bytes to read per second",
},
"read_bytes_sec_max": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum number of bytes to read",
},
"read_iops_sec": {
Type: schema.TypeInt,
Computed: true,
Description: "Number of io read operations per second",
},
"read_iops_sec_max": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum number of io read operations",
},
"size_iops_sec": {
Type: schema.TypeInt,
Computed: true,
Description: "Size of io operations",
},
"total_bytes_sec": {
Type: schema.TypeInt,
Computed: true,
Description: "Total size bytes per second",
},
"total_bytes_sec_max": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum total size of bytes per second",
},
"total_iops_sec": {
Type: schema.TypeInt,
Computed: true,
Description: "Total number of io operations per second",
},
"total_iops_sec_max": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum total number of io operations per second",
},
"write_bytes_sec": {
Type: schema.TypeInt,
Computed: true,
Description: "Number of bytes to write per second",
},
"write_bytes_sec_max": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum number of bytes to write per second",
},
"write_iops_sec": {
Type: schema.TypeInt,
Computed: true,
Description: "Number of write operations per second",
},
"write_iops_sec_max": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum number of write operations per second",
},
},
},
},
// "iqn": {
// Type: schema.TypeString,
// Computed: true,
// Description: "Disk IQN",
// },
// "login": {
// Type: schema.TypeString,
// Computed: true,
// Description: "Login to access the disk",
// },
"machine_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Machine ID",
},
"machine_name": {
Type: schema.TypeString,
Computed: true,
Description: "Machine name",
},
// "milestones": {
// Type: schema.TypeInt,
// Computed: true,
// Description: "Milestones",
// },
"disk_name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of disk",
},
"order": {
Type: schema.TypeInt,
Computed: true,
Description: "Disk order",
},
"params": {
Type: schema.TypeString,
Computed: true,
Description: "Disk params",
},
"parent_id": {
Type: schema.TypeInt,
Computed: true,
Description: "ID of the parent disk",
},
// "passwd": {
// Type: schema.TypeString,
// Computed: true,
// Description: "Password to access the disk",
// },
"pci_slot": {
Type: schema.TypeInt,
Computed: true,
Description: "ID of the pci slot to which the disk is connected",
},
"pool": {
Type: schema.TypeString,
Computed: true,
Description: "Pool for disk location",
},
"present_to": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
// "purge_attempts": {
// Type: schema.TypeInt,
// Computed: true,
// Description: "Number of deletion attempts",
// },
"purge_time": {
Type: schema.TypeInt,
Computed: true,
Description: "Time of the last deletion attempt",
},
// "reality_device_number": {
// Type: schema.TypeInt,
// Computed: true,
// Description: "Reality device number",
// },
// "reference_id": {
// Type: schema.TypeString,
// Computed: true,
// Description: "ID of the reference to the disk",
// },
"res_id": {
Type: schema.TypeString,
Computed: true,
Description: "Resource ID",
},
"res_name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the resource",
},
"role": {
Type: schema.TypeString,
Computed: true,
Description: "Disk role",
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Storage endpoint provider ID to create disk",
},
"sep_type": {
Type: schema.TypeString,
Computed: true,
Description: "Type SEP. Defines the type of storage system and contains one of the values set in the cloud platform",
},
"shareable": {
Type: schema.TypeBool,
Computed: true,
},
"size_max": {
Type: schema.TypeInt,
Computed: true,
Description: "Size in GB",
},
"size_used": {
Type: schema.TypeFloat,
Computed: true,
Description: "Number of used space, in GB",
},
"snapshots": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"guid": {
Type: schema.TypeString,
Computed: true,
Description: "ID of the snapshot",
},
"label": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the snapshot",
},
"res_id": {
Type: schema.TypeString,
Computed: true,
Description: "Reference to the snapshot",
},
"snap_set_guid": {
Type: schema.TypeString,
Computed: true,
Description: "The set snapshot ID",
},
"snap_set_time": {
Type: schema.TypeInt,
Computed: true,
Description: "The set time of the snapshot",
},
"timestamp": {
Type: schema.TypeInt,
Computed: true,
Description: "Snapshot time",
},
},
},
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Disk status",
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
Description: "Technical status of the disk",
},
"type": {
Type: schema.TypeString,
Computed: true,
Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'",
},
"vmid": {
Type: schema.TypeInt,
Computed: true,
Description: "Virtual Machine ID (Deprecated)",
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}
func DataSourceDiskListDeleted() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
@@ -64,6 +479,6 @@ func DataSourceDiskListDeleted() *schema.Resource {
Default: &constants.Timeout60s,
},
Schema: dataSourceDiskListSchemaMake(),
Schema: dataSourceDiskDeletedListSchemaMake(),
}
}

View File

@@ -16,9 +16,9 @@ func flattenDiskSnapshot(d *schema.ResourceData, snapshot disks.ItemSnapshot) {
d.Set("snap_set_time", snapshot.SnapSetTime)
}
func flattenDiskListUnattached(ul disks.ListDisksUnattached) []map[string]interface{} {
func flattenDiskListUnattached(ul *disks.ListDisksUnattached) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, unattachedDisk := range ul {
for _, unattachedDisk := range ul.Data {
unattachedDiskAcl, _ := json.Marshal(unattachedDisk.ACL)
tmp := map[string]interface{}{
"_ckey": unattachedDisk.CKey,
@@ -136,9 +136,9 @@ func flattenDiskSnapshotList(sl disks.ListSnapshots) []interface{} {
return res
}
func flattenDiskList(dl disks.ListDisks) []map[string]interface{} {
func flattenDiskList(dl *disks.ListDisks) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, disk := range dl {
for _, disk := range dl.Data {
diskAcl, _ := json.Marshal(disk.ACL)
temp := map[string]interface{}{
"account_id": disk.AccountID,

View File

@@ -19,7 +19,7 @@ func existAccountID(ctx context.Context, d *schema.ResourceData, m interface{})
return false, err
}
return len(accountList.FilterByID(accountId)) != 0, nil
return len(accountList.FilterByID(accountId).Data) != 0, nil
}
func existGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
@@ -32,5 +32,5 @@ func existGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool,
return false, err
}
return len(locationList.FilterByGID(gid)) != 0, nil
return len(locationList.FilterByGID(gid).Data) != 0, nil
}

View File

@@ -43,7 +43,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityDiskListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (disks.ListDisks, error) {
func utilityDiskListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListDisks, error) {
c := m.(*controller.ControllerCfg)
req := disks.ListRequest{}
@@ -59,6 +59,24 @@ func utilityDiskListCheckPresence(ctx context.Context, d *schema.ResourceData, m
if accountId, ok := d.GetOk("accountId"); ok {
req.AccountID = uint64(accountId.(int))
}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if account_name, ok := d.GetOk("account_name"); ok {
req.AccountName = account_name.(string)
}
if disk_max_size, ok := d.GetOk("disk_max_size"); ok {
req.DiskMaxSize = int64(disk_max_size.(int))
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if shared, ok := d.GetOk("shared"); ok {
req.Shared = shared.(bool)
}
log.Debugf("utilityDiskListCheckPresence: load disk list")
diskList, err := c.CloudAPI().Disks().List(ctx, req)

View File

@@ -0,0 +1,92 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Tim Tkachev, <tvtkachev@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package disks
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/disks"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityDiskListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListDisks, error) {
c := m.(*controller.ControllerCfg)
req := disks.ListDeletedRequest{}
if account_id, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(account_id.(int))
}
if typev, ok := d.GetOk("type"); ok {
req.Type = typev.(string)
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if account_name, ok := d.GetOk("account_name"); ok {
req.AccountName = account_name.(string)
}
if disk_max_size, ok := d.GetOk("disk_max_size"); ok {
req.DiskMaxSize = int64(disk_max_size.(int))
}
if shared, ok := d.GetOk("shared"); ok {
req.Shared = shared.(bool)
}
log.Debugf("utilityDiskListDeletedCheckPresence: load disk list")
diskList, err := c.CloudAPI().Disks().ListDeleted(ctx, req)
if err != nil {
return nil, err
}
return diskList, nil
}

View File

@@ -9,12 +9,31 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityDiskListUnattachedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (disks.ListDisksUnattached, error) {
func utilityDiskListUnattachedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListDisksUnattached, error) {
c := m.(*controller.ControllerCfg)
req := disks.ListUnattachedRequest{}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if accountId, ok := d.GetOk("accountId"); ok {
req.AccountID = uint64(accountId.(int))
}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if account_name, ok := d.GetOk("account_name"); ok {
req.AccountName = account_name.(string)
}
if disk_max_size, ok := d.GetOk("disk_max_size"); ok {
req.DiskMaxSize = int64(disk_max_size.(int))
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
log.Debugf("utilityDiskListUnattachedCheckPresence: load disk Unattached list")
unattachedList, err := c.CloudAPI().Disks().ListUnattached(ctx, req)

View File

@@ -41,7 +41,7 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityDiskListTypesDetailedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) ([]interface{}, error) {
func utilityDiskListTypesDetailedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListTypes, error) {
c := m.(*controller.ControllerCfg)
req := disks.ListTypesRequest{
Detailed: true,

View File

@@ -41,7 +41,7 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityDiskListTypesCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) ([]interface{}, error) {
func utilityDiskListTypesCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListTypes, error) {
c := m.(*controller.ControllerCfg)
req := disks.ListTypesRequest{
Detailed: false,

View File

@@ -50,6 +50,7 @@ func dataSourceExtnetListRead(ctx context.Context, d *schema.ResourceData, m int
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenExtnetList(extnetList))
d.Set("entry_count", extnetList.EntryCount)
return nil
}
@@ -59,7 +60,36 @@ func dataSourceExtnetListSchemaMake() map[string]*schema.Schema {
"account_id": {
Type: schema.TypeInt,
Optional: true,
Description: "filter by account ID",
Description: "Find by account ID",
},
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Find by name",
},
"network": {
Type: schema.TypeString,
Optional: true,
},
"vlan_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by VLAN ID",
},
"vnfdev_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by VnfDEV ID",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Find by status",
},
"page": {
Type: schema.TypeInt,
@@ -91,6 +121,10 @@ func dataSourceExtnetListSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}

View File

@@ -9,7 +9,7 @@ import (
func flattenExtnet(d *schema.ResourceData, e *extnet.RecordExtNet) {
d.Set("ckey", e.CKey)
d.Set("meta", flattens.FlattenMeta(e.Meta))
d.Set("check_ips", e.CheckIps)
d.Set("check_ips", e.CheckIPs)
d.Set("default", e.Default)
d.Set("default_qos", flattenExtnetDefaultQos(e.DefaultQOS))
d.Set("desc", e.Description)
@@ -105,9 +105,9 @@ func flattenExtnetsComputes(ecs extnet.ListExtNetExtends) []map[string]interface
return res
}
func flattenExtnetComputesList(ecl extnet.ListExtNetComputes) []map[string]interface{} {
func flattenExtnetComputesList(ecl *extnet.ListExtNetComputes) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, ec := range ecl {
for _, ec := range ecl.Data {
temp := map[string]interface{}{
"account_id": ec.AccountID,
"account_name": ec.AccountName,
@@ -122,9 +122,9 @@ func flattenExtnetComputesList(ecl extnet.ListExtNetComputes) []map[string]inter
return res
}
func flattenExtnetList(el extnet.ListExtNets) []map[string]interface{} {
func flattenExtnetList(el *extnet.ListExtNets) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, e := range el {
for _, e := range el.Data {
temp := map[string]interface{}{
"net_id": e.ID,
"ipcidr": e.IPCIDR,

View File

@@ -42,7 +42,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityExtnetComputesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (extnet.ListExtNetComputes, error) {
func utilityExtnetComputesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ListExtNetComputes, error) {
c := m.(*controller.ControllerCfg)
req := extnet.ListComputesRequest{
AccountID: uint64(d.Get("account_id").(int)),

View File

@@ -42,13 +42,31 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityExtnetListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (extnet.ListExtNets, error) {
func utilityExtnetListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ListExtNets, error) {
c := m.(*controller.ControllerCfg)
req := extnet.ListRequest{}
if accountId, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountId.(int))
}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if network, ok := d.GetOk("network"); ok {
req.Network = network.(string)
}
if vlan_id, ok := d.GetOk("vlan_id"); ok {
req.VLANID = uint64(vlan_id.(int))
}
if vnfdev_id, ok := d.GetOk("vnfdev_id"); ok {
req.VNFDevID = uint64(vnfdev_id.(int))
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}

View File

@@ -66,10 +66,6 @@ func dataSourceFlipgroupSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"client_ids": {
Type: schema.TypeList,
Computed: true,
@@ -77,13 +73,6 @@ func dataSourceFlipgroupSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"client_names": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"client_type": {
Type: schema.TypeString,
Computed: true,
@@ -96,26 +85,10 @@ func dataSourceFlipgroupSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"default_gw": {
Type: schema.TypeString,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"desc": {
Type: schema.TypeString,
Computed: true,
@@ -148,28 +121,16 @@ func dataSourceFlipgroupSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"network": {
Type: schema.TypeString,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
"net_mask": {
Type: schema.TypeInt,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
"ckey": {
Type: schema.TypeString,
Computed: true,
},
}

View File

@@ -53,12 +53,48 @@ func dataSourceFlipgroupList(ctx context.Context, d *schema.ResourceData, m inte
d.SetId(id.String())
d.Set("items", flattenFlipgroupList(fg_list))
d.Set("entry_count", fg_list.EntryCount)
return nil
}
func dataSourceFlipgroupListSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by Name",
},
"vins_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ViNS ID",
},
"vins_name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by ViNS name",
},
"extnet_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ExtNetID",
},
"by_ip": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by IP-address",
},
"rg_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by RG ID",
},
"page": {
Type: schema.TypeInt,
Optional: true,
@@ -82,10 +118,6 @@ func dataSourceFlipgroupListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"client_ids": {
Type: schema.TypeList,
Computed: true,
@@ -93,13 +125,6 @@ func dataSourceFlipgroupListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"client_names": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"client_type": {
Type: schema.TypeString,
Computed: true,
@@ -112,26 +137,10 @@ func dataSourceFlipgroupListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"default_gw": {
Type: schema.TypeString,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"desc": {
Type: schema.TypeString,
Computed: true,
@@ -164,33 +173,25 @@ func dataSourceFlipgroupListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"network": {
Type: schema.TypeString,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
"net_mask": {
Type: schema.TypeInt,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
"ckey": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
}

View File

@@ -38,19 +38,13 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/flipgroup"
)
func flattenFlipgroup(d *schema.ResourceData, fg *flipgroup.ItemFLIPGroup) {
func flattenFlipgroup(d *schema.ResourceData, fg *flipgroup.RecordFLIPGroup) {
d.Set("account_id", fg.AccountID)
d.Set("account_name", fg.AccountName)
d.Set("client_ids", fg.ClientIDs)
d.Set("client_names", fg.ClientNames)
d.Set("client_type", fg.ClientType)
d.Set("conn_id", fg.ConnID)
d.Set("conn_type", fg.ConnType)
d.Set("created_by", fg.CreatedBy)
d.Set("created_time", fg.CreatedTime)
d.Set("default_gw", fg.DefaultGW)
d.Set("deleted_by", fg.DeletedBy)
d.Set("deleted_time", fg.DeletedTime)
d.Set("desc", fg.Description)
d.Set("gid", fg.GID)
d.Set("guid", fg.GUID)
@@ -60,30 +54,19 @@ func flattenFlipgroup(d *schema.ResourceData, fg *flipgroup.ItemFLIPGroup) {
d.Set("name", fg.Name)
d.Set("net_id", fg.NetID)
d.Set("net_type", fg.NetType)
d.Set("network", fg.Network)
d.Set("rg_id", fg.RGID)
d.Set("rg_name", fg.RGName)
d.Set("status", fg.Status)
d.Set("updated_by", fg.UpdatedBy)
d.Set("updated_time", fg.UpdatedTime)
}
func flattenFlipgroupList(fg_list flipgroup.ListFLIPGroups) []map[string]interface{} {
func flattenFlipgroupList(fg_list *flipgroup.ListFLIPGroups) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, fg := range fg_list {
for _, fg := range fg_list.Data {
temp := map[string]interface{}{
"account_id": fg.AccountID,
"account_name": fg.AccountName,
"client_ids": fg.ClientIDs,
"client_names": fg.ClientNames,
"client_type": fg.ClientType,
"conn_id": fg.ConnID,
"conn_type": fg.ConnType,
"created_by": fg.CreatedBy,
"created_time": fg.CreatedTime,
"default_gw": fg.DefaultGW,
"deleted_by": fg.DeletedBy,
"deleted_time": fg.DeletedTime,
"desc": fg.Description,
"gid": fg.GID,
"guid": fg.GUID,
@@ -93,12 +76,7 @@ func flattenFlipgroupList(fg_list flipgroup.ListFLIPGroups) []map[string]interfa
"name": fg.Name,
"net_id": fg.NetID,
"net_type": fg.NetType,
"network": fg.Network,
"rg_id": fg.RGID,
"rg_name": fg.RGName,
"status": fg.Status,
"updated_by": fg.UpdatedBy,
"updated_time": fg.UpdatedTime,
}
res = append(res, temp)
}

View File

@@ -205,17 +205,6 @@ func resourceFlipgroupSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"client_names": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"conn_id": {
Type: schema.TypeInt,
Computed: true,
@@ -224,26 +213,10 @@ func resourceFlipgroupSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"default_gw": {
Type: schema.TypeString,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
@@ -256,28 +229,16 @@ func resourceFlipgroupSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"network": {
Type: schema.TypeString,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
"net_mask": {
Type: schema.TypeInt,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
"ckey": {
Type: schema.TypeString,
Computed: true,
},
}

View File

@@ -45,7 +45,7 @@ import (
log "github.com/sirupsen/logrus"
)
func handleClientIDsUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, fg *flipgroup.ItemFLIPGroup, warn *dc.Warnings) {
func handleClientIDsUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, fg *flipgroup.RecordFLIPGroup, warn *dc.Warnings) {
addedClients := make([]interface{}, 0)
removedClients := make([]interface{}, 0)
@@ -127,7 +127,7 @@ func addComputesAfterCreation(ctx context.Context, warnings *dc.Warnings, c *con
}
}
func utilityFlipgroupCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*flipgroup.ItemFLIPGroup, error) {
func utilityFlipgroupCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*flipgroup.RecordFLIPGroup, error) {
c := m.(*controller.ControllerCfg)
req := flipgroup.GetRequest{}
@@ -146,10 +146,38 @@ func utilityFlipgroupCheckPresence(ctx context.Context, d *schema.ResourceData,
return fg, err
}
func utilityFlipgroupListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (flipgroup.ListFLIPGroups, error) {
func utilityFlipgroupListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*flipgroup.ListFLIPGroups, error) {
c := m.(*controller.ControllerCfg)
req := flipgroup.ListRequest{}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if vinsId, ok := d.GetOk("vins_id"); ok {
req.VINSID = uint64(vinsId.(int))
}
if vinsName, ok := d.GetOk("vins_name"); ok {
req.VINSName = vinsName.(string)
}
if extNetId, ok := d.GetOk("extnet_id"); ok {
req.ExtNetID = uint64(extNetId.(int))
}
if byIp, ok := d.GetOk("by_ip"); ok {
req.ByIP = byIp.(string)
}
if rgId, ok := d.GetOk("rg_id"); ok {
req.RGID = uint64(rgId.(int))
}
if byId, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(byId.(int))
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}

View File

@@ -49,16 +49,72 @@ func dataSourceImageListRead(ctx context.Context, d *schema.ResourceData, m inte
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenImageList(imageList))
d.Set("entry_count", imageList.EntryCount)
return nil
}
func dataSourceImageListSchemaMake() map[string]*schema.Schema {
rets := map[string]*schema.Schema{
"account_id": {
"sep_id": {
Type: schema.TypeInt,
Optional: true,
Description: "optional account ID to include account images",
Description: "Filter by Storage Endpoint ID",
},
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by name",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by status",
},
"architecture": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by architecture",
},
"type_image": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by image type",
},
"image_size": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by image size",
},
"sep_name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by SEP name",
},
"pool": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by pool",
},
"public": {
Type: schema.TypeBool,
Optional: true,
Description: "Find public/private images",
},
"hot_resize": {
Type: schema.TypeBool,
Optional: true,
Description: "Find hot resizable images",
},
"bootable": {
Type: schema.TypeBool,
Optional: true,
Description: "Find bootable images",
},
"page": {
Type: schema.TypeInt,
@@ -78,6 +134,10 @@ func dataSourceImageListSchemaMake() map[string]*schema.Schema {
Schema: dataSourceImageSchemaMake(),
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return rets

View File

@@ -58,9 +58,9 @@ func flattenImage(d *schema.ResourceData, img *image.RecordImage) {
d.Set("version", img.Version)
}
func flattenImageList(il image.ListImages) []map[string]interface{} {
func flattenImageList(il *image.ListImages) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, img := range il {
for _, img := range il.Data {
temp := map[string]interface{}{
"account_id": img.AccountID,
"architecture": img.Architecture,

View File

@@ -19,7 +19,7 @@ func existAccountID(ctx context.Context, d *schema.ResourceData, m interface{})
return false, err
}
return len(accounts.FilterByID(accountId)) != 0, nil
return len(accounts.FilterByID(accountId).Data) != 0, nil
}
func existGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
@@ -32,5 +32,5 @@ func existGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool,
return false, err
}
return len(locationList.FilterByGID(gid)) != 0, nil
return len(locationList.FilterByGID(gid).Data) != 0, nil
}

View File

@@ -42,12 +42,56 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityImageListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (image.ListImages, error) {
func utilityImageListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*image.ListImages, error) {
c := m.(*controller.ControllerCfg)
req := image.ListRequest{}
if accountId, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountId.(int))
if sep_id, ok := d.GetOk("sep_id"); ok {
req.SEPID = uint64(sep_id.(int))
}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if architecture, ok := d.GetOk("architecture"); ok {
req.Architecture = architecture.(string)
}
if type_image, ok := d.GetOk("type_image"); ok {
req.TypeImage = type_image.(string)
}
if image_size, ok := d.GetOk("image_size"); ok {
req.ImageSize = uint64(image_size.(int))
}
if sep_name, ok := d.GetOk("sep_name"); ok {
req.SEPName = sep_name.(string)
}
if pool, ok := d.GetOk("pool"); ok {
req.Pool = pool.(string)
}
if public, ok := d.GetOk("public"); ok {
req.Public = public.(bool)
}
if hot_resize, ok := d.GetOk("hot_resize"); ok {
req.HotResize = hot_resize.(bool)
}
if bootable, ok := d.GetOk("bootable"); ok {
req.Bootable = bootable.(bool)
}
if page, ok := d.GetOk("page"); ok {

View File

@@ -0,0 +1,175 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Tim Tkachev, <tvtkachev@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package k8s
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceK8CIListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
list, err := utilityK8CIListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
d.SetId(uuid.New().String())
flattenK8CIList(d, list)
d.Set("entry_count", list.EntryCount)
return nil
}
func dataSourceK8CIListSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by name",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by status",
},
"worker_driver": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by worker driver",
},
"master_driver": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by master driver",
},
"network_plugin": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by network plugin",
},
"include_disabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Include deleted k8cis in result",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "Page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "Page size",
},
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"k8ci_id": {
Type: schema.TypeInt,
Computed: true,
Description: "K8CI ID",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "K8CI name",
},
"lb_image_id": {
Type: schema.TypeInt,
Computed: true,
Description: "LB Image ID",
},
"network_plugins": {
Type: schema.TypeList,
Computed: true,
Description: "List of available network plugins",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "K8CI Status",
},
"desc": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"version": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
}
func DataSourceK8CIList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceK8CIListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceK8CIListSchemaMake(),
}
}

View File

@@ -4,6 +4,7 @@ Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Tim Tkachev, <tvtkachev@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -60,7 +61,7 @@ func dataSourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{
}
curK8s := k8s.ItemK8SCluster{}
for _, k8sCluster := range k8sList {
for _, k8sCluster := range k8sList.Data {
if k8sCluster.ID == cluster.ID {
curK8s = k8sCluster
}

View File

@@ -135,6 +135,46 @@ func k8sWorkersGroupsSchemaMake() map[string]*schema.Schema {
func createK8sListSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by name",
},
"ip_address": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by IP address",
},
"rg_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by RG ID",
},
"lb_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by LB ID",
},
"bservice_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by BService ID",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by status",
},
"tech_status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by tech. status",
},
"includedeleted": {
Type: schema.TypeBool,
Optional: true,
@@ -276,6 +316,10 @@ func createK8sListSchema() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
}

View File

@@ -37,9 +37,34 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8ci"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8s"
)
func flattenK8CIItems(list *k8ci.ListK8CI) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, item := range list.Data {
temp := map[string]interface{}{
"k8ci_id": item.ID,
"name": item.Name,
"lb_image_id": item.LBImageID,
"network_plugins": item.NetworkPlugins,
"status": item.Status,
"desc": item.Description,
"created_time": item.CreatedTime,
"version": item.Version,
}
res = append(res, temp)
}
return res
}
func flattenK8CIList(d *schema.ResourceData, list *k8ci.ListK8CI) {
d.Set("items", flattenK8CIItems(list))
}
func flattenK8sDataComputes(d *schema.ResourceData, cluster *k8s.RecordK8S) {
d.Set("k8s_id", cluster.ID)
d.Set("masters", flattenMasterComputes(cluster))
@@ -262,9 +287,9 @@ func flattenWorkersGroup(workersGroups k8s.ListK8SGroups) []map[string]interface
return res
}
func flattenK8sItems(k8sItems k8s.ListK8SClusters) []map[string]interface{} {
func flattenK8sItems(k8sItems *k8s.ListK8SClusters) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, item := range k8sItems {
for _, item := range k8sItems.Data {
temp := map[string]interface{}{
"account_id": item.AccountID,
"account_name": item.Name,
@@ -299,8 +324,9 @@ func flattenK8sItems(k8sItems k8s.ListK8SClusters) []map[string]interface{} {
return res
}
func flattenK8sList(d *schema.ResourceData, k8sItems k8s.ListK8SClusters) {
func flattenK8sList(d *schema.ResourceData, k8sItems *k8s.ListK8SClusters) {
d.Set("items", flattenK8sItems(k8sItems))
d.Set("entry_count", k8sItems.EntryCount)
}
func flattenResourceK8sCP(d *schema.ResourceData, k8s k8s.RecordK8S, masters []compute.RecordCompute) {

View File

@@ -21,7 +21,7 @@ func existK8sID(ctx context.Context, d *schema.ResourceData, m interface{}) (boo
return false, err
}
return len(k8sList.FilterByID(k8sID)) != 0, nil
return len(k8sList.FilterByID(k8sID).Data) != 0, nil
}
func existK8sCIID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
@@ -34,7 +34,7 @@ func existK8sCIID(ctx context.Context, d *schema.ResourceData, m interface{}) (b
return false, err
}
return len(k8sciList.FilterByID(k8sciID)) != 0, nil
return len(k8sciList.FilterByID(k8sciID).Data) != 0, nil
}
func existRGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
@@ -47,7 +47,7 @@ func existRGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool
return false, err
}
return len(rgList.FilterByID(rgID)) != 0, nil
return len(rgList.FilterByID(rgID).Data) != 0, nil
}
func existExtNetID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
@@ -65,5 +65,5 @@ func existExtNetID(ctx context.Context, d *schema.ResourceData, m interface{}) (
return false, err
}
return len(extNetList.FilterByID(extNetID)) != 0, nil
return len(extNetList.FilterByID(extNetID).Data) != 0, nil
}

View File

@@ -267,7 +267,7 @@ func resourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{})
return diag.FromErr(err)
}
curK8s := k8s.ItemK8SCluster{}
for _, k8sCluster := range k8sList {
for _, k8sCluster := range k8sList.Data {
if k8sCluster.ID == cluster.ID {
curK8s = k8sCluster
}
@@ -299,17 +299,19 @@ func resourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{})
flattenResourceK8s(d, *cluster, masterComputeList, workersComputeList)
lbGetReq := lb.GetRequest{
LBID: cluster.LBID,
}
if d.Get("with_lb").(bool) || cluster.LBID != 0 {
lbGetReq := lb.GetRequest{
LBID: cluster.LBID,
}
lb, err := c.CloudAPI().LB().Get(ctx, lbGetReq)
if err != nil {
return diag.FromErr(err)
}
lb, err := c.CloudAPI().LB().Get(ctx, lbGetReq)
if err != nil {
return diag.FromErr(err)
}
d.Set("extnet_id", lb.ExtNetID)
d.Set("lb_ip", lb.PrimaryNode.FrontendIP)
d.Set("extnet_id", lb.ExtNetID)
d.Set("lb_ip", lb.PrimaryNode.FrontendIP)
}
kubeconfigReq := k8s.GetConfigRequest{
K8SID: cluster.ID,

View File

@@ -267,7 +267,7 @@ func resourceK8sCPRead(ctx context.Context, d *schema.ResourceData, m interface{
}
curK8s := k8s.ItemK8SCluster{}
for _, k8sCluster := range k8sList {
for _, k8sCluster := range k8sList.Data {
if k8sCluster.ID == cluster.ID {
curK8s = k8sCluster
}
@@ -302,13 +302,15 @@ func resourceK8sCPRead(ctx context.Context, d *schema.ResourceData, m interface{
LBID: cluster.LBID,
}
lb, err := c.CloudAPI().LB().Get(ctx, lbGetReq)
if err != nil {
return diag.FromErr(err)
}
if d.Get("with_lb").(bool) || cluster.LBID != 0 {
lb, err := c.CloudAPI().LB().Get(ctx, lbGetReq)
if err != nil {
return diag.FromErr(err)
}
d.Set("extnet_id", lb.ExtNetID)
d.Set("lb_ip", lb.PrimaryNode.FrontendIP)
d.Set("extnet_id", lb.ExtNetID)
d.Set("lb_ip", lb.PrimaryNode.FrontendIP)
}
kubeconfigReq := k8s.GetConfigRequest{
K8SID: cluster.ID,

View File

@@ -0,0 +1,83 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Tim Tkachev, <tvtkachev@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package k8s
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8ci"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityK8CIListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8ci.ListK8CI, error) {
c := m.(*controller.ControllerCfg)
req := k8ci.ListRequest{}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if worker_driver, ok := d.GetOk("worker_driver"); ok {
req.WorkerDriver = worker_driver.(string)
}
if master_driver, ok := d.GetOk("master_driver"); ok {
req.MasterDriver = master_driver.(string)
}
if network_plugin, ok := d.GetOk("network_plugin"); ok {
req.NetworkPlugins = network_plugin.(string)
}
if include_disabled, ok := d.GetOk("include_disabled"); ok {
req.IncludeDisabled = include_disabled.(bool)
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
resList, err := c.CloudAPI().K8CI().List(ctx, req)
if err != nil {
return nil, err
}
return resList, nil
}

View File

@@ -223,12 +223,44 @@ func utilityDataK8sCheckPresence(ctx context.Context, d *schema.ResourceData, m
return k8s, nil
}
func utilityK8sListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (k8s.ListK8SClusters, error) {
func utilityK8sListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8s.ListK8SClusters, error) {
c := m.(*controller.ControllerCfg)
req := k8s.ListRequest{
IncludeDeleted: false,
}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if ip_address, ok := d.GetOk("ip_address"); ok {
req.IPAddress = ip_address.(string)
}
if rg_id, ok := d.GetOk("rg_id"); ok {
req.RGID = uint64(rg_id.(int))
}
if lb_id, ok := d.GetOk("lb_id"); ok {
req.LBID = uint64(lb_id.(int))
}
if bservice_id, ok := d.GetOk("bservice_id"); ok {
req.BasicServiceID = uint64(bservice_id.(int))
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if tech_status, ok := d.GetOk("tech_status"); ok {
req.TechStatus = tech_status.(string)
}
k8sList, err := c.CloudAPI().K8S().List(ctx, req)
if err != nil {
return nil, err
@@ -237,10 +269,42 @@ func utilityK8sListCheckPresence(ctx context.Context, d *schema.ResourceData, m
return k8sList, nil
}
func utilityK8sListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (k8s.ListK8SClusters, error) {
func utilityK8sListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8s.ListK8SClusters, error) {
c := m.(*controller.ControllerCfg)
req := k8s.ListDeletedRequest{}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if ip_address, ok := d.GetOk("ip_address"); ok {
req.IPAddress = ip_address.(string)
}
if rg_id, ok := d.GetOk("rg_id"); ok {
req.RGID = uint64(rg_id.(int))
}
if lb_id, ok := d.GetOk("lb_id"); ok {
req.LBID = uint64(lb_id.(int))
}
if bservice_id, ok := d.GetOk("bservice_id"); ok {
req.BasicServiceID = uint64(bservice_id.(int))
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if tech_status, ok := d.GetOk("tech_status"); ok {
req.TechStatus = tech_status.(string)
}
k8sList, err := c.CloudAPI().K8S().ListDeleted(ctx, req)
if err != nil {
return nil, err

View File

@@ -214,6 +214,10 @@ func computeSnapshotsSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"reference_id": {
Type: schema.TypeInt,
Computed: true,
},
"res_id": {
Type: schema.TypeString,
Computed: true,
@@ -634,20 +638,8 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Computed: true,
},
"custom_fields": {
Type: schema.TypeList,
Type: schema.TypeString,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Type: schema.TypeString,
Computed: true,
},
"val": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"deleted_by": {
Type: schema.TypeString,
@@ -827,6 +819,14 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"stateless_sep_id": {
Type: schema.TypeInt,
Computed: true,
},
"stateless_sep_type": {
Type: schema.TypeString,
Computed: true,
},
}
}

View File

@@ -56,6 +56,7 @@ func dataSourceComputeListRead(ctx context.Context, d *schema.ResourceData, m in
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenComputeList(result))
d.Set("entry_count", computeList.EntryCount)
return nil
}
@@ -334,6 +335,56 @@ func itemComputeSchemaMake() map[string]*schema.Schema {
func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Find by name",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by AccountID",
},
"rg_name": {
Type: schema.TypeString,
Optional: true,
Description: "Find by resgroup name",
},
"rg_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by RGID",
},
"tech_status": {
Type: schema.TypeString,
Optional: true,
Description: "Find by tech status",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Find by status",
},
"ip_address": {
Type: schema.TypeString,
Optional: true,
Description: "Find by IP address",
},
"extnet_name": {
Type: schema.TypeString,
Optional: true,
Description: "Find by Extnet name",
},
"extnet_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by Extnet ID",
},
"includedeleted": {
Type: schema.TypeBool,
Optional: true,
@@ -359,6 +410,10 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
Schema: itemComputeSchemaMake(),
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}

View File

@@ -147,9 +147,9 @@ func flattenListACL(listAcl compute.ListACL) []map[string]interface{} {
return res
}
func flattenComputeList(computes compute.ListComputes) []map[string]interface{} {
func flattenComputeList(computes *compute.ListComputes) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, compute := range computes {
for _, compute := range computes.Data {
customFields, _ := json.Marshal(compute.CustomFields)
devices, _ := json.Marshal(compute.Devices)
temp := map[string]interface{}{
@@ -265,7 +265,7 @@ func flattenComputeDisksDemo(disksList compute.ListComputeDisks, extraDisks []in
func flattenNetwork(interfaces compute.ListInterfaces) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(interfaces))
//index := 0
for _, network := range interfaces {
temp := map[string]interface{}{
"net_id": network.NetID,
@@ -316,7 +316,6 @@ func flattenCompute(d *schema.ResourceData, computeRec compute.RecordCompute) er
d.Set("computeci_id", computeRec.ComputeCIID)
d.Set("created_by", computeRec.CreatedBy)
d.Set("created_time", computeRec.CreatedTime)
d.Set("custom_fields", flattenCustomFields(computeRec.CustomFields))
d.Set("deleted_by", computeRec.DeletedBy)
d.Set("deleted_time", computeRec.DeletedTime)
d.Set("description", computeRec.Description)
@@ -442,6 +441,7 @@ func flattenSnapshots(snapshots compute.SnapshotExtendList) []map[string]interfa
"guid": snapshot.GUID,
"label": snapshot.Label,
"res_id": snapshot.ResID,
"reference_id": snapshot.ReferenceID,
"snap_set_guid": snapshot.SnapSetGUID,
"snap_set_time": snapshot.SnapSetTime,
"timestamp": snapshot.TimeStamp,
@@ -503,18 +503,11 @@ func flattenListComputeDisks(disks compute.ListComputeDisks) []map[string]interf
return res
}
func flattenCustomFields(customFileds map[string]interface{}) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for key, val := range customFileds {
value, _ := json.Marshal(val)
temp := map[string]interface{}{
"key": key,
"val": string(value),
}
res = append(res, temp)
}
return res
func flattenCustomFields(customFields map[string]interface{}) string {
encoded, _ := json.Marshal(customFields)
return string(encoded)
}
func flattenOsUsers(osUsers compute.ListOSUser) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, user := range osUsers {
@@ -609,9 +602,9 @@ func flattenComputeAudits(computeAudits compute.ListAudits) []map[string]interfa
return res
}
func flattenPfwList(computePfws compute.ListPFWs) []map[string]interface{} {
func flattenPfwList(computePfws *compute.ListPFWs) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, computePfw := range computePfws {
for _, computePfw := range computePfws.Data {
temp := map[string]interface{}{
"pfw_id": computePfw.ID,
"local_ip": computePfw.LocalIP,
@@ -626,10 +619,10 @@ func flattenPfwList(computePfws compute.ListPFWs) []map[string]interface{} {
return res
}
func flattenUserList(d *schema.ResourceData, userList compute.RecordACL) {
d.Set("account_acl", flattenListACL(userList.AccountACL))
d.Set("compute_acl", flattenListACL(userList.ComputeACL))
d.Set("rg_acl", flattenListACL(userList.RGACL))
func flattenUserList(d *schema.ResourceData, userList *compute.ListUsers) {
d.Set("account_acl", flattenListACL(userList.Data.AccountACL))
d.Set("compute_acl", flattenListACL(userList.Data.ComputeACL))
d.Set("rg_acl", flattenListACL(userList.Data.RGACL))
}
func flattenComputeGetAudits(computeAudits compute.ListShortAudits) []map[string]interface{} {

View File

@@ -57,7 +57,7 @@ func existRgID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool
return false, err
}
return len(rgList.FilterByID(rgId)) != 0, nil
return len(rgList.FilterByID(rgId).Data) != 0, nil
}
func existImageId(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
@@ -70,11 +70,11 @@ func existImageId(ctx context.Context, d *schema.ResourceData, m interface{}) (b
return false, err
}
return len(imageList.FilterByID(imageId)) != 0, nil
return len(imageList.FilterByID(imageId).Data) != 0, nil
}
func existVinsIdInList(vinsId uint64, vinsList vins.ListVINS) bool {
for _, vins := range vinsList {
func existVinsIdInList(vinsId uint64, vinsList *vins.ListVINS) bool {
for _, vins := range vinsList.Data {
if vinsId == vins.ID {
return true
}
@@ -83,8 +83,8 @@ func existVinsIdInList(vinsId uint64, vinsList vins.ListVINS) bool {
return false
}
func existExtNetIdInList(extId uint64, extList extnet.ListExtNets) bool {
for _, ext := range extList {
func existExtNetIdInList(extId uint64, extList *extnet.ListExtNets) bool {
for _, ext := range extList.Data {
if extId == ext.ID {
return true
}

View File

@@ -4,7 +4,7 @@ Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Tim Tkachev, <tvtkachev@basistech.ru>
Tim Tkachev, <tvkachev@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -128,23 +128,32 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
createReqPPC.IS = IS.(string)
createReqX86.IS = IS.(string)
}
if !d.Get("with_default_vins").(bool) {
createReqX86.Interfaces = make([]kvmx86.Interface, 0)
}
if networks, ok := d.GetOk("network"); ok {
if networks.(*schema.Set).Len() > 0 {
ns := networks.(*schema.Set).List()
defaultNetwork := ns[0].(map[string]interface{})
createReqPPC.NetType = defaultNetwork["net_type"].(string)
createReqPPC.NetID = uint64(defaultNetwork["net_id"].(int))
interfaces := make([]kvmx86.Interface, 0)
for _, elem := range ns {
netInterfaceVal := elem.(map[string]interface{})
reqInterface := kvmx86.Interface{
NetType: netInterfaceVal["net_type"].(string),
NetID: uint64(netInterfaceVal["net_id"].(int)),
}
createReqX86.NetType = defaultNetwork["net_type"].(string)
createReqX86.NetID = uint64(defaultNetwork["net_id"].(int))
ipaddr, ipSet := netInterfaceVal["ip_address"]
if ipSet {
reqInterface.IPAddr = ipaddr.(string)
}
ipaddr, ipSet := defaultNetwork["ip_address"] // "ip_address" key is optional
if ipSet {
createReqPPC.IPAddr = ipaddr.(string)
createReqX86.IPAddr = ipaddr.(string)
interfaces = append(interfaces, reqInterface)
}
createReqX86.Interfaces = interfaces
}
}
@@ -181,6 +190,18 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
createReqX86.RAM = uint64(d.Get("ram").(int))
createReqX86.ImageID = uint64(d.Get("image_id").(int))
createReqX86.Driver = driver
if custom_fields, ok := d.GetOk("custom_fields"); ok {
val := custom_fields.(string)
val = strings.ReplaceAll(val, "\\", "")
val = strings.ReplaceAll(val, "\n", "")
val = strings.ReplaceAll(val, "\t", "")
val = strings.TrimSpace(val)
createReqX86.CustomFields = val
}
log.Debugf("resourceComputeCreate: creating Compute of type KVM VM x86")
apiResp, err := c.CloudAPI().KVMX86().Create(ctx, createReqX86)
if err != nil {
@@ -222,16 +243,6 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
return diag.FromErr(err)
}
}
argVal, ok = d.GetOk("network")
if ok && argVal.(*schema.Set).Len() > 0 {
log.Debugf("resourceComputeCreate: calling utilityComputeNetworksConfigure to attach %d network(s)", argVal.(*schema.Set).Len())
err = utilityComputeNetworksConfigure(ctx, d, m, false, true, computeId)
if err != nil {
log.Errorf("resourceComputeCreate: error when attaching networks to a new Compute ID %d: %s", computeId, err)
cleanup = true
return diag.FromErr(err)
}
}
// Note bene: we created compute in a STOPPED state (this is required to properly attach 1st network interface),
// now we need to start it before we report the sequence complete
@@ -573,11 +584,11 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
switch networkData["net_type"].(string) {
case "VINS":
if vinsId, ok := existVinsId(ctx, m, networkData["net_id"].(int)); !ok {
return diag.Errorf("resourceComputeUpdate: can't update compute because vins ID %d is not allowed or does not exist", vinsId)
return diag.Errorf("resourceComputeCreate: can't create compute because vins ID %d is not allowed or does not exist", vinsId)
}
case "EXTNET":
if extNetId, ok := existExtNetId(ctx, m, networkData["net_id"].(int)); !ok {
return diag.Errorf("resourceComputeUpdate: can't update compute because extnet ID %d is not allowed or does not exist", extNetId)
return diag.Errorf("resourceComputeCreate: can't create compute because extnet ID %d is not allowed or does not exist", extNetId)
}
default:
@@ -1334,6 +1345,35 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if d.HasChange("custom_fields") {
val := d.Get("custom_fields").(string)
val = strings.ReplaceAll(val, "\\", "")
val = strings.ReplaceAll(val, "\n", "")
val = strings.ReplaceAll(val, "\t", "")
val = strings.TrimSpace(val)
if len(val) > 0 {
req := compute.SetCustomFieldsRequest{
ComputeID: computeRec.ID,
CustomFields: val,
}
_, err := c.CloudAPI().Compute().SetCustomFields(ctx, req)
if err != nil {
return diag.FromErr(err)
}
} else {
req := compute.DeleteCustomFieldsRequest{
ComputeID: computeRec.ID,
}
_, err := c.CloudAPI().Compute().DeleteCustomFields(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
}
// we may reuse dataSourceComputeRead here as we maintain similarity
// between Compute resource and Compute data source schemas
defer resourceComputeRead(ctx, d, m)
@@ -1554,7 +1594,6 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "Name of this compute. Compute names are case sensitive and must be unique in the resource group.",
},
"rg_id": {
Type: schema.TypeInt,
Required: true,
@@ -1562,50 +1601,43 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
ValidateFunc: validation.IntAtLeast(1),
Description: "ID of the resource group where this compute should be deployed.",
},
"driver": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
StateFunc: statefuncs.StateFuncToUpper,
ValidateFunc: validation.StringInSlice([]string{"KVM_X86", "KVM_PPC"}, false), // observe case while validating
ValidateFunc: validation.StringInSlice([]string{"SVA_KVM_X86", "KVM_X86", "KVM_PPC"}, false), // observe case while validating
Description: "Hardware architecture of this compute instance.",
},
"cpu": {
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntBetween(1, constants.MaxCpusPerCompute),
Description: "Number of CPUs to allocate to this compute instance.",
},
"ram": {
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntAtLeast(constants.MinRamPerCompute),
Description: "Amount of RAM in MB to allocate to this compute instance.",
},
"image_id": {
Type: schema.TypeInt,
Required: true,
//ForceNew: true, //REDEPLOY
Description: "ID of the OS image to base this compute instance on.",
},
"boot_disk_size": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "This compute instance boot disk size in GB. Make sure it is large enough to accomodate selected OS image.",
},
"affinity_label": {
Type: schema.TypeString,
Optional: true,
Description: "Set affinity label for compute",
},
"affinity_rules": {
Type: schema.TypeList,
Optional: true,
@@ -1642,7 +1674,6 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
},
},
},
"anti_affinity_rules": {
Type: schema.TypeList,
Optional: true,
@@ -1679,7 +1710,6 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
},
},
},
"disks": {
Type: schema.TypeList,
Optional: true,
@@ -1687,6 +1717,22 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
Schema: disksSubresourceSchemaMake(),
},
},
"custom_fields": {
Type: schema.TypeString,
Optional: true,
},
"stateless": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Compute will be stateless (SVA_KVM_X86) if set to True",
},
"with_default_vins": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Create compute with default resgroup ViNS (true) or without any interfaces (false). This parameter is ignored if network block is specified",
},
"boot_disk": {
Type: schema.TypeSet,
Computed: true,
@@ -1862,7 +1908,6 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "compute purpose",
},
// The rest are Compute properties, which are "computed" once it is created
"account_id": {
Type: schema.TypeInt,
@@ -1917,22 +1962,6 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"custom_fields": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Type: schema.TypeString,
Computed: true,
},
"val": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,

View File

@@ -44,14 +44,14 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func matchComputes(computeList compute.ListComputes) compute.ListComputes {
func matchComputes(computeList *compute.ListComputes) *compute.ListComputes {
matched, _ := regexp.Compile("[a-zA-Z]+\\d+-[a-zA-Z]+\\d+-[a-zA-Z]+\\d+")
result := computeList.FilterFunc(func(ic compute.ItemCompute) bool {
res := matched.Match([]byte(ic.Name))
return !res
})
return result
return &result
}
func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceData, m interface{}, do_delta bool) error {

View File

@@ -40,10 +40,40 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityDataComputeListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (compute.ListComputes, error) {
func utilityDataComputeListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ListComputes, error) {
c := m.(*controller.ControllerCfg)
req := compute.ListRequest{}
if byId, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(byId.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if accountId, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountId.(int))
}
if rgName, ok := d.GetOk("rg_name"); ok {
req.RGName = rgName.(string)
}
if rgId, ok := d.GetOk("rg_id"); ok {
req.RGID = uint64(rgId.(int))
}
if techStatus, ok := d.GetOk("tech_status"); ok {
req.TechStatus = techStatus.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if ipAddress, ok := d.GetOk("ip_address"); ok {
req.IPAddress = ipAddress.(string)
}
if extNetName, ok := d.GetOk("extnet_name"); ok {
req.ExtNetName = extNetName.(string)
}
if extnetId, ok := d.GetOk("extnet_id"); ok {
req.ExtNetID = uint64(extnetId.(int))
}
if includeDeleted, ok := d.GetOk("includedeleted"); ok {
req.IncludeDeleted = includeDeleted.(bool)
}

View File

@@ -40,7 +40,7 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityComputePfwListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (compute.ListPFWs, error) {
func utilityComputePfwListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ListPFWs, error) {
c := m.(*controller.ControllerCfg)
req := compute.PFWListRequest{
ComputeID: uint64(d.Get("compute_id").(int)),

View File

@@ -40,7 +40,7 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityComputeUserListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (compute.RecordACL, error) {
func utilityComputeUserListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ListUsers, error) {
c := m.(*controller.ControllerCfg)
req := compute.UserListRequest{
ComputeID: uint64(d.Get("compute_id").(int)),
@@ -48,8 +48,8 @@ func utilityComputeUserListCheckPresence(ctx context.Context, d *schema.Resource
computeUserList, err := c.CloudAPI().Compute().UserList(ctx, req)
if err != nil {
return *computeUserList, err
return computeUserList, err
}
return *computeUserList, err
return computeUserList, err
}

View File

@@ -49,6 +49,7 @@ func dataSourceLBListRead(ctx context.Context, d *schema.ResourceData, m interfa
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenLBList(lbList))
d.Set("entry_count", lbList.EntryCount)
return nil
}

View File

@@ -49,6 +49,7 @@ func dataSourceLBListDeletedRead(ctx context.Context, d *schema.ResourceData, m
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenLBList(lbList))
d.Set("entry_count", lbList.EntryCount)
return nil
}

View File

@@ -241,9 +241,9 @@ func flattenLBBackends(backends []lb.ItemBackend) []map[string]interface{} {
return temp
}
func flattenLBList(lbl lb.ListLB) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(lbl))
for _, lb := range lbl {
func flattenLBList(lbl *lb.ListLB) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(lbl.Data))
for _, lb := range lbl.Data {
temp := map[string]interface{}{
"ha_mode": lb.HAMode,
"backends": flattenLBBackends(lb.Backends),

View File

@@ -45,6 +45,41 @@ func dsLBSchemaMake() map[string]*schema.Schema {
func dsLBListDeletedSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by name",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by Account ID",
},
"rg_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by RG ID",
},
"tech_status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by TechStatus",
},
"front_ip": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by FrontIP",
},
"back_ip": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by BackIP",
},
"page": {
Type: schema.TypeInt,
Optional: true,
@@ -62,11 +97,55 @@ func dsLBListDeletedSchemaMake() map[string]*schema.Schema {
Schema: dsLBItemSchemaMake(),
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
}
func dsLBListSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by name",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by Account ID",
},
"rg_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by RG ID",
},
"tech_status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by TechStatus",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by Status",
},
"front_ip": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by FrontIP",
},
"back_ip": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by BackIP",
},
"includedeleted": {
Type: schema.TypeBool,
Optional: true,
@@ -89,6 +168,10 @@ func dsLBListSchemaMake() map[string]*schema.Schema {
Schema: dsLBItemSchemaMake(),
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
}

View File

@@ -22,7 +22,7 @@ func existLBID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool
return false, err
}
return len(lbList.FilterByID(lbId)) != 0, nil
return len(lbList.FilterByID(lbId).Data) != 0, nil
}
func existRGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
@@ -36,7 +36,7 @@ func existRGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool
return false, err
}
return len(rgList.FilterByID(rgId)) != 0, nil
return len(rgList.FilterByID(rgId).Data) != 0, nil
}
func existExtNetID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
@@ -50,7 +50,7 @@ func existExtNetID(ctx context.Context, d *schema.ResourceData, m interface{}) (
return false, err
}
return len(extNetList.FilterByID(extNetID)) != 0, nil
return len(extNetList.FilterByID(extNetID).Data) != 0, nil
}
func existViNSID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
@@ -64,5 +64,5 @@ func existViNSID(ctx context.Context, d *schema.ResourceData, m interface{}) (bo
return false, err
}
return len(vinsList.FilterByID(vinsID)) != 0, nil
return len(vinsList.FilterByID(vinsID).Data) != 0, nil
}

View File

@@ -198,8 +198,6 @@ func resourceLBBackendUpdate(ctx context.Context, d *schema.ResourceData, m inte
return diag.FromErr(err)
}
//TODO: перенести servers сюда
return resourceLBBackendRead(ctx, d, m)
}

View File

@@ -120,9 +120,6 @@ func resourceLBFrontendDelete(ctx context.Context, d *schema.ResourceData, m int
}
func resourceLBFrontendEdit(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
//TODO: перенести bindings сюда
return nil
}

View File

@@ -42,10 +42,42 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityLBListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (lb.ListLB, error) {
func utilityLBListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*lb.ListLB, error) {
c := m.(*controller.ControllerCfg)
req := lb.ListRequest{}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if account_id, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(account_id.(int))
}
if rg_id, ok := d.GetOk("rg_id"); ok {
req.RGID = uint64(rg_id.(int))
}
if tech_status, ok := d.GetOk("tech_status"); ok {
req.TechStatus = tech_status.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if front_ip, ok := d.GetOk("front_ip"); ok {
req.FrontIP = front_ip.(string)
}
if back_ip, ok := d.GetOk("back_ip"); ok {
req.BackIP = back_ip.(string)
}
if includedeleted, ok := d.GetOk("includedeleted"); ok {
req.IncludeDeleted = includedeleted.(bool)
}

View File

@@ -42,10 +42,38 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityLBListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (lb.ListLB, error) {
func utilityLBListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*lb.ListLB, error) {
c := m.(*controller.ControllerCfg)
req := lb.ListDeletedRequest{}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if account_id, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(account_id.(int))
}
if rg_id, ok := d.GetOk("rg_id"); ok {
req.RGID = uint64(rg_id.(int))
}
if tech_status, ok := d.GetOk("tech_status"); ok {
req.TechStatus = tech_status.(string)
}
if front_ip, ok := d.GetOk("front_ip"); ok {
req.FrontIP = front_ip.(string)
}
if back_ip, ok := d.GetOk("back_ip"); ok {
req.BackIP = back_ip.(string)
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}

View File

@@ -43,9 +43,9 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
)
func flattenLocationsList(ll locations.ListLocations) []map[string]interface{} {
func flattenLocationsList(ll *locations.ListLocations) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, l := range ll {
for _, l := range ll.Data {
temp := map[string]interface{}{
"ckey": l.CKey,
"meta": flattens.FlattenMeta(l.Meta),
@@ -72,12 +72,33 @@ func dataSourceLocationsListRead(ctx context.Context, d *schema.ResourceData, m
d.SetId(id.String())
d.Set("items", flattenLocationsList(locations))
d.Set("entry_count", locations.EntryCount)
return nil
}
func dataSourceLocationsListSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"flag": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by flag",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by name",
},
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ID",
},
"location_code": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by location code",
},
"page": {
Type: schema.TypeInt,
Optional: true,
@@ -137,6 +158,10 @@ func dataSourceLocationsListSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
}

View File

@@ -42,17 +42,34 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityLocationsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (locations.ListLocations, error) {
func utilityLocationsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*locations.ListLocations, error) {
c := m.(*controller.ControllerCfg)
req := locations.ListRequest{}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if flag, ok := d.GetOk("flag"); ok {
req.Flag = flag.(string)
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if location_code, ok := d.GetOk("location_code"); ok {
req.LocationCode = location_code.(string)
}
log.Debugf("utilityLocationsListCheckPresence: load locations list")
locationsList, err := c.CloudAPI().Locations().List(ctx, req)
if err != nil {

View File

@@ -59,7 +59,7 @@ func utilityPfwCheckPresence(ctx context.Context, d *schema.ResourceData, m inte
return nil, err
}
for _, pfw := range pfws {
for _, pfw := range pfws.Data {
if pfw.ID == uint64(id) {
return &pfw, nil
}

View File

@@ -81,7 +81,7 @@ func resourcesSchemaMake() map[string]*schema.Schema {
Computed: true,
},
"disk_size_max": {
Type: schema.TypeInt,
Type: schema.TypeFloat,
Computed: true,
},
"extips": {
@@ -223,6 +223,10 @@ func resourceLimitsSchemaMake() map[string]*schema.Schema {
Type: schema.TypeFloat,
Computed: true,
},
"cu_dm": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_i": {
Type: schema.TypeFloat,
Computed: true,
@@ -254,14 +258,6 @@ func dataSourceRgSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Optional: true,
},
"resources": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: resourcesSchemaMake(),
},
},
"account_id": {
Type: schema.TypeInt,
Computed: true,

View File

@@ -50,12 +50,53 @@ func dataSourceRgListRead(ctx context.Context, d *schema.ResourceData, m interfa
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenRgList(rgList))
d.Set("entry_count", rgList.EntryCount)
return nil
}
func dataSourceRgListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Find by name",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by account ID",
},
"account_name": {
Type: schema.TypeString,
Optional: true,
Description: "Find by account name",
},
"created_after": {
Type: schema.TypeInt,
Optional: true,
Description: "Find RGs created after specific time (unix timestamp)",
},
"created_before": {
Type: schema.TypeInt,
Optional: true,
Description: "Find RGs created before specific time (unix timestamp)",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Find by status",
},
"lock_status": {
Type: schema.TypeString,
Optional: true,
Description: "Find by lock status",
},
"includedeleted": {
Type: schema.TypeBool,
Optional: true,
@@ -222,6 +263,10 @@ func dataSourceRgListSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}

View File

@@ -50,6 +50,8 @@ func dataSourceRgListComputesRead(ctx context.Context, d *schema.ResourceData, m
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenRgListComputes(listComputes))
d.Set("entry_count", listComputes.EntryCount)
return nil
}
@@ -92,12 +94,56 @@ func dataSourceRgListComputesSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "ID of the RG",
},
"reason": {
"compute_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by compute ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "reason for action",
Description: "Filter by name",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by account ID",
},
"tech_status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by tech. status",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by status",
},
"ip_address": {
Type: schema.TypeString,
Optional: true,
Description: "FIlter by IP address",
},
"extnet_name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by extnet name",
},
"extnet_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by extnet ID",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "Page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "Page size",
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -204,6 +250,10 @@ func dataSourceRgListComputesSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res

View File

@@ -50,12 +50,48 @@ func dataSourceRgListDeletedRead(ctx context.Context, d *schema.ResourceData, m
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenRgList(rgList))
d.Set("entry_count", rgList.EntryCount)
return nil
}
func dataSourceRgListDeletedSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by name",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by account ID",
},
"account_name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by account name",
},
"created_after": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter RGs created after certain point in time (unix timestamp)",
},
"created_before": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter RGs created before certain point in time (unix timestamp)",
},
"lock_status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by lock status",
},
"page": {
Type: schema.TypeInt,
Optional: true,
@@ -66,7 +102,6 @@ func dataSourceRgListDeletedSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Page size",
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -208,6 +243,10 @@ func dataSourceRgListDeletedSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}

View File

@@ -49,6 +49,8 @@ func dataSourceRgListLbRead(ctx context.Context, d *schema.ResourceData, m inter
d.SetId(strconv.Itoa(d.Get("rg_id").(int)))
d.Set("items", flattenRgListLb(listLb))
d.Set("entry_count", listLb.EntryCount)
return nil
}
@@ -244,7 +246,51 @@ func dataSourceRgListLbSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "ID of the RG",
},
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by name",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by account ID",
},
"tech_status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by tech. status",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by status",
},
"front_ip": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by frontend IP",
},
"back_ip": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by backend IP",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "Page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "Page size",
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -368,6 +414,10 @@ func dataSourceRgListLbSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res

View File

@@ -49,6 +49,8 @@ func dataSourceRgListPfwRead(ctx context.Context, d *schema.ResourceData, m inte
d.SetId(strconv.Itoa(d.Get("rg_id").(int)))
d.Set("items", flattenRgListPfw(listPfw))
d.Set("entry_count", listPfw.EntryCount)
return nil
}
@@ -59,7 +61,6 @@ func dataSourceRgListPfwSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "ID of the RG",
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -100,6 +101,10 @@ func dataSourceRgListPfwSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res

View File

@@ -49,6 +49,8 @@ func dataSourceRgListVinsRead(ctx context.Context, d *schema.ResourceData, m int
d.SetId(strconv.Itoa(d.Get("rg_id").(int)))
d.Set("items", flattenRgListVins(listVins))
d.Set("entry_count", listVins.EntryCount)
return nil
}
@@ -59,12 +61,36 @@ func dataSourceRgListVinsSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "ID of the RG",
},
"reason": {
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Reason for action",
Description: "Filter by name",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by account ID",
},
"ext_ip": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by external IP",
},
"vins_id": {
Type: schema.TypeInt,
Required: true,
Description: "Filter by ViNS ID",
},
"page": {
Type: schema.TypeInt,
Required: true,
Description: "Page number",
},
"size": {
Type: schema.TypeInt,
Required: true,
Description: "Page size",
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -137,6 +163,10 @@ func dataSourceRgListVinsSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res

View File

@@ -92,7 +92,7 @@ func flattenResgroup(d *schema.ResourceData, details rg.RecordResourceGroup) err
d.Set("def_net_type", details.DefNetType)
d.Set("name", details.Name)
d.Set("resources", flattenRgResource(details.Resources))
// d.Set("resources", flattenRgResource(details.Resources))
d.Set("account_name", details.AccountName)
d.Set("acl", flattenRgAcl(details.ACL))
d.Set("vms", details.Computes)
@@ -157,19 +157,8 @@ func flattenResource(resource rg.Resource) []map[string]interface{} {
return res
}
func flattenRgResource(itemResource rg.Resources) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"current": flattenResource(itemResource.Current),
"reserved": flattenResource(itemResource.Reserved),
}
res = append(res, temp)
return res
}
func flattenRg(d *schema.ResourceData, itemRg rg.RecordResourceGroup) {
d.Set("resources", flattenRgResource(itemRg.Resources))
// d.Set("resources", flattenRgResource(itemRg.Resources))
d.Set("account_id", itemRg.AccountID)
d.Set("account_name", itemRg.AccountName)
d.Set("acl", flattenRgAcl(itemRg.ACL))
@@ -218,9 +207,9 @@ func flattenRgAudits(rgAudits rg.ListAudits) []map[string]interface{} {
return res
}
func flattenRgList(rgl rg.ListResourceGroups) []map[string]interface{} {
func flattenRgList(rgl *rg.ListResourceGroups) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, rg := range rgl {
for _, rg := range rgl.Data {
temp := map[string]interface{}{
"account_acl": flattenRgAcl(rg.ACL),
"account_id": rg.AccountID,
@@ -282,13 +271,13 @@ func flattenRgResourceLimits(rl rg.ResourceLimits) []map[string]interface{} {
"cu_d": rl.CUD,
"cu_i": rl.CUI,
"cu_m": rl.CUM,
"cu_dm": rl.CUDM,
"cu_np": rl.CUNP,
"gpu_units": rl.GPUUnits,
}
res = append(res, temp)
return res
}
func flattenRules(list rg.ListRules) []map[string]interface{} {
@@ -309,9 +298,9 @@ func flattenRules(list rg.ListRules) []map[string]interface{} {
return res
}
func flattenRgListComputes(lc rg.ListComputes) []map[string]interface{} {
func flattenRgListComputes(lc *rg.ListComputes) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, compute := range lc {
for _, compute := range lc.Data {
temp := map[string]interface{}{
"account_id": compute.AccountID,
"account_name": compute.AccountName,
@@ -437,9 +426,9 @@ func flattenNode(node rg.RecordNode) []map[string]interface{} {
return res
}
func flattenRgListLb(listLb rg.ListLB) []map[string]interface{} {
func flattenRgListLb(listLb *rg.ListLB) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, lb := range listLb {
for _, lb := range listLb.Data {
temp := map[string]interface{}{
"ha_mode": lb.HAMode,
"acl": lb.ACL,
@@ -472,9 +461,9 @@ func flattenRgListLb(listLb rg.ListLB) []map[string]interface{} {
return res
}
func flattenRgListPfw(listPfw rg.ListPortForwards) []map[string]interface{} {
func flattenRgListPfw(listPfw *rg.ListPortForwards) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, pfw := range listPfw {
for _, pfw := range listPfw.Data {
temp := map[string]interface{}{
"public_port_end": pfw.PublicPortEnd,
"public_port_start": pfw.PublicPortStart,
@@ -491,9 +480,9 @@ func flattenRgListPfw(listPfw rg.ListPortForwards) []map[string]interface{} {
return res
}
func flattenRgListVins(lv rg.ListVINS) []map[string]interface{} {
func flattenRgListVins(lv *rg.ListVINS) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, vins := range lv {
for _, vins := range lv.Data {
temp := map[string]interface{}{
"account_id": vins.AccountID,
"account_name": vins.AccountName,
@@ -519,7 +508,7 @@ func flattenRgListVins(lv rg.ListVINS) []map[string]interface{} {
return res
}
func flattenRgAffinityGroupComputes(list rg.ListAffinityGroups) []map[string]interface{} {
func flattenRgAffinityGroupComputes(list rg.ListAffinityGroupsComputes) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, item := range list {
@@ -548,9 +537,9 @@ func flattenRgAffinityGroupsGet(list []uint64) []map[string]interface{} {
return res
}
func flattenRgListGroups(list map[string][]uint64) []map[string]interface{} {
func flattenRgListGroups(list *rg.ListAffinityGroups) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for groupKey, groupVal := range list {
for groupKey, groupVal := range list.Data {
temp := map[string]interface{}{
"label": groupKey,
"ids": groupVal,

View File

@@ -53,7 +53,7 @@ func existAccountID(ctx context.Context, d *schema.ResourceData, m interface{})
return false, err
}
return len(accountList.FilterByID(accountId)) != 0, nil
return len(accountList.FilterByID(accountId).Data) != 0, nil
}
func existGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
@@ -67,7 +67,7 @@ func existGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool,
return false, err
}
return len(locationList.FilterByGID(gid)) != 0, nil
return len(locationList.FilterByGID(gid).Data) != 0, nil
}
func existExtNetID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
@@ -83,5 +83,5 @@ func existExtNetID(ctx context.Context, d *schema.ResourceData, m interface{}) (
return false, err
}
return len(listExtNet.FilterByID(extNetId)) != 0, nil
return len(listExtNet.FilterByID(extNetId).Data) != 0, nil
}

View File

@@ -772,13 +772,13 @@ func ResourceRgSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Name of the account, which this resource group belongs to.",
},
"resources": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: resourcesSchemaMake(),
},
},
// "resources": {
// Type: schema.TypeList,
// Computed: true,
// Elem: &schema.Resource{
// Schema: resourcesSchemaMake(),
// },
// },
"acl": {
Type: schema.TypeList,

View File

@@ -40,7 +40,7 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityRgAffinityGroupComputesCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (rg.ListAffinityGroups, error) {
func utilityRgAffinityGroupComputesCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (rg.ListAffinityGroupsComputes, error) {
c := m.(*controller.ControllerCfg)
req := rg.AffinityGroupComputesRequest{
RGID: uint64(d.Get("rg_id").(int)),

View File

@@ -40,7 +40,7 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityRgAffinityGroupsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (map[string][]uint64, error) {
func utilityRgAffinityGroupsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListAffinityGroups, error) {
c := m.(*controller.ControllerCfg)
req := rg.AffinityGroupsListRequest{
RGID: uint64(d.Get("rg_id").(int)),

View File

@@ -42,10 +42,34 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityRgListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (rg.ListResourceGroups, error) {
func utilityRgListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListResourceGroups, error) {
c := m.(*controller.ControllerCfg)
req := rg.ListRequest{}
if byId, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(byId.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if accountId, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountId.(int))
}
if accountName, ok := d.GetOk("account_name"); ok {
req.AccountName = accountName.(string)
}
if createdAfter, ok := d.GetOk("created_after"); ok {
req.CreatedAfter = uint64(createdAfter.(int))
}
if createdBefore, ok := d.GetOk("created_before"); ok {
req.CreatedBefore = uint64(createdBefore.(int))
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if lockStatus, ok := d.GetOk("lock_status"); ok {
req.LockStatus = lockStatus.(string)
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}

View File

@@ -40,14 +40,50 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityRgListComputesCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (rg.ListComputes, error) {
func utilityRgListComputesCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListComputes, error) {
c := m.(*controller.ControllerCfg)
req := rg.ListComputesRequest{
RGID: uint64(d.Get("rg_id").(int)),
}
if reason, ok := d.GetOk("reason"); ok {
req.Reason = reason.(string)
if compute_id, ok := d.GetOk("compute_id"); ok {
req.ComputeID = uint64(compute_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if account_id, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(account_id.(int))
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if tech_status, ok := d.GetOk("tech_status"); ok {
req.TechStatus = tech_status.(string)
}
if ip_address, ok := d.GetOk("ip_address"); ok {
req.IPAddress = ip_address.(string)
}
if extnet_name, ok := d.GetOk("extnet_name"); ok {
req.ExtNetName = extnet_name.(string)
}
if extnet_id, ok := d.GetOk("extnet_id"); ok {
req.ExtNetID = uint64(extnet_id.(int))
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
listComputes, err := c.CloudAPI().RG().ListComputes(ctx, req)

View File

@@ -40,10 +40,38 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityRgListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (rg.ListResourceGroups, error) {
func utilityRgListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListResourceGroups, error) {
c := m.(*controller.ControllerCfg)
req := rg.ListDeletedRequest{}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if account_id, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(account_id.(int))
}
if account_name, ok := d.GetOk("account_name"); ok {
req.AccountName = account_name.(string)
}
if created_after, ok := d.GetOk("created_after"); ok {
req.CreatedAfter = uint64(created_after.(int))
}
if created_before, ok := d.GetOk("created_before"); ok {
req.CreatedBefore = uint64(created_before.(int))
}
if lock_status, ok := d.GetOk("lock_status"); ok {
req.LockStatus = lock_status.(string)
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}

View File

@@ -40,12 +40,48 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityRgListLbCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (rg.ListLB, error) {
func utilityRgListLbCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListLB, error) {
c := m.(*controller.ControllerCfg)
req := rg.ListLBRequest{
RGID: uint64(d.Get("rg_id").(int)),
}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if account_id, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(account_id.(int))
}
if tech_status, ok := d.GetOk("tech_status"); ok {
req.TechStatus = tech_status.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if front_ip, ok := d.GetOk("front_ip"); ok {
req.FrontIP = front_ip.(string)
}
if back_ip, ok := d.GetOk("back_ip"); ok {
req.BackIP = back_ip.(string)
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
listLb, err := c.CloudAPI().RG().ListLB(ctx, req)
if err != nil {
return nil, err

View File

@@ -40,7 +40,7 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityRgListPfwCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (rg.ListPortForwards, error) {
func utilityRgListPfwCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListPortForwards, error) {
c := m.(*controller.ControllerCfg)
req := rg.ListPFWRequest{
RGID: uint64(d.Get("rg_id").(int)),

View File

@@ -40,14 +40,34 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityRgListVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (rg.ListVINS, error) {
func utilityRgListVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListVINS, error) {
c := m.(*controller.ControllerCfg)
req := rg.ListVINSRequest{
RGID: uint64(d.Get("rg_id").(int)),
}
if val, ok := d.GetOk("reason"); ok {
req.Reason = val.(string)
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if account_id, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(account_id.(int))
}
if ext_ip, ok := d.GetOk("ext_ip"); ok {
req.ExtIP = ext_ip.(string)
}
if vins_id, ok := d.GetOk("vins_id"); ok {
req.VINSID = uint64(vins_id.(int))
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
listVins, err := c.CloudAPI().RG().ListVINS(ctx, req)

Some files were not shown because too many files have changed in this diff Show More