Migrate to sdkv2 and project structure refactoring

This commit is contained in:
stSolo
2022-06-29 11:34:14 +03:00
parent 3c2eb0407c
commit 3613bbea28
164 changed files with 5947 additions and 3928 deletions

View File

@@ -0,0 +1,59 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/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

@@ -0,0 +1,304 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package bservice
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/rudecs/terraform-provider-decort/internal/constants"
)
func dataSourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
bs, err := utilityBasicServiceCheckPresence(d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("account_id", bs.AccountId)
d.Set("account_name", bs.AccountName)
d.Set("base_domain", bs.BaseDomain)
d.Set("computes", flattenBasicServiceComputes(bs.Computes))
d.Set("cpu_total", bs.CPUTotal)
d.Set("created_by", bs.CreatedBy)
d.Set("created_time", bs.CreatedTime)
d.Set("deleted_by", bs.DeletedBy)
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("guid", bs.GUID)
d.Set("milestones", bs.Milestones)
d.Set("service_name", bs.Name)
d.Set("parent_srv_id", bs.ParentSrvId)
d.Set("parent_srv_type", bs.ParentSrvType)
d.Set("ram_total", bs.RamTotal)
d.Set("rg_id", bs.RGID)
d.Set("rg_name", bs.RGName)
d.Set("snapshots", flattenBasicServiceSnapshots(bs.Snapshots))
d.Set("ssh_key", bs.SSHKey)
d.Set("ssh_user", bs.SSHUser)
d.Set("status", bs.Status)
d.Set("tech_status", bs.TechStatus)
d.Set("updated_by", bs.UpdatedBy)
d.Set("updated_time", bs.UpdatedTime)
d.Set("user_managed", bs.UserManaged)
return nil
}
func flattenBasicServiceComputes(bscs BasicServiceComputes) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, bsc := range bscs {
temp := map[string]interface{}{
"compgroup_id": bsc.CompGroupId,
"compgroup_name": bsc.CompGroupName,
"compgroup_role": bsc.CompGroupRole,
"id": bsc.ID,
"name": bsc.Name,
}
res = append(res, temp)
}
return res
}
func flattenBasicServiceSnapshots(bsrvss BasicServiceSnapshots) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, bsrvs := range bsrvss {
temp := map[string]interface{}{
"guid": bsrvs.GUID,
"label": bsrvs.Label,
"timestamp": bsrvs.Timestamp,
"valid": bsrvs.Valid,
}
res = append(res, temp)
}
return res
}
func dataSourceBasicServiceSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"service_id": {
Type: schema.TypeInt,
Required: true,
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"base_domain": {
Type: schema.TypeString,
Computed: true,
},
"computes": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compgroup_id": {
Type: schema.TypeInt,
Computed: true,
},
"compgroup_name": {
Type: schema.TypeString,
Computed: true,
},
"compgroup_role": {
Type: schema.TypeString,
Computed: true,
},
"id": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"cpu_total": {
Type: schema.TypeInt,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"disk_total": {
Type: schema.TypeString,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"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,
},
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"service_name": {
Type: schema.TypeString,
Computed: true,
},
"parent_srv_id": {
Type: schema.TypeInt,
Computed: true,
},
"parent_srv_type": {
Type: schema.TypeString,
Computed: true,
},
"ram_total": {
Type: schema.TypeInt,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
},
"snapshots": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"guid": {
Type: schema.TypeString,
Computed: true,
},
"label": {
Type: schema.TypeString,
Computed: true,
},
"timestamp": {
Type: schema.TypeInt,
Computed: true,
},
"valid": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
"ssh_key": {
Type: schema.TypeString,
Computed: true,
},
"ssh_user": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"user_managed": {
Type: schema.TypeBool,
Computed: true,
},
}
return res
}
func DataSourceBasicService() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceBasicServiceRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceBasicServiceSchemaMake(),
}
}

View File

@@ -0,0 +1,69 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package bservice
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/rudecs/terraform-provider-decort/internal/constants"
)
func dataSourceBasicServiceDeletedListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
basicServiceDeletedList, err := utilityBasicServiceDeletedListCheckPresence(d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenBasicServiceList(basicServiceDeletedList))
return nil
}
func DataSourceBasicServiceDeletedList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceBasicServiceDeletedListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceBasicServiceListSchemaMake(),
}
}

View File

@@ -0,0 +1,302 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package bservice
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/rudecs/terraform-provider-decort/internal/constants"
)
func dataSourceBasicServiceGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
bsg, err := utilityBasicServiceGroupCheckPresence(d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
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("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)
return nil
}
func flattenBSGroupOSUsers(bsgosus BasicServiceGroupOSUsers) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, bsgosu := range bsgosus {
temp := map[string]interface{}{
"login": bsgosu.Login,
"password": bsgosu.Password,
}
res = append(res, temp)
}
return res
}
func flattenBSGroupComputes(bsgcs BasicServiceGroupComputes) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, bsgc := range bsgcs {
temp := map[string]interface{}{
"id": bsgc.ID,
"ip_addresses": bsgc.IPAdresses,
"name": bsgc.Name,
"os_users": flattenBSGroupOSUsers(bsgc.OSUsers),
}
res = append(res, temp)
}
return res
}
func dataSourceBasicServiceGroupSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"service_id": {
Type: schema.TypeInt,
Required: true,
},
"compgroup_id": {
Type: schema.TypeInt,
Required: true,
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"computes": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
"ip_addresses": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"os_users": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"login": {
Type: schema.TypeString,
Computed: true,
},
"password": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
},
},
"consistency": {
Type: schema.TypeBool,
Computed: true,
},
"cpu": {
Type: schema.TypeInt,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"disk": {
Type: schema.TypeInt,
Computed: true,
},
"driver": {
Type: schema.TypeString,
Computed: true,
},
"extnets": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"image_id": {
Type: schema.TypeInt,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"compgroup_name": {
Type: schema.TypeString,
Computed: true,
},
"parents": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"ram": {
Type: schema.TypeInt,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
},
"role": {
Type: schema.TypeString,
Computed: true,
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,
},
"seq_no": {
Type: schema.TypeInt,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
"timeout_start": {
Type: schema.TypeInt,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"vinses": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
}
return res
}
func DataSourceBasicServiceGroup() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceBasicServiceGroupRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceBasicServiceGroupSchemaMake(),
}
}

View File

@@ -0,0 +1,226 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package bservice
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/rudecs/terraform-provider-decort/internal/constants"
)
func flattenBasicServiceList(bsl BasicServiceList) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, bs := range bsl {
temp := map[string]interface{}{
"account_id": bs.AccountId,
"account_name": bs.AccountName,
"base_domain": bs.BaseDomain,
"created_by": bs.CreatedBy,
"created_time": bs.CreatedTime,
"deleted_by": bs.DeletedBy,
"deleted_time": bs.DeletedTime,
"gid": bs.GID,
"groups": bs.Groups,
"guid": bs.GUID,
"service_id": bs.ID,
"service_name": bs.Name,
"parent_srv_id": bs.ParentSrvId,
"parent_srv_type": bs.ParentSrvType,
"rg_id": bs.RGID,
"rg_name": bs.RGName,
"ssh_user": bs.SSHUser,
"status": bs.Status,
"tech_status": bs.TechStatus,
"updated_by": bs.UpdatedBy,
"updated_time": bs.UpdatedTime,
"user_managed": bs.UserManaged,
}
res = append(res, temp)
}
return res
}
func dataSourceBasicServiceListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
basicServiceList, err := utilityBasicServiceListCheckPresence(d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenBasicServiceList(basicServiceList))
return nil
}
func dataSourceBasicServiceListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"account_id": {
Type: schema.TypeInt,
Optional: true,
Description: "ID of the account to query for BasicService instances",
},
"rg_id": {
Type: schema.TypeInt,
Optional: true,
Description: "ID of the resource group to query for BasicService instances",
},
"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,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"base_domain": {
Type: schema.TypeString,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"groups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"service_id": {
Type: schema.TypeInt,
Computed: true,
},
"service_name": {
Type: schema.TypeString,
Computed: true,
},
"parent_srv_id": {
Type: schema.TypeInt,
Computed: true,
},
"parent_srv_type": {
Type: schema.TypeString,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
},
"ssh_user": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"user_managed": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
}
return res
}
func DataSourceBasicServiceList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceBasicServiceListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceBasicServiceListSchemaMake(),
}
}

View File

@@ -0,0 +1,104 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package bservice
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/rudecs/terraform-provider-decort/internal/constants"
)
func dataSourceBasicServiceSnapshotListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
basicServiceSnapshotList, err := utilityBasicServiceSnapshotListCheckPresence(d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenBasicServiceSnapshots(basicServiceSnapshotList))
return nil
}
func dataSourceBasicServiceSnapshotListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"service_id": {
Type: schema.TypeInt,
Required: true,
Description: "ID of the BasicService instance",
},
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"guid": {
Type: schema.TypeString,
Computed: true,
},
"label": {
Type: schema.TypeString,
Computed: true,
},
"timestamp": {
Type: schema.TypeInt,
Computed: true,
},
"valid": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
}
return res
}
func DataSourceBasicServiceSnapshotList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceBasicServiceSnapshotListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceBasicServiceSnapshotListSchemaMake(),
}
}

View File

@@ -0,0 +1,144 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/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

@@ -0,0 +1,564 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package bservice
import (
"context"
"net/url"
"strconv"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/rudecs/terraform-provider-decort/internal/constants"
"github.com/rudecs/terraform-provider-decort/internal/controller"
log "github.com/sirupsen/logrus"
)
func resourceBasicServiceCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceBasicServiceCreate")
if serviceId, ok := d.GetOk("service_id"); ok {
if exists, err := resourceBasicServiceExists(d, m); exists {
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(strconv.Itoa(serviceId.(int)))
d.Set("service_id", strconv.Itoa(serviceId.(int)))
diagnostics := resourceBasicServiceRead(ctx, d, m)
if diagnostics != nil {
return diagnostics
}
d.SetId(id.String())
return nil
}
return diag.Errorf("provided service id does not exist")
}
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
urlValues.Add("name", d.Get("service_name").(string))
urlValues.Add("rgId", strconv.Itoa(d.Get("rg_id").(int)))
if sshKey, ok := d.GetOk("ssh_key"); ok {
urlValues.Add("sshKey", sshKey.(string))
}
if sshUser, ok := d.GetOk("ssh_user"); ok {
urlValues.Add("sshUser", sshUser.(string))
}
serviceId, err := c.DecortAPICall("POST", bserviceCreateAPI, urlValues)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(serviceId)
d.Set("service_id", serviceId)
diagnostics := resourceBasicServiceRead(ctx, d, m)
if diagnostics != nil {
return diagnostics
}
d.SetId(id.String())
return nil
}
func resourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceBasicServiceRead")
bs, err := utilityBasicServiceCheckPresence(d, m)
if bs == nil {
d.SetId("")
return diag.FromErr(err)
}
d.Set("account_id", bs.AccountId)
d.Set("account_name", bs.AccountName)
d.Set("base_domain", bs.BaseDomain)
d.Set("computes", flattenBasicServiceComputes(bs.Computes))
d.Set("cpu_total", bs.CPUTotal)
d.Set("created_by", bs.CreatedBy)
d.Set("created_time", bs.CreatedTime)
d.Set("deleted_by", bs.DeletedBy)
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("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_type", bs.ParentSrvType)
d.Set("ram_total", bs.RamTotal)
d.Set("rg_id", bs.RGID)
d.Set("rg_name", bs.RGName)
d.Set("snapshots", flattenBasicServiceSnapshots(bs.Snapshots))
d.Set("ssh_key", bs.SSHKey)
d.Set("ssh_user", bs.SSHUser)
d.Set("status", bs.Status)
d.Set("tech_status", bs.TechStatus)
d.Set("updated_by", bs.UpdatedBy)
d.Set("updated_time", bs.UpdatedTime)
d.Set("user_managed", bs.UserManaged)
return nil
}
func resourceBasicServiceDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceBasicServiceDelete")
bs, err := utilityBasicServiceCheckPresence(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("POST", bserviceDeleteAPI, urlValues)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func resourceBasicServiceExists(d *schema.ResourceData, m interface{}) (bool, error) {
log.Debugf("resourceBasicServiceExists")
bservice, err := utilityBasicServiceCheckPresence(d, m)
if bservice == nil {
if err != nil {
return false, err
}
return false, nil
}
return true, nil
}
func resourceBasicServiceEdit(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceBasicServiceEdit")
c := m.(*controller.ControllerCfg)
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)))
_, err := c.DecortAPICall("POST", api, urlValues)
if err != nil {
return diag.FromErr(err)
}
urlValues = &url.Values{}
}
if d.HasChange("restore") {
restore := d.Get("restore").(bool)
if restore {
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
_, err := c.DecortAPICall("POST", bserviceRestoreAPI, urlValues)
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)))
_, err := c.DecortAPICall("POST", api, urlValues)
if err != nil {
return diag.FromErr(err)
}
urlValues = &url.Values{}
}
if d.HasChange("snapshots") {
deletedSnapshots := make([]interface{}, 0)
addedSnapshots := make([]interface{}, 0)
updatedSnapshots := make([]interface{}, 0)
old, new := d.GetChange("snapshots")
oldConv := old.([]interface{})
newConv := new.([]interface{})
for _, el := range oldConv {
if !isContainsSnapshot(newConv, el) {
deletedSnapshots = append(deletedSnapshots, el)
}
}
for _, el := range newConv {
if !isContainsSnapshot(oldConv, el) {
addedSnapshots = append(addedSnapshots, el)
} else {
if isRollback(oldConv, el) {
updatedSnapshots = append(updatedSnapshots, el)
}
}
}
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("POST", bserviceSnapshotDeleteAPI, urlValues)
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("POST", bserviceSnapshotCreateAPI, urlValues)
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("POST", bserviceSnapshotRollbackAPI, urlValues)
if err != nil {
return diag.FromErr(err)
}
urlValues = &url.Values{}
}
}
}
return nil
}
func isContainsSnapshot(els []interface{}, el interface{}) bool {
for _, elOld := range els {
elOldConv := elOld.(map[string]interface{})
elConv := el.(map[string]interface{})
if elOldConv["guid"].(string) == elConv["guid"].(string) {
return true
}
}
return false
}
func isRollback(els []interface{}, el interface{}) bool {
for _, elOld := range els {
elOldConv := elOld.(map[string]interface{})
elConv := el.(map[string]interface{})
if elOldConv["guid"].(string) == elConv["guid"].(string) &&
elOldConv["rollback"].(bool) != elConv["rollback"].(bool) &&
elConv["rollback"].(bool) {
return true
}
}
return false
}
func resourceBasicServiceSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"service_name": {
Type: schema.TypeString,
Required: true,
Description: "Name of the service",
},
"rg_id": {
Type: schema.TypeInt,
Required: true,
Description: "ID of the Resource Group where this service will be placed",
},
"ssh_key": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "SSH key to deploy for the specified user. Same key will be deployed to all computes of the service.",
},
"ssh_user": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "name of the user to deploy SSH key for. Pass empty string if no SSH key deployment is required",
},
"permanently": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "if set to False, Basic service will be deleted to recycle bin. Otherwise destroyed immediately",
},
"enable": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "if set to False, Basic service will be deleted to recycle bin. Otherwise destroyed immediately",
},
"restore": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Restores BasicService instance",
},
"start": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Start service. Starting a service technically means starting computes from all service groups according to group relations",
},
"service_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"base_domain": {
Type: schema.TypeString,
Computed: true,
},
"computes": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compgroup_id": {
Type: schema.TypeInt,
Computed: true,
},
"compgroup_name": {
Type: schema.TypeString,
Computed: true,
},
"compgroup_role": {
Type: schema.TypeString,
Computed: true,
},
"id": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"cpu_total": {
Type: schema.TypeInt,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"disk_total": {
Type: schema.TypeString,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"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,
},
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"parent_srv_id": {
Type: schema.TypeInt,
Computed: true,
},
"parent_srv_type": {
Type: schema.TypeString,
Computed: true,
},
"ram_total": {
Type: schema.TypeInt,
Computed: true,
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
},
"snapshots": {
Type: schema.TypeList,
Computed: true,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"guid": {
Type: schema.TypeString,
Computed: true,
},
"label": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"rollback": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"timestamp": {
Type: schema.TypeInt,
Computed: true,
},
"valid": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"user_managed": {
Type: schema.TypeBool,
Computed: true,
},
}
}
func ResourceBasicService() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceBasicServiceCreate,
ReadContext: resourceBasicServiceRead,
UpdateContext: resourceBasicServiceEdit,
DeleteContext: resourceBasicServiceDelete,
Exists: resourceBasicServiceExists,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout60s,
Read: &constants.Timeout30s,
Update: &constants.Timeout60s,
Delete: &constants.Timeout60s,
Default: &constants.Timeout60s,
},
Schema: resourceBasicServiceSchemaMake(),
}
}

View File

@@ -0,0 +1,671 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package bservice
import (
"context"
"net/url"
"strconv"
"strings"
"github.com/google/uuid"
"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"
"github.com/rudecs/terraform-provider-decort/internal/constants"
"github.com/rudecs/terraform-provider-decort/internal/controller"
log "github.com/sirupsen/logrus"
)
func resourceBasicServiceGroupCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceBasicServiceGroupCreate")
if compgroupId, ok := d.GetOk("compgroup_id"); ok {
if _, ok := d.GetOk("service_id"); ok {
if exists, err := resourceBasicServiceGroupExists(d, m); exists {
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(strconv.Itoa(compgroupId.(int)))
d.Set("compgroup_id", strconv.Itoa(compgroupId.(int)))
diagnostics := resourceBasicServiceGroupRead(ctx, d, m)
if diagnostics != nil {
return diagnostics
}
d.SetId(id.String())
return nil
}
return diag.Errorf("provided compgroup id does not exist")
}
}
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)))
if role, ok := d.GetOk("role"); ok {
urlValues.Add("role", role.(string))
}
if timeoutStart, ok := d.GetOk("timeout_start"); ok {
urlValues.Add("timeoutStart", strconv.Itoa(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
}
temp = "[" + temp + "]"
urlValues.Add("vinses", temp)
}
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
}
temp = "[" + temp + "]"
urlValues.Add("extnets", temp)
}
compgroupId, err := c.DecortAPICall("POST", bserviceGroupAddAPI, urlValues)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(compgroupId)
d.Set("compgroup_id", compgroupId)
diagnostics := resourceBasicServiceGroupRead(ctx, d, m)
if diagnostics != nil {
return diagnostics
}
d.SetId(id.String())
return nil
}
func resourceBasicServiceGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceBasicServiceGroupRead")
bsg, err := utilityBasicServiceGroupCheckPresence(d, m)
if bsg == 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)
return nil
}
func resourceBasicServiceGroupDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceBasicServiceGroupDelete")
bsg, err := utilityBasicServiceGroupCheckPresence(d, m)
if bsg == 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("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
_, err = c.DecortAPICall("POST", bserviceGroupRemoveAPI, urlValues)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func resourceBasicServiceGroupExists(d *schema.ResourceData, m interface{}) (bool, error) {
log.Debugf("resourceBasicServiceGroupExists")
bserviceGroup, err := utilityBasicServiceGroupCheckPresence(d, m)
if bserviceGroup == nil {
if err != nil {
return false, err
}
return false, nil
}
return true, nil
}
func resourceBasicServiceGroupEdit(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("POST", bserviceGroupResizeAPI, urlValues)
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
} 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)))
_, err := c.DecortAPICall("POST", api, urlValues)
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)))
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
_, err := c.DecortAPICall("POST", bserviceGroupUpdateAPI, urlValues)
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("POST", bserviceGroupUpdateExtnetAPI, urlValues)
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("POST", bserviceGroupUpdateVinsAPI, urlValues)
if err != nil {
return diag.FromErr(err)
}
urlValues = &url.Values{}
}
if d.HasChange("parents") {
deletedParents := make([]interface{}, 0)
addedParents := make([]interface{}, 0)
old, new := d.GetChange("parents")
oldConv := old.([]interface{})
newConv := new.([]interface{})
for _, el := range oldConv {
if !isContainsParent(newConv, el) {
deletedParents = append(deletedParents, el)
}
}
for _, el := range newConv {
if !isContainsParent(oldConv, el) {
addedParents = append(addedParents, el)
}
}
if len(deletedParents) > 0 {
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))
_, err := c.DecortAPICall("POST", bserviceGroupParentRemoveAPI, urlValues)
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("POST", bserviceGroupParentAddAPI, urlValues)
if err != nil {
return diag.FromErr(err)
}
urlValues = &url.Values{}
}
}
}
if d.HasChange("remove_computes") {
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)))
_, err := c.DecortAPICall("POST", bserviceGroupComputeRemoveAPI, urlValues)
if err != nil {
return diag.FromErr(err)
}
urlValues = &url.Values{}
}
}
}
return nil
}
func isContainsParent(els []interface{}, el interface{}) bool {
for _, elOld := range els {
elOldConv := elOld.(int)
elConv := el.(int)
if elOldConv == elConv {
return true
}
}
return false
}
func resourceBasicServiceGroupSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"service_id": {
Type: schema.TypeInt,
Required: true,
Description: "ID of the Basic Service to add a group to",
},
"compgroup_name": {
Type: schema.TypeString,
Required: true,
Description: "name of the Compute Group to add",
},
"comp_count": {
Type: schema.TypeInt,
Required: true,
Description: "computes number. Defines how many computes must be there in the group",
},
"cpu": {
Type: schema.TypeInt,
Required: true,
Description: "compute CPU number. All computes in the group have the same CPU count",
},
"ram": {
Type: schema.TypeInt,
Required: true,
Description: "compute RAM volume in MB. All computes in the group have the same RAM volume",
},
"disk": {
Type: schema.TypeInt,
Required: true,
Description: "compute boot disk size in GB",
},
"image_id": {
Type: schema.TypeInt,
Required: true,
Description: "OS image ID to create computes from",
},
"driver": {
Type: schema.TypeString,
Required: true,
Description: "compute driver like a KVM_X86, KVM_PPC, etc.",
},
"role": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "group role tag. Can be empty string, does not have to be unique",
},
"timeout_start": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "time of Compute Group readiness",
},
"extnets": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
Description: "list of external networks to connect computes to",
},
"vinses": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
Description: "list of ViNSes to connect computes to",
},
"mode": {
Type: schema.TypeString,
Optional: true,
Default: "RELATIVE",
ValidateFunc: validation.StringInSlice([]string{"RELATIVE", "ABSOLUTE"}, false),
Description: "(RELATIVE;ABSOLUTE) either delta or absolute value of computes",
},
"start": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Start the specified Compute Group within BasicService",
},
"force_stop": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "force stop Compute Group",
},
"force_update": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "force resize Compute Group",
},
"parents": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"remove_computes": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"compgroup_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"computes": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
"ip_addresses": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"os_users": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"login": {
Type: schema.TypeString,
Computed: true,
},
"password": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
},
},
"consistency": {
Type: schema.TypeBool,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,
},
"seq_no": {
Type: schema.TypeInt,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
}
}
func ResourceBasicServiceGroup() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceBasicServiceGroupCreate,
ReadContext: resourceBasicServiceGroupRead,
UpdateContext: resourceBasicServiceGroupEdit,
DeleteContext: resourceBasicServiceGroupDelete,
Exists: resourceBasicServiceGroupExists,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout60s,
Read: &constants.Timeout30s,
Update: &constants.Timeout60s,
Delete: &constants.Timeout60s,
Default: &constants.Timeout60s,
},
Schema: resourceBasicServiceGroupSchemaMake(),
}
}

View File

@@ -0,0 +1,75 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package bservice
import (
"encoding/json"
"net/url"
"strconv"
"github.com/rudecs/terraform-provider-decort/internal/controller"
log "github.com/sirupsen/logrus"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityBasicServiceDeletedListCheckPresence(d *schema.ResourceData, m interface{}) (BasicServiceList, error) {
basicServiceDeletedList := BasicServiceList{}
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
if accountId, ok := d.GetOk("account_id"); ok {
urlValues.Add("accountId", strconv.Itoa(accountId.(int)))
}
if rgId, ok := d.GetOk("rg_id"); ok {
urlValues.Add("rgId", strconv.Itoa(rgId.(int)))
}
if page, ok := d.GetOk("page"); ok {
urlValues.Add("page", strconv.Itoa(page.(int)))
}
if size, ok := d.GetOk("size"); ok {
urlValues.Add("size", strconv.Itoa(size.(int)))
}
log.Debugf("utilityBasicServiceDeletedListCheckPresence")
basicServiceDeletedListRaw, err := c.DecortAPICall("POST", bserviceListDeletedAPI, urlValues)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(basicServiceDeletedListRaw), &basicServiceDeletedList)
if err != nil {
return nil, err
}
return basicServiceDeletedList, nil
}

View File

@@ -0,0 +1,68 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package bservice
import (
"encoding/json"
"net/url"
"strconv"
"github.com/rudecs/terraform-provider-decort/internal/controller"
log "github.com/sirupsen/logrus"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityBasicServiceCheckPresence(d *schema.ResourceData, m interface{}) (*BasicServiceExtend, error) {
bservice := &BasicServiceExtend{}
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
if (strconv.Itoa(d.Get("service_id").(int))) != "0" {
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
} else {
urlValues.Add("serviceId", d.Id())
}
log.Debugf("utilityBasicServiceCheckPresence")
bserviceRaw, err := c.DecortAPICall("POST", bserviceGetAPI, urlValues)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(bserviceRaw), &bservice)
if err != nil {
return nil, err
}
return bservice, nil
}

View File

@@ -0,0 +1,69 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package bservice
import (
"encoding/json"
"net/url"
"strconv"
"github.com/rudecs/terraform-provider-decort/internal/controller"
log "github.com/sirupsen/logrus"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityBasicServiceGroupCheckPresence(d *schema.ResourceData, m interface{}) (*BasicServiceGroup, error) {
bserviceGroup := &BasicServiceGroup{}
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
if (strconv.Itoa(d.Get("compgroup_id").(int))) != "0" {
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
} else {
urlValues.Add("compgroupId", d.Id())
}
log.Debugf("utilityBasicServiceGroupCheckPresence")
bserviceGroupRaw, err := c.DecortAPICall("POST", bserviceGroupGetAPI, urlValues)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(bserviceGroupRaw), &bserviceGroup)
if err != nil {
return nil, err
}
return bserviceGroup, nil
}

View File

@@ -0,0 +1,75 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package bservice
import (
"encoding/json"
"net/url"
"strconv"
"github.com/rudecs/terraform-provider-decort/internal/controller"
log "github.com/sirupsen/logrus"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityBasicServiceListCheckPresence(d *schema.ResourceData, m interface{}) (BasicServiceList, error) {
basicServiceList := BasicServiceList{}
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
if accountId, ok := d.GetOk("account_id"); ok {
urlValues.Add("accountId", strconv.Itoa(accountId.(int)))
}
if rgId, ok := d.GetOk("rg_id"); ok {
urlValues.Add("rgId", strconv.Itoa(rgId.(int)))
}
if page, ok := d.GetOk("page"); ok {
urlValues.Add("page", strconv.Itoa(page.(int)))
}
if size, ok := d.GetOk("size"); ok {
urlValues.Add("size", strconv.Itoa(size.(int)))
}
log.Debugf("utilityBasicServiceListCheckPresence")
basicServiceListRaw, err := c.DecortAPICall("POST", bserviceListAPI, urlValues)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(basicServiceListRaw), &basicServiceList)
if err != nil {
return nil, err
}
return basicServiceList, nil
}

View File

@@ -0,0 +1,66 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
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://github.com/rudecs/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
*/
package bservice
import (
"encoding/json"
"net/url"
"strconv"
"github.com/rudecs/terraform-provider-decort/internal/controller"
log "github.com/sirupsen/logrus"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityBasicServiceSnapshotListCheckPresence(d *schema.ResourceData, m interface{}) (BasicServiceSnapshots, error) {
basicServiceSnapshotList := BasicServiceSnapshots{}
c := m.(*controller.ControllerCfg)
urlValues := &url.Values{}
if serviceId, ok := d.GetOk("service_id"); ok {
urlValues.Add("serviceId", strconv.Itoa(serviceId.(int)))
}
log.Debugf("utilityBasicServiceSnapshotListCheckPresence")
basicServiceSnapshotListRaw, err := c.DecortAPICall("POST", bserviceSnapshotListAPI, urlValues)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(basicServiceSnapshotListRaw), &basicServiceSnapshotList)
if err != nil {
return nil, err
}
return basicServiceSnapshotList, nil
}