This commit is contained in:
KasimBaybikov
2023-05-04 10:08:25 +03:00
parent 9bad8a6947
commit 8ca233dd32
288 changed files with 6645 additions and 11464 deletions

View File

@@ -1,60 +0,0 @@
/*
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>
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 bservice
const bserviceCreateAPI = "/restmachine/cloudapi/bservice/create"
const bserviceDeleteAPI = "/restmachine/cloudapi/bservice/delete"
const bserviceDisableAPI = "/restmachine/cloudapi/bservice/disable"
const bserviceEnableAPI = "/restmachine/cloudapi/bservice/enable"
const bserviceGetAPI = "/restmachine/cloudapi/bservice/get"
const bserviceGroupAddAPI = "/restmachine/cloudapi/bservice/groupAdd"
const bserviceGroupComputeRemoveAPI = "/restmachine/cloudapi/bservice/groupComputeRemove"
const bserviceGroupGetAPI = "/restmachine/cloudapi/bservice/groupGet"
const bserviceGroupParentAddAPI = "/restmachine/cloudapi/bservice/groupParentAdd"
const bserviceGroupParentRemoveAPI = "/restmachine/cloudapi/bservice/groupParentRemove"
const bserviceGroupRemoveAPI = "/restmachine/cloudapi/bservice/groupRemove"
const bserviceGroupResizeAPI = "/restmachine/cloudapi/bservice/groupResize"
const bserviceGroupStartAPI = "/restmachine/cloudapi/bservice/groupStart"
const bserviceGroupStopAPI = "/restmachine/cloudapi/bservice/groupStop"
const bserviceGroupUpdateAPI = "/restmachine/cloudapi/bservice/groupUpdate"
const bserviceGroupUpdateExtnetAPI = "/restmachine/cloudapi/bservice/groupUpdateExtnet"
const bserviceGroupUpdateVinsAPI = "/restmachine/cloudapi/bservice/groupUpdateVins"
const bserviceListAPI = "/restmachine/cloudapi/bservice/list"
const bserviceListDeletedAPI = "/restmachine/cloudapi/bservice/listDeleted"
const bserviceRestoreAPI = "/restmachine/cloudapi/bservice/restore"
const bserviceSnapshotCreateAPI = "/restmachine/cloudapi/bservice/snapshotCreate"
const bserviceSnapshotDeleteAPI = "/restmachine/cloudapi/bservice/snapshotDelete"
const bserviceSnapshotListAPI = "/restmachine/cloudapi/bservice/snapshotList"
const bserviceSnapshotRollbackAPI = "/restmachine/cloudapi/bservice/snapshotRollback"
const bserviceStartAPI = "/restmachine/cloudapi/bservice/start"
const bserviceStopAPI = "/restmachine/cloudapi/bservice/stop"

View File

@@ -47,7 +47,7 @@ func dataSourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m i
return diag.FromErr(err)
}
d.SetId(strconv.Itoa(bs.ID))
d.SetId(strconv.FormatUint(bs.ID, 10))
flattenService(d, bs)
@@ -77,6 +77,14 @@ func dataSourceBasicServiceSchemaMake() map[string]*schema.Schema {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"architecture": {
Type: schema.TypeString,
Computed: true,
},
"compgroup_id": {
Type: schema.TypeInt,
Computed: true,
@@ -93,10 +101,26 @@ func dataSourceBasicServiceSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"stack_id": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
@@ -132,8 +156,33 @@ func dataSourceBasicServiceSchemaMake() map[string]*schema.Schema {
"groups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"computes": {
Type: schema.TypeInt,
Computed: true,
},
"consistency": {
Type: schema.TypeBool,
Computed: true,
},
"id": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"groups_name": {

View File

@@ -38,6 +38,7 @@ 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/bservice"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
@@ -49,7 +50,7 @@ func dataSourceBasicServiceGroupRead(ctx context.Context, d *schema.ResourceData
id := uuid.New()
d.SetId(id.String())
d.Set("account_id", bsg.AccountId)
d.Set("account_id", bsg.AccountID)
d.Set("account_name", bsg.AccountName)
d.Set("computes", flattenBSGroupComputes(bsg.Computes))
d.Set("consistency", bsg.Consistency)
@@ -60,10 +61,10 @@ func dataSourceBasicServiceGroupRead(ctx context.Context, d *schema.ResourceData
d.Set("deleted_time", bsg.DeletedTime)
d.Set("disk", bsg.Disk)
d.Set("driver", bsg.Driver)
d.Set("extnets", bsg.Extnets)
d.Set("extnets", bsg.ExtNets)
d.Set("gid", bsg.GID)
d.Set("guid", bsg.GUID)
d.Set("image_id", bsg.ImageId)
d.Set("image_id", bsg.ImageID)
d.Set("milestones", bsg.Milestones)
d.Set("compgroup_name", bsg.Name)
d.Set("parents", bsg.Parents)
@@ -71,18 +72,18 @@ func dataSourceBasicServiceGroupRead(ctx context.Context, d *schema.ResourceData
d.Set("rg_id", bsg.RGID)
d.Set("rg_name", bsg.RGName)
d.Set("role", bsg.Role)
d.Set("sep_id", bsg.SepId)
d.Set("sep_id", bsg.SEPID)
d.Set("seq_no", bsg.SeqNo)
d.Set("status", bsg.Status)
d.Set("tech_status", bsg.TechStatus)
d.Set("timeout_start", bsg.TimeoutStart)
d.Set("updated_by", bsg.UpdatedBy)
d.Set("updated_time", bsg.UpdatedTime)
d.Set("vinses", bsg.Vinses)
d.Set("vinses", bsg.VINSes)
return nil
}
func flattenBSGroupOSUsers(bsgosus BasicServiceGroupOSUsers) []map[string]interface{} {
func flattenBSGroupOSUsers(bsgosus bservice.ListOSUsers) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, bsgosu := range bsgosus {
temp := map[string]interface{}{
@@ -95,12 +96,12 @@ func flattenBSGroupOSUsers(bsgosus BasicServiceGroupOSUsers) []map[string]interf
return res
}
func flattenBSGroupComputes(bsgcs BasicServiceGroupComputes) []map[string]interface{} {
func flattenBSGroupComputes(bsgcs bservice.ListGroupComputes) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, bsgc := range bsgcs {
temp := map[string]interface{}{
"id": bsgc.ID,
"ip_addresses": bsgc.IPAdresses,
"ip_addresses": bsgc.IPAddresses,
"name": bsgc.Name,
"os_users": flattenBSGroupOSUsers(bsgc.OSUsers),
}

View File

@@ -38,14 +38,15 @@ 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/bservice"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func flattenBasicServiceList(bsl BasicServiceList) []map[string]interface{} {
func flattenBasicServiceList(bsl bservice.ListBasicServices) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, bs := range bsl {
temp := map[string]interface{}{
"account_id": bs.AccountId,
"account_id": bs.AccountID,
"account_name": bs.AccountName,
"base_domain": bs.BaseDomain,
"created_by": bs.CreatedBy,
@@ -57,7 +58,7 @@ func flattenBasicServiceList(bsl BasicServiceList) []map[string]interface{} {
"guid": bs.GUID,
"service_id": bs.ID,
"service_name": bs.Name,
"parent_srv_id": bs.ParentSrvId,
"parent_srv_id": bs.ParentSrvID,
"parent_srv_type": bs.ParentSrvType,
"rg_id": bs.RGID,
"rg_name": bs.RGName,

View File

@@ -1,9 +1,62 @@
package bservice
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice"
)
func flattenService(d *schema.ResourceData, bs *BasicServiceExtend) {
d.Set("account_id", bs.AccountId)
func flattenResourceBasicServiceGroup(d *schema.ResourceData, bsg *bservice.RecordGroup) {
d.Set("account_id", bsg.AccountID)
d.Set("account_name", bsg.AccountName)
d.Set("computes", flattenBSGroupComputes(bsg.Computes))
d.Set("consistency", bsg.Consistency)
d.Set("cpu", bsg.CPU)
d.Set("created_by", bsg.CreatedBy)
d.Set("created_time", bsg.CreatedTime)
d.Set("deleted_by", bsg.DeletedBy)
d.Set("deleted_time", bsg.DeletedTime)
d.Set("disk", bsg.Disk)
d.Set("driver", bsg.Driver)
d.Set("extnets", bsg.ExtNets)
d.Set("gid", bsg.GID)
d.Set("guid", bsg.GUID)
d.Set("image_id", bsg.ImageID)
d.Set("milestones", bsg.Milestones)
d.Set("compgroup_name", bsg.Name)
d.Set("compgroup_id", bsg.ID)
d.Set("parents", bsg.Parents)
d.Set("ram", bsg.RAM)
d.Set("rg_id", bsg.RGID)
d.Set("rg_name", bsg.RGName)
d.Set("role", bsg.Role)
d.Set("sep_id", bsg.SEPID)
d.Set("seq_no", bsg.SeqNo)
d.Set("status", bsg.Status)
d.Set("tech_status", bsg.TechStatus)
d.Set("timeout_start", bsg.TimeoutStart)
d.Set("updated_by", bsg.UpdatedBy)
d.Set("updated_time", bsg.UpdatedTime)
d.Set("vinses", bsg.VINSes)
}
func flattenGroups(groups bservice.ListGroups) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, group := range groups {
temp := map[string]interface{}{
"computes": group.Computes,
"consistency": group.Consistency,
"id": group.ID,
"name": group.Name,
"status": group.Status,
"tech_status": group.TechStatus,
}
res = append(res, temp)
}
return res
}
func flattenService(d *schema.ResourceData, bs *bservice.RecordBasicService) {
d.Set("account_id", bs.AccountID)
d.Set("account_name", bs.AccountName)
d.Set("base_domain", bs.BaseDomain)
d.Set("computes", flattenBasicServiceComputes(bs.Computes))
@@ -14,15 +67,14 @@ func flattenService(d *schema.ResourceData, bs *BasicServiceExtend) {
d.Set("deleted_time", bs.DeletedTime)
d.Set("disk_total", bs.DiskTotal)
d.Set("gid", bs.GID)
d.Set("groups", bs.Groups)
d.Set("groups_name", bs.GroupsName)
d.Set("groups", flattenGroups(bs.Groups))
d.Set("guid", bs.GUID)
d.Set("milestones", bs.Milestones)
d.Set("service_name", bs.Name)
d.Set("service_id", bs.ID)
d.Set("parent_srv_id", bs.ParentSrvId)
d.Set("parent_srv_id", bs.ParentSrvID)
d.Set("parent_srv_type", bs.ParentSrvType)
d.Set("ram_total", bs.RamTotal)
d.Set("ram_total", bs.RAMTotal)
d.Set("rg_id", bs.RGID)
d.Set("rg_name", bs.RGName)
d.Set("snapshots", flattenBasicServiceSnapshots(bs.Snapshots))
@@ -35,15 +87,21 @@ func flattenService(d *schema.ResourceData, bs *BasicServiceExtend) {
d.Set("user_managed", bs.UserManaged)
}
func flattenBasicServiceComputes(bscs BasicServiceComputes) []map[string]interface{} {
func flattenBasicServiceComputes(bscs bservice.ListComputes) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, bsc := range bscs {
temp := map[string]interface{}{
"compgroup_id": bsc.CompGroupId,
"account_id": bsc.AccountID,
"architecture": bsc.Architecture,
"compgroup_id": bsc.CompGroupID,
"compgroup_name": bsc.CompGroupName,
"compgroup_role": bsc.CompGroupRole,
"id": bsc.ID,
"name": bsc.Name,
"rg_id": bsc.RGID,
"stack_id": bsc.StackID,
"status": bsc.Status,
"tech_status": bsc.TechStatus,
}
res = append(res, temp)
}
@@ -51,7 +109,7 @@ func flattenBasicServiceComputes(bscs BasicServiceComputes) []map[string]interfa
return res
}
func flattenBasicServiceSnapshots(bsrvss BasicServiceSnapshots) []map[string]interface{} {
func flattenBasicServiceSnapshots(bsrvss bservice.ListSnapshots) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, bsrvs := range bsrvss {
temp := map[string]interface{}{

View File

@@ -1,145 +0,0 @@
/*
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>
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 bservice
///Structs
type BasicServiceCompute struct {
CompGroupId int `json:"compgroupId"`
CompGroupName string `json:"compgroupName"`
CompGroupRole string `json:"compgroupRole"`
ID int `json:"id"`
Name string `json:"name"`
}
type BasicServiceComputes []BasicServiceCompute
type BasicServiceSnapshot struct {
GUID string `json:"guid"`
Label string `json:"label"`
Timestamp int `json:"timestamp"`
Valid bool `json:"valid"`
}
type BasicServiceSnapshots []BasicServiceSnapshot
type BasicService struct {
AccountId int `json:"accountId"`
AccountName string `json:"accountName"`
BaseDomain string `json:"baseDomain"`
CreatedBy string `json:"createdBy"`
CreatedTime int `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime int `json:"deletedTime"`
GID int `json:"gid"`
Groups []int `json:"groups"`
GUID int `json:"guid"`
ID int `json:"id"`
Name string `json:"name"`
ParentSrvId int `json:"parentSrvId"`
ParentSrvType string `json:"parentSrvType"`
RGID int `json:"rgId"`
RGName string `json:"rgName"`
SSHUser string `json:"sshUser"`
Status string `json:"status"`
TechStatus string `json:"techStatus"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime int `json:"updatedTime"`
UserManaged bool `json:"userManaged"`
}
type BasicServiceList []BasicService
type BasicServiceExtend struct {
BasicService
Computes BasicServiceComputes `json:"computes"`
CPUTotal int `json:"cpuTotal"`
DiskTotal int `json:"diskTotal"`
GroupsName []string `json:"groupsName"`
Milestones int `json:"milestones"`
RamTotal int `json:"ramTotal"`
Snapshots BasicServiceSnapshots `json:"snapshots"`
SSHKey string `json:"sshKey"`
}
type BasicServiceGroupOSUser struct {
Login string `json:"login"`
Password string `json:"password"`
}
type BasicServiceGroupOSUsers []BasicServiceGroupOSUser
type BasicServicceGroupCompute struct {
ID int `json:"id"`
IPAdresses []string `json:"ipAddresses"`
Name string `json:"name"`
OSUsers BasicServiceGroupOSUsers `json:"osUsers"`
}
type BasicServiceGroupComputes []BasicServicceGroupCompute
type BasicServiceGroup struct {
AccountId int `json:"accountId"`
AccountName string `json:"accountName"`
Computes BasicServiceGroupComputes `json:"computes"`
Consistency bool `json:"consistency"`
CPU int `json:"cpu"`
CreatedBy string `json:"createdBy"`
CreatedTime int `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime int `json:"deletedTime"`
Disk int `json:"disk"`
Driver string `json:"driver"`
Extnets []int `json:"extnets"`
GID int `json:"gid"`
GUID int `json:"guid"`
ID int `json:"id"`
ImageId int `json:"imageId"`
Milestones int `json:"milestones"`
Name string `json:"name"`
Parents []int `json:"parents"`
RAM int `json:"ram"`
RGID int `json:"rgId"`
RGName string `json:"rgName"`
Role string `json:"role"`
SepId int `json:"sepId"`
SeqNo int `json:"seqNo"`
ServiceId int `json:"serviceId"`
Status string `json:"status"`
TechStatus string `json:"techStatus"`
TimeoutStart int `json:"timeoutStart"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime int `json:"updatedTime"`
Vinses []int `json:"vinses"`
}

View File

@@ -34,12 +34,12 @@ package bservice
import (
"context"
"net/url"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
@@ -47,9 +47,8 @@ import (
func resourceBasicServiceCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceBasicServiceCreate")
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
req := bservice.CreateRequest{}
haveRGID, err := existRGID(ctx, d, m)
if err != nil {
@@ -60,32 +59,25 @@ func resourceBasicServiceCreate(ctx context.Context, d *schema.ResourceData, m i
return diag.Errorf("resourceBasicServiceCreate: can't create basic service because RGID %d is not allowed or does not exist", d.Get("rg_id").(int))
}
urlValues.Add("name", d.Get("service_name").(string))
urlValues.Add("rgId", strconv.Itoa(d.Get("rg_id").(int)))
req.Name = d.Get("service_name").(string)
req.RGID = uint64(d.Get("rg_id").(int))
if sshKey, ok := d.GetOk("ssh_key"); ok {
urlValues.Add("sshKey", sshKey.(string))
req.SSHKey = sshKey.(string)
}
if sshUser, ok := d.GetOk("ssh_user"); ok {
urlValues.Add("sshUser", sshUser.(string))
req.SSHUser = sshUser.(string)
}
serviceId, err := c.DecortAPICall(ctx, "POST", bserviceCreateAPI, urlValues)
serviceId, err := c.CloudAPI().BService().Create(ctx, req)
if err != nil {
return diag.FromErr(err)
}
serviceIdParsed, _ := strconv.Atoi(serviceId)
d.SetId(strconv.FormatUint(serviceId, 10))
d.Set("service_id", serviceId)
d.SetId(serviceId)
d.Set("service_id", serviceIdParsed)
diagnostics := resourceBasicServiceRead(ctx, d, m)
if diagnostics != nil {
return diagnostics
}
return nil
return resourceBasicServiceRead(ctx, d, m)
}
func resourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
@@ -112,10 +104,20 @@ func resourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m int
case status.Disabling:
log.Debugf("The basic service is in status: %s, troubles can occur with the update.", bs.Status)
case status.Deleted:
urlVal := &url.Values{}
urlVal.Add("serviceId", d.Id())
id, _ := strconv.ParseUint(d.Id(), 10, 64)
restoreReq := bservice.RestoreRequest{
ServiceID: id,
}
enableReq := bservice.EnableRequest{
ServiceID: id,
}
_, err := c.DecortAPICall(ctx, "POST", bserviceRestoreAPI, urlVal)
_, err := c.CloudAPI().BService().Restore(ctx, restoreReq)
if err != nil {
return diag.FromErr(err)
}
_, err = c.CloudAPI().BService().Enable(ctx, enableReq)
if err != nil {
return diag.FromErr(err)
}
@@ -146,31 +148,30 @@ func resourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m int
func resourceBasicServiceDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceBasicServiceDelete")
bs, err := utilityBasicServiceCheckPresence(ctx, d, m)
if bs == nil {
if err != nil {
return diag.FromErr(err)
}
return nil
}
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
urlValues.Add("permanently", strconv.FormatBool(d.Get("permanently").(bool)))
_, err = c.DecortAPICall(ctx, "POST", bserviceDeleteAPI, urlValues)
_, err := utilityBasicServiceCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
req := bservice.DeleteRequest{
ServiceID: uint64(d.Get("service_id").(int)),
Permanently: d.Get("permanently").(bool),
}
_, err = c.CloudAPI().BService().Delete(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func resourceBasicServiceUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceBasicServiceEdit")
log.Debugf("resourceBasicServiceUpdate")
c := m.(*controller.ControllerCfg)
haveRGID, err := existRGID(ctx, d, m)
@@ -201,10 +202,20 @@ func resourceBasicServiceUpdate(ctx context.Context, d *schema.ResourceData, m i
case status.Disabling:
log.Debugf("The basic service is in status: %s, troubles can occur with the update.", bs.Status)
case status.Deleted:
urlVal := &url.Values{}
urlVal.Add("serviceId", d.Id())
id, _ := strconv.ParseUint(d.Id(), 10, 64)
restoreReq := bservice.RestoreRequest{
ServiceID: id,
}
enableReq := bservice.EnableRequest{
ServiceID: id,
}
_, err := c.DecortAPICall(ctx, "POST", bserviceRestoreAPI, urlVal)
_, err := c.CloudAPI().BService().Restore(ctx, restoreReq)
if err != nil {
return diag.FromErr(err)
}
_, err = c.CloudAPI().BService().Enable(ctx, enableReq)
if err != nil {
return diag.FromErr(err)
}
@@ -228,50 +239,63 @@ func resourceBasicServiceUpdate(ctx context.Context, d *schema.ResourceData, m i
}
}
urlValues := &url.Values{}
if d.HasChange("enable") {
api := bserviceDisableAPI
enable := d.Get("enable").(bool)
if enable {
api = bserviceEnableAPI
}
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
req := bservice.EnableRequest{
ServiceID: uint64(d.Get("service_id").(int)),
}
_, err := c.DecortAPICall(ctx, "POST", api, urlValues)
if err != nil {
return diag.FromErr(err)
}
_, err := c.CloudAPI().BService().Enable(ctx, req)
if err != nil {
return diag.FromErr(err)
}
} else {
req := bservice.DisableRequest{
ServiceID: uint64(d.Get("service_id").(int)),
}
urlValues = &url.Values{}
_, err := c.CloudAPI().BService().Disable(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
}
if d.HasChange("restore") {
restore := d.Get("restore").(bool)
if restore {
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
_, err := c.DecortAPICall(ctx, "POST", bserviceRestoreAPI, urlValues)
req := bservice.RestoreRequest{
ServiceID: uint64(d.Get("service_id").(int)),
}
_, err := c.CloudAPI().BService().Restore(ctx, req)
if err != nil {
return diag.FromErr(err)
}
urlValues = &url.Values{}
}
}
if d.HasChange("start") {
api := bserviceStopAPI
start := d.Get("start").(bool)
if start {
api = bserviceStartAPI
}
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
req := bservice.StartRequest{
ServiceID: uint64(d.Get("service_id").(int)),
}
_, err := c.DecortAPICall(ctx, "POST", api, urlValues)
if err != nil {
return diag.FromErr(err)
}
_, err := c.CloudAPI().BService().Start(ctx, req)
if err != nil {
return diag.FromErr(err)
}
} else {
req := bservice.StopRequest{
ServiceID: uint64(d.Get("service_id").(int)),
}
urlValues = &url.Values{}
_, err := c.CloudAPI().BService().Stop(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
}
if d.HasChange("snapshots") {
@@ -300,42 +324,45 @@ func resourceBasicServiceUpdate(ctx context.Context, d *schema.ResourceData, m i
if len(deletedSnapshots) > 0 {
for _, snapshot := range deletedSnapshots {
snapshotConv := snapshot.(map[string]interface{})
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
urlValues.Add("label", snapshotConv["label"].(string))
_, err := c.DecortAPICall(ctx, "POST", bserviceSnapshotDeleteAPI, urlValues)
req := bservice.SnapshotDeleteRequest{
ServiceID: uint64(d.Get("service_id").(int)),
Label: snapshotConv["label"].(string),
}
_, err := c.CloudAPI().BService().SnapshotDelete(ctx, req)
if err != nil {
return diag.FromErr(err)
}
urlValues = &url.Values{}
}
}
if len(addedSnapshots) > 0 {
for _, snapshot := range addedSnapshots {
snapshotConv := snapshot.(map[string]interface{})
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
urlValues.Add("label", snapshotConv["label"].(string))
_, err := c.DecortAPICall(ctx, "POST", bserviceSnapshotCreateAPI, urlValues)
req := bservice.SnapshotCreateRequest{
ServiceID: uint64(d.Get("service_id").(int)),
Label: snapshotConv["label"].(string),
}
_, err := c.CloudAPI().BService().SnapshotCreate(ctx, req)
if err != nil {
return diag.FromErr(err)
}
urlValues = &url.Values{}
}
}
if len(updatedSnapshots) > 0 {
for _, snapshot := range updatedSnapshots {
snapshotConv := snapshot.(map[string]interface{})
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
urlValues.Add("label", snapshotConv["label"].(string))
_, err := c.DecortAPICall(ctx, "POST", bserviceSnapshotRollbackAPI, urlValues)
req := bservice.SnapshotRollbackRequest{
ServiceID: uint64(d.Get("service_id").(int)),
Label: snapshotConv["label"].(string),
}
_, err := c.CloudAPI().BService().SnapshotRollback(ctx, req)
if err != nil {
return diag.FromErr(err)
}
urlValues = &url.Values{}
}
}
@@ -402,7 +429,7 @@ func resourceBasicServiceSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "if set to False, Basic service will be deleted to recycle bin. Otherwise destroyed immediately",
Description: "Enable service. Enabling a service technically means setting model status of all computes and service itself to ENABLED. It does not start computes.",
},
"restore": {
Type: schema.TypeBool,
@@ -438,6 +465,14 @@ func resourceBasicServiceSchemaMake() map[string]*schema.Schema {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"architecture": {
Type: schema.TypeString,
Computed: true,
},
"compgroup_id": {
Type: schema.TypeInt,
Computed: true,
@@ -454,14 +489,29 @@ func resourceBasicServiceSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"stack_id": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"cpu_total": {
Type: schema.TypeInt,
Computed: true,
@@ -493,15 +543,33 @@ func resourceBasicServiceSchemaMake() map[string]*schema.Schema {
"groups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"groups_name": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"computes": {
Type: schema.TypeInt,
Computed: true,
},
"consistency": {
Type: schema.TypeBool,
Computed: true,
},
"id": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"guid": {

View File

@@ -34,14 +34,13 @@ package bservice
import (
"context"
"net/url"
"strconv"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
@@ -50,111 +49,63 @@ func resourceBasicServiceGroupCreate(ctx context.Context, d *schema.ResourceData
log.Debugf("resourceBasicServiceGroupCreate")
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
urlValues.Add("name", d.Get("compgroup_name").(string))
urlValues.Add("count", strconv.Itoa(d.Get("comp_count").(int)))
urlValues.Add("cpu", strconv.Itoa(d.Get("cpu").(int)))
urlValues.Add("ram", strconv.Itoa(d.Get("ram").(int)))
urlValues.Add("disk", strconv.Itoa(d.Get("disk").(int)))
urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int)))
urlValues.Add("driver", strings.ToUpper(d.Get("driver").(string)))
req := bservice.GroupAddRequest{
ServiceID: uint64(d.Get("service_id").(int)),
Name: d.Get("compgroup_name").(string),
Count: uint64(d.Get("comp_count").(int)),
CPU: uint64(d.Get("cpu").(int)),
RAM: uint64(d.Get("ram").(int)),
Disk: uint64(d.Get("disk").(int)),
ImageID: uint64(d.Get("image_id").(int)),
Driver: d.Get("driver").(string),
}
if role, ok := d.GetOk("role"); ok {
urlValues.Add("role", role.(string))
req.Role = role.(string)
}
if timeoutStart, ok := d.GetOk("timeout_start"); ok {
urlValues.Add("timeoutStart", strconv.Itoa(timeoutStart.(int)))
req.TimeoutStart = uint64(timeoutStart.(int))
}
if vinses, ok := d.GetOk("vinses"); ok {
vs := vinses.([]interface{})
temp := ""
l := len(vs)
for i, v := range vs {
s := strconv.Itoa(v.(int))
if i != (l - 1) {
s += ","
}
temp = temp + s
res := []uint64{}
for _, vins := range vinses.([]interface{}) {
res = append(res, uint64(vins.(int)))
}
temp = "[" + temp + "]"
urlValues.Add("vinses", temp)
req.VINSes = res
}
if extnets, ok := d.GetOk("extnets"); ok {
es := extnets.([]interface{})
temp := ""
l := len(es)
for i, e := range es {
s := strconv.Itoa(e.(int))
if i != (l - 1) {
s += ","
}
temp = temp + s
res := []uint64{}
for _, enet := range extnets.([]interface{}) {
res = append(res, uint64(enet.(int)))
}
temp = "[" + temp + "]"
urlValues.Add("extnets", temp)
req.ExtNets = res
}
compgroupId, err := c.DecortAPICall(ctx, "POST", bserviceGroupAddAPI, urlValues)
compgroupId, err := c.CloudAPI().BService().GroupAdd(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId(compgroupId)
d.SetId(strconv.FormatUint(compgroupId, 10))
d.Set("compgroup_id", compgroupId)
diagnostics := resourceBasicServiceGroupRead(ctx, d, m)
if diagnostics != nil {
return diagnostics
}
return nil
return resourceBasicServiceGroupRead(ctx, d, m)
}
func resourceBasicServiceGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceBasicServiceGroupRead")
bsg, err := utilityBasicServiceGroupCheckPresence(ctx, d, m)
if bsg == nil {
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
d.Set("account_id", bsg.AccountId)
d.Set("account_name", bsg.AccountName)
d.Set("computes", flattenBSGroupComputes(bsg.Computes))
d.Set("consistency", bsg.Consistency)
d.Set("cpu", bsg.CPU)
d.Set("created_by", bsg.CreatedBy)
d.Set("created_time", bsg.CreatedTime)
d.Set("deleted_by", bsg.DeletedBy)
d.Set("deleted_time", bsg.DeletedTime)
d.Set("disk", bsg.Disk)
d.Set("driver", bsg.Driver)
d.Set("extnets", bsg.Extnets)
d.Set("gid", bsg.GID)
d.Set("guid", bsg.GUID)
d.Set("image_id", bsg.ImageId)
d.Set("milestones", bsg.Milestones)
d.Set("compgroup_name", bsg.Name)
d.Set("compgroup_id", bsg.ID)
d.Set("parents", bsg.Parents)
d.Set("ram", bsg.RAM)
d.Set("rg_id", bsg.RGID)
d.Set("rg_name", bsg.RGName)
d.Set("role", bsg.Role)
d.Set("sep_id", bsg.SepId)
d.Set("seq_no", bsg.SeqNo)
d.Set("status", bsg.Status)
d.Set("tech_status", bsg.TechStatus)
d.Set("timeout_start", bsg.TimeoutStart)
d.Set("updated_by", bsg.UpdatedBy)
d.Set("updated_time", bsg.UpdatedTime)
d.Set("vinses", bsg.Vinses)
flattenResourceBasicServiceGroup(d, bsg)
return nil
}
@@ -163,19 +114,17 @@ func resourceBasicServiceGroupDelete(ctx context.Context, d *schema.ResourceData
log.Debugf("resourceBasicServiceGroupDelete")
bsg, err := utilityBasicServiceGroupCheckPresence(ctx, d, m)
if bsg == nil {
if err != nil {
return diag.FromErr(err)
}
return nil
if err != nil {
return diag.FromErr(err)
}
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
req := bservice.GroupRemoveRequest{
ServiceID: bsg.ServiceID,
CompGroupID: bsg.ID,
}
_, err = c.DecortAPICall(ctx, "POST", bserviceGroupRemoveAPI, urlValues)
_, err = c.CloudAPI().BService().GroupRemove(ctx, req)
if err != nil {
return diag.FromErr(err)
}
@@ -184,113 +133,106 @@ func resourceBasicServiceGroupDelete(ctx context.Context, d *schema.ResourceData
return nil
}
func resourceBasicServiceGroupEdit(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func resourceBasicServiceGroupUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceBasicServiceGroupEdit")
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
if d.HasChange("comp_count") {
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
urlValues.Add("count", strconv.Itoa(d.Get("comp_count").(int)))
urlValues.Add("mode", strings.ToUpper(d.Get("mode").(string)))
_, err := c.DecortAPICall(ctx, "POST", bserviceGroupResizeAPI, urlValues)
req := bservice.GroupResizeRequest{
ServiceID: uint64(d.Get("service_id").(int)),
CompGroupID: uint64(d.Get("compgroup_id").(int)),
Count: int64(d.Get("comp_count").(int)),
Mode: d.Get("mode").(string),
}
_, err := c.CloudAPI().BService().GroupResize(ctx, req)
if err != nil {
return diag.FromErr(err)
}
urlValues = &url.Values{}
}
if d.HasChange("start") {
api := bserviceGroupStopAPI
start := d.Get("start").(bool)
if start {
api = bserviceGroupStartAPI
req := bservice.GroupStartRequest{
ServiceID: uint64(d.Get("service_id").(int)),
CompGroupID: uint64(d.Get("compgroup_id").(int)),
}
_, err := c.CloudAPI().BService().GroupStart(ctx, req)
if err != nil {
return diag.FromErr(err)
}
} else {
urlValues.Add("force", strconv.FormatBool(d.Get("force_stop").(bool)))
}
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
req := bservice.GroupStopRequest{
ServiceID: uint64(d.Get("service_id").(int)),
CompGroupID: uint64(d.Get("compgroup_id").(int)),
Force: d.Get("force_stop").(bool),
}
_, err := c.DecortAPICall(ctx, "POST", api, urlValues)
if err != nil {
return diag.FromErr(err)
_, err := c.CloudAPI().BService().GroupStop(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
urlValues = &url.Values{}
}
if d.HasChanges("compgroup_name", "ram", "cpu", "disk", "role") {
urlValues.Add("name", d.Get("compgroup_name").(string))
urlValues.Add("cpu", strconv.Itoa(d.Get("cpu").(int)))
urlValues.Add("ram", strconv.Itoa(d.Get("ram").(int)))
urlValues.Add("disk", strconv.Itoa(d.Get("disk").(int)))
urlValues.Add("role", d.Get("role").(string))
urlValues.Add("force", strconv.FormatBool(d.Get("force_update").(bool)))
req := bservice.GroupUpdateRequest{
ServiceID: uint64(d.Get("service_id").(int)),
CompGroupID: uint64(d.Get("compgroup_id").(int)),
Name: d.Get("compgroup_name").(string),
Role: d.Get("role").(string),
CPU: uint64(d.Get("cpu").(int)),
RAM: uint64(d.Get("ram").(int)),
Disk: uint64(d.Get("disk").(int)),
Force: d.Get("force_update").(bool),
}
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
_, err := c.DecortAPICall(ctx, "POST", bserviceGroupUpdateAPI, urlValues)
_, err := c.CloudAPI().BService().GroupUpdate(ctx, req)
if err != nil {
return diag.FromErr(err)
}
urlValues = &url.Values{}
}
if d.HasChange("extnets") {
extnets := d.Get("extnets").([]interface{})
temp := ""
l := len(extnets)
for i, e := range extnets {
s := strconv.Itoa(e.(int))
if i != (l - 1) {
s += ",\n"
} else {
s += "\n"
}
temp = temp + s
}
temp = "[" + temp + "]"
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
urlValues.Add("extnets", temp)
_, err := c.DecortAPICall(ctx, "POST", bserviceGroupUpdateExtnetAPI, urlValues)
res := []uint64{}
for _, enet := range extnets {
res = append(res, uint64(enet.(int)))
}
req := bservice.GroupUpdateExtNetRequest{
ServiceID: uint64(d.Get("service_id").(int)),
CompGroupID: uint64(d.Get("compgroup_id").(int)),
ExtNets: res,
}
_, err := c.CloudAPI().BService().GroupUpdateExtNet(ctx, req)
if err != nil {
return diag.FromErr(err)
}
urlValues = &url.Values{}
}
if d.HasChange("vinses") {
vinses := d.Get("vinses").([]interface{})
temp := ""
l := len(vinses)
for i, v := range vinses {
s := strconv.Itoa(v.(int))
if i != (l - 1) {
s += ",\n"
} else {
s += "\n"
}
temp = temp + s
}
temp = "[" + temp + "]"
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
urlValues.Add("vinses", temp)
_, err := c.DecortAPICall(ctx, "POST", bserviceGroupUpdateVinsAPI, urlValues)
res := []uint64{}
for _, vins := range vinses {
res = append(res, uint64(vins.(int)))
}
req := bservice.GroupUpdateVINSRequest{
ServiceID: uint64(d.Get("service_id").(int)),
CompGroupID: uint64(d.Get("compgroup_id").(int)),
VINSes: res,
}
_, err := c.CloudAPI().BService().GroupUpdateVINS(ctx, req)
if err != nil {
return diag.FromErr(err)
}
urlValues = &url.Values{}
}
if d.HasChange("parents") {
@@ -315,31 +257,33 @@ func resourceBasicServiceGroupEdit(ctx context.Context, d *schema.ResourceData,
for _, parent := range deletedParents {
parentConv := parent.(int)
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
urlValues.Add("parentId", strconv.Itoa(parentConv))
req := bservice.GroupParentRemoveRequest{
ServiceID: uint64(d.Get("service_id").(int)),
CompGroupID: uint64(d.Get("compgroup_id").(int)),
ParentID: uint64(parentConv),
}
_, err := c.DecortAPICall(ctx, "POST", bserviceGroupParentRemoveAPI, urlValues)
_, err := c.CloudAPI().BService().GroupParentRemove(ctx, req)
if err != nil {
return diag.FromErr(err)
}
urlValues = &url.Values{}
}
}
if len(addedParents) > 0 {
for _, parent := range addedParents {
parentConv := parent.(int)
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
urlValues.Add("parentId", strconv.Itoa(parentConv))
_, err := c.DecortAPICall(ctx, "POST", bserviceGroupParentAddAPI, urlValues)
req := bservice.GroupParentAddRequest{
ServiceID: uint64(d.Get("service_id").(int)),
CompGroupID: uint64(d.Get("compgroup_id").(int)),
ParentID: uint64(parentConv),
}
_, err := c.CloudAPI().BService().GroupParentAdd(ctx, req)
if err != nil {
return diag.FromErr(err)
}
urlValues = &url.Values{}
}
}
}
@@ -348,16 +292,16 @@ func resourceBasicServiceGroupEdit(ctx context.Context, d *schema.ResourceData,
rcs := d.Get("remove_computes").([]interface{})
if len(rcs) > 0 {
for _, rc := range rcs {
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
urlValues.Add("computeId", strconv.Itoa(rc.(int)))
req := bservice.GroupComputeRemoveRequest{
ServiceID: uint64(d.Get("service_id").(int)),
CompGroupID: uint64(d.Get("compgroup_id").(int)),
ComputeID: uint64(rc.(int)),
}
_, err := c.DecortAPICall(ctx, "POST", bserviceGroupComputeRemoveAPI, urlValues)
_, err := c.CloudAPI().BService().GroupComputeRemove(ctx, req)
if err != nil {
return diag.FromErr(err)
}
urlValues = &url.Values{}
}
}
}
@@ -613,7 +557,7 @@ func ResourceBasicServiceGroup() *schema.Resource {
CreateContext: resourceBasicServiceGroupCreate,
ReadContext: resourceBasicServiceGroupRead,
UpdateContext: resourceBasicServiceGroupEdit,
UpdateContext: resourceBasicServiceGroupUpdate,
DeleteContext: resourceBasicServiceGroupDelete,
Importer: &schema.ResourceImporter{

View File

@@ -2,41 +2,23 @@ package bservice
import (
"context"
"encoding/json"
"net/url"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/rg"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func existRGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
rgList := []struct {
ID int `json:"id"`
}{}
req := rg.ListRequest{}
rgListAPI := "/restmachine/cloudapi/rg/list"
rgListRaw, err := c.DecortAPICall(ctx, "POST", rgListAPI, urlValues)
rgList, err := c.CloudAPI().RG().List(ctx, req)
if err != nil {
return false, err
}
err = json.Unmarshal([]byte(rgListRaw), &rgList)
if err != nil {
return false, err
}
rgId := uint64(d.Get("rg_id").(int))
haveRG := false
rgId := d.Get("rg_id").(int)
for _, rg := range rgList {
if rg.ID == rgId {
haveRG = true
break
}
}
return haveRG, nil
return len(rgList.FilterByID(rgId)) != 0, nil
}

View File

@@ -34,41 +34,33 @@ package bservice
import (
"context"
"encoding/json"
"net/url"
"strconv"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityBasicServiceDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (BasicServiceList, error) {
basicServiceDeletedList := BasicServiceList{}
func utilityBasicServiceDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (bservice.ListBasicServices, error) {
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
req := bservice.ListRequest{}
if accountId, ok := d.GetOk("account_id"); ok {
urlValues.Add("accountId", strconv.Itoa(accountId.(int)))
req.AccountID = uint64(accountId.(int))
}
if rgId, ok := d.GetOk("rg_id"); ok {
urlValues.Add("rgId", strconv.Itoa(rgId.(int)))
req.RGID = uint64(rgId.(int))
}
if page, ok := d.GetOk("page"); ok {
urlValues.Add("page", strconv.Itoa(page.(int)))
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
urlValues.Add("size", strconv.Itoa(size.(int)))
req.Size = uint64(size.(int))
}
log.Debugf("utilityBasicServiceDeletedListCheckPresence")
basicServiceDeletedListRaw, err := c.DecortAPICall(ctx, "POST", bserviceListDeletedAPI, urlValues)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(basicServiceDeletedListRaw), &basicServiceDeletedList)
basicServiceDeletedList, err := c.CloudAPI().BService().ListDeleted(ctx, req)
if err != nil {
return nil, err
}

View File

@@ -34,34 +34,31 @@ package bservice
import (
"context"
"encoding/json"
"net/url"
"strconv"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityBasicServiceCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*BasicServiceExtend, error) {
bservice := &BasicServiceExtend{}
func utilityBasicServiceCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*bservice.RecordBasicService, error) {
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
var id uint64
if (strconv.Itoa(d.Get("service_id").(int))) != "0" {
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
id = uint64(d.Get("service_id").(int))
} else {
urlValues.Add("serviceId", d.Id())
id, _ = strconv.ParseUint(d.Id(), 10, 64)
}
req := bservice.GetRequest{
ServiceID: id,
}
log.Debugf("utilityBasicServiceCheckPresence")
bserviceRaw, err := c.DecortAPICall(ctx, "POST", bserviceGetAPI, urlValues)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(bserviceRaw), &bservice)
bservice, err := c.CloudAPI().BService().Get(ctx, req)
if err != nil {
return nil, err
}

View File

@@ -34,35 +34,31 @@ package bservice
import (
"context"
"encoding/json"
"net/url"
"strconv"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityBasicServiceGroupCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*BasicServiceGroup, error) {
bserviceGroup := &BasicServiceGroup{}
func utilityBasicServiceGroupCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*bservice.RecordGroup, error) {
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
req := bservice.GroupGetRequest{
ServiceID: uint64(d.Get("service_id").(int)),
}
if (strconv.Itoa(d.Get("compgroup_id").(int))) != "0" {
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
req.CompGroupID = uint64(d.Get("compgroup_id").(int))
} else {
urlValues.Add("compgroupId", d.Id())
comGroupID, _ := strconv.ParseUint(d.Id(), 10, 64)
req.CompGroupID = comGroupID
}
log.Debugf("utilityBasicServiceGroupCheckPresence")
bserviceGroupRaw, err := c.DecortAPICall(ctx, "POST", bserviceGroupGetAPI, urlValues)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(bserviceGroupRaw), &bserviceGroup)
bserviceGroup, err := c.CloudAPI().BService().GroupGet(ctx, req)
if err != nil {
return nil, err
}

View File

@@ -34,41 +34,33 @@ package bservice
import (
"context"
"encoding/json"
"net/url"
"strconv"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityBasicServiceListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (BasicServiceList, error) {
basicServiceList := BasicServiceList{}
func utilityBasicServiceListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (bservice.ListBasicServices, error) {
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
req := bservice.ListRequest{}
if accountId, ok := d.GetOk("account_id"); ok {
urlValues.Add("accountId", strconv.Itoa(accountId.(int)))
req.AccountID = uint64(accountId.(int))
}
if rgId, ok := d.GetOk("rg_id"); ok {
urlValues.Add("rgId", strconv.Itoa(rgId.(int)))
req.RGID = uint64(rgId.(int))
}
if page, ok := d.GetOk("page"); ok {
urlValues.Add("page", strconv.Itoa(page.(int)))
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
urlValues.Add("size", strconv.Itoa(size.(int)))
req.Size = uint64(size.(int))
}
log.Debugf("utilityBasicServiceListCheckPresence")
basicServiceListRaw, err := c.DecortAPICall(ctx, "POST", bserviceListAPI, urlValues)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(basicServiceListRaw), &basicServiceList)
basicServiceList, err := c.CloudAPI().BService().List(ctx, req)
if err != nil {
return nil, err
}

View File

@@ -34,32 +34,28 @@ package bservice
import (
"context"
"encoding/json"
"net/url"
"strconv"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityBasicServiceSnapshotListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (BasicServiceSnapshots, error) {
basicServiceSnapshotList := BasicServiceSnapshots{}
func utilityBasicServiceSnapshotListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (bservice.ListSnapshots, error) {
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
var id uint64
if serviceId, ok := d.GetOk("service_id"); ok {
urlValues.Add("serviceId", strconv.Itoa(serviceId.(int)))
id = uint64(serviceId.(int))
}
req := bservice.SnapshotListRequest{
ServiceID: id,
}
log.Debugf("utilityBasicServiceSnapshotListCheckPresence")
basicServiceSnapshotListRaw, err := c.DecortAPICall(ctx, "POST", bserviceSnapshotListAPI, urlValues)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(basicServiceSnapshotListRaw), &basicServiceSnapshotList)
basicServiceSnapshotList, err := c.CloudAPI().BService().SnapshotList(ctx, req)
if err != nil {
return nil, err
}