diff --git a/internal/service/cloudbroker/account/account_rs.go b/internal/service/cloudbroker/account/account_rs.go deleted file mode 100644 index e9582b8..0000000 --- a/internal/service/cloudbroker/account/account_rs.go +++ /dev/null @@ -1,276 +0,0 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, - -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 account - -import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - -func resourceAccountSchemaMake() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "account_name": { - Type: schema.TypeString, - Required: true, - Description: "account name", - }, - "username": { - Type: schema.TypeString, - Required: true, - Description: "username of owner the account", - }, - "emailaddress": { - Type: schema.TypeString, - Optional: true, - Description: "email", - }, - "send_access_emails": { - Type: schema.TypeBool, - Optional: true, - Default: true, - Description: "if true send emails when a user is granted access to resources", - }, - "uniq_pools": { - Type: schema.TypeList, - Optional: true, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "users": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "user_id": { - Type: schema.TypeString, - Required: true, - }, - "access_type": { - Type: schema.TypeString, - Required: true, - }, - "recursive_delete": { - Type: schema.TypeBool, - Optional: true, - Default: false, - }, - }, - }, - }, - "cpu_allocation_parameter": { - Type: schema.TypeString, - Optional: true, - Computed: true, - Description: "set cpu allocation parameter", - }, - "cpu_allocation_ratio": { - Type: schema.TypeFloat, - Optional: true, - Computed: true, - Description: "set cpu allocation ratio", - }, - "restore": { - Type: schema.TypeBool, - Optional: true, - Description: "restore a deleted account", - }, - "permanently": { - Type: schema.TypeBool, - Optional: true, - Default: false, - Description: "whether to completely delete the account", - }, - "enable": { - Type: schema.TypeBool, - Optional: true, - Default: true, - Description: "enable/disable account", - }, - "resource_limits": { - Type: schema.TypeList, - Optional: true, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "cu_c": { - Type: schema.TypeFloat, - Optional: true, - Computed: true, - }, - "cu_d": { - Type: schema.TypeFloat, - Computed: true, - }, - "cu_dm": { - Type: schema.TypeFloat, - Optional: true, - Computed: true, - }, - "cu_i": { - Type: schema.TypeFloat, - Optional: true, - Computed: true, - }, - "cu_m": { - Type: schema.TypeFloat, - Optional: true, - Computed: true, - }, - "cu_np": { - Type: schema.TypeFloat, - Optional: true, - Computed: true, - }, - "gpu_units": { - Type: schema.TypeFloat, - Optional: true, - Computed: true, - }, - }, - }, - }, - "account_id": { - Type: schema.TypeInt, - Optional: true, - Computed: true, - }, - "dc_location": { - Type: schema.TypeString, - Computed: true, - }, - "ckey": { - Type: schema.TypeString, - Computed: true, - }, - // "meta": { - // Type: schema.TypeList, - // Computed: true, - // Elem: &schema.Schema{ - // Type: schema.TypeString, - // }, - // }, - "acl": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "explicit": { - Type: schema.TypeBool, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "right": { - Type: schema.TypeString, - Computed: true, - }, - "status": { - Type: schema.TypeString, - Computed: true, - }, - "type": { - Type: schema.TypeString, - Computed: true, - }, - "user_group_id": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - "company": { - Type: schema.TypeString, - Computed: true, - }, - "companyurl": { - Type: schema.TypeString, - Computed: true, - }, - "created_by": { - Type: schema.TypeString, - Computed: true, - }, - "created_time": { - Type: schema.TypeInt, - Computed: true, - }, - "deactivation_time": { - Type: schema.TypeFloat, - Computed: true, - }, - "deleted_by": { - Type: schema.TypeString, - Computed: true, - }, - "deleted_time": { - Type: schema.TypeInt, - Computed: true, - }, - "displayname": { - Type: schema.TypeString, - Computed: true, - }, - "guid": { - Type: schema.TypeInt, - Computed: true, - }, - "resource_types": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "status": { - Type: schema.TypeString, - Computed: true, - }, - "updated_time": { - Type: schema.TypeInt, - Computed: true, - }, - "version": { - Type: schema.TypeInt, - Computed: true, - }, - "vins": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeInt, - }, - }, - } -} diff --git a/internal/service/cloudbroker/account/schema.go b/internal/service/cloudbroker/account/schema.go new file mode 100644 index 0000000..2c359a5 --- /dev/null +++ b/internal/service/cloudbroker/account/schema.go @@ -0,0 +1,1992 @@ +package account + +import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + +func resourceAccountSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "account_name": { + Type: schema.TypeString, + Required: true, + Description: "account name", + }, + "username": { + Type: schema.TypeString, + Required: true, + Description: "username of owner the account", + }, + "emailaddress": { + Type: schema.TypeString, + Optional: true, + Description: "email", + }, + "send_access_emails": { + Type: schema.TypeBool, + Optional: true, + Default: true, + Description: "if true send emails when a user is granted access to resources", + }, + "uniq_pools": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "users": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "user_id": { + Type: schema.TypeString, + Required: true, + }, + "access_type": { + Type: schema.TypeString, + Required: true, + }, + "recursive_delete": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + }, + }, + }, + "cpu_allocation_parameter": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "set cpu allocation parameter", + }, + "cpu_allocation_ratio": { + Type: schema.TypeFloat, + Optional: true, + Computed: true, + Description: "set cpu allocation ratio", + }, + "restore": { + Type: schema.TypeBool, + Optional: true, + Description: "restore a deleted account", + }, + "permanently": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "whether to completely delete the account", + }, + "enable": { + Type: schema.TypeBool, + Optional: true, + Default: true, + Description: "enable/disable account", + }, + "resource_limits": { + Type: schema.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cu_c": { + Type: schema.TypeFloat, + Optional: true, + Computed: true, + }, + "cu_d": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_dm": { + Type: schema.TypeFloat, + Optional: true, + Computed: true, + }, + "cu_i": { + Type: schema.TypeFloat, + Optional: true, + Computed: true, + }, + "cu_m": { + Type: schema.TypeFloat, + Optional: true, + Computed: true, + }, + "cu_np": { + Type: schema.TypeFloat, + Optional: true, + Computed: true, + }, + "gpu_units": { + Type: schema.TypeFloat, + Optional: true, + Computed: true, + }, + }, + }, + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "dc_location": { + Type: schema.TypeString, + Computed: true, + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + // "meta": { + // Type: schema.TypeList, + // Computed: true, + // Elem: &schema.Schema{ + // Type: schema.TypeString, + // }, + // }, + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "company": { + Type: schema.TypeString, + Computed: true, + }, + "companyurl": { + Type: schema.TypeString, + Computed: true, + }, + "created_by": { + Type: schema.TypeString, + Computed: true, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + "deactivation_time": { + Type: schema.TypeFloat, + Computed: true, + }, + "deleted_by": { + Type: schema.TypeString, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "displayname": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "resource_types": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + }, + "version": { + Type: schema.TypeInt, + Computed: true, + }, + "vins": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + } +} + +func dataSourceAccountAuditsListSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the account", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Description: "Search Result", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "call": { + Type: schema.TypeString, + Computed: true, + }, + "responsetime": { + Type: schema.TypeFloat, + Computed: true, + }, + "statuscode": { + Type: schema.TypeInt, + Computed: true, + }, + "timestamp": { + Type: schema.TypeFloat, + Computed: true, + }, + "user": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + } + return res +} + +func dataSourceAccountComputesListSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the account", + }, + "compute_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by compute ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by compute name", + }, + "rg_name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by RG name", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by RG ID", + }, + "tech_status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by tech. status", + }, + "ip_address": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by IP address", + }, + "extnet_name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by extnet name", + }, + "extnet_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by extnet ID", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Description: "Search Result", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Computed: true, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "cpus": { + 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, + }, + "compute_id": { + Type: schema.TypeInt, + Computed: true, + }, + "compute_name": { + Type: schema.TypeString, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "registered": { + Type: schema.TypeBool, + Computed: true, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + }, + "total_disks_size": { + Type: schema.TypeInt, + Computed: true, + }, + "updated_by": { + Type: schema.TypeString, + Computed: true, + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + }, + "user_managed": { + Type: schema.TypeBool, + Computed: true, + }, + "vins_connected": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return res +} + +func dataSourceAccountListDeletedSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "acl": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by ACL", + }, + "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{ + "dc_location": { + Type: schema.TypeString, + Computed: true, + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "company": { + Type: schema.TypeString, + Computed: true, + }, + "companyurl": { + Type: schema.TypeString, + Computed: true, + }, + "cpu_allocation_parameter": { + Type: schema.TypeString, + Computed: true, + }, + "cpu_allocation_ratio": { + Type: schema.TypeFloat, + Computed: true, + }, + "created_by": { + Type: schema.TypeString, + Computed: true, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + "deactivation_time": { + Type: schema.TypeFloat, + Computed: true, + }, + "deleted_by": { + Type: schema.TypeString, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "displayname": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "resource_limits": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cu_c": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_d": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_dm": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_i": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_m": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_np": { + Type: schema.TypeFloat, + Computed: true, + }, + "gpu_units": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + "resource_types": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "send_access_emails": { + Type: schema.TypeBool, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "uniq_pools": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + }, + "version": { + Type: schema.TypeInt, + Computed: true, + }, + "vins": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } +} + +func dataSourceAccountDisksListSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the account", + }, + "disk_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by disk ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by disk name", + }, + "disk_max_size": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by disk max size", + }, + "type": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by disk type", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Description: "Search Result", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "disk_id": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_name": { + Type: schema.TypeString, + Computed: true, + }, + "pool_name": { + Type: schema.TypeString, + Computed: true, + }, + "sep_id": { + Type: schema.TypeInt, + Computed: true, + }, + "shareable": { + Type: schema.TypeBool, + Computed: true, + }, + "size_max": { + Type: schema.TypeInt, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return res +} + +func dataSourceAccountFlipGroupsListSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the account", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "vins_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ViNS ID", + }, + "vins_name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by ViNS name", + }, + "extnet_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by extnet ID", + }, + "by_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by IP", + }, + "flipgroup_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by flipgroup ID", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Description: "Search Result", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Computed: true, + }, + "client_type": { + Type: schema.TypeString, + Computed: true, + }, + "conn_type": { + Type: schema.TypeString, + Computed: true, + }, + "created_by": { + Type: schema.TypeString, + Computed: true, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + "default_gw": { + Type: schema.TypeString, + Computed: true, + }, + "deleted_by": { + Type: schema.TypeString, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "fg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "fg_name": { + Type: schema.TypeString, + Computed: true, + }, + "net_id": { + Type: schema.TypeInt, + Computed: true, + }, + "net_type": { + Type: schema.TypeString, + Computed: true, + }, + "netmask": { + Type: schema.TypeInt, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "updated_by": { + Type: schema.TypeString, + Computed: true, + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return res +} + +func dataSourceAccountResourceConsumptionGetSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Required: true, + }, + "consumed": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disksize": { + Type: schema.TypeFloat, + Computed: true, + }, + "disksizemax": { + Type: schema.TypeFloat, + Computed: true, + }, + "extips": { + Type: schema.TypeInt, + Computed: true, + }, + "exttraffic": { + Type: schema.TypeInt, + Computed: true, + }, + "gpu": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "seps": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeString, + Computed: true, + }, + "data_name": { + Type: schema.TypeString, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "reserved": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disksize": { + Type: schema.TypeFloat, + Computed: true, + }, + "disksizemax": { + Type: schema.TypeFloat, + Computed: true, + }, + "extips": { + Type: schema.TypeInt, + Computed: true, + }, + "exttraffic": { + Type: schema.TypeInt, + Computed: true, + }, + "gpu": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "seps": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeString, + Computed: true, + }, + "data_name": { + Type: schema.TypeString, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "resource_limits": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cu_c": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_d": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_dm": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_i": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_m": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_np": { + Type: schema.TypeFloat, + Computed: true, + }, + "gpu_units": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + } + + return res +} + +func dataSourceAccountListSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "acl": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by ACL", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by status", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + 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{ + "dc_location": { + Type: schema.TypeString, + Computed: true, + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "company": { + Type: schema.TypeString, + Computed: true, + }, + "companyurl": { + Type: schema.TypeString, + Computed: true, + }, + "cpu_allocation_parameter": { + Type: schema.TypeString, + Computed: true, + }, + "cpu_allocation_ratio": { + Type: schema.TypeFloat, + Computed: true, + }, + "created_by": { + Type: schema.TypeString, + Computed: true, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + "deactivation_time": { + Type: schema.TypeFloat, + Computed: true, + }, + "deleted_by": { + Type: schema.TypeString, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "displayname": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "resource_limits": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cu_c": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_d": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_dm": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_i": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_m": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_np": { + Type: schema.TypeFloat, + Computed: true, + }, + "gpu_units": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + "resource_types": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "send_access_emails": { + Type: schema.TypeBool, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "uniq_pools": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + }, + "version": { + Type: schema.TypeInt, + Computed: true, + }, + "vins": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return res +} + +func dataSourceAccountResourceConsumptionListSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Computed: true, + }, + "consumed": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disksize": { + Type: schema.TypeFloat, + Computed: true, + }, + "disksizemax": { + Type: schema.TypeFloat, + Computed: true, + }, + "extips": { + Type: schema.TypeInt, + Computed: true, + }, + "exttraffic": { + Type: schema.TypeInt, + Computed: true, + }, + "gpu": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "seps": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeString, + Computed: true, + }, + "data_name": { + Type: schema.TypeString, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "reserved": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disksize": { + Type: schema.TypeFloat, + Computed: true, + }, + "disksizemax": { + Type: schema.TypeFloat, + Computed: true, + }, + "extips": { + Type: schema.TypeInt, + Computed: true, + }, + "exttraffic": { + Type: schema.TypeInt, + Computed: true, + }, + "gpu": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "seps": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeString, + Computed: true, + }, + "data_name": { + Type: schema.TypeString, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return res +} + +func dataSourceAccountRGListSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the account", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by RG ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "vins_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ViNS ID", + }, + "vm_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by VM ID", + }, + + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by status", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Description: "Search Result", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "computes": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "started": { + Type: schema.TypeInt, + Computed: true, + }, + "stopped": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "resources": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "consumed": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disksize": { + Type: schema.TypeFloat, + Computed: true, + }, + "disksizemax": { + Type: schema.TypeInt, + Computed: true, + }, + "extips": { + Type: schema.TypeInt, + Computed: true, + }, + "exttraffic": { + Type: schema.TypeInt, + Computed: true, + }, + "gpu": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "seps": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeString, + Computed: true, + }, + "data_name": { + Type: schema.TypeString, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "limits": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disksize": { + Type: schema.TypeInt, + Computed: true, + }, + "disksizemax": { + Type: schema.TypeInt, + Computed: true, + }, + "extips": { + Type: schema.TypeInt, + Computed: true, + }, + "exttraffic": { + Type: schema.TypeInt, + Computed: true, + }, + "gpu": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "seps": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "reserved": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disksize": { + Type: schema.TypeInt, + Computed: true, + }, + "disksizemax": { + Type: schema.TypeInt, + Computed: true, + }, + "extips": { + Type: schema.TypeInt, + Computed: true, + }, + "exttraffic": { + Type: schema.TypeInt, + Computed: true, + }, + "gpu": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "seps": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeString, + Computed: true, + }, + "data_name": { + Type: schema.TypeString, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeFloat, + 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, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "updated_by": { + Type: schema.TypeString, + Computed: true, + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + }, + "vinses": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Optional: true, + }, + } + return res +} + +func dataSourceAccountVinsListSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the account", + }, + "vins_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ViNS ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by RG ID", + }, + "ext_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by external IP", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Description: "Search Result", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Computed: true, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "computes": { + 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, + }, + "external_ip": { + Type: schema.TypeString, + Computed: true, + }, + "vin_id": { + Type: schema.TypeInt, + Computed: true, + }, + "vin_name": { + Type: schema.TypeString, + Computed: true, + }, + "network": { + Type: schema.TypeString, + Computed: true, + }, + "pri_vnf_dev_id": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "updated_by": { + Type: schema.TypeString, + Computed: true, + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return res +} + +func dataSourceAccountSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Required: true, + }, + "dc_location": { + Type: schema.TypeString, + Computed: true, + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "company": { + Type: schema.TypeString, + Computed: true, + }, + "companyurl": { + Type: schema.TypeString, + Computed: true, + }, + "cpu_allocation_parameter": { + Type: schema.TypeString, + Computed: true, + }, + "cpu_allocation_ratio": { + Type: schema.TypeFloat, + Computed: true, + }, + "created_by": { + Type: schema.TypeString, + Computed: true, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + "deactivation_time": { + Type: schema.TypeInt, + Computed: true, + }, + "deleted_by": { + Type: schema.TypeString, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "displayname": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "resource_limits": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cu_c": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_d": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_dm": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_i": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_m": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_np": { + Type: schema.TypeFloat, + Computed: true, + }, + "gpu_units": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + "resource_types": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "send_access_emails": { + Type: schema.TypeBool, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "uniq_pools": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + }, + "version": { + Type: schema.TypeInt, + Computed: true, + }, + "vins": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + } +} diff --git a/internal/service/cloudbroker/audit/data_source_audit.go b/internal/service/cloudbroker/audit/data_source_audit.go new file mode 100644 index 0000000..5a6d7e4 --- /dev/null +++ b/internal/service/cloudbroker/audit/data_source_audit.go @@ -0,0 +1,68 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Sergey Kisil, + +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 audit + +import ( + "context" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceAuditRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + auditRec, err := utilityAuditCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") // ensure ID is empty in this case + return diag.FromErr(err) + } + + flattenAudit(d, auditRec) + d.SetId(d.Get("audit_guid").(string)) + + return nil +} + +func DataSourceAudit() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceAuditRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceAuditSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/audit/data_source_audit_linked_jobs.go b/internal/service/cloudbroker/audit/data_source_audit_linked_jobs.go new file mode 100644 index 0000000..488078f --- /dev/null +++ b/internal/service/cloudbroker/audit/data_source_audit_linked_jobs.go @@ -0,0 +1,71 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Sergey Kisil, + +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 audit + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceLinkedJobsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + linkedJobs, err := utilityLinkedJobsCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenLinkedJobs(linkedJobs)) + + return nil +} + +func DataSourceAuditLinkedJobs() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceLinkedJobsRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceLinkedJobsSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/audit/data_source_audit_list.go b/internal/service/cloudbroker/audit/data_source_audit_list.go new file mode 100644 index 0000000..9aca822 --- /dev/null +++ b/internal/service/cloudbroker/audit/data_source_audit_list.go @@ -0,0 +1,72 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Sergey Kisil, + +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 audit + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceAuditListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + auditList, err := utilityAuditListCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenAuditList(auditList)) + d.Set("entry_count", auditList.EntryCount) + + return nil +} + +func DataSourceAuditList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceAuditListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceAuditListSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/audit/flattens.go b/internal/service/cloudbroker/audit/flattens.go new file mode 100644 index 0000000..e6c16e7 --- /dev/null +++ b/internal/service/cloudbroker/audit/flattens.go @@ -0,0 +1,91 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Sergey Kisil, + +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 audit + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/audit" +) + +func flattenAudit(d *schema.ResourceData, au *audit.RecordAudit) { + log.Debugf("flattenAudit: decoded audit guid %s", d.Get("audit_guid").(string)) + + d.Set("apitask", au.Apitask) + d.Set("args", au.Arguments) + d.Set("call", au.Call) + d.Set("guid", au.GUID) + d.Set("kwargs", au.Kwargs) + d.Set("remote_addr", au.RemoteAddr) + d.Set("responsetime", au.ResponseTime) + d.Set("result", au.Result) + d.Set("status_code", au.StatusCode) + d.Set("tags", au.Tags) + d.Set("timestamp", au.Timestamp) + d.Set("timestamp_end", au.TimestampEnd) + d.Set("user", au.User) +} + +func flattenAuditList(au *audit.ListAudits) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(au.Data)) + for _, item := range au.Data { + temp := map[string]interface{}{ + "call": item.Call, + "guid": item.GUID, + "responsetime": item.ResponseTime, + "status_code": item.StatusCode, + "timestamp": item.Timestamp, + "user": item.User, + } + res = append(res, temp) + } + return res +} + +func flattenLinkedJobs(ljl *audit.ListLinkedJobs) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + linkedJobs := *ljl + for _, item := range linkedJobs { + temp := map[string]interface{}{ + "cmd": item.CMD, + "nid": item.NID, + "state": item.State, + "time_create": item.TimeCreate, + "time_start": item.TimeStart, + "time_stop": item.TimeStop, + "timeout": item.Timeout, + } + res = append(res, temp) + } + return res +} diff --git a/internal/service/cloudbroker/audit/schema.go b/internal/service/cloudbroker/audit/schema.go new file mode 100644 index 0000000..a5db461 --- /dev/null +++ b/internal/service/cloudbroker/audit/schema.go @@ -0,0 +1,198 @@ +package audit + +import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + +func dataSourceAuditSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "audit_guid": { + Type: schema.TypeString, + Required: true, + Description: "audit guid", + }, + + "apitask": { + Type: schema.TypeString, + Computed: true, + }, + "args": { + Type: schema.TypeString, + Computed: true, + }, + "call": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "kwargs": { + Type: schema.TypeString, + Computed: true, + }, + "remote_addr": { + Type: schema.TypeString, + Computed: true, + }, + "responsetime": { + Type: schema.TypeFloat, + Computed: true, + }, + "result": { + Type: schema.TypeString, + Computed: true, + }, + "status_code": { + Type: schema.TypeInt, + Computed: true, + }, + "tags": { + Type: schema.TypeString, + Computed: true, + }, + "timestamp": { + Type: schema.TypeFloat, + Computed: true, + }, + "timestamp_end": { + Type: schema.TypeFloat, + Computed: true, + }, + "user": { + Type: schema.TypeString, + Computed: true, + }, + } +} + +func dataSourceAuditListSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "timestamp_at": { + Type: schema.TypeInt, + Optional: true, + Description: "find all audits after point in time (unixtime)", + }, + "timestamp_to": { + Type: schema.TypeInt, + Optional: true, + Description: "find all audits before point in time (unixtime)", + }, + "user": { + Type: schema.TypeString, + Optional: true, + Description: "find by user (Mongo RegExp supported)", + }, + "call": { + Type: schema.TypeString, + Optional: true, + Description: "find by api endpoint (Mongo RegExp supported)", + }, + "status_code": { + Type: schema.TypeInt, + Optional: true, + Description: "find by HTTP status code", + }, + "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{ + "call": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "responsetime": { + Type: schema.TypeFloat, + Computed: true, + }, + "status_code": { + Type: schema.TypeInt, + Computed: true, + }, + "timestamp": { + Type: schema.TypeFloat, + Computed: true, + }, + "user": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + Description: "entry count", + }, + } +} + +func dataSourceLinkedJobsSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "audit_guid": { + Type: schema.TypeString, + Required: true, + Description: "audit guid", + }, + + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cmd": { + Type: schema.TypeString, + Computed: true, + Description: "cmd", + }, + "nid": { + Type: schema.TypeInt, + Computed: true, + Description: "nid", + }, + "state": { + Type: schema.TypeString, + Computed: true, + Description: "state", + }, + "time_create": { + Type: schema.TypeInt, + Computed: true, + Description: "time create", + }, + "time_start": { + Type: schema.TypeInt, + Computed: true, + Description: "time start", + }, + "time_stop": { + Type: schema.TypeInt, + Computed: true, + Description: "time stop", + }, + "timeout": { + Type: schema.TypeInt, + Computed: true, + Description: "timeout", + }, + }, + }, + }, + } +} diff --git a/internal/service/cloudbroker/audit/utility_audit.go b/internal/service/cloudbroker/audit/utility_audit.go new file mode 100644 index 0000000..a9274b4 --- /dev/null +++ b/internal/service/cloudbroker/audit/utility_audit.go @@ -0,0 +1,62 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Sergey Kisil, + +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 audit + +import ( + "context" + + log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/audit" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func utilityAuditCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*audit.RecordAudit, error) { + c := m.(*controller.ControllerCfg) + req := audit.GetRequest{} + + if d.Id() != "" { + req.AuditGuid = d.Id() + } else { + req.AuditGuid = d.Get("audit_guid").(string) + } + + log.Debugf("utilityStackCheckPresence: load stack") + auditInfo, err := c.CloudBroker().Audit().Get(ctx, req) + if err != nil { + return nil, err + } + + return auditInfo, nil +} diff --git a/internal/service/cloudbroker/audit/utility_audit_linked_jobs.go b/internal/service/cloudbroker/audit/utility_audit_linked_jobs.go new file mode 100644 index 0000000..f65f5a0 --- /dev/null +++ b/internal/service/cloudbroker/audit/utility_audit_linked_jobs.go @@ -0,0 +1,56 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Sergey Kisil, + +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 audit + +import ( + "context" + + log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/audit" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func utilityLinkedJobsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*audit.ListLinkedJobs, error) { + c := m.(*controller.ControllerCfg) + req := audit.LinkedJobsRequest{AuditGuid: d.Get("audit_guid").(string)} + + log.Debugf("utilityLinkedJobsCheckPresence: load linked jobs") + linkedJobsList, err := c.CloudBroker().Audit().LinkedJobs(ctx, req) + if err != nil { + return nil, err + } + + return linkedJobsList, nil +} diff --git a/internal/service/cloudbroker/audit/utility_audit_list.go b/internal/service/cloudbroker/audit/utility_audit_list.go new file mode 100644 index 0000000..6089351 --- /dev/null +++ b/internal/service/cloudbroker/audit/utility_audit_list.go @@ -0,0 +1,78 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Sergey Kisil, + +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 audit + +import ( + "context" + + log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/audit" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func utilityAuditListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*audit.ListAudits, error) { + c := m.(*controller.ControllerCfg) + req := audit.ListRequest{} + + if timestampAt, ok := d.GetOk("timestamp_at"); ok { + req.TimestampAt = uint64(timestampAt.(int)) + } + if timestampTo, ok := d.GetOk("timestamp_to"); ok { + req.TimestampTo = uint64(timestampTo.(int)) + } + if user, ok := d.GetOk("user"); ok { + req.User = user.(string) + } + if call, ok := d.GetOk("call"); ok { + req.Call = call.(string) + } + if statusCode, ok := d.GetOk("status_code"); ok { + req.StatusCode = uint64(statusCode.(int)) + } + if Page, ok := d.GetOk("page"); ok { + req.Page = uint64(Page.(int)) + } + if Size, ok := d.GetOk("size"); ok { + req.Size = uint64(Size.(int)) + } + + log.Debugf("utilityAuditListCheckPresence: load audit list") + auditList, err := c.CloudBroker().Audit().List(ctx, req) + if err != nil { + return nil, err + } + + return auditList, nil +} diff --git a/internal/service/cloudbroker/disks/data_source_disk_list_deleted.go b/internal/service/cloudbroker/disks/data_source_disk_list_deleted.go new file mode 100644 index 0000000..8fc88ae --- /dev/null +++ b/internal/service/cloudbroker/disks/data_source_disk_list_deleted.go @@ -0,0 +1,71 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package disks + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceDiskListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + diskList, err := utilityDiskListDeletedCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenDiskList(diskList)) + d.Set("entry_count", diskList.EntryCount) + + return nil +} + +func DataSourceDiskListDeleted() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceDiskListDeletedRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceDiskListDeletedSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/disks/schema.go b/internal/service/cloudbroker/disks/schema.go new file mode 100644 index 0000000..ba8f62f --- /dev/null +++ b/internal/service/cloudbroker/disks/schema.go @@ -0,0 +1,2017 @@ +package disks + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +func dataSourceDiskSchemaMake() map[string]*schema.Schema { + rets := map[string]*schema.Schema{ + "disk_id": { + Type: schema.TypeInt, + Required: true, + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "acl": { + Type: schema.TypeString, + Computed: true, + }, + "boot_partition": { + Type: schema.TypeInt, + Computed: true, + }, + "computes": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "compute_id": { + Type: schema.TypeString, + Computed: true, + }, + "compute_name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "destruction_time": { + Type: schema.TypeInt, + Computed: true, + }, + "devicename": { + Type: schema.TypeString, + Computed: true, + }, + "disk_path": { + Type: schema.TypeString, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "image_id": { + Type: schema.TypeInt, + Computed: true, + }, + "images": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "iotune": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "read_bytes_sec": { + Type: schema.TypeInt, + Computed: true, + }, + "read_bytes_sec_max": { + Type: schema.TypeInt, + Computed: true, + }, + "read_iops_sec": { + Type: schema.TypeInt, + Computed: true, + }, + "read_iops_sec_max": { + Type: schema.TypeInt, + Computed: true, + }, + "size_iops_sec": { + Type: schema.TypeInt, + Computed: true, + }, + "total_bytes_sec": { + Type: schema.TypeInt, + Computed: true, + }, + "total_bytes_sec_max": { + Type: schema.TypeInt, + Computed: true, + }, + "total_iops_sec": { + Type: schema.TypeInt, + Computed: true, + }, + "total_iops_sec_max": { + Type: schema.TypeInt, + Computed: true, + }, + "write_bytes_sec": { + Type: schema.TypeInt, + Computed: true, + }, + "write_bytes_sec_max": { + Type: schema.TypeInt, + Computed: true, + }, + "write_iops_sec": { + Type: schema.TypeInt, + Computed: true, + }, + "write_iops_sec_max": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "iqn": { + Type: schema.TypeString, + Computed: true, + }, + "login": { + Type: schema.TypeString, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_name": { + Type: schema.TypeString, + Computed: true, + }, + "order": { + Type: schema.TypeInt, + Computed: true, + }, + "params": { + Type: schema.TypeString, + Computed: true, + }, + "parent_id": { + Type: schema.TypeInt, + Computed: true, + }, + "passwd": { + Type: schema.TypeString, + Computed: true, + }, + "pci_slot": { + Type: schema.TypeInt, + Computed: true, + }, + "pool": { + Type: schema.TypeString, + Computed: true, + }, + "present_to": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "purge_attempts": { + Type: schema.TypeInt, + Computed: true, + }, + "purge_time": { + Type: schema.TypeInt, + Computed: true, + }, + "reality_device_number": { + Type: schema.TypeInt, + Computed: true, + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_name": { + Type: schema.TypeString, + Computed: true, + }, + "role": { + Type: schema.TypeString, + Computed: true, + }, + "sep_id": { + Type: schema.TypeInt, + Computed: true, + }, + "sep_type": { + Type: schema.TypeString, + Computed: true, + }, + "shareable": { + Type: schema.TypeBool, + Computed: true, + }, + "size_max": { + Type: schema.TypeInt, + Computed: true, + }, + "size_used": { + Type: schema.TypeFloat, + 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, + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_id": { + Type: schema.TypeString, + Computed: true, + }, + "snap_set_guid": { + Type: schema.TypeString, + Computed: true, + }, + "snap_set_time": { + Type: schema.TypeInt, + Computed: true, + }, + "timestamp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "vmid": { + Type: schema.TypeInt, + Computed: true, + }, + } + + return rets +} + +func dataSourceDiskListSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by name", + }, + "account_name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by account name", + }, + "disk_max_size": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by max disk size", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Find by status", + }, + "shared": { + Type: schema.TypeBool, + Optional: true, + Description: "Find by shared field", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "ID of the account the disks belong to", + }, + "type": { + Type: schema.TypeString, + Optional: true, + Description: "type of the disks", + }, + "sep_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by sep id", + }, + "pool": { + Type: schema.TypeString, + Optional: true, + Description: "Find by pool name", + }, + "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, + }, + "acl": { + Type: schema.TypeString, + Computed: true, + }, + "boot_partition": { + Type: schema.TypeInt, + Computed: true, + }, + "computes": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "compute_id": { + Type: schema.TypeString, + Computed: true, + }, + "compute_name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "destruction_time": { + Type: schema.TypeInt, + Computed: true, + }, + "devicename": { + Type: schema.TypeString, + Computed: true, + }, + "disk_path": { + Type: schema.TypeString, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_id": { + Type: schema.TypeInt, + Computed: true, + }, + "image_id": { + Type: schema.TypeInt, + Computed: true, + }, + "images": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "iotune": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "read_bytes_sec": { + Type: schema.TypeInt, + Computed: true, + }, + "read_bytes_sec_max": { + Type: schema.TypeInt, + Computed: true, + }, + "read_iops_sec": { + Type: schema.TypeInt, + Computed: true, + }, + "read_iops_sec_max": { + Type: schema.TypeInt, + Computed: true, + }, + "size_iops_sec": { + Type: schema.TypeInt, + Computed: true, + }, + "total_bytes_sec": { + Type: schema.TypeInt, + Computed: true, + }, + "total_bytes_sec_max": { + Type: schema.TypeInt, + Computed: true, + }, + "total_iops_sec": { + Type: schema.TypeInt, + Computed: true, + }, + "total_iops_sec_max": { + Type: schema.TypeInt, + Computed: true, + }, + "write_bytes_sec": { + Type: schema.TypeInt, + Computed: true, + }, + "write_bytes_sec_max": { + Type: schema.TypeInt, + Computed: true, + }, + "write_iops_sec": { + Type: schema.TypeInt, + Computed: true, + }, + "write_iops_sec_max": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "iqn": { + Type: schema.TypeString, + Computed: true, + }, + "login": { + Type: schema.TypeString, + Computed: true, + }, + "machine_id": { + Type: schema.TypeInt, + Computed: true, + }, + "machine_name": { + Type: schema.TypeString, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_name": { + Type: schema.TypeString, + Computed: true, + }, + "order": { + Type: schema.TypeInt, + Computed: true, + }, + "params": { + Type: schema.TypeString, + Computed: true, + }, + "parent_id": { + Type: schema.TypeInt, + Computed: true, + }, + "passwd": { + Type: schema.TypeString, + Computed: true, + }, + "pci_slot": { + Type: schema.TypeInt, + Computed: true, + }, + "pool": { + Type: schema.TypeString, + Computed: true, + }, + "present_to": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "purge_attempts": { + Type: schema.TypeInt, + Computed: true, + }, + "purge_time": { + Type: schema.TypeInt, + Computed: true, + }, + "reality_device_number": { + Type: schema.TypeInt, + Computed: true, + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_name": { + Type: schema.TypeString, + Computed: true, + }, + "role": { + Type: schema.TypeString, + Computed: true, + }, + "sep_id": { + Type: schema.TypeInt, + Computed: true, + }, + "sep_type": { + Type: schema.TypeString, + Computed: true, + }, + "shareable": { + Type: schema.TypeBool, + Computed: true, + }, + "size_max": { + Type: schema.TypeInt, + Computed: true, + }, + "size_used": { + Type: schema.TypeFloat, + 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, + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_id": { + Type: schema.TypeString, + Computed: true, + }, + "snap_set_guid": { + Type: schema.TypeString, + Computed: true, + }, + "snap_set_time": { + Type: schema.TypeInt, + Computed: true, + }, + "timestamp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "vmid": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return res +} + +func dataSourceDiskListDeletedSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by name", + }, + "account_name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by account name", + }, + "disk_max_size": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by max disk size", + }, + "shared": { + Type: schema.TypeBool, + Optional: true, + Description: "Find by shared field", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "ID of the account the disks belong to", + }, + "type": { + Type: schema.TypeString, + Optional: true, + Description: "type of the disks", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Computed: true, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "acl": { + Type: schema.TypeString, + Computed: true, + }, + "boot_partition": { + Type: schema.TypeInt, + Computed: true, + }, + "computes": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "compute_id": { + Type: schema.TypeString, + Computed: true, + }, + "compute_name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "destruction_time": { + Type: schema.TypeInt, + Computed: true, + }, + "devicename": { + Type: schema.TypeString, + Computed: true, + }, + "disk_path": { + Type: schema.TypeString, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_id": { + Type: schema.TypeInt, + Computed: true, + }, + "image_id": { + Type: schema.TypeInt, + Computed: true, + }, + "images": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "iotune": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "read_bytes_sec": { + Type: schema.TypeInt, + Computed: true, + }, + "read_bytes_sec_max": { + Type: schema.TypeInt, + Computed: true, + }, + "read_iops_sec": { + Type: schema.TypeInt, + Computed: true, + }, + "read_iops_sec_max": { + Type: schema.TypeInt, + Computed: true, + }, + "size_iops_sec": { + Type: schema.TypeInt, + Computed: true, + }, + "total_bytes_sec": { + Type: schema.TypeInt, + Computed: true, + }, + "total_bytes_sec_max": { + Type: schema.TypeInt, + Computed: true, + }, + "total_iops_sec": { + Type: schema.TypeInt, + Computed: true, + }, + "total_iops_sec_max": { + Type: schema.TypeInt, + Computed: true, + }, + "write_bytes_sec": { + Type: schema.TypeInt, + Computed: true, + }, + "write_bytes_sec_max": { + Type: schema.TypeInt, + Computed: true, + }, + "write_iops_sec": { + Type: schema.TypeInt, + Computed: true, + }, + "write_iops_sec_max": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "iqn": { + Type: schema.TypeString, + Computed: true, + }, + "login": { + Type: schema.TypeString, + Computed: true, + }, + "machine_id": { + Type: schema.TypeInt, + Computed: true, + }, + "machine_name": { + Type: schema.TypeString, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_name": { + Type: schema.TypeString, + Computed: true, + }, + "order": { + Type: schema.TypeInt, + Computed: true, + }, + "params": { + Type: schema.TypeString, + Computed: true, + }, + "parent_id": { + Type: schema.TypeInt, + Computed: true, + }, + "passwd": { + Type: schema.TypeString, + Computed: true, + }, + "pci_slot": { + Type: schema.TypeInt, + Computed: true, + }, + "pool": { + Type: schema.TypeString, + Computed: true, + }, + "present_to": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "purge_attempts": { + Type: schema.TypeInt, + Computed: true, + }, + "purge_time": { + Type: schema.TypeInt, + Computed: true, + }, + "reality_device_number": { + Type: schema.TypeInt, + Computed: true, + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_name": { + Type: schema.TypeString, + Computed: true, + }, + "role": { + Type: schema.TypeString, + Computed: true, + }, + "sep_id": { + Type: schema.TypeInt, + Computed: true, + }, + "sep_type": { + Type: schema.TypeString, + Computed: true, + }, + "shareable": { + Type: schema.TypeBool, + Computed: true, + }, + "size_max": { + Type: schema.TypeInt, + Computed: true, + }, + "size_used": { + Type: schema.TypeFloat, + 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, + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_id": { + Type: schema.TypeString, + Computed: true, + }, + "snap_set_guid": { + Type: schema.TypeString, + Computed: true, + }, + "snap_set_time": { + Type: schema.TypeInt, + Computed: true, + }, + "timestamp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "vmid": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return res +} + +func dataSourceDiskListTypesSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "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.Schema{ + Type: schema.TypeString, + }, + Description: "The types of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'", + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return res +} + +func dataSourceDiskListTypesDetailedSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "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{ + "pools": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + Description: "Pool name", + }, + "system": { + Type: schema.TypeString, + Computed: true, + }, + "types": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "The types of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'", + }, + }, + }, + }, + "sep_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Storage endpoint provider ID to create disk", + }, + "sep_name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } +} + +func dataSourceDiskListUnattachedSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by ID", + }, + "account_name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by account name", + }, + "disk_max_size": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by max disk size", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Find by status", + }, + "type": { + Type: schema.TypeString, + Optional: true, + Description: "type of the disks", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "ID of the account the disks belong to", + }, + "sep_id": { + Type: schema.TypeInt, + Optional: true, + Description: "ID of SEP", + }, + "pool": { + Type: schema.TypeString, + Optional: true, + }, + "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{ + "_ckey": { + Type: schema.TypeString, + Computed: true, + Description: "CKey", + }, + "_meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "Meta parameters", + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + Description: "ID of the account the disks belong to", + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + Description: "The name of the subscriber '(account') to whom this disk belongs", + }, + "acl": { + Type: schema.TypeString, + Computed: true, + }, + "boot_partition": { + Type: schema.TypeInt, + Computed: true, + Description: "Number of disk partitions", + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + Description: "Created time", + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + Description: "Deleted time", + }, + "desc": { + Type: schema.TypeString, + Computed: true, + Description: "Description of disk", + }, + "destruction_time": { + Type: schema.TypeInt, + Computed: true, + Description: "Time of final deletion", + }, + "disk_path": { + Type: schema.TypeString, + Computed: true, + Description: "Disk path", + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "ID of the grid (platform)", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "Disk ID on the storage side", + }, + "disk_id": { + Type: schema.TypeInt, + Computed: true, + Description: "The unique ID of the subscriber-owner of the disk", + }, + "image_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Image ID", + }, + "images": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Description: "IDs of images using the disk", + }, + "iotune": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "read_bytes_sec": { + Type: schema.TypeInt, + Computed: true, + Description: "Number of bytes to read per second", + }, + "read_bytes_sec_max": { + Type: schema.TypeInt, + Computed: true, + Description: "Maximum number of bytes to read", + }, + "read_iops_sec": { + Type: schema.TypeInt, + Computed: true, + Description: "Number of io read operations per second", + }, + "read_iops_sec_max": { + Type: schema.TypeInt, + Computed: true, + Description: "Maximum number of io read operations", + }, + "size_iops_sec": { + Type: schema.TypeInt, + Computed: true, + Description: "Size of io operations", + }, + "total_bytes_sec": { + Type: schema.TypeInt, + Computed: true, + Description: "Total size bytes per second", + }, + "total_bytes_sec_max": { + Type: schema.TypeInt, + Computed: true, + Description: "Maximum total size of bytes per second", + }, + "total_iops_sec": { + Type: schema.TypeInt, + Computed: true, + Description: "Total number of io operations per second", + }, + "total_iops_sec_max": { + Type: schema.TypeInt, + Computed: true, + Description: "Maximum total number of io operations per second", + }, + "write_bytes_sec": { + Type: schema.TypeInt, + Computed: true, + Description: "Number of bytes to write per second", + }, + "write_bytes_sec_max": { + Type: schema.TypeInt, + Computed: true, + Description: "Maximum number of bytes to write per second", + }, + "write_iops_sec": { + Type: schema.TypeInt, + Computed: true, + Description: "Number of write operations per second", + }, + "write_iops_sec_max": { + Type: schema.TypeInt, + Computed: true, + Description: "Maximum number of write operations per second", + }, + }, + }, + }, + "iqn": { + Type: schema.TypeString, + Computed: true, + Description: "Disk IQN", + }, + "login": { + Type: schema.TypeString, + Computed: true, + Description: "Login to access the disk", + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + Description: "Milestones", + }, + "disk_name": { + Type: schema.TypeString, + Computed: true, + Description: "Name of disk", + }, + "order": { + Type: schema.TypeInt, + Computed: true, + Description: "Disk order", + }, + "params": { + Type: schema.TypeString, + Computed: true, + Description: "Disk params", + }, + "parent_id": { + Type: schema.TypeInt, + Computed: true, + Description: "ID of the parent disk", + }, + "passwd": { + Type: schema.TypeString, + Computed: true, + Description: "Password to access the disk", + }, + "pci_slot": { + Type: schema.TypeInt, + Computed: true, + Description: "ID of the pci slot to which the disk is connected", + }, + "pool": { + Type: schema.TypeString, + Computed: true, + Description: "Pool for disk location", + }, + "present_to": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "purge_attempts": { + Type: schema.TypeInt, + Computed: true, + Description: "Number of deletion attempts", + }, + "purge_time": { + Type: schema.TypeInt, + Computed: true, + Description: "Time of the last deletion attempt", + }, + "reality_device_number": { + Type: schema.TypeInt, + Computed: true, + Description: "Reality device number", + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + Description: "ID of the reference to the disk", + }, + "res_id": { + Type: schema.TypeString, + Computed: true, + Description: "Resource ID", + }, + "res_name": { + Type: schema.TypeString, + Computed: true, + Description: "Name of the resource", + }, + "role": { + Type: schema.TypeString, + Computed: true, + Description: "Disk role", + }, + "sep_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Storage endpoint provider ID to create disk", + }, + "shareable": { + Type: schema.TypeBool, + Computed: true, + }, + "size_max": { + Type: schema.TypeInt, + Computed: true, + Description: "Size in GB", + }, + "size_used": { + Type: schema.TypeFloat, + Computed: true, + Description: "Number of used space, in GB", + }, + "snapshots": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + Description: "ID of the snapshot", + }, + "label": { + Type: schema.TypeString, + Computed: true, + Description: "Name of the snapshot", + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_id": { + Type: schema.TypeString, + Computed: true, + Description: "Reference to the snapshot", + }, + "snap_set_guid": { + Type: schema.TypeString, + Computed: true, + Description: "The set snapshot ID", + }, + "snap_set_time": { + Type: schema.TypeInt, + Computed: true, + Description: "The set time of the snapshot", + }, + "timestamp": { + Type: schema.TypeInt, + Computed: true, + Description: "Snapshot time", + }, + }, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "Disk status", + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + Description: "Technical status of the disk", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'", + }, + "vmid": { + Type: schema.TypeInt, + Computed: true, + Description: "Virtual Machine ID (Deprecated)", + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return res +} + +func dataSourceDiskSnapshotListSchemaMake() map[string]*schema.Schema { + rets := map[string]*schema.Schema{ + "disk_id": { + Type: schema.TypeInt, + Required: true, + Description: "The unique ID of the subscriber-owner of the disk", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + Description: "ID of the snapshot", + }, + "label": { + Type: schema.TypeString, + Computed: true, + Description: "Name of the snapshot", + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_id": { + Type: schema.TypeString, + Computed: true, + Description: "Reference to the snapshot", + }, + "snap_set_guid": { + Type: schema.TypeString, + Computed: true, + Description: "The set snapshot ID", + }, + "snap_set_time": { + Type: schema.TypeInt, + Computed: true, + Description: "The set time of the snapshot", + }, + "timestamp": { + Type: schema.TypeInt, + Computed: true, + Description: "Snapshot time", + }, + }, + }, + }, + } + return rets +} + +func dataSourceDiskSnapshotSchemaMake() map[string]*schema.Schema { + rets := map[string]*schema.Schema{ + "disk_id": { + Type: schema.TypeInt, + Required: true, + Description: "The unique ID of the subscriber-owner of the disk", + }, + "label": { + Type: schema.TypeString, + Required: true, + Description: "Name of the snapshot", + }, + "guid": { + Type: schema.TypeString, + Computed: true, + Description: "ID of the snapshot", + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_id": { + Type: schema.TypeString, + Computed: true, + Description: "Reference to the snapshot", + }, + "snap_set_guid": { + Type: schema.TypeString, + Computed: true, + Description: "The set snapshot ID", + }, + "snap_set_time": { + Type: schema.TypeInt, + Computed: true, + Description: "The set time of the snapshot", + }, + "timestamp": { + Type: schema.TypeInt, + Computed: true, + Description: "Snapshot time", + }, + } + return rets +} + +func resourceDiskSnapshotSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "disk_id": { + Type: schema.TypeInt, + Required: true, + //ForceNew: true, + Description: "The unique ID of the subscriber-owner of the disk", + }, + "label": { + Type: schema.TypeString, + Required: true, + //ForceNew: true, + Description: "Name of the snapshot", + }, + "rollback": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Needed in order to make a snapshot rollback", + }, + "timestamp": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Snapshot time", + }, + "guid": { + Type: schema.TypeString, + Computed: true, + Description: "ID of the snapshot", + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_id": { + Type: schema.TypeString, + Computed: true, + Description: "Reference to the snapshot", + }, + "snap_set_guid": { + Type: schema.TypeString, + Computed: true, + Description: "The set snapshot ID", + }, + "snap_set_time": { + Type: schema.TypeInt, + Computed: true, + Description: "The set time of the snapshot", + }, + } +} + +func resourceDiskSchemaMake() map[string]*schema.Schema { + rets := map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Required: true, + //ForceNew: true, + }, + "gid": { + Type: schema.TypeInt, + Required: true, + //ForceNew: true, + }, + "disk_name": { + Type: schema.TypeString, + Required: true, + }, + "type": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{"D", "B", "T"}, false), + Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'", + }, + + "desc": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "size_max": { + Type: schema.TypeInt, + Required: true, + }, + "ssd_size": { + Type: schema.TypeInt, + Optional: true, + }, + "iops": { + Type: schema.TypeInt, + Optional: true, + Description: "max IOPS disk can perform", + }, + "sep_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "pool": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "detach": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "detach disk from machine first", + }, + "permanently": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "whether to completely delete the disk, works only with non attached disks", + }, + "reason": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: "reason for an action", + }, + "shareable": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + "restore": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "restore deleting disk", + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "acl": { + Type: schema.TypeString, + Computed: true, + }, + "boot_partition": { + Type: schema.TypeInt, + Computed: true, + }, + "computes": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "compute_id": { + Type: schema.TypeString, + Computed: true, + }, + "compute_name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "destruction_time": { + Type: schema.TypeInt, + Computed: true, + }, + "devicename": { + Type: schema.TypeString, + Computed: true, + }, + "disk_path": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_id": { + Type: schema.TypeInt, + Computed: true, + }, + "image_id": { + Type: schema.TypeInt, + Computed: true, + }, + "images": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "iotune": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "read_bytes_sec": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "read_bytes_sec_max": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "read_iops_sec": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "read_iops_sec_max": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "size_iops_sec": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "total_bytes_sec": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "total_bytes_sec_max": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "total_iops_sec": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "total_iops_sec_max": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "write_bytes_sec": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "write_bytes_sec_max": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "write_iops_sec": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "write_iops_sec_max": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + }, + }, + }, + "iqn": { + Type: schema.TypeString, + Computed: true, + }, + "login": { + Type: schema.TypeString, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + + "order": { + Type: schema.TypeInt, + Computed: true, + }, + "params": { + Type: schema.TypeString, + Computed: true, + }, + "parent_id": { + Type: schema.TypeInt, + Computed: true, + }, + "passwd": { + Type: schema.TypeString, + Computed: true, + }, + "pci_slot": { + Type: schema.TypeInt, + Computed: true, + }, + "present_to": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "purge_attempts": { + Type: schema.TypeInt, + Computed: true, + }, + "purge_time": { + Type: schema.TypeInt, + Computed: true, + }, + "reality_device_number": { + Type: schema.TypeInt, + Computed: true, + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_name": { + Type: schema.TypeString, + Computed: true, + }, + "role": { + Type: schema.TypeString, + Computed: true, + }, + "sep_type": { + Type: schema.TypeString, + Computed: true, + }, + "size_used": { + Type: schema.TypeFloat, + 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, + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_id": { + Type: schema.TypeString, + Computed: true, + }, + "snap_set_guid": { + Type: schema.TypeString, + Computed: true, + }, + "snap_set_time": { + Type: schema.TypeInt, + Computed: true, + }, + "timestamp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + }, + "vmid": { + Type: schema.TypeInt, + Computed: true, + }, + } + + return rets +} diff --git a/internal/service/cloudbroker/disks/utility_disk_snapshot.go b/internal/service/cloudbroker/disks/utility_disk_snapshot.go new file mode 100644 index 0000000..1d182aa --- /dev/null +++ b/internal/service/cloudbroker/disks/utility_disk_snapshot.go @@ -0,0 +1,52 @@ +package disks + +import ( + "context" + "fmt" + log "github.com/sirupsen/logrus" + "strconv" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/disks" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityDiskSnapshotCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (disks.ItemSnapshot, error) { + log.Debugf("utilityDiskSnapshotCheckPresence: call for disk_id %d, label %s", + d.Get("disk_id").(int), + d.Get("label").(string)) + c := m.(*controller.ControllerCfg) + + req := disks.GetRequest{} + snapshot := disks.ItemSnapshot{} + + if d.Id() != "" { + arr := strings.Split(d.Id(), "#") + if len(arr) != 2 { + return snapshot, fmt.Errorf("broken state id") + } + req.DiskID, _ = strconv.ParseUint(arr[0], 10, 64) + } else { + req.DiskID = uint64(d.Get("disk_id").(int)) + } + + disk, err := c.CloudBroker().Disks().Get(ctx, req) + if err != nil { + return snapshot, err + } + + snapshots := disk.Snapshots + label := d.Get("label").(string) + for _, sn := range snapshots { + if label == sn.Label { + snapshot = sn + break + } + } + if label != snapshot.Label { + return snapshot, fmt.Errorf("snapshot with label \"%v\" not found", label) + } + + return snapshot, nil +} diff --git a/internal/service/cloudbroker/extnet/schema.go b/internal/service/cloudbroker/extnet/schema.go new file mode 100644 index 0000000..28b8545 --- /dev/null +++ b/internal/service/cloudbroker/extnet/schema.go @@ -0,0 +1,902 @@ +package extnet + +import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + +func dataSourceExtnetDefaultSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "extnet_id": { + Type: schema.TypeInt, + Computed: true, + }, + } +} + +func dataSourceExtnetListSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by account ID", + }, + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by name", + }, + "network": { + Type: schema.TypeString, + Optional: true, + }, + "vlan_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by VLAN ID", + }, + "vnfdev_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by VnfDEV ID", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Find by status", + }, + "page": { + Type: schema.TypeInt, + 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{ + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "meta", + }, + "default": { + Type: schema.TypeBool, + Computed: true, + }, + "default_qos": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "e_rate": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "in_burst": { + Type: schema.TypeInt, + Computed: true, + }, + "in_rate": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "free_ips": { + Type: schema.TypeInt, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "extnet_id": { + Type: schema.TypeInt, + Computed: true, + }, + "ipcidr": { + Type: schema.TypeString, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "network_id": { + Type: schema.TypeInt, + Computed: true, + }, + "ovs_bridge": { + Type: schema.TypeString, + Computed: true, + }, + "pre_reservations_num": { + Type: schema.TypeInt, + Computed: true, + }, + "pri_vnfdev_id": { + Type: schema.TypeInt, + Computed: true, + }, + "shared_with": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "vlan_id": { + Type: schema.TypeInt, + Computed: true, + }, + "vnfs": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dhcp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "check_ips": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } +} + +func dataSourceStaticRouteListSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "extnet_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of ExtNet", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "compute_ids": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "destination": { + Type: schema.TypeString, + Computed: true, + }, + "gateway": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "netmask": { + Type: schema.TypeString, + Computed: true, + }, + "route_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } +} + +func dataSourceStaticRouteSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "extnet_id": { + Type: schema.TypeInt, + Required: true, + Description: "Unique ID of the ExtNet", + }, + "route_id": { + Type: schema.TypeInt, + Required: true, + Description: "Unique ID of the static route", + }, + "compute_ids": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "destination": { + Type: schema.TypeString, + Computed: true, + }, + "gateway": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "netmask": { + Type: schema.TypeString, + Computed: true, + }, + } +} + +func dataSourceExtnetSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "extnet_id": { + Type: schema.TypeInt, + Required: true, + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "meta", + }, + "default": { + Type: schema.TypeBool, + Computed: true, + }, + "default_qos": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "e_rate": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "in_burst": { + Type: schema.TypeInt, + Computed: true, + }, + "in_rate": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "free_ips": { + Type: schema.TypeInt, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "ipcidr": { + Type: schema.TypeString, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "network_id": { + Type: schema.TypeInt, + Computed: true, + }, + "ovs_bridge": { + Type: schema.TypeString, + Computed: true, + }, + "pre_reservations_num": { + Type: schema.TypeInt, + Computed: true, + }, + "pri_vnfdev_id": { + Type: schema.TypeInt, + Computed: true, + }, + "shared_with": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "vlan_id": { + Type: schema.TypeInt, + Computed: true, + }, + "vnfs": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dhcp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "check_ips": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "dns": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "excluded": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "client_type": { + Type: schema.TypeString, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "domain_name": { + Type: schema.TypeString, + Computed: true, + }, + "hostname": { + Type: schema.TypeString, + Computed: true, + }, + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "mac": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "vm_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "gateway": { + Type: schema.TypeString, + Computed: true, + }, + "network": { + Type: schema.TypeString, + Computed: true, + }, + "prefix": { + Type: schema.TypeInt, + Computed: true, + }, + "reservations": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "client_type": { + Type: schema.TypeString, + Computed: true, + }, + "domain_name": { + Type: schema.TypeString, + Computed: true, + }, + "hostname": { + Type: schema.TypeString, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "mac": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "vm_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + } +} + +func resourceStaticRouteSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "extnet_id": { + Type: schema.TypeInt, + Required: true, + Description: "Unique ID of the ExtNet", + }, + "route_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Unique ID of the static route", + }, + "compute_ids": { + Type: schema.TypeSet, + Optional: true, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "destination": { + Type: schema.TypeString, + Required: true, + }, + "gateway": { + Type: schema.TypeString, + Required: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "netmask": { + Type: schema.TypeString, + Required: true, + }, + } +} + +func resourceExtnetSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "External network name", + }, + "gid": { + Type: schema.TypeInt, + Required: true, + Description: "Grid (platform) ID", + }, + "ipcidr": { + Type: schema.TypeString, + Required: true, + // ForceNew: true, + Description: "IP network CIDR", + }, + "vlan_id": { + Type: schema.TypeInt, + Required: true, + // ForceNew: true, + Description: "VLAN ID", + }, + "gateway": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "External network gateway IP address", + }, + "dns": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "List of DNS addresses", + }, + "ntp": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "List of NTP addresses", + }, + "check_ips": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "IPs to check network availability", + }, + "virtual": { + Type: schema.TypeBool, + Optional: true, + Description: "If true - platform DHCP server will not be created", + }, + "desc": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Optional description", + }, + "start_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Start of IP range to be explicitly included", + }, + "end_ip": { + Type: schema.TypeString, + Optional: true, + Description: "End of IP range to be explicitly included", + }, + "vnfdev_ip": { + Type: schema.TypeString, + Optional: true, + Description: "IP to create VNFDev with", + }, + "pre_reservations_num": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Number of pre created reservations", + }, + "ovs_bridge": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "OpenvSwith bridge name for ExtNet connection", + }, + "enable": { + Type: schema.TypeBool, + Optional: true, + Default: true, + Description: "Disable/Enable extnet", + }, + "set_default": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Set current extnet as default (can not be undone)", + }, + "excluded_ips": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "IPs to exclude in current extnet pool", + }, + "excluded_ips_range": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip_start": { + Type: schema.TypeString, + Required: true, + }, + "ip_end": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + Description: "Range of IPs to exclude in current extnet pool", + }, + "default_qos": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "e_rate": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "in_burst": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "in_rate": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + }, + }, + }, + "restart": { + Type: schema.TypeBool, + Optional: true, + Description: "restart extnet vnf device", + }, + "migrate": { + Type: schema.TypeInt, + Optional: true, + }, + "shared_with": { + Type: schema.TypeSet, + Computed: true, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "meta", + }, + "default": { + Type: schema.TypeBool, + Computed: true, + }, + "free_ips": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "extnet_id": { + Type: schema.TypeInt, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "network_id": { + Type: schema.TypeInt, + Computed: true, + }, + "pri_vnfdev_id": { + Type: schema.TypeInt, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "vnfs": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dhcp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "excluded": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "client_type": { + Type: schema.TypeString, + Computed: true, + }, + "domain_name": { + Type: schema.TypeString, + Computed: true, + }, + "hostname": { + Type: schema.TypeString, + Computed: true, + }, + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "mac": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "vm_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "network": { + Type: schema.TypeString, + Computed: true, + }, + "prefix": { + Type: schema.TypeInt, + Computed: true, + }, + "routes": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "compute_ids": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "destination": { + Type: schema.TypeString, + Computed: true, + }, + "gateway": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "netmask": { + Type: schema.TypeString, + Computed: true, + }, + "route_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "reservations": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "client_type": { + Type: schema.TypeString, + Computed: true, + }, + "domain_name": { + Type: schema.TypeString, + Computed: true, + }, + "hostname": { + Type: schema.TypeString, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "mac": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "vm_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + } +} diff --git a/internal/service/cloudbroker/flipgroup/schema.go b/internal/service/cloudbroker/flipgroup/schema.go new file mode 100644 index 0000000..8274d04 --- /dev/null +++ b/internal/service/cloudbroker/flipgroup/schema.go @@ -0,0 +1,471 @@ +package flipgroup + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +func dataSourceFlipgroupSchemaMake() map[string]*schema.Schema { + rets := map[string]*schema.Schema{ + "flipgroup_id": { + Type: schema.TypeInt, + Required: true, + Description: "flipgroup_id", + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + Description: "account_id", + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + Description: "account_name", + }, + "client_ids": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Description: "client_ids", + }, + "client_names": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "client_names", + }, + "client_type": { + Type: schema.TypeString, + Computed: true, + Description: "client_type", + }, + "conn_id": { + Type: schema.TypeInt, + Computed: true, + Description: "conn_id", + }, + "conn_type": { + Type: schema.TypeString, + Computed: true, + Description: "conn_type", + }, + "created_by": { + Type: schema.TypeString, + Computed: true, + Description: "created_by", + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + Description: "created_time", + }, + "default_gw": { + Type: schema.TypeString, + Computed: true, + Description: "default_gw", + }, + "deleted_by": { + Type: schema.TypeString, + Computed: true, + Description: "deleted_by", + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + Description: "deleted_time", + }, + "description": { + Type: schema.TypeString, + Computed: true, + Description: "description", + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "gid", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "ip": { + Type: schema.TypeString, + Computed: true, + Description: "ip", + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + Description: "milestones", + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "name", + }, + "net_id": { + Type: schema.TypeInt, + Computed: true, + Description: "net_id", + }, + "net_type": { + Type: schema.TypeString, + Computed: true, + Description: "net_type", + }, + "network": { + Type: schema.TypeString, + Computed: true, + Description: "network", + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + Description: "rg_id", + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + Description: "rg_name", + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "status", + }, + "updated_by": { + Type: schema.TypeString, + Computed: true, + Description: "updated_by", + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + Description: "updated_time", + }, + } + return rets +} + +func dataSourceFlipgroupsListSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Optional: true, + Description: "name", + }, + "vins_id": { + Type: schema.TypeInt, + Optional: true, + Description: "vins_id", + }, + "vins_name": { + Type: schema.TypeString, + Optional: true, + Description: "vins_name", + }, + "extnet_id": { + Type: schema.TypeInt, + Optional: true, + Description: "extnet_id", + }, + "by_ip": { + Type: schema.TypeString, + Optional: true, + Description: "by_ip", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "rg_id", + }, + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "by_id", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ckey": { + Type: schema.TypeString, + Computed: true, + Description: "ckey", + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + Description: "account_id", + }, + "client_ids": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Description: "client_ids", + }, + "client_type": { + Type: schema.TypeString, + Computed: true, + Description: "client_type", + }, + "conn_id": { + Type: schema.TypeInt, + Computed: true, + Description: "conn_id", + }, + "conn_type": { + Type: schema.TypeString, + Computed: true, + Description: "conn_type", + }, + "default_gw": { + Type: schema.TypeString, + Computed: true, + Description: "default_gw", + }, + "description": { + Type: schema.TypeString, + Computed: true, + Description: "description", + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "gid", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "flipgroup_id": { + Type: schema.TypeInt, + Computed: true, + Description: "flipgroup_id", + }, + "ip": { + Type: schema.TypeString, + Computed: true, + Description: "ip", + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + Description: "milestones", + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "name", + }, + "net_id": { + Type: schema.TypeInt, + Computed: true, + Description: "net_id", + }, + "net_type": { + Type: schema.TypeString, + Computed: true, + Description: "net_type", + }, + "net_mask": { + Type: schema.TypeInt, + Computed: true, + Description: "net_mask", + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "status", + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + Description: "entry_count", + }, + } + return res +} + +func resourceFlipgroupSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Required: true, + Description: "Account ID", + }, + "name": { + Type: schema.TypeString, + Required: true, + Description: "Flipgroup name", + }, + "net_id": { + Type: schema.TypeInt, + Required: true, + Description: "EXTNET or ViNS ID", + }, + "net_type": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{"EXTNET", "VINS"}, true), + Description: "Network type, EXTNET or VINS", + }, + "client_type": { + Type: schema.TypeString, + Required: true, + Description: "Type of client, 'compute' ('vins' will be later)", + ValidateFunc: validation.StringInSlice([]string{"compute"}, true), + }, + "ip": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "IP address to associate with this group. If empty, the platform will autoselect IP address", + }, + "desc": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Text description of this Flipgroup instance", + }, + "client_ids": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Description: "List of clients attached to this Flipgroup instance", + }, + "client_names": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "client_names", + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + Description: "account_name", + }, + "flipgroup_id": { + Type: schema.TypeInt, + Computed: true, + }, + "conn_id": { + Type: schema.TypeInt, + Computed: true, + }, + "conn_type": { + Type: schema.TypeString, + Computed: true, + }, + "created_by": { + Type: schema.TypeString, + Computed: true, + Description: "created_by", + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + Description: "created_time", + }, + "default_gw": { + Type: schema.TypeString, + Computed: true, + }, + "deleted_by": { + Type: schema.TypeString, + Computed: true, + Description: "deleted_by", + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + Description: "deleted_time", + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "gid", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + Description: "milestones", + }, + "network": { + Type: schema.TypeString, + Computed: true, + Description: "network", + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + Description: "rg_id", + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + Description: "rg_name", + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "updated_by": { + Type: schema.TypeString, + Computed: true, + Description: "updated_by", + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + Description: "updated_time", + }, + "net_mask": { + Type: schema.TypeInt, + Computed: true, + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + } +} diff --git a/internal/service/cloudbroker/grid/schema.go b/internal/service/cloudbroker/grid/schema.go new file mode 100644 index 0000000..7295af4 --- /dev/null +++ b/internal/service/cloudbroker/grid/schema.go @@ -0,0 +1,590 @@ +package grid + +import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + +func dataSourceGetGridSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "grid_id": { + Type: schema.TypeInt, + Required: true, + }, + "auth_broker": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "flag": { + Type: schema.TypeString, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "id": { + Type: schema.TypeInt, + Computed: true, + }, + "location_code": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + } +} + +func dataSourceGridListSchemaMake() map[string]*schema.Schema { + rets := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "by id", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "name", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "page size", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Description: "grid list", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "resources": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "current": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeInt, + Computed: true, + }, + "ext_ips": { + Type: schema.TypeInt, + Computed: true, + }, + "ext_traffic": { + Type: schema.TypeInt, + Computed: true, + }, + "gpu": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "seps": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeString, + Computed: true, + }, + "data_name": { + Type: schema.TypeString, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "reserved": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeInt, + Computed: true, + }, + "ext_ips": { + Type: schema.TypeInt, + Computed: true, + }, + "ext_traffic": { + Type: schema.TypeInt, + Computed: true, + }, + "gpu": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "seps": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeString, + Computed: true, + }, + "data_name": { + Type: schema.TypeString, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + "auth_broker": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "flag": { + Type: schema.TypeString, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "id": { + Type: schema.TypeInt, + Computed: true, + }, + "location_code": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + Description: "entry count", + }, + } + + return rets +} + +func dataSourceGridListEmailsSchemaMake() map[string]*schema.Schema { + rets := map[string]*schema.Schema{ + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "page size", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Description: "grid list emails", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + Description: "entry count", + }, + } + + return rets +} + +func dataSourceGridGetConsumptionSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "grid_id": { + Type: schema.TypeInt, + Required: true, + }, + "consumed": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeInt, + Computed: true, + }, + "ext_ips": { + Type: schema.TypeInt, + Computed: true, + }, + "ext_traffic": { + Type: schema.TypeInt, + Computed: true, + }, + "gpu": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "seps": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeString, + Computed: true, + }, + "data_name": { + Type: schema.TypeString, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "reserved": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeInt, + Computed: true, + }, + "ext_ips": { + Type: schema.TypeInt, + Computed: true, + }, + "ext_traffic": { + Type: schema.TypeInt, + Computed: true, + }, + "gpu": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "seps": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeString, + Computed: true, + }, + "data_name": { + Type: schema.TypeString, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + } +} + +func dataSourceGridListConsumptionSchemaMake() map[string]*schema.Schema { + rets := map[string]*schema.Schema{ + "items": { + Type: schema.TypeList, + Computed: true, + Description: "grid list consumption", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "consumed": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeInt, + Computed: true, + }, + "ext_ips": { + Type: schema.TypeInt, + Computed: true, + }, + "ext_traffic": { + Type: schema.TypeInt, + Computed: true, + }, + "gpu": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "seps": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeString, + Computed: true, + }, + "data_name": { + Type: schema.TypeString, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "reserved": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeInt, + Computed: true, + }, + "ext_ips": { + Type: schema.TypeInt, + Computed: true, + }, + "ext_traffic": { + Type: schema.TypeInt, + Computed: true, + }, + "gpu": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "seps": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeString, + Computed: true, + }, + "data_name": { + Type: schema.TypeString, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + Description: "entry count", + }, + } + return rets +} + +func dataSourceGridGetStatusSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "status": { + Type: schema.TypeBool, + Computed: true, + }, + } +} + +func dataSourceGridPostStatusSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "status": { + Type: schema.TypeBool, + Computed: true, + }, + } +} + +func dataSourceGridGetDiagnosisSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "gid": { + Type: schema.TypeInt, + Required: true, + }, + "diagnosis": { + Type: schema.TypeString, + Computed: true, + }, + } +} + +func dataSourceGridPostDiagnosisSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "gid": { + Type: schema.TypeInt, + Required: true, + }, + "diagnosis": { + Type: schema.TypeString, + Computed: true, + }, + } +} diff --git a/internal/service/cloudbroker/image/api.go b/internal/service/cloudbroker/image/api.go deleted file mode 100644 index 1de91be..0000000 --- a/internal/service/cloudbroker/image/api.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, - -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 image - -const imageCreateAPI = "/restmachine/cloudbroker/image/createImage" -const imageSyncCreateAPI = "/restmachine/cloudbroker/image/syncCreateImage" -const imageCreateVirtualAPI = "/restmachine/cloudbroker/image/createVirtual" -const imageCreateCDROMAPI = "/restmachine/cloudbroker/image/createCDROMImage" -const imageListStacksApi = "/restmachine/cloudbroker/image/listStacks" -const imageGetAPI = "/restmachine/cloudbroker/image/get" -const imageListGetAPI = "/restmachine/cloudbroker/image/list" -const imageEditAPI = "/restmachine/cloudbroker/image/edit" -const imageDeleteAPI = "/restmachine/cloudbroker/image/delete" -const imageDeleteCDROMAPI = "/restmachine/cloudbroker/image/deleteCDROMImage" -const imageEnableAPI = "/restmachine/cloudbroker/image/enable" -const imageDisableAPI = "/restmachine/cloudbroker/image/disable" -const imageEditNameAPI = "/restmachine/cloudbroker/image/rename" -const imageLinkAPI = "/restmachine/cloudbroker/image/link" -const imageShareAPI = "/restmachine/cloudbroker/image/share" -const imageComputeciSetAPI = "/restmachine/cloudbroker/image/computeciSet" -const imageComputeciUnsetAPI = "/restmachine/cloudbroker/image/computeciUnset" -const imageUpdateNodesAPI = "/restmachine/cloudbroker/image/updateNodes" -const imageDeleteImagesAPI = "/restmachine/cloudbroker/image/deleteImages" diff --git a/internal/service/cloudbroker/image/resource_delete_images.go b/internal/service/cloudbroker/image/resource_delete_images.go deleted file mode 100644 index f434d91..0000000 --- a/internal/service/cloudbroker/image/resource_delete_images.go +++ /dev/null @@ -1,105 +0,0 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, - -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 image - -import ( - "context" - - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" -) - -func resourceCreateListImages(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - return nil -} - -func resourceDeleteListImages(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - return nil -} - -func resourceReadListImages(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - return nil -} - -func resourceDeleteImagesSchemaMake() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "image_ids": { - Type: schema.TypeList, - Required: true, - ForceNew: true, - MinItems: 1, - Elem: &schema.Schema{ - Type: schema.TypeInt, - }, - Description: "images ids for deleting", - }, - "reason": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - Description: "reason for deleting the images", - }, - "permanently": { - Type: schema.TypeBool, - Optional: true, - ForceNew: true, - Default: false, - Description: "whether to completely delete the images", - }, - } - -} - -func ResourceDeleteImages() *schema.Resource { - return &schema.Resource{ - SchemaVersion: 1, - - CreateContext: resourceCreateListImages, - ReadContext: resourceReadListImages, - DeleteContext: resourceDeleteListImages, - - Importer: &schema.ResourceImporter{ - StateContext: schema.ImportStatePassthroughContext, - }, - - Timeouts: &schema.ResourceTimeout{ - Create: &constants.Timeout60s, - Read: &constants.Timeout30s, - Update: &constants.Timeout60s, - Delete: &constants.Timeout60s, - Default: &constants.Timeout60s, - }, - - Schema: resourceDeleteImagesSchemaMake(), - } -} diff --git a/internal/service/cloudbroker/image/schema.go b/internal/service/cloudbroker/image/schema.go new file mode 100644 index 0000000..33faa76 --- /dev/null +++ b/internal/service/cloudbroker/image/schema.go @@ -0,0 +1,1718 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +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 image + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func dataSourceImageListStacksSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "image_id": { + Type: schema.TypeInt, + Required: true, + Description: "image id", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "page size", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "find by name", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "find by status", + }, + "type_image": { + Type: schema.TypeString, + Optional: true, + Description: "find by type", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "meta", + }, + "api_url": { + Type: schema.TypeString, + Computed: true, + }, + "api_key": { + Type: schema.TypeString, + Computed: true, + }, + "app_id": { + Type: schema.TypeString, + Computed: true, + }, + "cpu_allocation_ratio": { + Type: schema.TypeFloat, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "descr": { + Type: schema.TypeString, + Computed: true, + }, + "drivers": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "eco": { + Type: schema.TypeString, + Computed: true, + }, + "error": { + Type: schema.TypeInt, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "id": { + Type: schema.TypeInt, + Computed: true, + }, + "images": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "login": { + Type: schema.TypeString, + Computed: true, + }, + "mem_allocation_ratio": { + Type: schema.TypeFloat, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "packages": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "libvirt_bin": { + Type: schema.TypeList, + Computed: true, + Description: "libvirt_bin", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installed_size": { + Type: schema.TypeString, + Computed: true, + Description: "installed_size", + }, + "ver": { + Type: schema.TypeString, + Computed: true, + Description: "ver", + }, + }, + }, + }, + "libvirt_daemon": { + Type: schema.TypeList, + Computed: true, + Description: "libvirt_daemon", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installed_size": { + Type: schema.TypeString, + Computed: true, + Description: "installed_size", + }, + "ver": { + Type: schema.TypeString, + Computed: true, + Description: "ver", + }, + }, + }, + }, + "lvm2_lockd": { + Type: schema.TypeList, + Computed: true, + Description: "lvm2_lockd", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installed_size": { + Type: schema.TypeString, + Computed: true, + Description: "installed_size", + }, + "ver": { + Type: schema.TypeString, + Computed: true, + Description: "ver", + }, + }, + }, + }, + "openvswitch_common": { + Type: schema.TypeList, + Computed: true, + Description: "openvswitch_common", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installed_size": { + Type: schema.TypeString, + Computed: true, + Description: "installed_size", + }, + "ver": { + Type: schema.TypeString, + Computed: true, + Description: "ver", + }, + }, + }, + }, + "openvswitch_switch": { + Type: schema.TypeList, + Computed: true, + Description: "openvswitch_switch", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installed_size": { + Type: schema.TypeString, + Computed: true, + Description: "installed_size", + }, + "ver": { + Type: schema.TypeString, + Computed: true, + Description: "ver", + }, + }, + }, + }, + "qemu_system_x86": { + Type: schema.TypeList, + Computed: true, + Description: "qemu_system_x86", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installed_size": { + Type: schema.TypeString, + Computed: true, + Description: "installed_size", + }, + "ver": { + Type: schema.TypeString, + Computed: true, + Description: "ver", + }, + }, + }, + }, + "sanlock": { + Type: schema.TypeList, + Computed: true, + Description: "sanlock", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installed_size": { + Type: schema.TypeString, + Computed: true, + Description: "installed_size", + }, + "ver": { + Type: schema.TypeString, + Computed: true, + Description: "ver", + }, + }, + }, + }, + }, + }, + }, + "passwd": { + Type: schema.TypeString, + Computed: true, + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + Description: "items of stacks list", + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + Description: "entry count", + }, + } +} + +func dataSourceImageListSchemaMake() map[string]*schema.Schema { + rets := map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeInt, + Optional: true, + Description: "find by storage endpoint provider ID", + }, + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "find by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "find by name", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "find by status", + }, + "architecture": { + Type: schema.TypeString, + Optional: true, + Description: "find by architecture", + }, + "type_image": { + Type: schema.TypeString, + Optional: true, + Description: "find by type", + }, + "image_size": { + Type: schema.TypeInt, + Optional: true, + Description: "find by image size", + }, + "sep_name": { + Type: schema.TypeString, + Optional: true, + Description: "find by SEP name", + }, + "pool": { + Type: schema.TypeString, + Optional: true, + Description: "find by pool", + }, + "public": { + Type: schema.TypeBool, + Optional: true, + Description: "find by public True or False", + }, + "hot_resize": { + Type: schema.TypeBool, + Optional: true, + Description: "find by hot resize True or False", + }, + "bootable": { + Type: schema.TypeBool, + Optional: true, + Description: "find by bootable True or False", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "page size", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Description: "image list", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "unc_path": { + Type: schema.TypeString, + Computed: true, + Description: "unc path", + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "meta", + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + Description: "AccountId to make the image exclusive", + }, + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "architecture": { + Type: schema.TypeString, + Computed: true, + Description: "binary architecture of this image, one of X86_64 of PPC64_LE", + }, + "boot_type": { + Type: schema.TypeString, + Computed: true, + Description: "Boot type of image bios or uefi", + }, + "bootable": { + Type: schema.TypeBool, + Computed: true, + Description: "Does this image boot OS", + }, + "computeci_id": { + Type: schema.TypeInt, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "drivers": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "List of types of compute suitable for image. Example: [ \"KVM_X86\" ]", + }, + "enabled": { + Type: schema.TypeBool, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "grid (platform) ID where this template should be create in", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "history": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "id": { + Type: schema.TypeInt, + Computed: true, + }, + "timestamp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "hot_resize": { + Type: schema.TypeBool, + Computed: true, + Description: "Does this machine supports hot resize", + }, + "image_id": { + Type: schema.TypeInt, + Computed: true, + Description: "image id", + }, + "last_modified": { + Type: schema.TypeInt, + Computed: true, + }, + "link_to": { + Type: schema.TypeInt, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "Name of the rescue disk", + }, + "password": { + Type: schema.TypeString, + Computed: true, + Description: "Optional password for the image", + }, + "pool_name": { + Type: schema.TypeString, + Computed: true, + Description: "pool for image create", + }, + "present_to": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "provider_name": { + Type: schema.TypeString, + Computed: true, + }, + "purge_attempts": { + Type: schema.TypeInt, + Computed: true, + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_name": { + Type: schema.TypeString, + Computed: true, + }, + "rescuecd": { + Type: schema.TypeBool, + Computed: true, + }, + "sep_id": { + Type: schema.TypeInt, + Computed: true, + Description: "storage endpoint provider ID", + }, + "shared_with": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "size": { + Type: schema.TypeInt, + Computed: true, + Description: "image size", + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "status", + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + Description: "tech atatus", + }, + "image_type": { + Type: schema.TypeString, + Computed: true, + Description: "Image type linux, windows or other", + }, + "url": { + Type: schema.TypeString, + Computed: true, + Description: "URL where to download media from", + }, + "username": { + Type: schema.TypeString, + Computed: true, + Description: "Optional username for the image", + }, + "version": { + Type: schema.TypeString, + Computed: true, + Description: "version", + }, + "virtual": { + Type: schema.TypeBool, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + Description: "entry count", + }, + } + + return rets +} + +func dataSourceImageSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "image_id": { + Type: schema.TypeInt, + Required: true, + Description: "image id", + }, + "unc_path": { + Type: schema.TypeString, + Computed: true, + Description: "unc path", + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "meta", + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + Description: "AccountId to make the image exclusive", + }, + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "architecture": { + Type: schema.TypeString, + Computed: true, + Description: "binary architecture of this image, one of X86_64 of PPC64_LE", + }, + "boot_type": { + Type: schema.TypeString, + Computed: true, + Description: "Boot type of image bios or uefi", + }, + "bootable": { + Type: schema.TypeBool, + Computed: true, + Description: "Does this image boot OS", + }, + "computeci_id": { + Type: schema.TypeInt, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "drivers": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "List of types of compute suitable for image. Example: [ \"KVM_X86\" ]", + }, + "enabled": { + Type: schema.TypeBool, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "grid (platform) ID where this template should be create in", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "history": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "id": { + Type: schema.TypeInt, + Computed: true, + }, + "timestamp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "hot_resize": { + Type: schema.TypeBool, + Computed: true, + Description: "Does this machine supports hot resize", + }, + "last_modified": { + Type: schema.TypeInt, + Computed: true, + }, + "link_to": { + Type: schema.TypeInt, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "Name of the rescue disk", + }, + "password": { + Type: schema.TypeString, + Computed: true, + Description: "Optional password for the image", + }, + "pool_name": { + Type: schema.TypeString, + Computed: true, + Description: "pool for image create", + }, + "present_to": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "provider_name": { + Type: schema.TypeString, + Computed: true, + }, + "purge_attempts": { + Type: schema.TypeInt, + Computed: true, + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_name": { + Type: schema.TypeString, + Computed: true, + }, + "rescuecd": { + Type: schema.TypeBool, + Computed: true, + }, + "sep_id": { + Type: schema.TypeInt, + Computed: true, + Description: "storage endpoint provider ID", + }, + "shared_with": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "size": { + Type: schema.TypeInt, + Computed: true, + Description: "image size", + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "status", + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + Description: "tech atatus", + }, + "image_type": { + Type: schema.TypeString, + Computed: true, + Description: "Image type linux, windows or other", + }, + "url": { + Type: schema.TypeString, + Computed: true, + Description: "URL where to download media from", + }, + "username": { + Type: schema.TypeString, + Computed: true, + Description: "Optional username for the image", + }, + "version": { + Type: schema.TypeString, + Computed: true, + Description: "version", + }, + } +} + +func resourceCDROMImageSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "Name of the rescue disk", + }, + "url": { + Type: schema.TypeString, + Required: true, + Description: "URL where to download ISO from", + }, + "gid": { + Type: schema.TypeInt, + Required: true, + Description: "grid (platform) ID where this template should be create in", + }, + "drivers": { + Type: schema.TypeList, + Required: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "List of types of compute suitable for image. Example: [ \"KVM_X86\" ]", + }, + "hot_resize": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + Description: "Does this machine supports hot resize", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "AccountId to make the image exclusive", + }, + "username_dl": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "username for upload binary media", + }, + "password_dl": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "password for upload binary media", + }, + "sep_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "storage endpoint provider ID", + }, + "pool_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "pool for image create", + }, + "architecture": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "binary architecture of this image, one of X86_64 of PPC64_LE", + }, + "permanently": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + Description: "Whether to completely delete the image", + }, + "bootable": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + Description: "Does this image boot OS", + }, + "enabled": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + "computeci_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "shared_with": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "enabled_stacks": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "unc_path": { + Type: schema.TypeString, + Computed: true, + Description: "unc path", + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "meta", + }, + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true}, + "type": { + Type: schema.TypeString, + Computed: true}, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "boot_type": { + Type: schema.TypeString, + Computed: true, + Description: "Boot type of image bios or uefi", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "image_id": { + Type: schema.TypeInt, + Computed: true, + Description: "image id", + }, + "image_type": { + Type: schema.TypeString, + Computed: true, + Description: "Image type linux, windows or other", + }, + "link_to": { + Type: schema.TypeInt, + Computed: true, + Description: "", + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "provider_name": { + Type: schema.TypeString, + Computed: true, + }, + "purge_attempts": { + Type: schema.TypeInt, + Computed: true, + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_name": { + Type: schema.TypeString, + Computed: true, + }, + "rescuecd": { + Type: schema.TypeBool, + Computed: true, + }, + "last_modified": { + Type: schema.TypeInt, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "present_to": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "status", + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + Description: "tech atatus", + }, + "version": { + Type: schema.TypeString, + Computed: true, + Description: "version", + }, + "size": { + Type: schema.TypeInt, + Computed: true, + Description: "image size", + }, + "history": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "id": { + Type: schema.TypeInt, + Computed: true, + }, + "timestamp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + } +} + +func resourceImageSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "Name of the rescue disk", + }, + "url": { + Type: schema.TypeString, + Required: true, + Description: "URL where to download media from", + }, + "gid": { + Type: schema.TypeInt, + Required: true, + Description: "grid (platform) ID where this template should be create in", + }, + "boot_type": { + Type: schema.TypeString, + Required: true, + Description: "Boot type of image bios or uefi", + }, + "image_type": { + Type: schema.TypeString, + Required: true, + Description: "Image type linux, windows or other", + }, + "drivers": { + Type: schema.TypeList, + Required: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "List of types of compute suitable for image. Example: [ \"KVM_X86\" ]", + }, + "hot_resize": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + Description: "Does this machine supports hot resize", + }, + "username": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Optional username for the image", + }, + "password": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Optional password for the image", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "AccountId to make the image exclusive", + }, + "username_dl": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "username for upload binary media", + }, + "password_dl": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "password for upload binary media", + }, + "sep_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "storage endpoint provider ID", + }, + "pool_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "pool for image create", + }, + "architecture": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "binary architecture of this image, one of X86_64 of PPC64_LE", + }, + "permanently": { + Type: schema.TypeBool, + Optional: true, + Description: "Whether to completely delete the image", + }, + "bootable": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + Description: "Does this image boot OS", + }, + "enabled": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + "computeci_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "sync_mode": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Create image from a media identified by URL (in synchronous mode)", + }, + "enabled_stacks": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "shared_with": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "reason": { + Type: schema.TypeString, + Optional: true, + }, + "unc_path": { + Type: schema.TypeString, + Computed: true, + Description: "unc path", + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "meta", + }, + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true}, + "type": { + Type: schema.TypeString, + Computed: true}, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "image_id": { + Type: schema.TypeInt, + Computed: true, + Description: "image id", + }, + "link_to": { + Type: schema.TypeInt, + Computed: true, + Description: "", + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "provider_name": { + Type: schema.TypeString, + Computed: true, + }, + "purge_attempts": { + Type: schema.TypeInt, + Computed: true, + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_name": { + Type: schema.TypeString, + Computed: true, + }, + "rescuecd": { + Type: schema.TypeBool, + Computed: true, + }, + "last_modified": { + Type: schema.TypeInt, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "present_to": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "status", + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + Description: "tech atatus", + }, + "version": { + Type: schema.TypeString, + Computed: true, + Description: "version", + }, + "size": { + Type: schema.TypeInt, + Computed: true, + Description: "image size", + }, + "history": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "id": { + Type: schema.TypeInt, + Computed: true, + }, + "timestamp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + } +} + +func resourceVirtualImageSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "link_to": { + Type: schema.TypeInt, + Required: true, + Description: "ID of real image to link this virtual image to upon creation", + }, + "name": { + Type: schema.TypeString, + Required: true, + Description: "Name of the rescue disk", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "AccountId to make the image exclusive", + }, + "bootable": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + Description: "Does this image boot OS", + }, + "computeci_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "enabled": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + "hot_resize": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + Description: "Does this machine supports hot resize", + }, + "password": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Optional password for the image", + }, + "username": { + Type: schema.TypeString, + Computed: true, + Optional: true, + Description: "Optional username for the image", + }, + "shared_with": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "enabled_stacks": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "permanently": { + Type: schema.TypeBool, + Optional: true, + Description: "Whether to completely delete the image", + }, + "reason": { + Type: schema.TypeString, + Optional: true, + }, + "unc_path": { + Type: schema.TypeString, + Computed: true, + Description: "unc path", + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "meta", + }, + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "architecture": { + Type: schema.TypeString, + Computed: true, + Description: "binary architecture of this image, one of X86_64 of PPC64_LE", + }, + "boot_type": { + Type: schema.TypeString, + Computed: true, + Description: "Boot type of image bios or uefi", + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "drivers": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "List of types of compute suitable for image. Example: [ \"KVM_X86\" ]", + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "grid (platform) ID where this template should be create in", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "history": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "id": { + Type: schema.TypeInt, + Computed: true, + }, + "timestamp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "image_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Image id", + }, + "last_modified": { + Type: schema.TypeInt, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "pool_name": { + Type: schema.TypeString, + Computed: true, + Description: "pool for image create", + }, + "present_to": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "provider_name": { + Type: schema.TypeString, + Computed: true, + }, + "purge_attempts": { + Type: schema.TypeInt, + Computed: true, + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_name": { + Type: schema.TypeString, + Computed: true, + }, + "rescuecd": { + Type: schema.TypeBool, + Computed: true, + }, + "sep_id": { + Type: schema.TypeInt, + Computed: true, + Description: "storage endpoint provider ID", + }, + "size": { + Type: schema.TypeInt, + Computed: true, + Description: "image size", + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "status", + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + Description: "tech atatus", + }, + "image_type": { + Type: schema.TypeString, + Computed: true, + Description: "Image type linux, windows or other", + }, + "url": { + Type: schema.TypeString, + Computed: true, + Description: "URL where to download media from", + }, + "version": { + Type: schema.TypeString, + Computed: true, + Description: "version", + }, + } +} diff --git a/internal/service/cloudbroker/image/utility_resource_create.go b/internal/service/cloudbroker/image/utility_resource_create.go new file mode 100644 index 0000000..2220c40 --- /dev/null +++ b/internal/service/cloudbroker/image/utility_resource_create.go @@ -0,0 +1,151 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +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 image + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/image" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/ic" +) + +func SyncCreateRequest(ctx context.Context, d *schema.ResourceData, m interface{}) (image.SyncCreateRequest, error) { + req := image.SyncCreateRequest{ + Name: d.Get("name").(string), + URL: d.Get("url").(string), + BootType: d.Get("boot_type").(string), + ImageType: d.Get("image_type").(string), + } + + c := m.(*controller.ControllerCfg) + + if err := ic.ExistGID(ctx, uint64(d.Get("gid").(int)), c); err != nil { + return req, err + } + + req.GID = uint64(d.Get("gid").(int)) + + drivers := []string{} + for _, driver := range d.Get("drivers").([]interface{}) { + drivers = append(drivers, driver.(string)) + } + req.Drivers = drivers + + if hotresize, ok := d.GetOk("hot_resize"); ok { + req.HotResize = hotresize.(bool) + } + if username, ok := d.GetOk("username"); ok { + req.Username = username.(string) + } + if password, ok := d.GetOk("password"); ok { + req.Password = password.(string) + } + if accountId, ok := d.GetOk("account_id"); ok { + req.AccountID = uint64(accountId.(int)) + } + if usernameDL, ok := d.GetOk("username_dl"); ok { + req.UsernameDL = usernameDL.(string) + } + if passwordDL, ok := d.GetOk("password_dl"); ok { + req.PasswordDL = passwordDL.(string) + } + if sepId, ok := d.GetOk("sep_id"); ok { + req.SEPID = uint64(sepId.(int)) + } + if poolName, ok := d.GetOk("pool_name"); ok { + req.PoolName = poolName.(string) + } + if architecture, ok := d.GetOk("architecture"); ok { + req.Architecture = architecture.(string) + } + if bootable, ok := d.GetOk("bootable"); ok { + req.Bootable = bootable.(bool) + } + return req, nil +} + +func CreateRequest(ctx context.Context, d *schema.ResourceData, m interface{}) (image.CreateRequest, error) { + req := image.CreateRequest{ + Name: d.Get("name").(string), + URL: d.Get("url").(string), + BootType: d.Get("boot_type").(string), + ImageType: d.Get("image_type").(string), + } + + c := m.(*controller.ControllerCfg) + + if err := ic.ExistGID(ctx, uint64(d.Get("gid").(int)), c); err != nil { + return req, err + } + + req.GID = uint64(d.Get("gid").(int)) + + drivers := []string{} + for _, driver := range d.Get("drivers").([]interface{}) { + drivers = append(drivers, driver.(string)) + } + req.Drivers = drivers + + if hotresize, ok := d.GetOk("hot_resize"); ok { + req.HotResize = hotresize.(bool) + } + if username, ok := d.GetOk("username"); ok { + req.Username = username.(string) + } + if password, ok := d.GetOk("password"); ok { + req.Password = password.(string) + } + if accountId, ok := d.GetOk("account_id"); ok { + req.AccountID = uint64(accountId.(int)) + } + if usernameDL, ok := d.GetOk("username_dl"); ok { + req.UsernameDL = usernameDL.(string) + } + if passwordDL, ok := d.GetOk("password_dl"); ok { + req.PasswordDL = passwordDL.(string) + } + if sepId, ok := d.GetOk("sep_id"); ok { + req.SEPID = uint64(sepId.(int)) + } + if poolName, ok := d.GetOk("pool_name"); ok { + req.PoolName = poolName.(string) + } + if architecture, ok := d.GetOk("architecture"); ok { + req.Architecture = architecture.(string) + } + if bootable, ok := d.GetOk("bootable"); ok { + req.Bootable = bootable.(bool) + } + return req, nil +} diff --git a/internal/service/cloudbroker/k8ci/data_source_k8ci.go b/internal/service/cloudbroker/k8ci/data_source_k8ci.go new file mode 100644 index 0000000..a65366e --- /dev/null +++ b/internal/service/cloudbroker/k8ci/data_source_k8ci.go @@ -0,0 +1,72 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Tim Tkachev, +Sergey Kisil, + +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 k8ci + +import ( + "context" + "strconv" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceK8CIRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + data, err := utilityK8CICheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + d.SetId(strconv.Itoa(d.Get("k8ci_id").(int))) + flattenK8CIItems(d, data) + + return nil +} + +func DataSourceK8CI() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceK8CIRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceK8CISchemaMake(), + } +} diff --git a/internal/service/cloudbroker/k8ci/data_source_k8ci_list.go b/internal/service/cloudbroker/k8ci/data_source_k8ci_list.go new file mode 100644 index 0000000..a6ba360 --- /dev/null +++ b/internal/service/cloudbroker/k8ci/data_source_k8ci_list.go @@ -0,0 +1,73 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Tim Tkachev, +Sergey Kisil, + +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 k8ci + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceK8CIListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + list, err := utilityK8CIListCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + d.SetId(uuid.New().String()) + d.Set("items", flattenK8CIListItems(list)) + d.Set("entry_count", list.EntryCount) + + return nil +} + +func DataSourceK8CIList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceK8CIListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceK8CIListSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/k8ci/data_source_k8ci_list_deleted.go b/internal/service/cloudbroker/k8ci/data_source_k8ci_list_deleted.go new file mode 100644 index 0000000..33c26d1 --- /dev/null +++ b/internal/service/cloudbroker/k8ci/data_source_k8ci_list_deleted.go @@ -0,0 +1,73 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Tim Tkachev, +Sergey Kisil, + +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 k8ci + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceK8CIListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + list, err := utilityK8CIListDeletedCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + d.SetId(uuid.New().String()) + d.Set("items", flattenK8CIListItems(list)) + d.Set("entry_count", list.EntryCount) + + return nil +} + +func DataSourceK8CIListDeleted() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceK8CIListDeletedRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceK8CIListDeletedSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/k8ci/flattens.go b/internal/service/cloudbroker/k8ci/flattens.go new file mode 100644 index 0000000..20245c5 --- /dev/null +++ b/internal/service/cloudbroker/k8ci/flattens.go @@ -0,0 +1,92 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Sergey Kisil, + +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 k8ci + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8ci" +) + +func flattenK8CIListItems(list *k8ci.ListK8CI) []map[string]interface{} { + log.Debug("flattenK8CIListItems") + res := make([]map[string]interface{}, 0, len(list.Data)) + for _, item := range list.Data { + temp := map[string]interface{}{ + "created_time": item.CreatedTime, + "desc": item.Description, + "gid": item.GID, + "guid": item.GUID, + "k8ci_id": item.ID, + "lb_image_id": item.LBImageID, + "master_driver": item.MasterDriver, + "master_image_id": item.MasterImageID, + "max_master_count": item.MaxMasterCount, + "max_worker_count": item.MaxWorkerCount, + "name": item.Name, + "shared_with": item.SharedWith, + "status": item.Status, + "version": item.Version, + "worker_driver": item.WorkerDriver, + "worker_image_id": item.WorkerImageID, + } + res = append(res, temp) + } + + return res +} + +func flattenK8CIItems(d *schema.ResourceData, data *k8ci.RecordK8CI) error { + log.Debugf("flattenK8CI: ID %d", data.ID) + + d.Set("desc", data.Description) + d.Set("gid", data.GID) + d.Set("guid", data.GUID) + d.Set("k8ci_id", data.ID) + d.Set("lb_image_id", data.LBImageID) + d.Set("master_driver", data.MasterDriver) + d.Set("master_image_id", data.MasterImageID) + d.Set("max_master_count", data.MaxMasterCount) + d.Set("max_worker_count", data.MaxWorkerCount) + d.Set("milestones", data.Milestones) + d.Set("name", data.Name) + d.Set("network_plugins", data.NetworkPlugins) + d.Set("shared_with", data.SharedWith) + d.Set("status", data.Status) + d.Set("version", data.Version) + d.Set("worker_driver", data.WorkerDriver) + d.Set("worker_image_id", data.WorkerImageID) + + return nil +} diff --git a/internal/service/cloudbroker/k8ci/resource_check_input_values.go b/internal/service/cloudbroker/k8ci/resource_check_input_values.go new file mode 100644 index 0000000..822e62c --- /dev/null +++ b/internal/service/cloudbroker/k8ci/resource_check_input_values.go @@ -0,0 +1,60 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Sergey Kisil, + +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 k8ci + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/ic" +) + +func checkParamsExistence(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) diag.Diagnostics { + var errs []error + + masterImageId := uint64(d.Get("master_image_id").(int)) + workerImageId := uint64(d.Get("worker_image_id").(int)) + + if err := ic.ExistImage(ctx, masterImageId, c); err != nil { + errs = append(errs, err) + } + + if err := ic.ExistImage(ctx, workerImageId, c); err != nil { + errs = append(errs, err) + } + + return dc.ErrorsToDiagnostics(errs) +} diff --git a/internal/service/cloudbroker/k8ci/resource_k8ci.go b/internal/service/cloudbroker/k8ci/resource_k8ci.go new file mode 100644 index 0000000..2eee5c3 --- /dev/null +++ b/internal/service/cloudbroker/k8ci/resource_k8ci.go @@ -0,0 +1,360 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Sergey Kisil, + +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 k8ci + +import ( + "context" + "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/cloudbroker/k8ci" + "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/dc" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/status" +) + +func resourceK8CICreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("resourceK8CICreate: called for k8ci %s", d.Get("name").(string)) + + c := m.(*controller.ControllerCfg) + + if diags := checkParamsExistence(ctx, d, c); diags != nil { + return diags + } + + req := k8ci.CreateRequest{ + Name: d.Get("name").(string), + Version: d.Get("version").(string), + MasterDriver: d.Get("master_driver").(string), + WorkerDriver: d.Get("worker_driver").(string), + MaxMasterCount: uint64(d.Get("max_master_count").(int)), + MaxWorkerCount: uint64(d.Get("max_worker_count").(int)), + MasterImageID: uint64(d.Get("master_image_id").(int)), + WorkerImageID: uint64(d.Get("worker_image_id").(int)), + } + + var networkPlugins []string + for _, item := range d.Get("network_plugins").([]interface{}) { + networkPlugins = append(networkPlugins, item.(string)) + } + req.NetworkPlugins = networkPlugins + + if desc, ok := d.GetOk("desc"); ok { + req.Description = desc.(string) + } + if sharedWithInterface, ok := d.GetOk("shared_with"); ok { + sharedWithList := sharedWithInterface.(*schema.Set).List() + var sharedWith []uint64 + for _, item := range sharedWithList { + sharedWith = append(sharedWith, uint64(item.(int))) + } + req.SharedWith = sharedWith + } + + k8ciID, err := c.CloudBroker().K8CI().Create(ctx, req) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + d.SetId(strconv.FormatUint(k8ciID, 10)) + + warnings := dc.Warnings{} + + if enabled, ok := d.GetOk("enabled"); ok { + log.Debugf("resourceK8CICreate: enable=%t k8ci_id %d after completing its resource configuration", enabled, k8ciID) + if enabled.(bool) { + enabledReq := k8ci.EnableRequest{ + K8CIID: k8ciID, + } + if _, err := c.CloudBroker().K8CI().Enable(ctx, enabledReq); err != nil { + warnings.Add(err) + } + } else { + disableReq := k8ci.DisableRequest{ + K8CIID: k8ciID, + } + if _, err := c.CloudBroker().K8CI().Disable(ctx, disableReq); err != nil { + warnings.Add(err) + } + } + } + + return append(warnings.Get(), resourceK8CIRead(ctx, d, m)...) +} + +func resourceK8CIRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + // c := m.(*controller.ControllerCfg) + log.Debugf("resourceK8CIRead: called for k8ci id %s, name %s", d.Id(), d.Get("name").(string)) + + k8ciRec, err := utilityK8CICheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + hasChanged := false + + switch k8ciRec.Status { + case status.Deleted: + // restoreReq := k8ci.RestoreRequest{K8CIID: k8ciRec.ID} + + // _, err := c.CloudBroker().K8CI().Restore(ctx, restoreReq) + // if err != nil { + // return diag.FromErr(err) + // } + + // if enabled, ok := d.GetOk("enabled"); ok { + // if enabled.(bool) { + // enabledReq := k8ci.EnableRequest{K8CIID: k8ciRec.ID} + // _, err := c.CloudBroker().K8CI().Enable(ctx, enabledReq) + // if err != nil { + // return diag.FromErr(err) + // } + // } + // } + // hasChanged = true + case status.Destroyed: + d.SetId("") + // return resourceK8CICreate(ctx, d, m) + return diag.Errorf("The resource cannot be updated because it has been destroyed") + case status.Disabled: + log.Debugf("The k8ci is in status: %s, troubles may occur with update. Please, enable k8ci first.", k8ciRec.Status) + case status.Redeploying: + case status.Deleting: + case status.Destroying: + return diag.Errorf("The k8ci is in progress with status: %s", k8ciRec.Status) + case status.Modeled: + return diag.Errorf("The k8ci is in status: %s, please, contact support for more information", k8ciRec.Status) + } + + if hasChanged { + k8ciRec, err = utilityK8CICheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + } + + flattenK8CIItems(d, k8ciRec) + + return nil +} + +func resourceK8CIUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("resourceK8CIUpdate: called for k8ci %s, id: %s", d.Get("name").(string), d.Id()) + c := m.(*controller.ControllerCfg) + + if diags := checkParamsExistence(ctx, d, c); diags != nil { + return diags + } + + k8ciRec, err := utilityK8CICheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + warnings := dc.Warnings{} + + hasChanged := false + + switch k8ciRec.Status { + case status.Deleted: + restoreReq := k8ci.RestoreRequest{K8CIID: k8ciRec.ID} + _, err := c.CloudBroker().K8CI().Restore(ctx, restoreReq) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + if enabled, ok := d.GetOk("enabled"); ok { + if enabled.(bool) { + enabledReq := k8ci.EnableRequest{K8CIID: k8ciRec.ID} + _, err := c.CloudBroker().K8CI().Enable(ctx, enabledReq) + if err != nil { + warnings.Add(err) + } + } else { + disableReq := k8ci.DisableRequest{K8CIID: k8ciRec.ID} + if _, err := c.CloudBroker().K8CI().Disable(ctx, disableReq); err != nil { + warnings.Add(err) + } + } + } + hasChanged = true + case status.Destroyed: + d.SetId("") + return diag.Errorf("The resource cannot be updated because it has been destroyed") + // return resourceK8CICreate(ctx, d, m) + case status.Disabled: + log.Debugf("The k8ci is in status: %s, troubles may occur with update. Please, enable k8ci first.", k8ciRec.Status) + case status.Redeploying: + case status.Deleting: + case status.Destroying: + return diag.Errorf("The k8ci is in progress with status: %s", k8ciRec.Status) + case status.Modeled: + return diag.Errorf("The k8ci is in status: %s, please, contact support for more information", k8ciRec.Status) + } + + if hasChanged { + k8ciRec, err = utilityK8CICheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + } + + if d.HasChange("enabled") { + err := resourceK8CIChangeEnable(ctx, d, k8ciRec.ID, m) + if err != nil { + return diag.FromErr(err) + } + } + + if d.HasChange("shared_with") { + err := resourceK8CIChangeSharedWith(ctx, d, k8ciRec.ID, m) + if err != nil { + return diag.FromErr(err) + } + } + + return append(resourceK8CIRead(ctx, d, m), warnings.Get()...) +} + +func resourceK8CIDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("resourceK8CIDelete: called for k8ci %s, id: %s", d.Get("name").(string), d.Id()) + c := m.(*controller.ControllerCfg) + k8ciId, _ := strconv.ParseUint(d.Id(), 10, 64) + req := k8ci.DeleteRequest{ + K8CIID: k8ciId, + } + if permanently, ok := d.GetOk("permanently"); ok { + req.Permanently = permanently.(bool) + } + + if _, err := c.CloudBroker().K8CI().Delete(ctx, req); err != nil { + return diag.FromErr(err) + } + + d.SetId("") + + return nil +} + +func ResourceK8CI() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + CreateContext: resourceK8CICreate, + ReadContext: resourceK8CIRead, + UpdateContext: resourceK8CIUpdate, + DeleteContext: resourceK8CIDelete, + + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: &constants.Timeout30m, + Read: &constants.Timeout600s, + Update: &constants.Timeout600s, + Delete: &constants.Timeout600s, + Default: &constants.Timeout600s, + }, + + Schema: resourceK8CISchemaMake(), + } +} + +func resourceK8CIChangeEnable(ctx context.Context, d *schema.ResourceData, k8ciId uint64, m interface{}) error { + c := m.(*controller.ControllerCfg) + + enabled := d.Get("enabled").(bool) + if enabled { + req := k8ci.EnableRequest{ + K8CIID: k8ciId, + } + if _, err := c.CloudBroker().K8CI().Enable(ctx, req); err != nil { + return err + } + } else { + req := k8ci.DisableRequest{ + K8CIID: k8ciId, + } + if _, err := c.CloudBroker().K8CI().Disable(ctx, req); err != nil { + return err + } + } + + return nil +} + +func resourceK8CIChangeSharedWith(ctx context.Context, d *schema.ResourceData, k8ciId uint64, m interface{}) error { + c := m.(*controller.ControllerCfg) + + oldSet, newSet := d.GetChange("shared_with") + + deletedSharedWith := (oldSet.(*schema.Set).Difference(newSet.(*schema.Set))).List() + if len(deletedSharedWith) > 0 { + for _, userAcessInterface := range deletedSharedWith { + removeReq := k8ci.AccessRemoveRequest{ + K8CIID: k8ciId, + AccountId: uint64(userAcessInterface.(int)), + } + + if _, err := c.CloudBroker().K8CI().AccessRemove(ctx, removeReq); err != nil { + return err + } + } + } + + addedSharedWith := (newSet.(*schema.Set).Difference(oldSet.(*schema.Set))).List() + if len(addedSharedWith) > 0 { + for _, userAcessInterface := range addedSharedWith { + removeReq := k8ci.AccessAddRequest{ + K8CIID: k8ciId, + AccountId: uint64(userAcessInterface.(int)), + } + + if _, err := c.CloudBroker().K8CI().AccessAdd(ctx, removeReq); err != nil { + return err + } + } + } + + return nil +} diff --git a/internal/service/cloudbroker/k8ci/schema.go b/internal/service/cloudbroker/k8ci/schema.go new file mode 100644 index 0000000..1a2a251 --- /dev/null +++ b/internal/service/cloudbroker/k8ci/schema.go @@ -0,0 +1,478 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Tim Tkachev, +Sergey Kisil, + +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 k8ci + +import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + +func dataSourceK8CISchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "k8ci_id": { + Type: schema.TypeInt, + Required: true, + Description: "K8CI ID", + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "gid", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "lb_image_id": { + Type: schema.TypeInt, + Computed: true, + Description: "LB Image ID", + }, + "master_driver": { + Type: schema.TypeString, + Computed: true, + }, + "master_image_id": { + Type: schema.TypeInt, + Computed: true, + }, + "max_master_count": { + Type: schema.TypeInt, + Computed: true, + }, + "max_worker_count": { + Type: schema.TypeInt, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "K8CI name", + }, + "network_plugins": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "shared_with": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "K8CI Status", + }, + "version": { + Type: schema.TypeString, + Computed: true, + }, + "worker_driver": { + Type: schema.TypeString, + Computed: true, + }, + "worker_image_id": { + Type: schema.TypeInt, + Computed: true, + }, + } +} + +func dataSourceK8CIListSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by status", + }, + "worker_driver": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by worker driver", + }, + "master_driver": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by master driver", + }, + "network_plugin": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by network plugin", + }, + "include_disabled": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Include deleted k8cis in result", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "gid", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "k8ci_id": { + Type: schema.TypeInt, + Computed: true, + Description: "K8CI ID", + }, + "lb_image_id": { + Type: schema.TypeInt, + Computed: true, + Description: "LB Image ID", + }, + "master_driver": { + Type: schema.TypeString, + Computed: true, + }, + "master_image_id": { + Type: schema.TypeInt, + Computed: true, + }, + "max_master_count": { + Type: schema.TypeInt, + Computed: true, + }, + "max_worker_count": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "K8CI name", + }, + "shared_with": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "K8CI Status", + }, + "version": { + Type: schema.TypeString, + Computed: true, + }, + "worker_driver": { + Type: schema.TypeString, + Computed: true, + }, + "worker_image_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } +} + +func dataSourceK8CIListDeletedSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "worker_driver": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by worker driver", + }, + "master_driver": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by master driver", + }, + "network_plugin": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by network plugin", + }, + "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{ + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "gid", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "k8ci_id": { + Type: schema.TypeInt, + Computed: true, + Description: "K8CI ID", + }, + "lb_image_id": { + Type: schema.TypeInt, + Computed: true, + Description: "LB Image ID", + }, + "master_driver": { + Type: schema.TypeString, + Computed: true, + }, + "master_image_id": { + Type: schema.TypeInt, + Computed: true, + }, + "max_master_count": { + Type: schema.TypeInt, + Computed: true, + }, + "max_worker_count": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "K8CI name", + }, + "shared_with": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "K8CI Status", + }, + "version": { + Type: schema.TypeString, + Computed: true, + }, + "worker_driver": { + Type: schema.TypeString, + Computed: true, + }, + "worker_image_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } +} + +func resourceK8CISchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "K8CI name", + }, + "version": { + Type: schema.TypeString, + Required: true, + }, + "master_driver": { + Type: schema.TypeString, + Required: true, + }, + "master_image_id": { + Type: schema.TypeInt, + Required: true, + }, + "max_master_count": { + Type: schema.TypeInt, + Required: true, + }, + "max_worker_count": { + Type: schema.TypeInt, + Required: true, + }, + "worker_image_id": { + Type: schema.TypeInt, + Required: true, + }, + "worker_driver": { + Type: schema.TypeString, + Required: true, + }, + "network_plugins": { + Type: schema.TypeList, + Required: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "enabled": { + Type: schema.TypeBool, + Optional: true, + }, + "permanently": { + Type: schema.TypeBool, + Default: false, + Optional: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + Optional: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "gid", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "k8ci_id": { + Type: schema.TypeInt, + Computed: true, + Description: "K8CI ID", + }, + "lb_image_id": { + Type: schema.TypeInt, + Computed: true, + Description: "LB Image ID", + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "shared_with": { + Type: schema.TypeSet, + Computed: true, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "K8CI Status", + }, + } +} diff --git a/internal/service/cloudbroker/k8ci/utility_k8ci.go b/internal/service/cloudbroker/k8ci/utility_k8ci.go new file mode 100644 index 0000000..0426b9c --- /dev/null +++ b/internal/service/cloudbroker/k8ci/utility_k8ci.go @@ -0,0 +1,63 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Tim Tkachev, +Sergey Kisil, + +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 k8ci + +import ( + "context" + "strconv" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8ci" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityK8CICheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8ci.RecordK8CI, error) { + c := m.(*controller.ControllerCfg) + req := k8ci.GetRequest{} + + if d.Id() != "" { + k8ciId, _ := strconv.ParseUint(d.Id(), 10, 64) + req.K8CIID = k8ciId + } else { + req.K8CIID = uint64(d.Get("k8ci_id").(int)) + } + + res, err := c.CloudBroker().K8CI().Get(ctx, req) + if err != nil { + return nil, err + } + + return res, nil +} diff --git a/internal/service/cloudbroker/k8ci/utility_k8ci_list.go b/internal/service/cloudbroker/k8ci/utility_k8ci_list.go new file mode 100644 index 0000000..85101af --- /dev/null +++ b/internal/service/cloudbroker/k8ci/utility_k8ci_list.go @@ -0,0 +1,84 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Tim Tkachev, +Sergey Kisil, + +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 k8ci + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8ci" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityK8CIListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8ci.ListK8CI, error) { + c := m.(*controller.ControllerCfg) + + req := k8ci.ListRequest{} + + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } + if worker_driver, ok := d.GetOk("worker_driver"); ok { + req.WorkerDriver = worker_driver.(string) + } + if master_driver, ok := d.GetOk("master_driver"); ok { + req.MasterDriver = master_driver.(string) + } + if network_plugin, ok := d.GetOk("network_plugin"); ok { + req.NetworkPlugins = network_plugin.(string) + } + if include_disabled, ok := d.GetOk("include_disabled"); ok { + req.IncludeDisabled = include_disabled.(bool) + } + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + + resList, err := c.CloudBroker().K8CI().List(ctx, req) + if err != nil { + return nil, err + } + + return resList, nil +} diff --git a/internal/service/cloudbroker/k8ci/utility_k8ci_list_deleted.go b/internal/service/cloudbroker/k8ci/utility_k8ci_list_deleted.go new file mode 100644 index 0000000..86d123a --- /dev/null +++ b/internal/service/cloudbroker/k8ci/utility_k8ci_list_deleted.go @@ -0,0 +1,78 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Tim Tkachev, +Sergey Kisil, + +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 k8ci + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8ci" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityK8CIListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8ci.ListK8CI, error) { + c := m.(*controller.ControllerCfg) + + req := k8ci.ListDeletedRequest{} + + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + if worker_driver, ok := d.GetOk("worker_driver"); ok { + req.WorkerDriver = worker_driver.(string) + } + if master_driver, ok := d.GetOk("master_driver"); ok { + req.MasterDriver = master_driver.(string) + } + if network_plugin, ok := d.GetOk("network_plugin"); ok { + req.NetworkPlugins = network_plugin.(string) + } + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + + resList, err := c.CloudBroker().K8CI().ListDeleted(ctx, req) + if err != nil { + return nil, err + } + + return resList, nil +} diff --git a/internal/service/cloudbroker/k8s/data_source_k8s.go b/internal/service/cloudbroker/k8s/data_source_k8s.go new file mode 100644 index 0000000..4b1ec0b --- /dev/null +++ b/internal/service/cloudbroker/k8s/data_source_k8s.go @@ -0,0 +1,140 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Tim Tkachev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package k8s + +import ( + "context" + "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/cloudbroker/compute" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func dataSourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("dataSourceK8sRead: called with k8s id %d", d.Get("k8s_id").(int)) + cluster, err := utilityK8sCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + d.SetId(strconv.FormatUint(cluster.ID, 10)) + + k8sList, err := utilityK8sListCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + curK8s := k8s.ItemK8S{} + for _, k8sCluster := range k8sList.Data { + if k8sCluster.ID == cluster.ID { + curK8s = k8sCluster + } + } + if curK8s.ID == 0 { + return diag.Errorf("Cluster with id %d not found in List clusters", cluster.ID) + } + + d.Set("desc", curK8s.Description) + d.Set("gid", curK8s.GID) + d.Set("guid", curK8s.GUID) + d.Set("milestones", curK8s.Milestones) + d.Set("service_account", flattenServiceAccount(curK8s.ServiceAccount)) + d.Set("ssh_key", curK8s.SSHKey) + d.Set("vins_id", curK8s.VINSID) + + masterComputeList := make([]compute.RecordCompute, 0, len(cluster.K8SGroups.Masters.DetailedInfo)) + workersComputeList := make([]compute.RecordCompute, 0, len(cluster.K8SGroups.Workers)) + for _, masterNode := range cluster.K8SGroups.Masters.DetailedInfo { + compute, err := utilityComputeCheckPresence(ctx, d, m, masterNode.ID) + if err != nil { + return diag.FromErr(err) + } + masterComputeList = append(masterComputeList, *compute) + } + for _, worker := range cluster.K8SGroups.Workers { + for _, info := range worker.DetailedInfo { + compute, err := utilityComputeCheckPresence(ctx, d, m, info.ID) + if err != nil { + return diag.FromErr(err) + } + workersComputeList = append(workersComputeList, *compute) + } + } + + c := m.(*controller.ControllerCfg) + + getConfigReq := k8s.GetConfigRequest{K8SID: cluster.ID} + + kubeconfig, err := c.CloudBroker().K8S().GetConfig(ctx, getConfigReq) + if err != nil { + log.Warnf("could not get kubeconfig: %v", err) + } + + d.Set("kubeconfig", kubeconfig) + + getLbReq := lb.GetRequest{LBID: cluster.LBID} + lb, err := c.CloudBroker().LB().Get(ctx, getLbReq) + if err != nil { + return diag.FromErr(err) + } + + d.Set("extnet_id", lb.ExtNetID) + d.Set("lb_ip", lb.PrimaryNode.FrontendIP) + + flattenK8sData(d, cluster, masterComputeList, workersComputeList) + return nil +} + +func DataSourceK8s() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceK8sRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceK8sSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/k8s/data_source_k8s_computes.go b/internal/service/cloudbroker/k8s/data_source_k8s_computes.go new file mode 100644 index 0000000..898abea --- /dev/null +++ b/internal/service/cloudbroker/k8s/data_source_k8s_computes.go @@ -0,0 +1,73 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Tim Tkachev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package k8s + +import ( + "context" + "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/terraform-provider-decort/internal/constants" +) + +func dataSourceK8sComputesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("dataSourceK8sComputesRead: called with k8s id %d", d.Get("k8s_id").(int)) + cluster, err := utilityK8sCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + d.SetId(strconv.FormatUint(cluster.ID, 10)) + flattenK8sDataComputes(d, cluster) + + return nil +} + +func DataSourceK8sComputes() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceK8sComputesRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout60s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceK8sComputesSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/k8s/data_source_k8s_list.go b/internal/service/cloudbroker/k8s/data_source_k8s_list.go new file mode 100644 index 0000000..1d24bca --- /dev/null +++ b/internal/service/cloudbroker/k8s/data_source_k8s_list.go @@ -0,0 +1,75 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Tim Tkachev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package k8s + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceK8sListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debug("dataSourceK8sListRead starting") + list, err := utilityK8sListCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenK8sItems(list)) + d.Set("entry_count", list.EntryCount) + + return nil +} + +func DataSourceK8sList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceK8sListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceK8sListSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/k8s/data_source_k8s_list_deleted.go b/internal/service/cloudbroker/k8s/data_source_k8s_list_deleted.go new file mode 100644 index 0000000..08ec800 --- /dev/null +++ b/internal/service/cloudbroker/k8s/data_source_k8s_list_deleted.go @@ -0,0 +1,75 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Tim Tkachev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package k8s + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceK8sListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debug("dataSourceK8sListDeletedRead starting") + list, err := utilityK8sListDeletedCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenK8sItems(list)) + d.Set("entry_count", list.EntryCount) + + return nil +} + +func DataSourceK8sListDeleted() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceK8sListDeletedRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceK8sListDeletedSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/k8s/data_source_k8s_wg.go b/internal/service/cloudbroker/k8s/data_source_k8s_wg.go new file mode 100644 index 0000000..9152f74 --- /dev/null +++ b/internal/service/cloudbroker/k8s/data_source_k8s_wg.go @@ -0,0 +1,73 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package k8s + +import ( + "context" + "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/terraform-provider-decort/internal/constants" +) + +func dataSourceK8sWgRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("dataSourceK8sWgRead: called with k8s id %d", d.Get("k8s_id").(int)) + + wg, workersComputeList, err := utilityDataK8sWgCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + d.SetId(strconv.FormatUint(wg.ID, 10)) + flattenWg(d, wg, workersComputeList) + + return nil +} + +func DataSourceK8sWg() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceK8sWgRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceK8sWgSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/k8s/data_source_k8s_wg_cloud_init.go b/internal/service/cloudbroker/k8s/data_source_k8s_wg_cloud_init.go new file mode 100644 index 0000000..f4828b4 --- /dev/null +++ b/internal/service/cloudbroker/k8s/data_source_k8s_wg_cloud_init.go @@ -0,0 +1,74 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package k8s + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceK8sWgCloudInitRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("dataSourceK8sWgCloudInitRead: called with k8s id %d and wg id %d", d.Get("k8s_id").(int), d.Get("wg_id").(int)) + + metaData, err := utilityK8sWgCloudInitCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("cloud_init", metaData) + + return nil +} + +func DataSourceK8sWgCloudInit() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceK8sWgCloudInitRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceK8sWgCloudInitSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/k8s/data_source_k8s_wg_list.go b/internal/service/cloudbroker/k8s/data_source_k8s_wg_list.go new file mode 100644 index 0000000..b3c2b49 --- /dev/null +++ b/internal/service/cloudbroker/k8s/data_source_k8s_wg_list.go @@ -0,0 +1,85 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package k8s + +import ( + "context" + "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/cloudbroker/compute" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceK8sWgListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("dataSourceK8sWgListRead: called with k8s id %d and wg id %d", d.Get("k8s_id").(int), d.Get("wg_id").(int)) + wgList, err := utilityK8sWgListCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + d.SetId(strconv.Itoa(d.Get("k8s_id").(int))) + + workersComputeList := make(map[uint64][]compute.RecordCompute) + for _, worker := range *wgList { + workersComputeList[worker.ID] = make([]compute.RecordCompute, 0, len(worker.DetailedInfo)) + for _, info := range worker.DetailedInfo { + compute, err := utilityComputeCheckPresence(ctx, d, m, info.ID) + if err != nil { + return diag.FromErr(err) + } + workersComputeList[worker.ID] = append(workersComputeList[worker.ID], *compute) + } + } + flattenItemsWg(d, *wgList, workersComputeList) + + return nil +} + +func DataSourceK8sWgList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceK8sWgListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceK8sWgListSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/k8s/flattens.go b/internal/service/cloudbroker/k8s/flattens.go new file mode 100644 index 0000000..f3794d6 --- /dev/null +++ b/internal/service/cloudbroker/k8s/flattens.go @@ -0,0 +1,397 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package k8s + +import ( + "encoding/json" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s" +) + +func flattenResourceK8sCP(d *schema.ResourceData, k8s k8s.RecordK8S, masters []compute.RecordCompute) { + d.Set("acl", flattenAcl(k8s.ACL)) + d.Set("account_id", k8s.AccountID) + d.Set("account_name", k8s.AccountName) + d.Set("k8sci_id", k8s.CIID) + d.Set("bservice_id", k8s.BServiceID) + d.Set("created_by", k8s.CreatedBy) + d.Set("created_time", k8s.CreatedTime) + d.Set("deleted_by", k8s.DeletedBy) + d.Set("deleted_time", k8s.DeletedTime) + d.Set("k8s_ci_name", k8s.K8CIName) + d.Set("with_lb", k8s.LBID != 0) + d.Set("lb_id", k8s.LBID) + d.Set("k8s_id", k8s.ID) + d.Set("name", k8s.Name) + d.Set("rg_id", k8s.RGID) + d.Set("rg_name", k8s.RGName) + d.Set("status", k8s.Status) + d.Set("tech_status", k8s.TechStatus) + d.Set("updated_by", k8s.UpdatedBy) + d.Set("updated_time", k8s.UpdatedTime) + d.Set("network_plugin", k8s.NetworkPlugin) + + flattenCPParams(d, k8s.K8SGroups.Masters, masters) +} + +func flattenCPParams(d *schema.ResourceData, mastersGroup k8s.MasterGroup, masters []compute.RecordCompute) { + d.Set("cpu", mastersGroup.CPU) + d.Set("detailed_info", flattenDetailedInfo(mastersGroup.DetailedInfo, masters)) + d.Set("disk", mastersGroup.Disk) + d.Set("master_id", mastersGroup.ID) + d.Set("master_name", mastersGroup.Name) + d.Set("num", mastersGroup.Num) + d.Set("ram", mastersGroup.RAM) +} + +func flattenK8sData(d *schema.ResourceData, cluster *k8s.RecordK8S, masters []compute.RecordCompute, workers []compute.RecordCompute) { + d.Set("acl", flattenAcl(cluster.ACL)) + d.Set("account_id", cluster.AccountID) + d.Set("account_name", cluster.AccountName) + d.Set("bservice_id", cluster.BServiceID) + d.Set("k8sci_id", cluster.CIID) + d.Set("created_by", cluster.CreatedBy) + d.Set("created_time", cluster.CreatedTime) + d.Set("deleted_by", cluster.DeletedBy) + d.Set("deleted_time", cluster.DeletedTime) + d.Set("k8s_id", cluster.ID) + d.Set("k8s_ci_name", cluster.K8CIName) + d.Set("k8s_groups", flattenK8sGroups(cluster.K8SGroups, masters, workers)) + d.Set("lb_id", cluster.LBID) + d.Set("network_plugin", cluster.NetworkPlugin) + d.Set("name", cluster.Name) + d.Set("rg_id", cluster.RGID) + d.Set("rg_name", cluster.RGName) + d.Set("status", cluster.Status) + d.Set("tech_status", cluster.TechStatus) + d.Set("updated_by", cluster.UpdatedBy) + d.Set("updated_time", cluster.UpdatedTime) +} + +func flattenAcl(acl k8s.RecordACLGroup) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "account_acl": flattenAclList(acl.AccountACL), + "k8s_acl": flattenAclList(acl.K8SACL), + "rg_acl": flattenAclList(acl.RGACL), + } + + res = append(res, temp) + return res +} + +func flattenAclList(aclList k8s.ListACL) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(aclList)) + for _, acl := range aclList { + temp := map[string]interface{}{ + "explicit": acl.Explicit, + "guid": acl.GUID, + "right": acl.Right, + "status": acl.Status, + "type": acl.Type, + "user_group_id": acl.UserGroupID, + } + res = append(res, temp) + } + return res +} + +func flattenK8sGroups(k8sGroups k8s.RecordK8SGroups, masters []compute.RecordCompute, workers []compute.RecordCompute) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "masters": flattenMasterGroup(k8sGroups.Masters, masters), + "workers": flattenWorkerGroup(k8sGroups.Workers, workers), + } + res = append(res, temp) + return res +} + +func flattenMasterGroup(mastersGroup k8s.MasterGroup, masters []compute.RecordCompute) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "cpu": mastersGroup.CPU, + "detailed_info": flattenDetailedInfo(mastersGroup.DetailedInfo, masters), + "disk": mastersGroup.Disk, + "master_id": mastersGroup.ID, + "name": mastersGroup.Name, + "num": mastersGroup.Num, + "ram": mastersGroup.RAM, + } + + res = append(res, temp) + return res +} + +func flattenDetailedInfo(detailedInfoList k8s.ListDetailedInfo, computes []compute.RecordCompute) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(detailedInfoList)) + if computes != nil { + for i, detailedInfo := range detailedInfoList { + temp := map[string]interface{}{ + "external_ip": detailedInfo.ExternalIp, + "compute_id": detailedInfo.ID, + "name": detailedInfo.Name, + "status": detailedInfo.Status, + "tech_status": detailedInfo.TechStatus, + "interfaces": flattenInterfaces(computes[i].Interfaces), + } + res = append(res, temp) + } + } else { + for _, detailedInfo := range detailedInfoList { + temp := map[string]interface{}{ + "external_ip": detailedInfo.ExternalIp, + "compute_id": detailedInfo.ID, + "name": detailedInfo.Name, + "status": detailedInfo.Status, + "tech_status": detailedInfo.TechStatus, + } + res = append(res, temp) + } + } + + return res +} + +func flattenInterfaces(interfaces compute.ListInterfaces) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(interfaces)) + for _, interfaceCompute := range interfaces { + temp := map[string]interface{}{ + "def_gw": interfaceCompute.DefGW, + "ip_address": interfaceCompute.IPAddress, + } + res = append(res, temp) + } + + return res +} + +func flattenWorkerGroup(k8SGroupList k8s.ListK8SGroup, workers []compute.RecordCompute) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(k8SGroupList)) + for _, k8sGroup := range k8SGroupList { + labels := make([]string, 0) + for _, label := range k8sGroup.Labels { + if strings.HasPrefix(label, "workersGroupName") { + continue + } + labels = append(labels, label) + } + temp := map[string]interface{}{ + "annotations": k8sGroup.Annotations, + "cpu": k8sGroup.CPU, + "detailed_info": flattenDetailedInfo(k8sGroup.DetailedInfo, workers), + "disk": k8sGroup.Disk, + "guid": k8sGroup.GUID, + "id": k8sGroup.ID, + "labels": labels, + "name": k8sGroup.Name, + "num": k8sGroup.Num, + "ram": k8sGroup.RAM, + "taints": k8sGroup.Taints, + } + + res = append(res, temp) + } + return res +} + +func flattenServiceAccount(sa k8s.ServiceAccount) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "guid": sa.GUID, + "password": sa.Password, + "username": sa.Username, + } + res = append(res, temp) + return res +} + +func flattenK8sItems(k8sList *k8s.ListK8S) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(k8sList.Data)) + for _, item := range k8sList.Data { + aclStrArray := make([]string, 0, len(item.ACL)) + for _, acl := range item.ACL { + aclStrArray = append(aclStrArray, acl.(string)) + } + data, _ := json.Marshal(item.Config) + temp := map[string]interface{}{ + "account_id": item.AccountID, + "account_name": item.Name, + "acl": aclStrArray, + "bservice_id": item.BServiceID, + "k8sci_id": item.CIID, + "kubeconfig": string(data), + "created_by": item.CreatedBy, + "created_time": item.CreatedTime, + "deleted_by": item.DeletedBy, + "deleted_time": item.DeletedTime, + "desc": item.Description, + "extnet_id": item.ExtNetID, + "gid": item.GID, + "guid": item.GUID, + "k8s_id": item.ID, + "lb_id": item.LBID, + "milestones": item.Milestones, + "k8s_name": item.Name, + "network_plugin": item.NetworkPlugin, + "rg_id": item.RGID, + "rg_name": item.RGName, + "service_account": flattenServiceAccount(item.ServiceAccount), + "ssh_key": item.SSHKey, + "status": item.Status, + "tech_status": item.TechStatus, + "updated_by": item.UpdatedBy, + "updated_time": item.UpdatedTime, + "vins_id": item.VINSID, + "workers_groups": flattenWorkersGroupList(item.WorkersGroup), + } + + res = append(res, temp) + } + return res +} + +func flattenWorkersGroupList(k8SGroupList k8s.ListK8SGroup) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(k8SGroupList)) + for _, k8sGroup := range k8SGroupList { + labels := make([]string, 0) + for _, label := range k8sGroup.Labels { + if strings.HasPrefix(label, "workersGroupName") { + continue + } + labels = append(labels, label) + } + temp := map[string]interface{}{ + "annotations": k8sGroup.Annotations, + "guid": k8sGroup.GUID, + "id": k8sGroup.ID, + "labels": labels, + "taints": k8sGroup.Taints, + } + + res = append(res, temp) + } + return res +} + +func flattenK8sDataComputes(d *schema.ResourceData, cluster *k8s.RecordK8S) { + d.Set("k8s_id", cluster.ID) + d.Set("masters", flattenMasterComputes(cluster)) + d.Set("workers", flattenWorkerComputes(cluster)) +} + +func flattenMasterComputes(cluster *k8s.RecordK8S) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(cluster.K8SGroups.Masters.DetailedInfo)) + for _, comp := range cluster.K8SGroups.Masters.DetailedInfo { + temp := map[string]interface{}{ + "id": comp.ID, + "name": comp.Name, + "status": comp.Status, + "tech_status": comp.TechStatus, + "group_name": cluster.K8SGroups.Masters.Name, + } + res = append(res, temp) + } + + return res +} + +func flattenWorkerComputes(cluster *k8s.RecordK8S) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(cluster.K8SGroups.Workers)) + for _, wg := range cluster.K8SGroups.Workers { + for _, comp := range wg.DetailedInfo { + temp := map[string]interface{}{ + "id": comp.ID, + "name": comp.Name, + "status": comp.Status, + "tech_status": comp.TechStatus, + "group_name": wg.Name, + } + res = append(res, temp) + } + } + + return res +} + +func flattenItemsWg(d *schema.ResourceData, wgList k8s.ListK8SGroup, computes map[uint64][]compute.RecordCompute) { + d.Set("items", flattenWgList(wgList, computes)) +} + +func flattenWgList(wgList k8s.ListK8SGroup, computesMap map[uint64][]compute.RecordCompute) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + for _, wg := range wgList { + computes := computesMap[wg.ID] + temp := map[string]interface{}{ + "annotations": wg.Annotations, + "cpu": wg.CPU, + "wg_id": wg.ID, + "detailed_info": flattenDetailedInfo(wg.DetailedInfo, computes), + "disk": wg.Disk, + "guid": wg.GUID, + "labels": wg.Labels, + "name": wg.Name, + "num": wg.Num, + "ram": wg.RAM, + "taints": wg.Taints, + } + + res = append(res, temp) + } + return res +} + +func flattenWg(d *schema.ResourceData, wg *k8s.RecordK8SGroup, computes []compute.RecordCompute) { + labels := make([]string, 0) + for _, label := range wg.Labels { + if strings.HasPrefix(label, "workersGroupName") { + continue + } + + labels = append(labels, label) + } + + d.Set("annotations", wg.Annotations) + d.Set("cpu", wg.CPU) + d.Set("detailed_info", flattenDetailedInfo(wg.DetailedInfo, computes)) + d.Set("disk", wg.Disk) + d.Set("guid", wg.GUID) + d.Set("labels", labels) + d.Set("name", wg.Name) + d.Set("num", wg.Num) + d.Set("ram", wg.RAM) + d.Set("taints", wg.Taints) +} diff --git a/internal/service/cloudbroker/k8s/models.go b/internal/service/cloudbroker/k8s/models.go deleted file mode 100644 index 0bf70ff..0000000 --- a/internal/service/cloudbroker/k8s/models.go +++ /dev/null @@ -1,131 +0,0 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -/* -Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud -Orchestration Technology) with Terraform by Hashicorp. - -Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort - -Please see README.md to learn where to place source code so that it -builds seamlessly. - -Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki -*/ - -package k8s - -import ( - "encoding/json" - "fmt" - "strconv" -) - -type K8sNodeRecord struct { - ID int `json:"id"` - Name string `json:"name"` - Disk int `json:"disk"` - Cpu int `json:"cpu"` - Num int `json:"num"` - Ram int `json:"ram"` - DetailedInfo []struct { - ID int `json:"id"` - Name string `json:"name"` - } `json:"detailedInfo"` -} - -//K8sRecord represents k8s instance -type K8sRecord struct { - AccountID int `json:"accountId"` - AccountName string `json:"accountName"` - CI int `json:"ciId"` - ID int `json:"id"` - Groups struct { - Masters K8sNodeRecord `json:"masters"` - Workers []K8sNodeRecord `json:"workers"` - } `json:"k8sGroups"` - LbID int `json:"lbId"` - Name string `json:"name"` - RgID int `json:"rgId"` - RgName string `json:"rgName"` -} - -//LbRecord represents load balancer instance -type LbRecord struct { - ID int `json:"id"` - Name string `json:"name"` - RgID int `json:"rgId"` - VinsID int `json:"vinsId"` - ExtNetID int `json:"extnetId"` - PrimaryNode struct { - BackendIP string `json:"backendIp"` - ComputeID int `json:"computeId"` - FrontendIP string `json:"frontendIp"` - NetworkID int `json:"networkId"` - } `json:"primaryNode"` -} - -//Blasphemous workaround for parsing Result value -type TaskResult int - -func (r *TaskResult) UnmarshalJSON(b []byte) error { - if b[0] == '"' { - b := b[1 : len(b)-1] - if len(b) == 0 { - *r = 0 - return nil - } - n, err := strconv.Atoi(string(b)) - if err != nil { - return err - } - *r = TaskResult(n) - } else if b[0] == '[' { - res := []interface{}{} - if err := json.Unmarshal(b, &res); err != nil { - return err - } - if n, ok := res[0].(float64); ok { - *r = TaskResult(n) - } else { - return fmt.Errorf("could not unmarshal %v into int", res[0]) - } - } - - return nil -} - -//AsyncTask represents a long task completion status -type AsyncTask struct { - AuditID string `json:"auditId"` - Completed bool `json:"completed"` - Error string `json:"error"` - Log []string `json:"log"` - Result TaskResult `json:"result"` - Stage string `json:"stage"` - Status string `json:"status"` - UpdateTime uint64 `json:"updateTime"` - UpdatedTime uint64 `json:"updatedTime"` -} - -type SshKeyConfig struct { - User string - SshKey string - UserShell string -} diff --git a/internal/service/cloudbroker/k8s/node_subresource.go b/internal/service/cloudbroker/k8s/node_subresource.go deleted file mode 100644 index 14b4269..0000000 --- a/internal/service/cloudbroker/k8s/node_subresource.go +++ /dev/null @@ -1,130 +0,0 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -/* -Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud -Orchestration Technology) with Terraform by Hashicorp. - -Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort - -Please see README.md to learn where to place source code so that it -builds seamlessly. - -Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki -*/ - -package k8s - -import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s" -) - -func nodeMasterDefault() k8s.MasterGroup { - return k8s.MasterGroup{ - Num: 1, - CPU: 2, - RAM: 2048, - Disk: 0, - } -} - -func nodeWorkerDefault() k8s.RecordK8SGroup { - return k8s.RecordK8SGroup{ - Num: 1, - CPU: 1, - RAM: 1024, - Disk: 0, - } -} - -func parseWorkerNode(nodeList []interface{}) k8s.RecordK8SGroup { - node := nodeList[0].(map[string]interface{}) - - return k8s.RecordK8SGroup{ - Num: uint64(node["num"].(int)), - CPU: uint64(node["cpu"].(int)), - RAM: uint64(node["ram"].(int)), - Disk: uint64(node["disk"].(int)), - } -} - -func parseMasterNode(nodeList []interface{}) k8s.MasterGroup { - node := nodeList[0].(map[string]interface{}) - - return k8s.MasterGroup{ - Num: uint64(node["num"].(int)), - CPU: uint64(node["cpu"].(int)), - RAM: uint64(node["ram"].(int)), - Disk: uint64(node["disk"].(int)), - } -} - -func workerNodeToResource(node k8s.RecordK8SGroup) []interface{} { - mp := make(map[string]interface{}) - - mp["num"] = node.Num - mp["cpu"] = node.CPU - mp["ram"] = node.RAM - mp["disk"] = node.Disk - - return []interface{}{mp} -} - -func masterNodeToResource(node k8s.MasterGroup) []interface{} { - mp := make(map[string]interface{}) - - mp["num"] = node.Num - mp["cpu"] = node.CPU - mp["ram"] = node.RAM - mp["disk"] = node.Disk - - return []interface{}{mp} -} - -func nodeK8sSubresourceSchemaMake() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "num": { - Type: schema.TypeInt, - Required: true, - Description: "Number of nodes to create.", - }, - - "cpu": { - Type: schema.TypeInt, - Required: true, - ForceNew: true, - Description: "Node CPU count.", - }, - - "ram": { - Type: schema.TypeInt, - Required: true, - ForceNew: true, - Description: "Node RAM in MB.", - }, - - "disk": { - Type: schema.TypeInt, - Required: true, - ForceNew: true, - Description: "Node boot disk size in GB.", - }, - } -} diff --git a/internal/service/cloudbroker/k8s/resource_check_input_values.go b/internal/service/cloudbroker/k8s/resource_check_input_values.go new file mode 100644 index 0000000..ebcb1aa --- /dev/null +++ b/internal/service/cloudbroker/k8s/resource_check_input_values.go @@ -0,0 +1,76 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Tim Tkachev, +Sergey Kisil, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package k8s + +import ( + "context" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/ic" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func checkParamsExistence(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) diag.Diagnostics { + var errs []error + + rgid := uint64(d.Get("rg_id").(int)) + k8ciId := uint64(d.Get("k8sci_id").(int)) + extNetId := uint64(d.Get("extnet_id").(int)) + vinsId := uint64(d.Get("vins_id").(int)) + + if err := ic.ExistRG(ctx, rgid, c); err != nil { + errs = append(errs, err) + } + + if err := ic.ExistK8CI(ctx, k8ciId, c); err != nil { + errs = append(errs, err) + } + + if _, ok := d.GetOk("extnet_id"); ok { + if err := ic.ExistExtNetInK8s(ctx, extNetId, c); err != nil { + errs = append(errs, err) + } + } + + if _, ok := d.GetOk("vins_id"); ok { + if err := ic.ExistVinsInK8s(ctx, vinsId, c); err != nil { + errs = append(errs, err) + } + } + + return dc.ErrorsToDiagnostics(errs) +} diff --git a/internal/service/cloudbroker/k8s/resource_k8s.go b/internal/service/cloudbroker/k8s/resource_k8s.go deleted file mode 100644 index efea256..0000000 --- a/internal/service/cloudbroker/k8s/resource_k8s.go +++ /dev/null @@ -1,372 +0,0 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -/* -Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud -Orchestration Technology) with Terraform by Hashicorp. - -Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort - -Please see README.md to learn where to place source code so that it -builds seamlessly. - -Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki -*/ - -package k8s - -import ( - "context" - "fmt" - "strconv" - "time" - - "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/cloudbroker/k8s" - "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb" - "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/tasks" - "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" - "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" -) - -func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Debugf("resourceK8sCreate: called with name %s, rg %d", d.Get("name").(string), d.Get("rg_id").(int)) - - c := m.(*controller.ControllerCfg) - req := k8s.CreateRequest{} - - req.Name = d.Get("name").(string) - req.RGID = uint64(d.Get("rg_id").(int)) - req.K8CIID = uint64(d.Get("k8sci_id").(int)) - req.WorkerGroupName = d.Get("wg_name").(string) - - var masterNode k8s.MasterGroup - if masters, ok := d.GetOk("masters"); ok { - masterNode = parseMasterNode(masters.([]interface{})) - } else { - masterNode = nodeMasterDefault() - } - req.MasterNum = uint64(masterNode.Num) - req.MasterCPU = uint64(masterNode.CPU) - req.MasterRAM = uint64(masterNode.RAM) - req.MasterDisk = uint64(masterNode.Disk) - - var workerNode k8s.RecordK8SGroup - if workers, ok := d.GetOk("workers"); ok { - workerNode = parseWorkerNode(workers.([]interface{})) - } else { - workerNode = nodeWorkerDefault() - } - req.WorkerNum = uint64(workerNode.Num) - req.WorkerCPU = uint64(workerNode.CPU) - req.WorkerRAM = uint64(workerNode.RAM) - req.WorkerDisk = uint64(workerNode.Disk) - - if withLB, ok := d.GetOk("with_lb"); ok { - req.WithLB = withLB.(bool) - } else { - req.WithLB = true - } - - if extNet, ok := d.GetOk("extnet_id"); ok { - req.ExtNetID = uint64(extNet.(int)) - } else { - req.ExtNetID = 0 - } - - if desc, ok := d.GetOk("desc"); ok { - req.Description = desc.(string) - } - - resp, err := c.CloudBroker().K8S().Create(ctx, req) - if err != nil { - return diag.FromErr(err) - } - - tasksReq := tasks.GetRequest{ - AuditID: resp, - } - - for { - task, err := c.CloudBroker().Tasks().Get(ctx, tasksReq) - if err != nil { - return diag.FromErr(err) - } - - log.Debugf("resourceK8sCreate: instance creating - %s", task.Stage) - - if task.Completed { - if task.Error != "" { - return diag.FromErr(fmt.Errorf("cannot create k8s instance: %v", task.Error)) - } - - d.SetId(strconv.Itoa(int(task.Result))) - break - } - - time.Sleep(time.Second * 10) - } - - return resourceK8sRead(ctx, d, m) -} - -func resourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Debugf("resourceK8sRead: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int)) - - k8sData, err := utilityK8sCheckPresence(ctx, d, m) - if err != nil { - d.SetId("") - return diag.FromErr(err) - } - - d.Set("name", k8sData.Name) - d.Set("rg_id", k8sData.RGID) - d.Set("k8sci_id", k8sData.CIID) - d.Set("wg_name", k8sData.K8SGroups.Workers[0].Name) - d.Set("masters", masterNodeToResource(k8sData.K8SGroups.Masters)) - d.Set("workers", workerNodeToResource(k8sData.K8SGroups.Workers[0])) - d.Set("default_wg_id", k8sData.K8SGroups.Workers[0].ID) - - c := m.(*controller.ControllerCfg) - - lbReq := lb.GetRequest{ - LBID: k8sData.LBID, - } - - lbData, err := c.CloudBroker().LB().Get(ctx, lbReq) - if err != nil { - return diag.FromErr(err) - } - - d.Set("extnet_id", lbData.ExtNetID) - d.Set("lb_ip", lbData.PrimaryNode.FrontendIP) - - configReq := k8s.GetConfigRequest{ - K8SID: k8sData.ID, - } - - kubeconfig, err := c.CloudBroker().K8S().GetConfig(ctx, configReq) - if err != nil { - log.Warnf("could not get kubeconfig: %v", err) - return nil - } - - d.Set("kubeconfig", kubeconfig) - - return nil -} - -func resourceK8sUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Debugf("resourceK8sUpdate: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int)) - - c := m.(*controller.ControllerCfg) - k8sId, _ := strconv.ParseUint(d.Id(), 10, 64) - - if d.HasChange("name") { - req := k8s.UpdateRequest{ - K8SID: k8sId, - Name: d.Get("name").(string), - } - - _, err := c.CloudBroker().K8S().Update(ctx, req) - if err != nil { - return diag.FromErr(err) - } - } - - if d.HasChange("workers") { - k8sData, err := utilityK8sCheckPresence(ctx, d, m) - if err != nil { - return diag.FromErr(err) - } - - wg := k8sData.K8SGroups.Workers[0] - deleteReq := k8s.DeleteWorkerFromGroupRequest{ - K8SID: k8sId, - WorkersGroupID: wg.ID, - } - addReq := k8s.WorkerAddRequest{ - K8SID: k8sId, - WorkersGroupID: wg.ID, - } - - newWorkers := parseWorkerNode(d.Get("workers").([]interface{})) - - if newWorkers.Num > wg.Num { - addReq.Num = uint64(newWorkers.Num - wg.Num) - if _, err := c.CloudBroker().K8S().WorkerAdd(ctx, addReq); err != nil { - return diag.FromErr(err) - } - } else { - for i := wg.Num - 1; i >= newWorkers.Num; i-- { - deleteReq.WorkerID = wg.DetailedInfo[i].ID - if _, err := c.CloudBroker().K8S().DeleteWorkerFromGroup(ctx, deleteReq); err != nil { - return diag.FromErr(err) - } - } - } - } - - return nil -} - -func resourceK8sDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Debugf("resourceK8sDelete: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int)) - - k8sData, err := utilityK8sCheckPresence(ctx, d, m) - if err != nil { - return diag.FromErr(err) - } - - c := m.(*controller.ControllerCfg) - req := k8s.DeleteRequest{ - K8SID: k8sData.ID, - } - if perm, ok := d.GetOk("permanently"); ok { - req.Permanently = perm.(bool) - } else { - req.Permanently = false - } - - _, err = c.CloudBroker().K8S().Delete(ctx, req) - if err != nil { - return diag.FromErr(err) - } - - return nil -} - -func resourceK8sSchemaMake() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - Description: "Name of the cluster.", - }, - - "rg_id": { - Type: schema.TypeInt, - Required: true, - ForceNew: true, - Description: "Resource group ID that this instance belongs to.", - }, - - "k8sci_id": { - Type: schema.TypeInt, - Required: true, - ForceNew: true, - Description: "ID of the k8s catalog item to base this instance on.", - }, - - "wg_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - Description: "Name for first worker group created with cluster.", - }, - - "masters": { - Type: schema.TypeList, - Optional: true, - ForceNew: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: nodeK8sSubresourceSchemaMake(), - }, - Description: "Master node(s) configuration.", - }, - - "workers": { - Type: schema.TypeList, - Optional: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: nodeK8sSubresourceSchemaMake(), - }, - Description: "Worker node(s) configuration.", - }, - - //"with_lb": { - //Type: schema.TypeBool, - //Optional: true, - //ForceNew: true, - //Default: true, - //Description: "Create k8s with load balancer if true.", - //}, - - "extnet_id": { - Type: schema.TypeInt, - Optional: true, - Computed: true, - ForceNew: true, - Description: "ID of the external network to connect workers to. If omitted network will be chosen by the platfom.", - }, - - //"desc": { - //Type: schema.TypeString, - //Optional: true, - //Description: "Text description of this instance.", - //}, - - "lb_ip": { - Type: schema.TypeString, - Computed: true, - Description: "IP address of default load balancer.", - }, - - "default_wg_id": { - Type: schema.TypeInt, - Computed: true, - Description: "ID of default workers group for this instace.", - }, - - "kubeconfig": { - Type: schema.TypeString, - Computed: true, - Description: "Kubeconfig for cluster access.", - }, - } -} - -func ResourceK8s() *schema.Resource { - return &schema.Resource{ - SchemaVersion: 1, - - CreateContext: resourceK8sCreate, - ReadContext: resourceK8sRead, - UpdateContext: resourceK8sUpdate, - DeleteContext: resourceK8sDelete, - - Importer: &schema.ResourceImporter{ - StateContext: schema.ImportStatePassthroughContext, - }, - - Timeouts: &schema.ResourceTimeout{ - Create: &constants.Timeout20m, - Read: &constants.Timeout30s, - Update: &constants.Timeout20m, - Delete: &constants.Timeout60s, - Default: &constants.Timeout60s, - }, - - Schema: resourceK8sSchemaMake(), - } -} diff --git a/internal/service/cloudbroker/k8s/resource_k8s_cp.go b/internal/service/cloudbroker/k8s/resource_k8s_cp.go new file mode 100644 index 0000000..e0773e7 --- /dev/null +++ b/internal/service/cloudbroker/k8s/resource_k8s_cp.go @@ -0,0 +1,554 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, +Tim Tkachev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package k8s + +import ( + "context" + "fmt" + "strconv" + "strings" + "time" + + "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/cloudbroker/compute" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/tasks" + "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/dc" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/status" +) + +func resourceK8sCPCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("resourceK8sControlPlaneCreate: called with name %s, rg %d", d.Get("name").(string), d.Get("rg_id").(int)) + + c := m.(*controller.ControllerCfg) + + if diags := checkParamsExistence(ctx, d, c); diags != nil { + return diags + } + + createReq := k8s.CreateRequest{ + Name: d.Get("name").(string), + RGID: uint64(d.Get("rg_id").(int)), + K8CIID: uint64(d.Get("k8sci_id").(int)), + WorkerGroupName: "temp", + NetworkPlugin: d.Get("network_plugin").(string), + } + + if num, ok := d.GetOk("num"); ok { + createReq.MasterNum = uint64(num.(int)) + } else { + createReq.MasterNum = 1 + } + + if cpu, ok := d.GetOk("cpu"); ok { + createReq.MasterCPU = uint64(cpu.(int)) + } else { + createReq.MasterCPU = 2 + } + + if ram, ok := d.GetOk("ram"); ok { + createReq.MasterRAM = uint64(ram.(int)) + } else { + createReq.MasterRAM = 2048 + } + + if disk, ok := d.GetOk("disk"); ok { + createReq.MasterDisk = uint64(disk.(int)) + } else { + createReq.MasterDisk = 0 + } + + if sepId, ok := d.GetOk("sep_id"); ok { + createReq.MasterSEPID = uint64(sepId.(int)) + } + + if sepPool, ok := d.GetOk("sep_pool"); ok { + createReq.MasterSEPPool = sepPool.(string) + } + + if withLB, ok := d.GetOk("with_lb"); ok { + createReq.WithLB = withLB.(bool) + } else { + createReq.WithLB = true + } + + if extNet, ok := d.GetOk("extnet_id"); ok { + createReq.ExtNetID = uint64(extNet.(int)) + } else { + createReq.ExtNetID = 0 + } + + if vins, ok := d.GetOk("vins_id"); ok { + createReq.VinsId = uint64(vins.(int)) + } else { + createReq.VinsId = 0 + } + + if haMode, ok := d.GetOk("ha_mode"); ok { + createReq.HighlyAvailable = haMode.(bool) + } + + if additionalSans, ok := d.GetOk("additional_sans"); ok { + addSans := additionalSans.([]interface{}) + resSans := make([]string, 0) + for _, san := range addSans { + resSans = append(resSans, san.(string)) + } + + createReq.AdditionalSANs = resSans + } + + if clusterConfig, ok := d.GetOk("cluster_config"); ok { + createReq.ClusterConfiguration = clusterConfig.(string) + } + + if kubeletConfig, ok := d.GetOk("kubelet_config"); ok { + createReq.KubeletConfiguration = kubeletConfig.(string) + } + + if kubeProxyConfig, ok := d.GetOk("kube_proxy_config"); ok { + createReq.KubeProxyConfiguration = kubeProxyConfig.(string) + } + + if joinConfig, ok := d.GetOk("join_config"); ok { + createReq.JoinConfiguration = joinConfig.(string) + } + + if initConfig, ok := d.GetOk("init_config"); ok { + createReq.InitConfiguration = initConfig.(string) + } + + if oidcCertificate, ok := d.GetOk("oidc_cert"); ok { + createReq.OidcCertificate = oidcCertificate.(string) + } + + if extNetOnly, ok := d.GetOk("extnet_only"); ok { + createReq.ExtNetOnly = extNetOnly.(bool) + } + + if desc, ok := d.GetOk("desc"); ok { + createReq.Description = desc.(string) + } + + resp, err := c.CloudBroker().K8S().Create(ctx, createReq) + if err != nil { + return diag.FromErr(err) + } + + taskReq := tasks.GetRequest{ + AuditID: strings.Trim(resp, `"`), + } + + for { + task, err := c.CloudBroker().Tasks().Get(ctx, taskReq) + if err != nil { + return diag.FromErr(err) + } + + log.Debugf("resourceK8sControlPlaneCreate: instance creating - %s", task.Stage) + + if task.Completed { + if task.Error != "" { + return diag.FromErr(fmt.Errorf("cannot create k8s instance: %v", task.Error)) + } + + d.SetId(strconv.Itoa(int(task.Result))) + break + } + + time.Sleep(time.Second * 20) + } + + cluster, err := utilityK8sCheckPresence(ctx, d, m) + if err != nil { + return diag.FromErr(err) + } + + delWGReq := k8s.WorkersGroupDeleteRequest{ + K8SID: cluster.ID, + WorkersGroupID: cluster.K8SGroups.Workers[0].ID, + } + + _, err = c.CloudBroker().K8S().WorkersGroupDelete(ctx, delWGReq) + if err != nil { + return diag.FromErr(err) + } + + return resourceK8sCPRead(ctx, d, m) +} + +func resourceK8sCPRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("resourceK8sCPRead: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int)) + + k8sData, err := utilityK8sCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + switch k8sData.Status { + case status.Modeled: + return diag.Errorf("The k8s cluster is in status: %s, please, contact support for more information", k8sData.Status) + case status.Destroying: + return diag.Errorf("The k8s cluster is in progress with status: %s", k8sData.Status) + case status.Destroyed: + d.SetId("") + return diag.Errorf("The resource cannot be updated because it has been destroyed") + case status.Disabled: + log.Debugf("The k8s cluster is in status: %s, troubles may occur with update. Please, enable compute first.", k8sData.Status) + } + c := m.(*controller.ControllerCfg) + + if d.Get("start").(bool) { + if k8sData.TechStatus == "STOPPED" { + req := k8s.StartRequest{ + K8SID: k8sData.ID, + } + _, err := c.CloudBroker().K8S().Start(ctx, req) + if err != nil { + return diag.FromErr(err) + } + } + } + + k8sList, err := utilityK8sListCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + curK8s := k8s.ItemK8S{} + for _, k8sCluster := range k8sList.Data { + if k8sCluster.ID == k8sData.ID { + curK8s = k8sCluster + } + } + if curK8s.ID == 0 { + return diag.Errorf("Cluster with id %d not found", k8sData.ID) + } + + d.Set("vins_id", curK8s.VINSID) + + masterComputeList := make([]compute.RecordCompute, 0, len(k8sData.K8SGroups.Masters.DetailedInfo)) + for _, masterNode := range k8sData.K8SGroups.Masters.DetailedInfo { + compute, err := utilityComputeCheckPresence(ctx, d, m, masterNode.ID) + if err != nil { + return diag.FromErr(err) + } + masterComputeList = append(masterComputeList, *compute) + } + + var warnings dc.Warnings + + if _, ok := d.GetOk("k8s_id"); !ok { + for _, worker := range k8sData.K8SGroups.Workers { + err := fmt.Errorf("found worker-group with ID %d. Make sure to import it to decort_k8s_wg resource if you wish to manage it", worker.ID) + warnings.Add(err) + } + } + + flattenResourceK8sCP(d, *k8sData, masterComputeList) + + lbGetReq := lb.GetRequest{ + LBID: k8sData.LBID, + } + + if d.Get("with_lb").(bool) || k8sData.LBID != 0 { + lb, err := c.CloudBroker().LB().Get(ctx, lbGetReq) + if err != nil { + return diag.FromErr(err) + } + + d.Set("extnet_id", lb.ExtNetID) + d.Set("lb_ip", lb.PrimaryNode.FrontendIP) + } + + kubeconfigReq := k8s.GetConfigRequest{ + K8SID: k8sData.ID, + } + + kubeconfig, err := c.CloudBroker().K8S().GetConfig(ctx, kubeconfigReq) + if err != nil { + log.Warnf("could not get kubeconfig: %v", err) + } + + d.Set("kubeconfig", kubeconfig) + + return warnings.Get() +} + +func resourceK8sCPUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("resourceK8sControlPlaneUpdate: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int)) + + c := m.(*controller.ControllerCfg) + + if diags := checkParamsExistence(ctx, d, c); diags != nil { + return diags + } + + k8sData, err := utilityK8sCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + hasChanged := false + + switch k8sData.Status { + case status.Modeled: + return diag.Errorf("The k8s cluster is in status: %s, please, contact support for more information", k8sData.Status) + case status.Deleted: + err := handleRestore(ctx, d, c, k8sData) + if err != nil { + return diag.FromErr(err) + } + hasChanged = true + case status.Destroying: + return diag.Errorf("The k8s cluster is in progress with status: %s", k8sData.Status) + case status.Destroyed: + d.SetId("") + return diag.Errorf("The resource cannot be updated because it has been destroyed") + case status.Disabled: + log.Debugf("The k8s cluster is in status: %s, troubles may occur with update. Please, enable compute first.", k8sData.Status) + } + + if hasChanged { + k8sData, err = utilityK8sCheckPresence(ctx, d, m) + if k8sData == nil { + d.SetId("") + if err != nil { + return diag.FromErr(err) + } + return nil + } + } + + if d.HasChanges("name", "desc") { + err := handleUpdate(ctx, d, c, k8sData) + if err != nil { + return diag.FromErr(err) + } + } + + if d.HasChange("enabled") { + err := handleEnable(ctx, c, d.Get("enabled").(bool), k8sData.ID) + if err != nil { + return diag.FromErr(err) + } + } + + if d.HasChange("start") { + err := handleStart(ctx, c, d.Get("start").(bool), k8sData) + if err != nil { + return diag.FromErr(err) + } + } + + if d.HasChange("num") { + err := handleUpdateNum(ctx, d, c, k8sData) + if err != nil { + return diag.FromErr(err) + } + } + + return nil +} + +func resourceK8sCPDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("resourceK8sControlPlaneDelete: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int)) + + k8sData, err := utilityK8sCheckPresence(ctx, d, m) + if err != nil { + return diag.FromErr(err) + } + + c := m.(*controller.ControllerCfg) + req := k8s.DeleteRequest{ + K8SID: k8sData.ID, + Permanently: d.Get("permanently").(bool), + } + + _, err = c.CloudBroker().K8S().Delete(ctx, req) + if err != nil { + return diag.FromErr(err) + } + + d.SetId("") + + return nil +} + +func ResourceK8sCP() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + CreateContext: resourceK8sCPCreate, + ReadContext: resourceK8sCPRead, + UpdateContext: resourceK8sCPUpdate, + DeleteContext: resourceK8sCPDelete, + + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: &constants.Timeout30m, + Read: &constants.Timeout600s, + Update: &constants.Timeout600s, + Delete: &constants.Timeout600s, + Default: &constants.Timeout600s, + }, + + Schema: resourceK8sCPSchemaMake(), + } +} + +func handleUpdateNum(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, k8sData *k8s.RecordK8S) error { + + oldVal, newVal := d.GetChange("num") + + if oldVal.(int) > newVal.(int) { + ids := make([]string, 0) + for i := oldVal.(int) - 1; i >= newVal.(int); i-- { + id := k8sData.K8SGroups.Masters.DetailedInfo[i].ID + ids = append(ids, strconv.FormatUint(id, 10)) + } + + req := k8s.DeleteMasterFromGroupRequest{ + K8SID: k8sData.ID, + MasterGroupID: k8sData.K8SGroups.Masters.ID, + MasterIDs: ids, + } + + _, err := c.CloudBroker().K8S().DeleteMasterFromGroup(ctx, req) + if err != nil { + return err + } + } + + return nil +} + +func handleUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, k8sData *k8s.RecordK8S) error { + updateReq := k8s.UpdateRequest{K8SID: k8sData.ID} + + if d.HasChange("name") { + updateReq.Name = d.Get("name").(string) + } + + if d.HasChange("desc") { + updateReq.Description = d.Get("desc").(string) + } + + _, err := c.CloudBroker().K8S().Update(ctx, updateReq) + if err != nil { + return err + } + + return nil +} + +func handleRestore(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, k8sData *k8s.RecordK8S) error { + + if restore, ok := d.GetOk("restore"); ok && restore.(bool) { + restoreReq := k8s.RestoreRequest{ + K8SID: k8sData.ID, + } + + _, err := c.CloudBroker().K8S().Restore(ctx, restoreReq) + if err != nil { + return err + } + + err = handleEnable(ctx, c, d.Get("enabled").(bool), k8sData.ID) + if err != nil { + return err + } + + err = handleStart(ctx, c, d.Get("start").(bool), k8sData) + if err != nil { + return err + } + } + + return nil +} + +func handleEnable(ctx context.Context, c *controller.ControllerCfg, enable bool, k8sId uint64) error { + if enable { + enableReq := k8s.EnableRequest{K8SID: k8sId} + + _, err := c.CloudBroker().K8S().Enable(ctx, enableReq) + if err != nil { + return err + } + + } else { + disableReq := k8s.DisableRequest{K8SID: k8sId} + + _, err := c.CloudBroker().K8S().Disable(ctx, disableReq) + if err != nil { + return err + } + } + return nil +} + +func handleStart(ctx context.Context, c *controller.ControllerCfg, start bool, k8sData *k8s.RecordK8S) error { + if start { + if k8sData.TechStatus == "STOPPED" { + startReq := k8s.StartRequest{K8SID: k8sData.ID} + + _, err := c.CloudBroker().K8S().Start(ctx, startReq) + if err != nil { + return err + } + } + } else { + if k8sData.TechStatus == "STARTED" { + stopReq := k8s.StopRequest{K8SID: k8sData.ID} + + _, err := c.CloudBroker().K8S().Stop(ctx, stopReq) + if err != nil { + return err + } + } + } + return nil +} diff --git a/internal/service/cloudbroker/k8s/schema.go b/internal/service/cloudbroker/k8s/schema.go new file mode 100644 index 0000000..724b4cb --- /dev/null +++ b/internal/service/cloudbroker/k8s/schema.go @@ -0,0 +1,1836 @@ +package k8s + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +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 +*/ + +func dataSourceK8sComputesSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "k8s_id": { + Type: schema.TypeInt, + Required: true, + }, + "masters": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "group_name": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "workers": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "group_name": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + } +} + +func dataSourceK8sListDeletedSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "ip_address": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by ipAddress", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by RGID", + }, + "lb_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by LBID", + }, + "basic_service_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by BasicServiceID", + }, + "tech_status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by Tech Status", + }, + "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, + }, + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "bservice_id": { + Type: schema.TypeInt, + Computed: true, + }, + "k8sci_id": { + 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, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "extnet_id": { + Type: schema.TypeInt, + Computed: true, + Description: "ID of the external network to connect workers to. If omitted network will be chosen by the platfom.", + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "k8s_id": { + Type: schema.TypeInt, + Computed: true, + }, + "kubeconfig": { + Type: schema.TypeString, + Computed: true, + Description: "Kubeconfig for cluster access.", + }, + "lb_id": { + Type: schema.TypeInt, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "network_plugin": { + Type: schema.TypeString, + Computed: true, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + }, + "service_account": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "password": { + Type: schema.TypeString, + Computed: true, + }, + "username": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "ssh_key": { + 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, + }, + "vins_id": { + Type: schema.TypeInt, + Computed: true, + }, + "workers_groups": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "annotations": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "detailed_info": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "external_ip": { + Type: schema.TypeString, + Computed: true, + }, + "compute_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, + }, + "interfaces": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "def_gw": { + Type: schema.TypeString, + Computed: true, + }, + "ip_address": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "disk": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "id": { + Type: schema.TypeInt, + Computed: true, + }, + "labels": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "num": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "taints": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + }, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } +} + +func dataSourceK8sListSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "ip_address": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by ipAddress", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by RGID", + }, + "lb_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by LBID", + }, + "basic_service_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by BasicServiceID", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by status", + }, + "tech_status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by Tech Status", + }, + "include_deleted": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Include deleted k8s in result", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Computed: true, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "bservice_id": { + Type: schema.TypeInt, + Computed: true, + }, + "k8sci_id": { + 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, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "extnet_id": { + Type: schema.TypeInt, + Computed: true, + Description: "ID of the external network to connect workers to. If omitted network will be chosen by the platfom.", + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "k8s_id": { + Type: schema.TypeInt, + Computed: true, + }, + "kubeconfig": { + Type: schema.TypeString, + Computed: true, + Description: "Kubeconfig for cluster access.", + }, + "lb_id": { + Type: schema.TypeInt, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "k8s_name": { + Type: schema.TypeString, + Computed: true, + }, + "network_plugin": { + Type: schema.TypeString, + Computed: true, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + }, + "service_account": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "password": { + Type: schema.TypeString, + Computed: true, + }, + "username": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "ssh_key": { + 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, + }, + "vins_id": { + Type: schema.TypeInt, + Computed: true, + }, + "workers_groups": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "annotations": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "id": { + Type: schema.TypeInt, + Computed: true, + }, + "labels": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "taints": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + }, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } +} + +func dataSourceK8sWgCloudInitSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "k8s_id": { + Type: schema.TypeInt, + Required: true, + Description: "Kubernetes cluster ID", + }, + "wg_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the workers compute group", + }, + "cloud_init": { + Type: schema.TypeString, + Computed: true, + Description: "Worker group Cloud init", + }, + } +} + +func dataSourceK8sWgListSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "k8s_id": { + Type: schema.TypeInt, + Required: true, + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "annotations": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "detailed_info": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "external_ip": { + Type: schema.TypeString, + Computed: true, + }, + "compute_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, + }, + "interfaces": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "def_gw": { + Type: schema.TypeString, + Computed: true, + }, + "ip_address": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "disk": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "wg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "labels": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "num": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "taints": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + }, + }, + } +} + +func dataSourceK8sWgSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "k8s_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of k8s instance.", + }, + "wg_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of k8s worker Group.", + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "Name of the worker group.", + }, + "num": { + Type: schema.TypeInt, + Computed: true, + Description: "Number of worker nodes to create.", + }, + "cpu": { + Type: schema.TypeInt, + Computed: true, + Description: "Worker node CPU count.", + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + Description: "Worker node RAM in MB.", + }, + "disk": { + Type: schema.TypeInt, + Computed: true, + Description: "Worker node boot disk size. If unspecified or 0, size is defined by OS image size.", + }, + "detailed_info": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "external_ip": { + Type: schema.TypeString, + Computed: true, + }, + "compute_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, + }, + "interfaces": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "def_gw": { + Type: schema.TypeString, + Computed: true, + }, + "ip_address": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "labels": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "annotations": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "taints": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + } +} + +func dataSourceK8sSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "k8s_id": { + Type: schema.TypeInt, + Required: true, + }, + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "account_acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "k8s_acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "rg_acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "bservice_id": { + Type: schema.TypeInt, + Computed: true, + }, + "k8sci_id": { + 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, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "extnet_id": { + Type: schema.TypeInt, + Computed: true, + Description: "ID of the external network to connect workers to. If omitted network will be chosen by the platfom.", + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "k8s_ci_name": { + Type: schema.TypeString, + Computed: true, + }, + "k8s_groups": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "masters": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "detailed_info": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "external_ip": { + Type: schema.TypeString, + Computed: true, + }, + "compute_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, + }, + "interfaces": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "def_gw": { + Type: schema.TypeString, + Computed: true, + }, + "ip_address": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "disk": { + Type: schema.TypeInt, + Computed: true, + }, + "master_id": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "num": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "workers": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "annotations": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "detailed_info": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "external_ip": { + Type: schema.TypeString, + Computed: true, + }, + "compute_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, + }, + "interfaces": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "def_gw": { + Type: schema.TypeString, + Computed: true, + }, + "ip_address": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "disk": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "id": { + Type: schema.TypeInt, + Computed: true, + }, + "labels": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "num": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "taints": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + }, + }, + }, + }, + }, + "kubeconfig": { + Type: schema.TypeString, + Computed: true, + Description: "Kubeconfig for cluster access.", + }, + "lb_id": { + Type: schema.TypeInt, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "lb_ip": { + Type: schema.TypeString, + Computed: true, + Description: "IP address of default load balancer.", + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "network_plugin": { + Type: schema.TypeString, + Computed: true, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + }, + "service_account": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "password": { + Type: schema.TypeString, + Computed: true, + }, + "username": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "ssh_key": { + 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, + }, + "vins_id": { + Type: schema.TypeInt, + Computed: true, + }, + } +} + +func resourceK8sCPSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "Name of the cluster.", + }, + "rg_id": { + Type: schema.TypeInt, + Required: true, + Description: "Resource group ID that this instance belongs to.", + }, + "k8sci_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the k8s catalog item to base this instance on.", + }, + "network_plugin": { + Type: schema.TypeString, + Required: true, + Description: "Network plugin to be used", + ValidateFunc: validation.StringInSlice([]string{"flannel", "weavenet", "calico"}, true), + }, + "num": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + ValidateFunc: validation.IntInSlice([]int{1, 3}), + Description: "Number of VMs to create. Can be either 1 or 3", + }, + "cpu": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Node CPU count.", + }, + "ram": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Node RAM in MB.", + }, + "disk": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Node boot disk size in GB.", + }, + "sep_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Storage Endpoint ID", + }, + "sep_pool": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Storage Endpoint Pool", + }, + "with_lb": { + Type: schema.TypeBool, + Optional: true, + Default: true, + Description: "Create k8s with load balancer if true.", + }, + "extnet_only": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Use only selected ExtNet for infrastructure connections", + }, + "join_config": { + Type: schema.TypeString, + Optional: true, + Description: "is used to configure the behavior and settings for joining a node to a cluster. It includes parameters such as the cluster's control plane endpoint, token, and certificate key. insert a valid JSON string with all levels of nesting.", + }, + "kube_proxy_config": { + Type: schema.TypeString, + Optional: true, + Description: "is used to configure the behavior and settings of the Kube-proxy, which is responsible for network proxying and load balancing within the cluster. It includes parameters such as proxy mode, cluster IP ranges, and other Kube-proxy specific configurations. insert a valid JSON string with all levels of nesting.", + }, + "kubelet_config": { + Type: schema.TypeString, + Optional: true, + Description: "is used to configure the behavior and settings of the Kubelet, which is the primary node agent that runs on each node in the cluster. It includes parameters such as node IP address, resource allocation, pod eviction policies, and other Kubelet-specific configurations. insert a valid JSON string with all levels of nesting.", + }, + "cluster_config": { + Type: schema.TypeString, + Optional: true, + Description: "is used to define global settings and configurations for the entire cluster. It includes parameters such as cluster name, DNS settings, authentication methods, and other cluster-wide configurations. insert a valid JSON string with all levels of nesting.", + }, + "init_config": { + Type: schema.TypeString, + Optional: true, + Description: "is used to define settings and actions that should be performed before any other component in the cluster starts. It allows you to configure things like node registration, network setup, and other initialization tasks. insert a valid JSON string with all levels of nesting.", + }, + "additional_sans": { + Type: schema.TypeList, + Optional: true, + Description: "Optional extra Subject Alternative Names (SANs) to use for the API Server serving certificate. Can be both IP addresses and DNS names", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "ha_mode": { + Type: schema.TypeBool, + Optional: true, + Description: "Use Highly Available schema for LB deploy", + }, + "oidc_cert": { + Type: schema.TypeString, + Optional: true, + Description: "insert ssl certificate in x509 pem format", + }, + "extnet_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "ID of the external network to connect workers to. If omitted network will be chosen by the platfom.", + }, + "vins_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "ID of default vins for this instace.", + }, + "desc": { + Type: schema.TypeString, + Optional: true, + Description: "Text description of this instance.", + }, + "start": { + Type: schema.TypeBool, + Optional: true, + Default: true, + Description: "Start k8s cluster.", + }, + "enabled": { + Type: schema.TypeBool, + Optional: true, + Default: true, + Description: "Enable k8s cluster", + }, + "permanently": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "whether to completely delete the account", + }, + "restore": { + Type: schema.TypeBool, + Optional: true, + }, + "detailed_info": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "compute_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, + }, + "interfaces": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "def_gw": { + Type: schema.TypeString, + Computed: true, + }, + "ip_address": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "master_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Master group ID.", + }, + "master_name": { + Type: schema.TypeString, + Computed: true, + Description: "Master group name.", + }, + "lb_ip": { + Type: schema.TypeString, + Computed: true, + Description: "IP address of default load balancer.", + }, + "default_wg_id": { + Type: schema.TypeInt, + Computed: true, + Description: "ID of default workers group for this instace.", + }, + "kubeconfig": { + Type: schema.TypeString, + Computed: true, + Description: "Kubeconfig for cluster access.", + }, + "k8s_id": { + Type: schema.TypeInt, + Computed: true, + }, + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "account_acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "k8s_acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "rg_acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "bservice_id": { + 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, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "k8s_ci_name": { + Type: schema.TypeString, + Computed: true, + }, + "lb_id": { + Type: schema.TypeInt, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + }, + "ssh_key": { + 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, + }, + } +} + +func resourceK8sWgSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "k8s_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of k8s instance.", + }, + "name": { + Type: schema.TypeString, + Required: true, + Description: "Name of the worker group.", + }, + "num": { + Type: schema.TypeInt, + Optional: true, + Default: 1, + Description: "Number of worker nodes to create.", + }, + "cpu": { + Type: schema.TypeInt, + Optional: true, + Default: 1, + Description: "Worker node CPU count.", + }, + "ram": { + Type: schema.TypeInt, + Optional: true, + Default: 1024, + Description: "Worker node RAM in MB.", + }, + "disk": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Worker node boot disk size. If unspecified or 0, size is defined by OS image size.", + }, + "labels": { + Type: schema.TypeList, + Computed: true, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "annotations": { + Type: schema.TypeList, + Computed: true, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "taints": { + Type: schema.TypeList, + Computed: true, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "worker_sep_id": { + Type: schema.TypeInt, + Optional: true, + }, + "worker_sep_pool": { + Type: schema.TypeString, + Optional: true, + }, + "cloud_init": { + Type: schema.TypeString, + Optional: true, + DiffSuppressFunc: cloudInitDiffSupperss, + }, + "wg_id": { + Type: schema.TypeInt, + Computed: true, + Description: "ID of k8s worker Group.", + }, + "detailed_info": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "compute_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, + }, + "interfaces": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "def_gw": { + Type: schema.TypeString, + Computed: true, + }, + "ip_address": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + } +} diff --git a/internal/service/cloudbroker/k8s/utility_k8s_list.go b/internal/service/cloudbroker/k8s/utility_k8s_list.go new file mode 100644 index 0000000..3491a2a --- /dev/null +++ b/internal/service/cloudbroker/k8s/utility_k8s_list.go @@ -0,0 +1,86 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package k8s + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityK8sListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8s.ListK8S, error) { + c := m.(*controller.ControllerCfg) + req := k8s.ListRequest{} + + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + if ip_address, ok := d.GetOk("ip_address"); ok { + req.IPAddress = ip_address.(string) + } + if rg_id, ok := d.GetOk("rg_id"); ok { + req.RGID = uint64(rg_id.(int)) + } + if lb_id, ok := d.GetOk("lb_id"); ok { + req.LBID = uint64(lb_id.(int)) + } + if bservice_id, ok := d.GetOk("bservice_id"); ok { + req.BasicServiceID = uint64(bservice_id.(int)) + } + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } + if tech_status, ok := d.GetOk("tech_status"); ok { + req.TechStatus = tech_status.(string) + } + if includeDeleted, ok := d.GetOk("include_deleted"); ok { + req.IncludeDeleted = includeDeleted.(bool) + } + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + + k8sList, err := c.CloudBroker().K8S().List(ctx, req) + if err != nil { + return nil, err + } + + return k8sList, nil +} diff --git a/internal/service/cloudbroker/k8s/utility_k8s_list_deleted.go b/internal/service/cloudbroker/k8s/utility_k8s_list_deleted.go new file mode 100644 index 0000000..4e5a25d --- /dev/null +++ b/internal/service/cloudbroker/k8s/utility_k8s_list_deleted.go @@ -0,0 +1,80 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki +*/ + +package k8s + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityK8sListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8s.ListK8S, error) { + c := m.(*controller.ControllerCfg) + req := k8s.ListDeletedRequest{} + + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + if ip_address, ok := d.GetOk("ip_address"); ok { + req.IPAddress = ip_address.(string) + } + if rg_id, ok := d.GetOk("rg_id"); ok { + req.RGID = uint64(rg_id.(int)) + } + if lb_id, ok := d.GetOk("lb_id"); ok { + req.LBID = uint64(lb_id.(int)) + } + if bservice_id, ok := d.GetOk("bservice_id"); ok { + req.BasicServiceID = uint64(bservice_id.(int)) + } + if tech_status, ok := d.GetOk("tech_status"); ok { + req.TechStatus = tech_status.(string) + } + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + + k8sList, err := c.CloudBroker().K8S().ListDeleted(ctx, req) + if err != nil { + return nil, err + } + + return k8sList, nil +} diff --git a/internal/service/cloudbroker/kvmvm/data_source_compute_affinity_relations.go b/internal/service/cloudbroker/kvmvm/data_source_compute_affinity_relations.go new file mode 100644 index 0000000..00b710b --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/data_source_compute_affinity_relations.go @@ -0,0 +1,71 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceComputeAffinityRelationsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + affinityRelationsList, err := utilityComputeAffinityRelationsCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + flattenAffinityRelations(d, affinityRelationsList) + + return nil +} + +func DataSourceComputeAffinityRelations() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceComputeAffinityRelationsRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceComputeAffinityRelationsSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/kvmvm/data_source_compute_audits.go b/internal/service/cloudbroker/kvmvm/data_source_compute_audits.go new file mode 100644 index 0000000..892c74f --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/data_source_compute_audits.go @@ -0,0 +1,69 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceComputeAuditsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + computeAudits, err := utilityComputeAuditsCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenComputeAudits(computeAudits)) + return nil +} + +func DataSourceComputeAudits() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceComputeAuditsRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceComputeAuditsSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/kvmvm/data_source_compute_boot_order_get.go b/internal/service/cloudbroker/kvmvm/data_source_compute_boot_order_get.go new file mode 100644 index 0000000..e75d4a5 --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/data_source_compute_boot_order_get.go @@ -0,0 +1,70 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceComputeBootOrderGetRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + result, err := utilityComputeBootOrderGetCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("boot_order", result) + + return nil +} + +func DataSourceComputeBootOrderGet() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceComputeBootOrderGetRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceComputeBootOrderGetSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/kvmvm/data_source_compute_get_audits.go b/internal/service/cloudbroker/kvmvm/data_source_compute_get_audits.go new file mode 100644 index 0000000..2f10b03 --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/data_source_compute_get_audits.go @@ -0,0 +1,69 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceComputeGetAuditsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + computeAudits, err := utilityComputeGetAuditsCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenComputeGetAudits(computeAudits)) + return nil +} + +func DataSourceComputeGetAudits() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceComputeGetAuditsRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceComputeGetAuditsSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/kvmvm/data_source_compute_get_console_url.go b/internal/service/cloudbroker/kvmvm/data_source_compute_get_console_url.go new file mode 100644 index 0000000..cdc9812 --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/data_source_compute_get_console_url.go @@ -0,0 +1,74 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + "strings" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceComputeGetConsoleUrlRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + computeConsoleUrl, err := utilityComputeGetConsoleUrlCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + result := strings.ReplaceAll(computeConsoleUrl, "\"", "") + result = strings.ReplaceAll(result, "\\", "") + d.Set("console_url", result) + + return nil +} + +func DataSourceComputeGetConsoleUrl() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceComputeGetConsoleUrlRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceComputeGetConsoleUrlSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/kvmvm/data_source_compute_get_log.go b/internal/service/cloudbroker/kvmvm/data_source_compute_get_log.go new file mode 100644 index 0000000..1b7583c --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/data_source_compute_get_log.go @@ -0,0 +1,71 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceComputeGetLogRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + computeGetLog, err := utilityComputeGetLogCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("log", computeGetLog) + + return nil +} + +func DataSourceComputeGetLog() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceComputeGetLogRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceComputeGetLogSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/kvmvm/data_source_compute_list.go b/internal/service/cloudbroker/kvmvm/data_source_compute_list.go new file mode 100644 index 0000000..4b69585 --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/data_source_compute_list.go @@ -0,0 +1,77 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceComputeListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + computeList, err := utilityDataComputeListCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + result := computeList + if d.Get("ignore_k8s").(bool) { + // matches automatically generated names like "s234-g2134-c1" etc + result = matchComputes(computeList) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenComputeList(result)) + d.Set("entry_count", computeList.EntryCount) + + return nil +} + +func DataSourceComputeList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceComputeListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceComputeListSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/kvmvm/data_source_compute_list_deleted.go b/internal/service/cloudbroker/kvmvm/data_source_compute_list_deleted.go new file mode 100644 index 0000000..19ba391 --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/data_source_compute_list_deleted.go @@ -0,0 +1,78 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceComputeListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + computeList, err := utilityDataComputeListDeletedCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + result := computeList + if d.Get("ignore_k8s").(bool) { + // matches automatically generated names like "s234-g2134-c1" etc + result = matchComputes(computeList) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenComputeList(result)) + d.Set("entry_count", computeList.EntryCount) + + return nil +} + +func DataSourceComputeListDeleted() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceComputeListDeletedRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceComputeListDeletedSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/kvmvm/data_source_compute_migrate_storage_info.go b/internal/service/cloudbroker/kvmvm/data_source_compute_migrate_storage_info.go new file mode 100644 index 0000000..6706ff4 --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/data_source_compute_migrate_storage_info.go @@ -0,0 +1,70 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceComputeMigrateStorageInfoRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + result, err := utilityComputeMigrateStorageInfoCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("migrate_storage_info", result) + + return nil +} + +func DataSourceComputeMigrateStorageInfo() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceComputeMigrateStorageInfoRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceComputeMigrateStorageInfoSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/kvmvm/data_source_compute_pci_device_list.go b/internal/service/cloudbroker/kvmvm/data_source_compute_pci_device_list.go new file mode 100644 index 0000000..d799e3d --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/data_source_compute_pci_device_list.go @@ -0,0 +1,72 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceComputePCIDeviceListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + computePCIDeviceList, err := utilityComputePCIDeviceListCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenPCIDevice(computePCIDeviceList.Data)) + d.Set("entry_count", computePCIDeviceList.EntryCount) + + return nil +} + +func DataSourceComputePCIDeviceList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceComputePCIDeviceListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceComputePCIDeviceListSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/kvmvm/data_source_compute_pfw_list.go b/internal/service/cloudbroker/kvmvm/data_source_compute_pfw_list.go new file mode 100644 index 0000000..4f55b6e --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/data_source_compute_pfw_list.go @@ -0,0 +1,72 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceComputePfwListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + computePfwList, err := utilityComputePfwListCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenPfwList(computePfwList)) + d.Set("entry_count", computePfwList.EntryCount) + + return nil +} + +func DataSourceComputePfwList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceComputePfwListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceComputePfwListSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/kvmvm/data_source_compute_snapshot_list.go b/internal/service/cloudbroker/kvmvm/data_source_compute_snapshot_list.go new file mode 100644 index 0000000..f0cc248 --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/data_source_compute_snapshot_list.go @@ -0,0 +1,72 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceComputeSnapshotListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + computeSnapshotList, err := utilityComputeSnapshotListCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenSnapshotList(computeSnapshotList)) + d.Set("entry_count", computeSnapshotList.EntryCount) + + return nil +} + +func DataSourceComputeSnapshotList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceComputeSnapshotListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceComputeSnapshotListSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/kvmvm/data_source_compute_snapshot_usage.go b/internal/service/cloudbroker/kvmvm/data_source_compute_snapshot_usage.go new file mode 100644 index 0000000..2986453 --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/data_source_compute_snapshot_usage.go @@ -0,0 +1,71 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceComputeSnapshotUsageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + computeSnapshotUsage, err := utilityComputeSnapshotUsageCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenSnapshotUsage(*computeSnapshotUsage)) + + return nil +} + +func DataSourceComputeSnapshotUsage() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceComputeSnapshotUsageRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceComputeSnapshotUsageSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/kvmvm/data_source_compute_user_list.go b/internal/service/cloudbroker/kvmvm/data_source_compute_user_list.go new file mode 100644 index 0000000..acc701f --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/data_source_compute_user_list.go @@ -0,0 +1,71 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceComputeUserListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + computeUserList, err := utilityComputeUserListCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + flattenUserList(d, computeUserList) + + return nil +} + +func DataSourceComputeUserList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceComputeUserListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceComputeUserListSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/kvmvm/data_source_compute_vgpu_list.go b/internal/service/cloudbroker/kvmvm/data_source_compute_vgpu_list.go new file mode 100644 index 0000000..ba26c75 --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/data_source_compute_vgpu_list.go @@ -0,0 +1,72 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceComputeVGPUListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + computeVGPUList, err := utilityComputeVGPUListCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenVGPU(computeVGPUList.Data)) + d.Set("entry_count", computeVGPUList.EntryCount) + + return nil +} + +func DataSourceComputeVGPUList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceComputeVGPUListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceComputeVGPUListSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/kvmvm/schema.go b/internal/service/cloudbroker/kvmvm/schema.go new file mode 100644 index 0000000..4a2be6e --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/schema.go @@ -0,0 +1,3398 @@ +package kvmvm + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/statefuncs" +) + +func dataSourceComputeSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "compute_id": { + Type: schema.TypeInt, + Required: true, + Description: "Get compute by id", + }, + "reason": { + Type: schema.TypeString, + Optional: true, + Description: "reason for action", + }, + + "account_id": { + Type: schema.TypeInt, + Computed: true, + Description: "ID of the account this compute instance belongs to.", + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + Description: "Name of the account this compute instance belongs to.", + }, + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "affinity_label": { + Type: schema.TypeString, + Computed: true, + }, + "affinity_rules": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "key": { + Type: schema.TypeString, + Computed: true, + }, + "mode": { + Type: schema.TypeString, + Computed: true, + }, + "policy": { + Type: schema.TypeString, + Computed: true, + }, + "topology": { + Type: schema.TypeString, + Computed: true, + }, + "value": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "affinity_weight": { + Type: schema.TypeInt, + Computed: true, + }, + "anti_affinity_rules": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "key": { + Type: schema.TypeString, + Computed: true, + }, + "mode": { + Type: schema.TypeString, + Computed: true, + }, + "policy": { + Type: schema.TypeString, + Computed: true, + }, + "topology": { + Type: schema.TypeString, + Computed: true, + }, + "value": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "arch": { + Type: schema.TypeString, + Computed: true, + }, + "boot_order": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "cd_image_id": { + Type: schema.TypeInt, + Computed: true, + }, + "clone_reference": { + Type: schema.TypeInt, + Computed: true, + }, + "clones": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "computeci_id": { + Type: schema.TypeInt, + Computed: true, + }, + "cpus": { + Type: schema.TypeInt, + Computed: true, + }, + "created_by": { + Type: schema.TypeString, + Computed: true, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + "custom_fields": { //NEED + Type: schema.TypeString, + Computed: true, + }, + "deleted_by": { + Type: schema.TypeString, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "devices": { //NEED + Type: schema.TypeString, + Computed: true, + }, + "disks": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + }, + "boot_partition": { + Type: schema.TypeInt, + Computed: true, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "destruction_time": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_path": { + Type: schema.TypeString, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_id": { + Type: schema.TypeInt, + Computed: true, + }, + "image_id": { + Type: schema.TypeInt, + Computed: true, + }, + "images": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "iotune": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "read_bytes_sec": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "read_bytes_sec_max": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "read_iops_sec": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "read_iops_sec_max": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "size_iops_sec": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "total_bytes_sec": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "total_bytes_sec_max": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "total_iops_sec": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "total_iops_sec_max": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "write_bytes_sec": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "write_bytes_sec_max": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "write_iops_sec": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "write_iops_sec_max": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + }, + }, + }, + "iqn": { + Type: schema.TypeString, + Computed: true, + }, + "login": { + Type: schema.TypeString, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "order": { + Type: schema.TypeInt, + Computed: true, + }, + "params": { + Type: schema.TypeString, + Computed: true, + }, + "parent_id": { + Type: schema.TypeInt, + Computed: true, + }, + "passwd": { + Type: schema.TypeString, + Computed: true, + }, + "pci_slot": { + Type: schema.TypeInt, + Computed: true, + }, + "pool": { + Type: schema.TypeString, + Computed: true, + }, + "present_to": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "purge_attempts": { + Type: schema.TypeInt, + Computed: true, + }, + "purge_time": { + Type: schema.TypeInt, + Computed: true, + }, + "reality_device_number": { + Type: schema.TypeInt, + Computed: true, + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_id": { + Type: schema.TypeString, + Computed: true, + }, + "res_name": { + Type: schema.TypeString, + Computed: true, + }, + "role": { + Type: schema.TypeString, + Computed: true, + }, + "sep_id": { + Type: schema.TypeInt, + Computed: true, + }, + "shareable": { + Type: schema.TypeBool, + Computed: true, + }, + "size_max": { + Type: schema.TypeInt, + Computed: true, + }, + "size_used": { + Type: schema.TypeFloat, + 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, + }, + "res_id": { + Type: schema.TypeString, + Computed: true, + }, + "snap_set_guid": { + Type: schema.TypeString, + Computed: true, + }, + "snap_set_time": { + Type: schema.TypeInt, + Computed: true, + }, + "timestamp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "vmid": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "driver": { + Type: schema.TypeString, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "image_id": { + Type: schema.TypeInt, + Computed: true, + }, + "interfaces": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "conn_id": { + Type: schema.TypeInt, + Computed: true, + }, + "conn_type": { + Type: schema.TypeString, + Computed: true, + }, + "def_gw": { + Type: schema.TypeString, + Computed: true, + }, + "flip_group_id": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "ip_address": { + Type: schema.TypeString, + Computed: true, + }, + "listen_ssh": { + Type: schema.TypeBool, + Computed: true, + }, + "mac": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "net_id": { + Type: schema.TypeInt, + Computed: true, + }, + "netmask": { + Type: schema.TypeInt, + Computed: true, + }, + "net_type": { + Type: schema.TypeString, + Computed: true, + }, + "pci_slot": { + Type: schema.TypeInt, + Computed: true, + }, + "qos": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "e_rate": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "in_brust": { + Type: schema.TypeInt, + Computed: true, + }, + "in_rate": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "target": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "vnfs": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + }, + }, + }, + "lock_status": { + Type: schema.TypeString, + Computed: true, + }, + "manager_id": { + Type: schema.TypeInt, + Computed: true, + }, + "manager_type": { + Type: schema.TypeString, + Computed: true, + }, + "migrationjob": { + Type: schema.TypeInt, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "need_reboot": { + Type: schema.TypeBool, + Computed: true, + }, + "os_users": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "login": { + Type: schema.TypeString, + Computed: true, + }, + "password": { + Type: schema.TypeString, + Computed: true, + }, + "public_key": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "pinned": { + Type: schema.TypeBool, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "registered": { + Type: schema.TypeBool, + Computed: true, + }, + "res_name": { + Type: schema.TypeString, + Computed: true, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + }, + "snap_sets": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "disks": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "label": { + Type: schema.TypeString, + Computed: true, + }, + "timestamp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "stack_id": { + Type: schema.TypeInt, + Computed: true, + }, + "stack_name": { + Type: schema.TypeString, + Computed: true, + }, + "stateless_sep_id": { + Type: schema.TypeInt, + Computed: true, + }, + "stateless_sep_type": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "tags": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "key": { + Type: schema.TypeString, + Computed: true, + }, + "val": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + }, + "updated_by": { + Type: schema.TypeString, + Computed: true, + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + }, + "user_data": { + Type: schema.TypeString, + Computed: true, + }, + "user_managed": { + Type: schema.TypeBool, + Computed: true, + }, + "vgpus": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "virtual_image_id": { + Type: schema.TypeInt, + Computed: true, + }, + + //extra parameters + "boot_disk_size": { + Type: schema.TypeInt, + Computed: true, + }, + "boot_disk_id": { + Type: schema.TypeInt, + Computed: true, + }, + "sep_id": { + Type: schema.TypeInt, + Computed: true, + }, + "pool": { + Type: schema.TypeString, + Computed: true, + }, + "extra_disks": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Description: "IDs of the extra disk(s) attached to this compute.", + }, + "network": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "net_id": { + Type: schema.TypeInt, + Computed: true, + }, + "net_type": { + Type: schema.TypeString, + Computed: true, + }, + "ip_address": { + Type: schema.TypeString, + Computed: true, + }, + "mac": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + Description: "Network connection(s) for this compute.", + }, + } + return res +} + +func dataSourceComputeListSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by AccountID", + }, + "rg_name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by resgroup name", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by RGID", + }, + "tech_status": { + Type: schema.TypeString, + Optional: true, + Description: "Find by tech status", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Find by status", + }, + "ip_address": { + Type: schema.TypeString, + Optional: true, + Description: "Find by IP address", + }, + "extnet_name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by Extnet name", + }, + "extnet_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by Extnet ID", + }, + "includedeleted": { + Type: schema.TypeBool, + Optional: true, + }, + "page": { + Type: schema.TypeInt, + Optional: true, + }, + "size": { + Type: schema.TypeInt, + Optional: true, + }, + "ignore_k8s": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "If set to true, ignores any VMs associated with any k8s cluster", + }, + + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "affinity_label": { + Type: schema.TypeString, + Computed: true, + }, + "affinity_rules": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "key": { + Type: schema.TypeString, + Computed: true, + }, + "mode": { + Type: schema.TypeString, + Computed: true, + }, + "policy": { + Type: schema.TypeString, + Computed: true, + }, + "topology": { + Type: schema.TypeString, + Computed: true, + }, + "value": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "affinity_weight": { + Type: schema.TypeInt, + Computed: true, + }, + "anti_affinity_rules": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "key": { + Type: schema.TypeString, + Computed: true, + }, + "mode": { + Type: schema.TypeString, + Computed: true, + }, + "policy": { + Type: schema.TypeString, + Computed: true, + }, + "topology": { + Type: schema.TypeString, + Computed: true, + }, + "value": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "arch": { + Type: schema.TypeString, + Computed: true, + }, + "boot_order": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "bootdisk_size": { + Type: schema.TypeInt, + Computed: true, + }, + "cd_image_id": { + Type: schema.TypeInt, + Computed: true, + }, + "clone_reference": { + Type: schema.TypeInt, + Computed: true, + }, + "clones": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "computeci_id": { + Type: schema.TypeInt, + Computed: true, + }, + "cpus": { + Type: schema.TypeInt, + Computed: true, + }, + "created_by": { + Type: schema.TypeString, + Computed: true, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + "custom_fields": { //NEED + Type: schema.TypeString, + Computed: true, + }, + "deleted_by": { + Type: schema.TypeString, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "devices": { //NEED + Type: schema.TypeString, + Computed: true, + }, + "disks": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "disk_id": { + Type: schema.TypeInt, + Computed: true, + }, + "pci_slot": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "driver": { + Type: schema.TypeString, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "compute_id": { + Type: schema.TypeInt, + Computed: true, + }, + "image_id": { + Type: schema.TypeInt, + Computed: true, + }, + "interfaces": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "conn_id": { + Type: schema.TypeInt, + Computed: true, + }, + "conn_type": { + Type: schema.TypeString, + Computed: true, + }, + "def_gw": { + Type: schema.TypeString, + Computed: true, + }, + "flip_group_id": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "ip_address": { + Type: schema.TypeString, + Computed: true, + }, + "listen_ssh": { + Type: schema.TypeBool, + Computed: true, + }, + "mac": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "net_id": { + Type: schema.TypeInt, + Computed: true, + }, + "netmask": { + Type: schema.TypeInt, + Computed: true, + }, + "net_type": { + Type: schema.TypeString, + Computed: true, + }, + "pci_slot": { + Type: schema.TypeInt, + Computed: true, + }, + "qos": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "e_rate": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "in_brust": { + Type: schema.TypeInt, + Computed: true, + }, + "in_rate": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "target": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "vnfs": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + }, + }, + }, + "lock_status": { + Type: schema.TypeString, + Computed: true, + }, + "manager_id": { + Type: schema.TypeInt, + Computed: true, + }, + "manager_type": { + Type: schema.TypeString, + Computed: true, + }, + "migrationjob": { + Type: schema.TypeInt, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "need_reboot": { + Type: schema.TypeBool, + Computed: true, + }, + "os_users": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "login": { + Type: schema.TypeString, + Computed: true, + }, + "password": { + Type: schema.TypeString, + Computed: true, + }, + "public_key": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "pinned": { + Type: schema.TypeBool, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "registered": { + Type: schema.TypeBool, + Computed: true, + }, + "res_name": { + Type: schema.TypeString, + Computed: true, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + }, + "snap_sets": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "disks": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "label": { + Type: schema.TypeString, + Computed: true, + }, + "timestamp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "stack_id": { + Type: schema.TypeInt, + Computed: true, + }, + "stateless_sep_id": { + Type: schema.TypeInt, + Computed: true, + }, + "stateless_sep_type": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "tags": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "key": { + Type: schema.TypeString, + Computed: true, + }, + "val": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + }, + "total_disk_size": { + Type: schema.TypeInt, + Computed: true, + }, + "updated_by": { + Type: schema.TypeString, + Computed: true, + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + }, + "user_data": { + Type: schema.TypeString, + Computed: true, + }, + "user_managed": { + Type: schema.TypeBool, + Computed: true, + }, + "vgpus": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "vins_connected": { + Type: schema.TypeInt, + Computed: true, + }, + "virtual_image_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return res +} + +func dataSourceComputeListDeletedSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by AccountID", + }, + "rg_name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by resgroup name", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by RGID", + }, + "tech_status": { + Type: schema.TypeString, + Optional: true, + Description: "Find by tech status", + }, + "ip_address": { + Type: schema.TypeString, + Optional: true, + Description: "Find by IP address", + }, + "extnet_name": { + Type: schema.TypeString, + Optional: true, + Description: "Find by Extnet name", + }, + "extnet_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by Extnet ID", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + }, + "size": { + Type: schema.TypeInt, + Optional: true, + }, + "ignore_k8s": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "If set to true, ignores any VMs associated with any k8s cluster", + }, + + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "affinity_label": { + Type: schema.TypeString, + Computed: true, + }, + "affinity_rules": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "key": { + Type: schema.TypeString, + Computed: true, + }, + "mode": { + Type: schema.TypeString, + Computed: true, + }, + "policy": { + Type: schema.TypeString, + Computed: true, + }, + "topology": { + Type: schema.TypeString, + Computed: true, + }, + "value": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "affinity_weight": { + Type: schema.TypeInt, + Computed: true, + }, + "anti_affinity_rules": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "key": { + Type: schema.TypeString, + Computed: true, + }, + "mode": { + Type: schema.TypeString, + Computed: true, + }, + "policy": { + Type: schema.TypeString, + Computed: true, + }, + "topology": { + Type: schema.TypeString, + Computed: true, + }, + "value": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "arch": { + Type: schema.TypeString, + Computed: true, + }, + "boot_order": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "bootdisk_size": { + Type: schema.TypeInt, + Computed: true, + }, + "cd_image_id": { + Type: schema.TypeInt, + Computed: true, + }, + "clone_reference": { + Type: schema.TypeInt, + Computed: true, + }, + "clones": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "computeci_id": { + Type: schema.TypeInt, + Computed: true, + }, + "cpus": { + Type: schema.TypeInt, + Computed: true, + }, + "created_by": { + Type: schema.TypeString, + Computed: true, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + "custom_fields": { //NEED + Type: schema.TypeString, + Computed: true, + }, + "deleted_by": { + Type: schema.TypeString, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "devices": { //NEED + Type: schema.TypeString, + Computed: true, + }, + "disks": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "disk_id": { + Type: schema.TypeInt, + Computed: true, + }, + "pci_slot": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "driver": { + Type: schema.TypeString, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "compute_id": { + Type: schema.TypeInt, + Computed: true, + }, + "image_id": { + Type: schema.TypeInt, + Computed: true, + }, + "interfaces": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "conn_id": { + Type: schema.TypeInt, + Computed: true, + }, + "conn_type": { + Type: schema.TypeString, + Computed: true, + }, + "def_gw": { + Type: schema.TypeString, + Computed: true, + }, + "flip_group_id": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "ip_address": { + Type: schema.TypeString, + Computed: true, + }, + "listen_ssh": { + Type: schema.TypeBool, + Computed: true, + }, + "mac": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "net_id": { + Type: schema.TypeInt, + Computed: true, + }, + "netmask": { + Type: schema.TypeInt, + Computed: true, + }, + "net_type": { + Type: schema.TypeString, + Computed: true, + }, + "pci_slot": { + Type: schema.TypeInt, + Computed: true, + }, + "qos": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "e_rate": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "in_brust": { + Type: schema.TypeInt, + Computed: true, + }, + "in_rate": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "target": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "vnfs": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + }, + }, + }, + "lock_status": { + Type: schema.TypeString, + Computed: true, + }, + "manager_id": { + Type: schema.TypeInt, + Computed: true, + }, + "manager_type": { + Type: schema.TypeString, + Computed: true, + }, + "migrationjob": { + Type: schema.TypeInt, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "need_reboot": { + Type: schema.TypeBool, + Computed: true, + }, + "os_users": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "login": { + Type: schema.TypeString, + Computed: true, + }, + "password": { + Type: schema.TypeString, + Computed: true, + }, + "public_key": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "pinned": { + Type: schema.TypeBool, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "registered": { + Type: schema.TypeBool, + Computed: true, + }, + "res_name": { + Type: schema.TypeString, + Computed: true, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + }, + "snap_sets": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "disks": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "label": { + Type: schema.TypeString, + Computed: true, + }, + "timestamp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "stack_id": { + Type: schema.TypeInt, + Computed: true, + }, + "stateless_sep_id": { + Type: schema.TypeInt, + Computed: true, + }, + "stateless_sep_type": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "tags": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "key": { + Type: schema.TypeString, + Computed: true, + }, + "val": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + }, + "total_disk_size": { + Type: schema.TypeInt, + Computed: true, + }, + "updated_by": { + Type: schema.TypeString, + Computed: true, + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + }, + "user_data": { + Type: schema.TypeString, + Computed: true, + }, + "user_managed": { + Type: schema.TypeBool, + Computed: true, + }, + "vgpus": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "vins_connected": { + Type: schema.TypeInt, + Computed: true, + }, + "virtual_image_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return res +} + +func dataSourceComputeAuditsSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "compute_id": { + Type: schema.TypeInt, + Required: true, + }, + + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "call": { + Type: schema.TypeString, + Computed: true, + }, + "responsetime": { + Type: schema.TypeFloat, + Computed: true, + }, + "statuscode": { + Type: schema.TypeInt, + Computed: true, + }, + "timestamp": { + Type: schema.TypeFloat, + Computed: true, + }, + "user": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + } +} + +func dataSourceComputeGetAuditsSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "compute_id": { + Type: schema.TypeInt, + Required: true, + }, + "reason": { + Type: schema.TypeString, + Optional: true, + }, + + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "epoch": { + Type: schema.TypeFloat, + Computed: true, + }, + "message": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + } +} + +func dataSourceComputeGetConsoleUrlSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "compute_id": { + Type: schema.TypeInt, + Required: true, + }, + "console_url": { + Type: schema.TypeString, + Computed: true, + }, + } +} + +func dataSourceComputePfwListSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "compute_id": { + Type: schema.TypeInt, + Required: true, + }, + "reason": { + Type: schema.TypeString, + Optional: true, + }, + + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "pfw_id": { + Type: schema.TypeInt, + Computed: true, + }, + "local_ip": { + Type: schema.TypeString, + Computed: true, + }, + "local_port": { + Type: schema.TypeInt, + Computed: true, + }, + "protocol": { + Type: schema.TypeString, + Computed: true, + }, + "public_port_end": { + Type: schema.TypeInt, + Computed: true, + }, + "public_port_start": { + Type: schema.TypeInt, + Computed: true, + }, + "vm_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } +} + +func dataSourceComputeUserListSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "compute_id": { + Type: schema.TypeInt, + Required: true, + }, + + "account_acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "compute_acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "rg_acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + } + + return res +} + +func dataSourceComputeSnapshotListSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "compute_id": { + Type: schema.TypeInt, + Required: true, + }, + + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "disks": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "label": { + Type: schema.TypeString, + Computed: true, + }, + "timestamp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return res +} + +func dataSourceComputeAffinityRelationsSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "compute_id": { + Type: schema.TypeInt, + Required: true, + }, + + "other_node": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "other_node_indirect": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "other_node_indirect_soft": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "other_node_soft": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "same_node": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "same_node_soft": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + } + return res +} + +func dataSourceComputeBootOrderGetSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "compute_id": { + Type: schema.TypeInt, + Required: true, + }, + + "boot_order": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + } + return res +} + +func dataSourceComputeMigrateStorageInfoSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "compute_id": { + Type: schema.TypeInt, + Required: true, + }, + + "migrate_storage_info": { + Type: schema.TypeString, + Computed: true, + }, + } + return res +} + +func dataSourceComputeSnapshotUsageSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "compute_id": { + Type: schema.TypeInt, + Required: true, + }, + "label": { + Type: schema.TypeString, + Optional: true, + }, + + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "count": { + Type: schema.TypeInt, + Computed: true, + }, + "stored": { + Type: schema.TypeFloat, + Computed: true, + }, + "label": { + Type: schema.TypeString, + Computed: true, + }, + "timestamp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + } +} + +func dataSourceComputePCIDeviceListSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "compute_id": { + Type: schema.TypeInt, + Required: true, + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by RG id", + }, + "device_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by device id", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Find by status", + }, + "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{ + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "compute_id": { + Type: schema.TypeInt, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "hwpath": { + Type: schema.TypeString, + Computed: true, + }, + "device_id": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "stack_id": { + Type: schema.TypeInt, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "system_name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } +} + +func dataSourceComputeVGPUListSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "compute_id": { + Type: schema.TypeInt, + Required: true, + }, + "gpu_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by GPU id", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Optional: true, + Description: "Find by type", + }, + "status": { + Type: schema.TypeString, + Computed: true, + Optional: true, + Description: "Find by status", + }, + "includedeleted": { + Type: schema.TypeBool, + Optional: true, + Description: "Include deleted computes. If using field 'status', then includedeleted will be ignored", + }, + "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.Schema{ + Type: schema.TypeString, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } +} + +func dataSourceComputeGetLogSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "compute_id": { + Type: schema.TypeInt, + Required: true, + }, + "path": { + Type: schema.TypeString, + Required: true, + }, + "log": { + Type: schema.TypeString, + Computed: true, + }, + } +} + +func resourceComputeSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "Name of this compute. Compute names are case sensitive and must be unique in the resource group.", + }, + "rg_id": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntAtLeast(1), + Description: "ID of the resource group where this compute should be deployed.", + }, + "driver": { + Type: schema.TypeString, + Required: true, + StateFunc: statefuncs.StateFuncToUpper, + ValidateFunc: validation.StringInSlice([]string{"SVA_KVM_X86", "KVM_X86", "KVM_PPC"}, false), // observe case while validating + Description: "Hardware architecture of this compute instance.", + }, + "cpu": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(1, constants.MaxCpusPerCompute), + Description: "Number of CPUs to allocate to this compute instance.", + }, + "ram": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntAtLeast(constants.MinRamPerCompute), + Description: "Amount of RAM in MB to allocate to this compute instance.", + }, + "image_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the OS image to base this compute instance on.", + }, + "boot_disk_size": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "This compute instance boot disk size in GB. Make sure it is large enough to accomodate selected OS image.", + }, + "sep_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "ID of SEP to create bootDisk on. Uses image's sepId if not set.", + }, + "pool": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Pool to use if sepId is set, can be also empty if needed to be chosen by system.", + }, + "cloud_init": { + Type: schema.TypeString, + Optional: true, + Description: "Optional cloud_init parameters. Applied when creating new compute instance only, ignored in all other cases.", + }, + "description": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Optional text description of this compute instance.", + }, + "started": { + Type: schema.TypeBool, + Optional: true, + Default: true, + Description: "Is compute started.", + }, + "alt_boot_id": { + Type: schema.TypeInt, + Optional: true, + Default: 0, + Description: "ID of CD-ROM live image to boot", + }, + "stack_id": { + Type: schema.TypeInt, + Optional: true, + Default: 0, + Description: "ID of stack to start compute", + }, + "is": { + Type: schema.TypeString, + Optional: true, + Description: "system name", + }, + "ipa_type": { + Type: schema.TypeString, + Optional: true, + Description: "compute purpose", + }, + "custom_fields": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "network": { + Type: schema.TypeSet, + Optional: true, + MinItems: 1, + MaxItems: constants.MaxNetworksPerCompute, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "net_type": { + Type: schema.TypeString, + Required: true, + StateFunc: statefuncs.StateFuncToUpper, + ValidateFunc: validation.StringInSlice([]string{"EXTNET", "VINS"}, false), // observe case while validating + Description: "Type of the network for this connection, either EXTNET or VINS.", + }, + + "net_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the network for this connection.", + }, + + "ip_address": { + Type: schema.TypeString, + Optional: true, + Computed: true, + DiffSuppressFunc: networkSubresIPAddreDiffSupperss, + Description: "Optional IP address to assign to this connection. This IP should belong to the selected network and free for use.", + }, + + "mac": { + Type: schema.TypeString, + Computed: true, + Description: "MAC address associated with this connection. MAC address is assigned automatically.", + }, + }, + }, + Description: "Optional network connection(s) for this compute. You may specify several network blocks, one for each connection.", + }, + "reason": { + Type: schema.TypeString, + Optional: true, + Description: "reason for action", + }, + "affinity_label": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Set affinity label for compute", + }, + "affinity_rules": { + Type: schema.TypeSet, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "topology": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{"node", "compute"}, false), + Description: "compute or node, for whom rule applies", + }, + "policy": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{"RECOMMENDED", "REQUIRED"}, false), + Description: "RECOMMENDED or REQUIRED, the degree of 'strictness' of this rule", + }, + "mode": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{"EQ", "NE", "ANY"}, false), + Description: "EQ or NE or ANY - the comparison mode is 'value', recorded by the specified 'key'", + }, + "key": { + Type: schema.TypeString, + Required: true, + Description: "key that are taken into account when analyzing this rule will be identified", + }, + "value": { + Type: schema.TypeString, + Required: true, + Description: "value that must match the key to be taken into account when analyzing this rule", + }, + }, + }, + }, + "anti_affinity_rules": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "topology": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{"node", "compute"}, false), + Description: "compute or node, for whom rule applies", + }, + "policy": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{"RECOMMENDED", "REQUIRED"}, false), + Description: "RECOMMENDED or REQUIRED, the degree of 'strictness' of this rule", + }, + "mode": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{"EQ", "NE", "ANY"}, false), + Description: "EQ or NE or ANY - the comparison mode is 'value', recorded by the specified 'key'", + }, + "key": { + Type: schema.TypeString, + Required: true, + Description: "key that are taken into account when analyzing this rule will be identified", + }, + "value": { + Type: schema.TypeString, + Required: true, + Description: "value that must match the key to be taken into account when analyzing this rule", + }, + }, + }, + }, + "disks": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "disk_name": { + Type: schema.TypeString, + Required: true, + Description: "Name for disk", + }, + "size": { + Type: schema.TypeInt, + Required: true, + Description: "Disk size in GiB", + }, + "sep_id": { + Type: schema.TypeInt, + Computed: true, + Optional: true, + Description: "Storage endpoint provider ID; by default the same with boot disk", + }, + "disk_type": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"B", "D"}, false), + Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data'", + }, + "pool": { + Type: schema.TypeString, + Computed: true, + Optional: true, + Description: "Pool name; by default will be chosen automatically", + }, + "desc": { + Type: schema.TypeString, + Computed: true, + Optional: true, + Description: "Optional description", + }, + "image_id": { + Type: schema.TypeInt, + Computed: true, + Optional: true, + Description: "Specify image id for create disk from template", + }, + "permanently": { + Type: schema.TypeBool, + Computed: true, + Optional: true, + Description: "Disk deletion status", + }, + "disk_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Disk ID", + }, + "shareable": { + Type: schema.TypeBool, + Computed: true, + }, + "size_max": { + Type: schema.TypeInt, + Computed: true, + }, + "size_used": { + Type: schema.TypeInt, + Computed: true, + }, + "reason": { + Type: schema.TypeString, + Optional: true, + Description: "reason for action", + }, + }, + }, + }, + "extra_disks": { + Type: schema.TypeSet, + Optional: true, + MaxItems: constants.MaxExtraDisksPerCompute, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Description: "Optional list of IDs of extra disks to attach to this compute. You may specify several extra disks.", + }, + "tags": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "key": { + Type: schema.TypeString, + Required: true, + }, + "value": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, + "port_forwarding": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "public_port_start": { + Type: schema.TypeInt, + Required: true, + }, + "public_port_end": { + Type: schema.TypeInt, + Optional: true, + Default: -1, + }, + "local_port": { + Type: schema.TypeInt, + Required: true, + }, + "proto": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{"tcp", "udp"}, false), + }, + "rule_id": { + Type: schema.TypeInt, + Computed: true, + }, + "reason": { + Type: schema.TypeString, + Optional: true, + Description: "reason for action", + }, + }, + }, + }, + "user_access": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "username": { + Type: schema.TypeString, + Required: true, + }, + "access_type": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, + "snapshot": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "label": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, + "rollback": { + Type: schema.TypeSet, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "label": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, + "cd": { + Type: schema.TypeSet, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cdrom_id": { + Type: schema.TypeInt, + Required: true, + }, + "reason": { + Type: schema.TypeString, + Optional: true, + Description: "reason for action", + }, + }, + }, + }, + "pin_to_stack": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "target_stack_id": { + Type: schema.TypeInt, + Optional: true, + }, + "force_pin": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "enabled": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + Description: "If true - enable compute, else - disable", + }, + "pause": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "reset": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "restore": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "auto_start": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Flag for redeploy compute", + }, + "force_stop": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Flag for redeploy compute", + }, + "data_disks": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"KEEP", "DETACH", "DESTROY"}, false), + Default: "DETACH", + Description: "Flag for redeploy compute", + }, + "detach_disks": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + "permanently": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + // Computed properties + "account_id": { + Type: schema.TypeInt, + Computed: true, + Description: "ID of the account this compute instance belongs to.", + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + Description: "Name of the account this compute instance belongs to.", + }, + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "affinity_weight": { + Type: schema.TypeInt, + Computed: true, + }, + "arch": { + Type: schema.TypeString, + Computed: true, + }, + "boot_order": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "boot_disk_id": { + Type: schema.TypeInt, + Computed: true, + Description: "This compute instance boot disk ID.", + }, + "cd_image_id": { + Type: schema.TypeInt, + Computed: true, + }, + "clone_reference": { + Type: schema.TypeInt, + Computed: true, + }, + "clones": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "computeci_id": { + 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, + }, + "devices": { + Type: schema.TypeString, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "compute_id": { + Type: schema.TypeInt, + Computed: true, + }, + "interfaces": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "conn_id": { + Type: schema.TypeInt, + Computed: true, + }, + "conn_type": { + Type: schema.TypeString, + Computed: true, + }, + "def_gw": { + Type: schema.TypeString, + Computed: true, + }, + "flip_group_id": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "ip_address": { + Type: schema.TypeString, + Computed: true, + }, + "listen_ssh": { + Type: schema.TypeBool, + Computed: true, + }, + "mac": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "net_id": { + Type: schema.TypeInt, + Computed: true, + }, + "netmask": { + Type: schema.TypeInt, + Computed: true, + }, + "net_type": { + Type: schema.TypeString, + Computed: true, + }, + "pci_slot": { + Type: schema.TypeInt, + Computed: true, + }, + "qos": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "e_rate": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "in_brust": { + Type: schema.TypeInt, + Computed: true, + }, + "in_rate": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "target": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "vnfs": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + }, + }, + }, + "lock_status": { + Type: schema.TypeString, + Computed: true, + }, + "manager_id": { + Type: schema.TypeInt, + Computed: true, + }, + "manager_type": { + Type: schema.TypeString, + Computed: true, + }, + "migrationjob": { + Type: schema.TypeInt, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "need_reboot": { + Type: schema.TypeBool, + Computed: true, + }, + "os_users": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + Description: "GUID of this guest OS user.", + }, + + "login": { + Type: schema.TypeString, + Computed: true, + Description: "Login name of this guest OS user.", + }, + + "password": { + Type: schema.TypeString, + Computed: true, + //Sensitive: true, + Description: "Password of this guest OS user.", + }, + + "public_key": { + Type: schema.TypeString, + Computed: true, + Description: "SSH public key of this guest OS user.", + }, + }, + }, + Description: "Guest OS users provisioned on this compute instance.", + }, + "pinned": { + Type: schema.TypeBool, + Computed: true, + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + }, + "registered": { + Type: schema.TypeBool, + Computed: true, + }, + "res_name": { + Type: schema.TypeString, + Computed: true, + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + Description: "Name of the resource group where this compute instance is located.", + }, + "snap_sets": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "disks": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "label": { + Type: schema.TypeString, + Computed: true, + }, + "timestamp": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "stack_name": { + Type: schema.TypeString, + Computed: true, + Description: "Name of the stack, on which VM started", + }, + "stateless_sep_id": { + Type: schema.TypeInt, + Computed: true, + }, + "stateless_sep_type": { + 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, + }, + "vgpus": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "virtual_image_id": { + Type: schema.TypeInt, + Computed: true, + }, + } +} diff --git a/internal/service/cloudbroker/kvmvm/utility_compute_affinity_relations.go b/internal/service/cloudbroker/kvmvm/utility_compute_affinity_relations.go new file mode 100644 index 0000000..93e3f5f --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/utility_compute_affinity_relations.go @@ -0,0 +1,55 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityComputeAffinityRelationsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.RecordAffinityRelations, error) { + c := m.(*controller.ControllerCfg) + req := compute.AffinityRelationsRequest{ + ComputeID: uint64(d.Get("compute_id").(int)), + } + + affinityRelations, err := c.CloudBroker().Compute().AffinityRelations(ctx, req) + if err != nil { + return nil, err + } + + return affinityRelations, nil +} diff --git a/internal/service/cloudbroker/kvmvm/utility_compute_audits.go b/internal/service/cloudbroker/kvmvm/utility_compute_audits.go new file mode 100644 index 0000000..9696228 --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/utility_compute_audits.go @@ -0,0 +1,54 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityComputeAuditsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (compute.ListDetailedAudits, error) { + c := m.(*controller.ControllerCfg) + req := compute.AuditsRequest{ + ComputeID: uint64(d.Get("compute_id").(int)), + } + + computeAudits, err := c.CloudBroker().Compute().Audits(ctx, req) + if err != nil { + return nil, err + } + return computeAudits, nil +} diff --git a/internal/service/cloudbroker/kvmvm/utility_compute_boot_order_get.go b/internal/service/cloudbroker/kvmvm/utility_compute_boot_order_get.go new file mode 100644 index 0000000..e314d10 --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/utility_compute_boot_order_get.go @@ -0,0 +1,55 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityComputeBootOrderGetCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) ([]string, error) { + c := m.(*controller.ControllerCfg) + + req := compute.BootOrderGetRequest{ + ComputeID: uint64(d.Get("compute_id").(int)), + } + result, err := c.CloudBroker().Compute().BootOrderGet(ctx, req) + if err != nil { + return nil, err + } + + return result, nil +} diff --git a/internal/service/cloudbroker/kvmvm/utility_compute_get_audits.go b/internal/service/cloudbroker/kvmvm/utility_compute_get_audits.go new file mode 100644 index 0000000..82325f6 --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/utility_compute_get_audits.go @@ -0,0 +1,59 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityComputeGetAuditsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (compute.ListAudits, error) { + c := m.(*controller.ControllerCfg) + req := compute.GetAuditsRequest{ + ComputeID: uint64(d.Get("compute_id").(int)), + } + + if reason, ok := d.GetOk("reason"); ok { + req.Reason = reason.(string) + } + + computeAudits, err := c.CloudBroker().Compute().GetAudits(ctx, req) + if err != nil { + return nil, err + } + + return computeAudits, nil +} diff --git a/internal/service/cloudbroker/kvmvm/utility_compute_get_console_url.go b/internal/service/cloudbroker/kvmvm/utility_compute_get_console_url.go new file mode 100644 index 0000000..d9287d3 --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/utility_compute_get_console_url.go @@ -0,0 +1,55 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityComputeGetConsoleUrlCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) { + c := m.(*controller.ControllerCfg) + + req := compute.GetConsoleURLRequest{ + ComputeID: uint64(d.Get("compute_id").(int)), + } + computeConsoleUrl, err := c.CloudBroker().Compute().GetConsoleURL(ctx, req) + if err != nil { + return "", err + } + + return computeConsoleUrl, nil +} diff --git a/internal/service/cloudbroker/kvmvm/utility_compute_get_log.go b/internal/service/cloudbroker/kvmvm/utility_compute_get_log.go new file mode 100644 index 0000000..3e9ff2a --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/utility_compute_get_log.go @@ -0,0 +1,56 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityComputeGetLogCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) { + c := m.(*controller.ControllerCfg) + req := compute.GetLogRequest{ + ComputeID: uint64(d.Get("compute_id").(int)), + Path: d.Get("path").(string), + } + + computeGetLog, err := c.CloudBroker().Compute().GetLog(ctx, req) + if err != nil { + return "", err + } + + return computeGetLog, nil +} diff --git a/internal/service/cloudbroker/kvmvm/utility_compute_list.go b/internal/service/cloudbroker/kvmvm/utility_compute_list.go new file mode 100644 index 0000000..83d3816 --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/utility_compute_list.go @@ -0,0 +1,104 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + "regexp" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityDataComputeListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ListComputes, error) { + c := m.(*controller.ControllerCfg) + req := compute.ListRequest{} + + if byId, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(byId.(int)) + } + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + if accountId, ok := d.GetOk("account_id"); ok { + req.AccountID = uint64(accountId.(int)) + } + if rgName, ok := d.GetOk("rg_name"); ok { + req.RGName = rgName.(string) + } + if rgId, ok := d.GetOk("rg_id"); ok { + req.RGID = uint64(rgId.(int)) + } + if techStatus, ok := d.GetOk("tech_status"); ok { + req.TechStatus = techStatus.(string) + } + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } + if ipAddress, ok := d.GetOk("ip_address"); ok { + req.IPAddress = ipAddress.(string) + } + if extNetName, ok := d.GetOk("extnet_name"); ok { + req.ExtNetName = extNetName.(string) + } + if extnetId, ok := d.GetOk("extnet_id"); ok { + req.ExtNetID = uint64(extnetId.(int)) + } + if includeDeleted, ok := d.GetOk("includedeleted"); ok { + req.IncludeDeleted = includeDeleted.(bool) + } + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + + listComputes, err := c.CloudBroker().Compute().List(ctx, req) + if err != nil { + return nil, err + } + + return listComputes, nil +} + +func matchComputes(computeList *compute.ListComputes) *compute.ListComputes { + matched, _ := regexp.Compile(`[a-zA-Z]+\\d+-[a-zA-Z]+\\d+-[a-zA-Z]+\\d+`) + result := computeList.FilterFunc(func(ic compute.ItemCompute) bool { + res := matched.Match([]byte(ic.Name)) + return !res + }) + + return &result +} diff --git a/internal/service/cloudbroker/kvmvm/utility_compute_list_deleted.go b/internal/service/cloudbroker/kvmvm/utility_compute_list_deleted.go new file mode 100644 index 0000000..e947709 --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/utility_compute_list_deleted.go @@ -0,0 +1,87 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityDataComputeListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ListComputes, error) { + c := m.(*controller.ControllerCfg) + req := compute.ListDeletedRequest{} + + if byId, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(byId.(int)) + } + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + if accountId, ok := d.GetOk("account_id"); ok { + req.AccountID = uint64(accountId.(int)) + } + if rgName, ok := d.GetOk("rg_name"); ok { + req.RGName = rgName.(string) + } + if rgId, ok := d.GetOk("rg_id"); ok { + req.RGID = uint64(rgId.(int)) + } + if techStatus, ok := d.GetOk("tech_status"); ok { + req.TechStatus = techStatus.(string) + } + if ipAddress, ok := d.GetOk("ip_address"); ok { + req.IPAddress = ipAddress.(string) + } + if extNetName, ok := d.GetOk("extnet_name"); ok { + req.ExtNetName = extNetName.(string) + } + if extnetId, ok := d.GetOk("extnet_id"); ok { + req.ExtNetID = uint64(extnetId.(int)) + } + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + + listComputes, err := c.CloudBroker().Compute().ListDeleted(ctx, req) + if err != nil { + return nil, err + } + + return listComputes, nil +} diff --git a/internal/service/cloudbroker/kvmvm/utility_compute_migrate_storage_info.go b/internal/service/cloudbroker/kvmvm/utility_compute_migrate_storage_info.go new file mode 100644 index 0000000..2023d82 --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/utility_compute_migrate_storage_info.go @@ -0,0 +1,55 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityComputeMigrateStorageInfoCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) { + c := m.(*controller.ControllerCfg) + + req := compute.MigrateStorageInfoRequest{ + ComputeID: uint64(d.Get("compute_id").(int)), + } + result, err := c.CloudBroker().Compute().MigrateStorageInfo(ctx, req) + if err != nil { + return "", err + } + + return result, nil +} diff --git a/internal/service/cloudbroker/kvmvm/utility_compute_pci_device_list.go b/internal/service/cloudbroker/kvmvm/utility_compute_pci_device_list.go new file mode 100644 index 0000000..36a1311 --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/utility_compute_pci_device_list.go @@ -0,0 +1,70 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityComputePCIDeviceListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ListPCIDevices, error) { + c := m.(*controller.ControllerCfg) + req := compute.ListPCIDeviceRequest{ + ComputeID: uint64(d.Get("compute_id").(int)), + } + if rgId, ok := d.GetOk("rg_id"); ok { + req.RGID = uint64(rgId.(int)) + } + if devId, ok := d.GetOk("device_id"); ok { + req.DevID = uint64(devId.(int)) + } + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + + listPCIDevice, err := c.CloudBroker().Compute().ListPCIDevice(ctx, req) + if err != nil { + return nil, err + } + + return listPCIDevice, err +} diff --git a/internal/service/cloudbroker/pfw/utility_pfw.go b/internal/service/cloudbroker/kvmvm/utility_compute_pfw_list.go similarity index 75% rename from internal/service/cloudbroker/pfw/utility_pfw.go rename to internal/service/cloudbroker/kvmvm/utility_compute_pfw_list.go index d04462b..1eaf0a6 100644 --- a/internal/service/cloudbroker/pfw/utility_pfw.go +++ b/internal/service/cloudbroker/kvmvm/utility_compute_pfw_list.go @@ -1,8 +1,9 @@ /* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. Authors: Petr Krutov, Stanislav Solovev, +Kasim Baybikov, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -29,40 +30,30 @@ builds seamlessly. Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki */ -package pfw +package kvmvm import ( "context" - "strconv" - "strings" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" ) -func utilityPfwCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ItemPFW, error) { +func utilityComputePfwListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ListPFW, error) { c := m.(*controller.ControllerCfg) req := compute.PFWListRequest{ ComputeID: uint64(d.Get("compute_id").(int)), } - pfws, err := c.CloudBroker().Compute().PFWList(ctx, req) - if err != nil { - return nil, err + if reason, ok := d.GetOk("reason"); ok { + req.Reason = reason.(string) } - idS := strings.Split(d.Id(), "-")[1] - id, err := strconv.Atoi(idS) + listPFWs, err := c.CloudBroker().Compute().PFWList(ctx, req) if err != nil { return nil, err } - for _, pfw := range pfws { - if pfw.ID == uint64(id) { - return &pfw, nil - } - } - - return nil, nil + return listPFWs, err } diff --git a/internal/service/cloudbroker/kvmvm/utility_compute_shapshot_usage.go b/internal/service/cloudbroker/kvmvm/utility_compute_shapshot_usage.go new file mode 100644 index 0000000..ecaffbd --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/utility_compute_shapshot_usage.go @@ -0,0 +1,59 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityComputeSnapshotUsageCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ListSnapshotUsage, error) { + c := m.(*controller.ControllerCfg) + req := compute.SnapshotUsageRequest{ + ComputeID: uint64(d.Get("compute_id").(int)), + } + + if label, ok := d.GetOk("label"); ok { + req.Label = label.(string) + } + + computeSnapshotUsage, err := c.CloudBroker().Compute().SnapshotUsage(ctx, req) + if err != nil { + return nil, err + } + + return &computeSnapshotUsage, err +} diff --git a/internal/service/cloudbroker/snapshot/utility_snapshot_list.go b/internal/service/cloudbroker/kvmvm/utility_compute_snapshot_list.go similarity index 80% rename from internal/service/cloudbroker/snapshot/utility_snapshot_list.go rename to internal/service/cloudbroker/kvmvm/utility_compute_snapshot_list.go index d970ee9..62ab5ee 100644 --- a/internal/service/cloudbroker/snapshot/utility_snapshot_list.go +++ b/internal/service/cloudbroker/kvmvm/utility_compute_snapshot_list.go @@ -1,54 +1,55 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, - -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 snapshot - -import ( - "context" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute" - "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" -) - -func utilitySnapshotListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (compute.ListSnapshots, error) { - c := m.(*controller.ControllerCfg) - req := compute.SnapshotListRequest{ - ComputeID: uint64(d.Get("compute_id").(int)), - } - - snapshotList, err := c.CloudBroker().Compute().SnapshotList(ctx, req) - if err != nil { - return nil, err - } - - return snapshotList, nil -} +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityComputeSnapshotListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ListSnapShot, error) { + c := m.(*controller.ControllerCfg) + req := compute.SnapshotListRequest{ + ComputeID: uint64(d.Get("compute_id").(int)), + } + + listSnapshots, err := c.CloudBroker().Compute().SnapshotList(ctx, req) + if err != nil { + return nil, err + } + + return listSnapshots, err +} diff --git a/internal/service/cloudbroker/kvmvm/utility_compute_user_list.go b/internal/service/cloudbroker/kvmvm/utility_compute_user_list.go new file mode 100644 index 0000000..e59830b --- /dev/null +++ b/internal/service/cloudbroker/kvmvm/utility_compute_user_list.go @@ -0,0 +1,55 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 kvmvm + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityComputeUserListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ListUsers, error) { + c := m.(*controller.ControllerCfg) + req := compute.UserListRequest{ + ComputeID: uint64(d.Get("compute_id").(int)), + } + + computeUserList, err := c.CloudBroker().Compute().UserList(ctx, req) + if err != nil { + return computeUserList, err + } + + return computeUserList, err +} diff --git a/internal/service/cloudbroker/lb/lb_resource_subresource.go b/internal/service/cloudbroker/kvmvm/utility_compute_vgpu_list.go similarity index 52% rename from internal/service/cloudbroker/lb/lb_resource_subresource.go rename to internal/service/cloudbroker/kvmvm/utility_compute_vgpu_list.go index 7a82cf5..0f5d568 100644 --- a/internal/service/cloudbroker/lb/lb_resource_subresource.go +++ b/internal/service/cloudbroker/kvmvm/utility_compute_vgpu_list.go @@ -30,66 +30,44 @@ builds seamlessly. Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki */ -package lb +package kvmvm -import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +import ( + "context" -func lbResourceSchemaMake() map[string]*schema.Schema { - sch := createLBSchema() - sch["rg_id"] = &schema.Schema{ - Type: schema.TypeInt, - Required: true, - } + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) - sch["name"] = &schema.Schema{ - Type: schema.TypeString, - Required: true, +func utilityComputeVGPUListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ListVGPUs, error) { + c := m.(*controller.ControllerCfg) + req := compute.ListVGPURequest{ + ComputeID: uint64(d.Get("compute_id").(int)), } - - sch["extnet_id"] = &schema.Schema{ - Type: schema.TypeInt, - Required: true, + if GPUID, ok := d.GetOk("gpu_id"); ok { + req.GPUID = uint64(GPUID.(int)) } - - sch["vins_id"] = &schema.Schema{ - Type: schema.TypeInt, - Required: true, + if typeVGPU, ok := d.GetOk("type"); ok { + req.Type = typeVGPU.(string) } - - sch["start"] = &schema.Schema{ - Type: schema.TypeBool, - Optional: true, + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) } - - sch["desc"] = &schema.Schema{ - Type: schema.TypeString, - Optional: true, - Computed: true, + if includeDeleted, ok := d.GetOk("includedeleted"); ok { + req.IncludeDeleted = includeDeleted.(bool) } - - sch["enable"] = &schema.Schema{ - Type: schema.TypeBool, - Optional: true, + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) } - - sch["restart"] = &schema.Schema{ - Type: schema.TypeBool, - Optional: true, - } - - sch["restore"] = &schema.Schema{ - Type: schema.TypeBool, - Optional: true, + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) } - sch["config_reset"] = &schema.Schema{ - Type: schema.TypeBool, - Optional: true, + listVGPU, err := c.CloudBroker().Compute().ListVGPU(ctx, req) + if err != nil { + return nil, err } - sch["permanently"] = &schema.Schema{ - Type: schema.TypeBool, - Optional: true, - } - return sch + return listVGPU, err } diff --git a/internal/service/cloudbroker/lb/lb_data_subresource.go b/internal/service/cloudbroker/lb/lb_data_subresource.go deleted file mode 100644 index 3d0341d..0000000 --- a/internal/service/cloudbroker/lb/lb_data_subresource.go +++ /dev/null @@ -1,177 +0,0 @@ -/* -Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, -Kasim Baybikov, - -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 lb - -import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - -func dsLBSchemaMake() map[string]*schema.Schema { - sch := createLBSchema() - sch["lb_id"] = &schema.Schema{ - Type: schema.TypeInt, - Required: true, - } - return sch -} - - -func dsLBListDeletedSchemaMake() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "by_id": { - Type: schema.TypeInt, - Optional: true, - Description: "Filter by ID", - }, - "name": { - Type: schema.TypeString, - Optional: true, - Description: "Filter by name", - }, - "account_id": { - Type: schema.TypeInt, - Optional: true, - Description: "Filter by Account ID", - }, - "rg_id": { - Type: schema.TypeInt, - Optional: true, - Description: "Filter by RG ID", - }, - "tech_status": { - Type: schema.TypeString, - Optional: true, - Description: "Filter by TechStatus", - }, - "front_ip": { - Type: schema.TypeString, - Optional: true, - Description: "Filter by FrontIP", - }, - "back_ip": { - Type: schema.TypeString, - Optional: true, - Description: "Filter by BackIP", - }, - "page": { - Type: schema.TypeInt, - Optional: true, - Default: 0, - }, - "size": { - Type: schema.TypeInt, - Optional: true, - Default: 0, - }, - "items": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: createLBListSchema(), - }, - }, - "entry_count": { - Type: schema.TypeInt, - Computed: true, - }, - } -} - -func dsLBListSchemaMake() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "by_id": { - Type: schema.TypeInt, - Optional: true, - Description: "Filter by ID", - }, - "name": { - Type: schema.TypeString, - Optional: true, - Description: "Filter by name", - }, - "account_id": { - Type: schema.TypeInt, - Optional: true, - Description: "Filter by Account ID", - }, - "rg_id": { - Type: schema.TypeInt, - Optional: true, - Description: "Filter by RG ID", - }, - "tech_status": { - Type: schema.TypeString, - Optional: true, - Description: "Filter by TechStatus", - }, - "status": { - Type: schema.TypeString, - Optional: true, - Description: "Filter by Status", - }, - "front_ip": { - Type: schema.TypeString, - Optional: true, - Description: "Filter by FrontIP", - }, - "back_ip": { - Type: schema.TypeString, - Optional: true, - Description: "Filter by BackIP", - }, - "includedeleted": { - Type: schema.TypeBool, - Optional: true, - Default: false, - }, - "page": { - Type: schema.TypeInt, - Optional: true, - Default: 0, - }, - "size": { - Type: schema.TypeInt, - Optional: true, - Default: 0, - }, - "items": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: createLBListSchema(), - }, - }, - "entry_count": { - Type: schema.TypeInt, - Computed: true, - }, - } -} diff --git a/internal/service/cloudbroker/lb/lb_schema.go b/internal/service/cloudbroker/lb/lb_schema.go deleted file mode 100644 index 9f30ca8..0000000 --- a/internal/service/cloudbroker/lb/lb_schema.go +++ /dev/null @@ -1,702 +0,0 @@ -/* -Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, -Kasim Baybikov, - -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 lb - -import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - -func createLBSchema() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "ha_mode": { - Type: schema.TypeBool, - Computed: true, - }, - "ckey": { - Type: schema.TypeString, - Computed: true, - }, - "meta": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "acl": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "backends": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "algorithm": { - Type: schema.TypeString, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "server_default_settings": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "downinter": { - Type: schema.TypeInt, - Computed: true, - }, - "fall": { - Type: schema.TypeInt, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "inter": { - Type: schema.TypeInt, - Computed: true, - }, - "maxconn": { - Type: schema.TypeInt, - Computed: true, - }, - "maxqueue": { - Type: schema.TypeInt, - Computed: true, - }, - "rise": { - Type: schema.TypeInt, - Computed: true, - }, - "slowstart": { - Type: schema.TypeInt, - Computed: true, - }, - "weight": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "servers": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "address": { - Type: schema.TypeString, - Computed: true, - }, - "check": { - Type: schema.TypeString, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "port": { - Type: schema.TypeInt, - Computed: true, - }, - "server_settings": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "downinter": { - Type: schema.TypeInt, - Computed: true, - }, - "fall": { - Type: schema.TypeInt, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "inter": { - Type: schema.TypeInt, - Computed: true, - }, - "maxconn": { - Type: schema.TypeInt, - Computed: true, - }, - "maxqueue": { - Type: schema.TypeInt, - Computed: true, - }, - "rise": { - Type: schema.TypeInt, - Computed: true, - }, - "slowstart": { - Type: schema.TypeInt, - Computed: true, - }, - "weight": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - "desc": { - Type: schema.TypeString, - Computed: true, - }, - "dp_api_user": { - Type: schema.TypeString, - Computed: true, - }, - "dp_api_password": { - Type: schema.TypeString, - Computed: true, - }, - "extnet_id": { - Type: schema.TypeInt, - Computed: true, - }, - "frontends": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "backend": { - Type: schema.TypeString, - Computed: true, - }, - "bindings": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "address": { - Type: schema.TypeString, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "port": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - "gid": { - Type: schema.TypeInt, - Computed: true, - }, - "guid": { - Type: schema.TypeInt, - Computed: true, - }, - "lb_id": { - Type: schema.TypeInt, - Computed: true, - }, - "image_id": { - Type: schema.TypeInt, - Computed: true, - }, - "milestones": { - Type: schema.TypeInt, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "primary_node": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "backend_ip": { - Type: schema.TypeString, - Computed: true, - }, - "compute_id": { - Type: schema.TypeInt, - Computed: true, - }, - "frontend_ip": { - Type: schema.TypeString, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "mgmt_ip": { - Type: schema.TypeString, - Computed: true, - }, - "network_id": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "rg_id": { - Type: schema.TypeInt, - Computed: true, - }, - "secondary_node": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "backend_ip": { - Type: schema.TypeString, - Computed: true, - }, - "compute_id": { - Type: schema.TypeInt, - Computed: true, - }, - "frontend_ip": { - Type: schema.TypeString, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "mgmt_ip": { - Type: schema.TypeString, - Computed: true, - }, - "network_id": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "status": { - Type: schema.TypeString, - Computed: true, - }, - "tech_status": { - Type: schema.TypeString, - Computed: true, - }, - "vins_id": { - Type: schema.TypeInt, - Computed: true, - }, - } -} - -func createLBListSchema() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "ha_mode": { - Type: schema.TypeBool, - Computed: true, - }, - "acl": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "backends": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "algorithm": { - Type: schema.TypeString, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "server_default_settings": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "downinter": { - Type: schema.TypeInt, - Computed: true, - }, - "fall": { - Type: schema.TypeInt, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "inter": { - Type: schema.TypeInt, - Computed: true, - }, - "maxconn": { - Type: schema.TypeInt, - Computed: true, - }, - "maxqueue": { - Type: schema.TypeInt, - Computed: true, - }, - "rise": { - Type: schema.TypeInt, - Computed: true, - }, - "slowstart": { - Type: schema.TypeInt, - Computed: true, - }, - "weight": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "servers": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "address": { - Type: schema.TypeString, - Computed: true, - }, - "check": { - Type: schema.TypeString, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "port": { - Type: schema.TypeInt, - Computed: true, - }, - "server_settings": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "downinter": { - Type: schema.TypeInt, - Computed: true, - }, - "fall": { - Type: schema.TypeInt, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "inter": { - Type: schema.TypeInt, - Computed: true, - }, - "maxconn": { - Type: schema.TypeInt, - Computed: true, - }, - "maxqueue": { - Type: schema.TypeInt, - Computed: true, - }, - "rise": { - Type: schema.TypeInt, - Computed: true, - }, - "slowstart": { - Type: schema.TypeInt, - Computed: true, - }, - "weight": { - 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, - }, - "desc": { - Type: schema.TypeString, - Computed: true, - }, - "dp_api_user": { - Type: schema.TypeString, - Computed: true, - }, - "dp_api_password": { - Type: schema.TypeString, - Computed: true, - }, - "extnet_id": { - Type: schema.TypeInt, - Computed: true, - }, - "frontends": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "backend": { - Type: schema.TypeString, - Computed: true, - }, - "bindings": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "address": { - Type: schema.TypeString, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "port": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - "gid": { - Type: schema.TypeInt, - Computed: true, - }, - "guid": { - Type: schema.TypeInt, - Computed: true, - }, - "lb_id": { - Type: schema.TypeInt, - Computed: true, - }, - "milestones": { - Type: schema.TypeInt, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "primary_node": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "backend_ip": { - Type: schema.TypeString, - Computed: true, - }, - "compute_id": { - Type: schema.TypeInt, - Computed: true, - }, - "frontend_ip": { - Type: schema.TypeString, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "mgmt_ip": { - Type: schema.TypeString, - Computed: true, - }, - "network_id": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "rg_id": { - Type: schema.TypeInt, - Computed: true, - }, - "rg_name": { - Type: schema.TypeString, - Computed: true, - }, - "secondary_node": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "backend_ip": { - Type: schema.TypeString, - Computed: true, - }, - "compute_id": { - Type: schema.TypeInt, - Computed: true, - }, - "frontend_ip": { - Type: schema.TypeString, - Computed: true, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - }, - "mgmt_ip": { - Type: schema.TypeString, - Computed: true, - }, - "network_id": { - 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, - }, - "vins_id": { - Type: schema.TypeInt, - Computed: true, - }, - } -} \ No newline at end of file diff --git a/internal/service/cloudbroker/lb/schema.go b/internal/service/cloudbroker/lb/schema.go new file mode 100644 index 0000000..afe0f41 --- /dev/null +++ b/internal/service/cloudbroker/lb/schema.go @@ -0,0 +1,1868 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 lb + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +func dsLBSchemaMake() map[string]*schema.Schema { + sch := map[string]*schema.Schema{ + "lb_id": { + Type: schema.TypeInt, + Required: true, + }, + "ha_mode": { + Type: schema.TypeBool, + Computed: true, + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "acl": { + Type: schema.TypeString, + Computed: true, + }, + "backend_haip": { + Type: schema.TypeString, + Computed: true, + }, + "backends": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "algorithm": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "server_default_settings": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "downinter": { + Type: schema.TypeInt, + Computed: true, + }, + "fall": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "inter": { + Type: schema.TypeInt, + Computed: true, + }, + "maxconn": { + Type: schema.TypeInt, + Computed: true, + }, + "maxqueue": { + Type: schema.TypeInt, + Computed: true, + }, + "rise": { + Type: schema.TypeInt, + Computed: true, + }, + "slowstart": { + Type: schema.TypeInt, + Computed: true, + }, + "weight": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "servers": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "address": { + Type: schema.TypeString, + Computed: true, + }, + "check": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "port": { + Type: schema.TypeInt, + Computed: true, + }, + "server_settings": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "downinter": { + Type: schema.TypeInt, + Computed: true, + }, + "fall": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "inter": { + Type: schema.TypeInt, + Computed: true, + }, + "maxconn": { + Type: schema.TypeInt, + Computed: true, + }, + "maxqueue": { + Type: schema.TypeInt, + Computed: true, + }, + "rise": { + Type: schema.TypeInt, + Computed: true, + }, + "slowstart": { + Type: schema.TypeInt, + Computed: true, + }, + "weight": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "dp_api_password": { + Type: schema.TypeString, + Computed: true, + }, + "dp_api_user": { + Type: schema.TypeString, + Computed: true, + }, + "extnet_id": { + Type: schema.TypeInt, + Computed: true, + }, + "frontend_haip": { + Type: schema.TypeString, + Computed: true, + }, + "frontends": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "backend": { + Type: schema.TypeString, + Computed: true, + }, + "bindings": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "address": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "port": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "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, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "part_k8s": { + Type: schema.TypeBool, + Computed: true, + }, + "primary_node": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "backend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "compute_id": { + Type: schema.TypeInt, + Computed: true, + }, + "frontend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "mgmt_ip": { + Type: schema.TypeString, + Computed: true, + }, + "network_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "secondary_node": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "backend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "compute_id": { + Type: schema.TypeInt, + Computed: true, + }, + "frontend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "mgmt_ip": { + Type: schema.TypeString, + Computed: true, + }, + "network_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + }, + "vins_id": { + Type: schema.TypeInt, + Computed: true, + }, + } + + return sch +} + +func dsLBListDeletedSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by Account ID", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by RG ID", + }, + "tech_status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by TechStatus", + }, + "front_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by FrontIP", + }, + "back_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by BackIP", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Default: 0, + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Default: 0, + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ha_mode": { + Type: schema.TypeBool, + Computed: true, + }, + "acl": { + Type: schema.TypeString, + Computed: true, + }, + "backend_haip": { + Type: schema.TypeString, + Computed: true, + }, + "backends": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "algorithm": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "server_default_settings": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "downinter": { + Type: schema.TypeInt, + Computed: true, + }, + "fall": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "inter": { + Type: schema.TypeInt, + Computed: true, + }, + "maxconn": { + Type: schema.TypeInt, + Computed: true, + }, + "maxqueue": { + Type: schema.TypeInt, + Computed: true, + }, + "rise": { + Type: schema.TypeInt, + Computed: true, + }, + "slowstart": { + Type: schema.TypeInt, + Computed: true, + }, + "weight": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "servers": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "address": { + Type: schema.TypeString, + Computed: true, + }, + "check": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "port": { + Type: schema.TypeInt, + Computed: true, + }, + "server_settings": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "downinter": { + Type: schema.TypeInt, + Computed: true, + }, + "fall": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "inter": { + Type: schema.TypeInt, + Computed: true, + }, + "maxconn": { + Type: schema.TypeInt, + Computed: true, + }, + "maxqueue": { + Type: schema.TypeInt, + Computed: true, + }, + "rise": { + Type: schema.TypeInt, + Computed: true, + }, + "slowstart": { + Type: schema.TypeInt, + Computed: true, + }, + "weight": { + 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, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "dp_api_user": { + Type: schema.TypeString, + Computed: true, + }, + "dp_api_password": { + Type: schema.TypeString, + Computed: true, + }, + "extnet_id": { + Type: schema.TypeInt, + Computed: true, + }, + "frontend_haip": { + Type: schema.TypeString, + Computed: true, + }, + "frontends": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "backend": { + Type: schema.TypeString, + Computed: true, + }, + "bindings": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "address": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "port": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "lb_id": { + Type: schema.TypeInt, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "primary_node": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "backend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "compute_id": { + Type: schema.TypeInt, + Computed: true, + }, + "frontend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "mgmt_ip": { + Type: schema.TypeString, + Computed: true, + }, + "network_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + }, + "secondary_node": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "backend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "compute_id": { + Type: schema.TypeInt, + Computed: true, + }, + "frontend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "mgmt_ip": { + Type: schema.TypeString, + Computed: true, + }, + "network_id": { + 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, + }, + "vins_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } +} + +func dsLBListSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by Account ID", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by RG ID", + }, + "tech_status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by TechStatus", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by Status", + }, + "front_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by FrontIP", + }, + "back_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by BackIP", + }, + "includedeleted": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Default: 0, + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Default: 0, + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ha_mode": { + Type: schema.TypeBool, + Computed: true, + }, + "acl": { + Type: schema.TypeString, + Computed: true, + }, + "backend_haip": { + Type: schema.TypeString, + Computed: true, + }, + "backends": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "algorithm": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "server_default_settings": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "downinter": { + Type: schema.TypeInt, + Computed: true, + }, + "fall": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "inter": { + Type: schema.TypeInt, + Computed: true, + }, + "maxconn": { + Type: schema.TypeInt, + Computed: true, + }, + "maxqueue": { + Type: schema.TypeInt, + Computed: true, + }, + "rise": { + Type: schema.TypeInt, + Computed: true, + }, + "slowstart": { + Type: schema.TypeInt, + Computed: true, + }, + "weight": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "servers": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "address": { + Type: schema.TypeString, + Computed: true, + }, + "check": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "port": { + Type: schema.TypeInt, + Computed: true, + }, + "server_settings": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "downinter": { + Type: schema.TypeInt, + Computed: true, + }, + "fall": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "inter": { + Type: schema.TypeInt, + Computed: true, + }, + "maxconn": { + Type: schema.TypeInt, + Computed: true, + }, + "maxqueue": { + Type: schema.TypeInt, + Computed: true, + }, + "rise": { + Type: schema.TypeInt, + Computed: true, + }, + "slowstart": { + Type: schema.TypeInt, + Computed: true, + }, + "weight": { + 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, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "dp_api_user": { + Type: schema.TypeString, + Computed: true, + }, + "dp_api_password": { + Type: schema.TypeString, + Computed: true, + }, + "extnet_id": { + Type: schema.TypeInt, + Computed: true, + }, + "frontend_haip": { + Type: schema.TypeString, + Computed: true, + }, + "frontends": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "backend": { + Type: schema.TypeString, + Computed: true, + }, + "bindings": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "address": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "port": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "lb_id": { + Type: schema.TypeInt, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "primary_node": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "backend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "compute_id": { + Type: schema.TypeInt, + Computed: true, + }, + "frontend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "mgmt_ip": { + Type: schema.TypeString, + Computed: true, + }, + "network_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + }, + "secondary_node": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "backend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "compute_id": { + Type: schema.TypeInt, + Computed: true, + }, + "frontend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "mgmt_ip": { + Type: schema.TypeString, + Computed: true, + }, + "network_id": { + 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, + }, + "vins_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } +} + +func lbResourceSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "rg_id": { + Type: schema.TypeInt, + Required: true, + }, + "name": { + Type: schema.TypeString, + Required: true, + }, + "extnet_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "vins_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "ha_mode": { + Type: schema.TypeBool, + Optional: true, + }, + "start": { + Type: schema.TypeBool, + Optional: true, + }, + "desc": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + + "enable": { + Type: schema.TypeBool, + Optional: true, + }, + "restart": { + Type: schema.TypeBool, + Optional: true, + }, + "restore": { + Type: schema.TypeBool, + Optional: true, + }, + "config_reset": { + Type: schema.TypeBool, + Optional: true, + }, + "permanently": { + Type: schema.TypeBool, + Optional: true, + }, + + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "acl": { + Type: schema.TypeString, + Computed: true, + }, + "backend_haip": { + Type: schema.TypeString, + Computed: true, + }, + "backends": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "algorithm": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "server_default_settings": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "downinter": { + Type: schema.TypeInt, + Computed: true, + }, + "fall": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "inter": { + Type: schema.TypeInt, + Computed: true, + }, + "maxconn": { + Type: schema.TypeInt, + Computed: true, + }, + "maxqueue": { + Type: schema.TypeInt, + Computed: true, + }, + "rise": { + Type: schema.TypeInt, + Computed: true, + }, + "slowstart": { + Type: schema.TypeInt, + Computed: true, + }, + "weight": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "servers": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "address": { + Type: schema.TypeString, + Computed: true, + }, + "check": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "port": { + Type: schema.TypeInt, + Computed: true, + }, + "server_settings": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "downinter": { + Type: schema.TypeInt, + Computed: true, + }, + "fall": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "inter": { + Type: schema.TypeInt, + Computed: true, + }, + "maxconn": { + Type: schema.TypeInt, + Computed: true, + }, + "maxqueue": { + Type: schema.TypeInt, + Computed: true, + }, + "rise": { + Type: schema.TypeInt, + Computed: true, + }, + "slowstart": { + Type: schema.TypeInt, + Computed: true, + }, + "weight": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + "dp_api_user": { + Type: schema.TypeString, + Computed: true, + }, + "dp_api_password": { + Type: schema.TypeString, + Computed: true, + }, + "frontend_haip": { + Type: schema.TypeString, + Computed: true, + }, + "frontends": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "backend": { + Type: schema.TypeString, + Computed: true, + }, + "bindings": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "address": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "port": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "lb_id": { + Type: schema.TypeInt, + Computed: true, + }, + "image_id": { + Type: schema.TypeInt, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "part_k8s": { + Type: schema.TypeBool, + Computed: true, + }, + "primary_node": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "backend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "compute_id": { + Type: schema.TypeInt, + Computed: true, + }, + "frontend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "mgmt_ip": { + Type: schema.TypeString, + Computed: true, + }, + "network_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "secondary_node": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "backend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "compute_id": { + Type: schema.TypeInt, + Computed: true, + }, + "frontend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "mgmt_ip": { + Type: schema.TypeString, + Computed: true, + }, + "network_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + }, + } +} + +func resourceLbBackendSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "lb_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the LB instance to backendCreate", + }, + "name": { + Type: schema.TypeString, + Required: true, + Description: "Must be unique among all backends of this LB - name of the new backend to create", + }, + "algorithm": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{"roundrobin", "static-rr", "leastconn"}, false), + }, + "inter": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "downinter": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "rise": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "fall": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "slowstart": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "maxconn": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "maxqueue": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "weight": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "servers": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "address": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "check": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "port": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "server_settings": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "downinter": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "fall": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "inter": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "maxconn": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "maxqueue": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "rise": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "slowstart": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "weight": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + } +} + +func resourceLbBackendServerSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "lb_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the LB instance to backendCreate", + }, + "backend_name": { + Type: schema.TypeString, + Required: true, + Description: "Must be unique among all backends of this LB - name of the new backend to create", + }, + "name": { + Type: schema.TypeString, + Required: true, + Description: "Must be unique among all servers defined for this backend - name of the server definition to add.", + }, + "address": { + Type: schema.TypeString, + Required: true, + Description: "IP address of the server.", + }, + "port": { + Type: schema.TypeInt, + Required: true, + Description: "Port number on the server", + }, + "check": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{"disabled", "enabled"}, false), + Description: "set to disabled if this server should be used regardless of its state.", + }, + "inter": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "downinter": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "rise": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "fall": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "slowstart": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "maxconn": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "maxqueue": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "weight": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + + "guid": { + Type: schema.TypeString, + Computed: true, + }, + } +} + +func resourceLbFrontendSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "lb_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the LB instance to backendCreate", + }, + "backend_name": { + Type: schema.TypeString, + Required: true, + }, + "name": { + Type: schema.TypeString, + Required: true, + }, + + "bindings": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "address": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "port": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + } +} + +func resourceLbFrontendBindSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "lb_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the LB instance to backendCreate", + }, + "frontend_name": { + Type: schema.TypeString, + Required: true, + Description: "Must be unique among all backends of this LB - name of the new backend to create", + }, + "name": { + Type: schema.TypeString, + Required: true, + }, + "address": { + Type: schema.TypeString, + Required: true, + }, + "port": { + Type: schema.TypeInt, + Required: true, + }, + + "guid": { + Type: schema.TypeString, + Computed: true, + }, + } +} diff --git a/internal/service/cloudbroker/pcidevice/flattens.go b/internal/service/cloudbroker/pcidevice/flattens.go new file mode 100644 index 0000000..f88645c --- /dev/null +++ b/internal/service/cloudbroker/pcidevice/flattens.go @@ -0,0 +1,49 @@ +package pcidevice + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/pcidevice" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens" +) + +func flattenPcidevice(d *schema.ResourceData, pd *pcidevice.ItemPCIDevice) { + log.Debugf("flattenPCIDevice: ID %d", pd.ID) + + d.Set("ckey", pd.CKey) + d.Set("meta", flattens.FlattenMeta(pd.Meta)) + d.Set("compute_id", pd.ComputeID) + d.Set("description", pd.Description) + d.Set("guid", pd.GUID) + d.Set("hw_path", pd.HwPath) + d.Set("device_id", pd.ID) + d.Set("name", pd.Name) + d.Set("rg_id", pd.RGID) + d.Set("stack_id", pd.StackID) + d.Set("status", pd.Status) + d.Set("system_name", pd.SystemName) +} + +func flattenPcideviceList(pl *pcidevice.ListPCIDevices) []map[string]interface{} { + log.Debug("flattenPCIDeviceList") + + res := make([]map[string]interface{}, 0, len(pl.Data)) + for _, item := range pl.Data { + temp := map[string]interface{}{ + "ckey": item.CKey, + "meta": flattens.FlattenMeta(item.Meta), + "compute_id": item.ComputeID, + "description": item.Description, + "guid": item.GUID, + "hw_path": item.HwPath, + "device_id": item.ID, + "rg_id": item.RGID, + "name": item.Name, + "stack_id": item.StackID, + "status": item.Status, + "system_name": item.SystemName, + } + res = append(res, temp) + } + return res +} diff --git a/internal/service/cloudbroker/pcidevice/schema.go b/internal/service/cloudbroker/pcidevice/schema.go new file mode 100644 index 0000000..bfc8d84 --- /dev/null +++ b/internal/service/cloudbroker/pcidevice/schema.go @@ -0,0 +1,252 @@ +package pcidevice + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +func dataSourcePcideviceSchemaMake() map[string]*schema.Schema { + rets := map[string]*schema.Schema{ + "device_id": { + Type: schema.TypeInt, + Required: true, + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "compute_id": { + Type: schema.TypeInt, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "hw_path": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "stack_id": { + Type: schema.TypeInt, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "system_name": { + Type: schema.TypeString, + Computed: true, + }, + } + return rets +} + +func dataSourcePcideviceListSchemaMake() map[string]*schema.Schema { + rets := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "by_id", + }, + "compute_id": { + Type: schema.TypeInt, + Optional: true, + Description: "compute_id", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "name", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "rg_id", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "status", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "page size", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Description: "pcidevice list", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "device_id": { + Type: schema.TypeInt, + Required: true, + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "compute_id": { + Type: schema.TypeInt, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "hw_path": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "stack_id": { + Type: schema.TypeInt, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "system_name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + Description: "entry count", + }, + } + return rets +} + +func resourcePcideviceSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "stack_id": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntAtLeast(1), + Description: "stackId", + }, + "rg_id": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntAtLeast(1), + Description: "Resource GROUP", + }, + "name": { + Type: schema.TypeString, + Required: true, + Description: "Name of Device", + }, + "hw_path": { + Type: schema.TypeString, + Required: true, + Description: "PCI address of the device", + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "compute_id": { + Type: schema.TypeInt, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "description, just for information", + }, + "device_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "enable": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Enable pci device", + }, + "force_delete": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Force delete", + }, + "force_disable": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Force disable", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "system_name": { + Type: schema.TypeString, + Computed: true, + }, + } +} diff --git a/internal/service/cloudbroker/pfw/api.go b/internal/service/cloudbroker/pfw/api.go deleted file mode 100644 index 5c2a38e..0000000 --- a/internal/service/cloudbroker/pfw/api.go +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, - -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 pfw - -const ComputePfwListAPI = "/restmachine/cloudbroker/compute/pfwList" -const ComputePfwAddAPI = "/restmachine/cloudbroker/compute/pfwAdd" -const ComputePfwDelAPI = "/restmachine/cloudbroker/compute/pfwDel" diff --git a/internal/service/cloudbroker/pfw/resource_pfw.go b/internal/service/cloudbroker/pfw/resource_pfw.go deleted file mode 100644 index b0c151c..0000000 --- a/internal/service/cloudbroker/pfw/resource_pfw.go +++ /dev/null @@ -1,199 +0,0 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, - -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 pfw - -import ( - "context" - "fmt" - - "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/cloudbroker/compute" - "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" - "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" -) - -func resourcePfwCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Debugf("resourcePfwCreate: called for compute %d", d.Get("compute_id").(int)) - - c := m.(*controller.ControllerCfg) - req := compute.PFWAddRequest{} - req.ComputeID = uint64(d.Get("compute_id").(int)) - req.PublicPortStart = uint64(d.Get("public_port_start").(int)) - req.LocalBasePort = uint64(d.Get("local_base_port").(int)) - req.Proto = d.Get("proto").(string) - - if portEnd, ok := d.GetOk("public_port_end"); ok { - req.PublicPortEnd = int64(portEnd.(int)) - } - - pfwId, err := c.CloudBroker().Compute().PFWAdd(ctx, req) - if err != nil { - return diag.FromErr(err) - } - - d.SetId(fmt.Sprintf("%d-%d", d.Get("compute_id").(int), pfwId)) - - pfw, err := utilityPfwCheckPresence(ctx, d, m) - if err != nil { - return diag.FromErr(err) - } - - d.Set("local_ip", pfw.LocalIP) - if _, ok := d.GetOk("public_port_end"); !ok { - d.Set("public_port_end", pfw.PublicPortEnd) - } - - return nil -} - -func resourcePfwRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Debugf("resourcePfwRead: called for compute %d, rule %s", d.Get("compute_id").(int), d.Id()) - - pfw, err := utilityPfwCheckPresence(ctx, d, m) - if pfw == nil { - d.SetId("") - return diag.FromErr(err) - } - - d.Set("compute_id", pfw.VMID) - d.Set("public_port_start", pfw.PublicPortStart) - d.Set("public_port_end", pfw.PublicPortEnd) - d.Set("local_ip", pfw.LocalIP) - d.Set("local_base_port", pfw.LocalPort) - d.Set("proto", pfw.Protocol) - - return nil -} - -func resourcePfwDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Debugf("resourcePfwDelete: called for compute %d, rule %s", d.Get("compute_id").(int), d.Id()) - - pfw, err := utilityPfwCheckPresence(ctx, d, m) - if pfw == nil { - if err != nil { - return diag.FromErr(err) - } - return nil - } - - c := m.(*controller.ControllerCfg) - req := compute.PFWDelRequest{ - ComputeID: uint64(d.Get("compute_id").(int)), - RuleID: pfw.ID, - } - - _, err = c.CloudBroker().Compute().PFWDel(ctx, req) - if err != nil { - return diag.FromErr(err) - } - - d.SetId("") - - return nil -} - -func resourcePfwSchemaMake() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "compute_id": { - Type: schema.TypeInt, - Required: true, - ForceNew: true, - Description: "ID of compute instance.", - }, - - "public_port_start": { - Type: schema.TypeInt, - Required: true, - ForceNew: true, - ValidateFunc: validation.IntBetween(1, 65535), - Description: "External start port number for the rule.", - }, - - "public_port_end": { - Type: schema.TypeInt, - Optional: true, - Computed: true, - ForceNew: true, - ValidateFunc: validation.IntBetween(1, 65535), - Description: "End port number (inclusive) for the ranged rule.", - }, - - "local_ip": { - Type: schema.TypeString, - Computed: true, - Description: "IP address of compute instance.", - }, - - "local_base_port": { - Type: schema.TypeInt, - Required: true, - ForceNew: true, - ValidateFunc: validation.IntBetween(1, 65535), - Description: "Internal base port number.", - }, - - "proto": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice([]string{"tcp", "udp"}, false), - Description: "Network protocol, either 'tcp' or 'udp'.", - }, - } -} - -func ResourcePfw() *schema.Resource { - return &schema.Resource{ - SchemaVersion: 1, - - CreateContext: resourcePfwCreate, - ReadContext: resourcePfwRead, - DeleteContext: resourcePfwDelete, - - Importer: &schema.ResourceImporter{ - StateContext: schema.ImportStatePassthroughContext, - }, - - Timeouts: &schema.ResourceTimeout{ - Create: &constants.Timeout60s, - Read: &constants.Timeout30s, - Update: &constants.Timeout60s, - Delete: &constants.Timeout60s, - Default: &constants.Timeout60s, - }, - - Schema: resourcePfwSchemaMake(), - } -} diff --git a/internal/service/cloudbroker/rg/data_source_rg_get_resource_consumption.go b/internal/service/cloudbroker/rg/data_source_rg_get_resource_consumption.go new file mode 100644 index 0000000..b09ddf5 --- /dev/null +++ b/internal/service/cloudbroker/rg/data_source_rg_get_resource_consumption.go @@ -0,0 +1,70 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 rg + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceRGResourceConsumptionGetRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + RGResourceConsumptionRec, err := utilityRGResourceConsumptionGetCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + flattenRGResourceConsumption(d, RGResourceConsumptionRec) + return nil +} + +func DataSourceRGResourceConsumptionGet() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceRGResourceConsumptionGetRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceRGResourceConsumptionGetSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/rg/data_source_rg_list_computes.go b/internal/service/cloudbroker/rg/data_source_rg_list_computes.go new file mode 100644 index 0000000..cc0dd94 --- /dev/null +++ b/internal/service/cloudbroker/rg/data_source_rg_list_computes.go @@ -0,0 +1,72 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 rg + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceRgListComputesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + listComputes, err := utilityRgListComputesCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenRgListComputes(listComputes)) + d.Set("entry_count", listComputes.EntryCount) + + return nil +} + +func DataSourceRgListComputes() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceRgListComputesRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceRgListComputesSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/rg/data_source_rg_list_deleted.go b/internal/service/cloudbroker/rg/data_source_rg_list_deleted.go new file mode 100644 index 0000000..b4470b2 --- /dev/null +++ b/internal/service/cloudbroker/rg/data_source_rg_list_deleted.go @@ -0,0 +1,72 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 rg + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceRgListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + rgList, err := utilityRgListDeletedCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenRgList(rgList)) + d.Set("entry_count", rgList.EntryCount) + + return nil +} + +func DataSourceRgListDeleted() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceRgListDeletedRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceRgListDeletedSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/rg/data_source_rg_list_lb.go b/internal/service/cloudbroker/rg/data_source_rg_list_lb.go new file mode 100644 index 0000000..a4521fe --- /dev/null +++ b/internal/service/cloudbroker/rg/data_source_rg_list_lb.go @@ -0,0 +1,71 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 rg + +import ( + "context" + "strconv" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceRgListLbRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + listLb, err := utilityRgListLbCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + d.SetId(strconv.Itoa(d.Get("rg_id").(int))) + d.Set("items", flattenRgListLb(listLb)) + d.Set("entry_count", listLb.EntryCount) + + return nil +} + +func DataSourceRgListLb() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceRgListLbRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceRgListLbSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/rg/data_source_rg_list_pfw.go b/internal/service/cloudbroker/rg/data_source_rg_list_pfw.go new file mode 100644 index 0000000..3e3a372 --- /dev/null +++ b/internal/service/cloudbroker/rg/data_source_rg_list_pfw.go @@ -0,0 +1,71 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 rg + +import ( + "context" + "strconv" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceRgListPfwRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + listPfw, err := utilityRgListPfwCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + d.SetId(strconv.Itoa(d.Get("rg_id").(int))) + d.Set("items", flattenRgListPfw(listPfw)) + d.Set("entry_count", listPfw.EntryCount) + + return nil +} + +func DataSourceRgListPfw() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceRgListPfwRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceRgListPfwSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/rg/data_source_rg_list_vins.go b/internal/service/cloudbroker/rg/data_source_rg_list_vins.go new file mode 100644 index 0000000..4a5ae09 --- /dev/null +++ b/internal/service/cloudbroker/rg/data_source_rg_list_vins.go @@ -0,0 +1,71 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 rg + +import ( + "context" + "strconv" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceRgListVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + listVins, err := utilityRgListVinsCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + d.SetId(strconv.Itoa(d.Get("rg_id").(int))) + d.Set("items", flattenRgListVins(listVins)) + d.Set("entry_count", listVins.EntryCount) + + return nil +} + +func DataSourceRgListVins() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceRgListVinsRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceRgListVinsSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/rg/data_source_rg_resource_consumption_list.go b/internal/service/cloudbroker/rg/data_source_rg_resource_consumption_list.go new file mode 100644 index 0000000..74ea889 --- /dev/null +++ b/internal/service/cloudbroker/rg/data_source_rg_resource_consumption_list.go @@ -0,0 +1,71 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 rg + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceRGResourceConsumptionListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + rgResourceConsumptionList, err := utilityRGResourceConsumptionListCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenRGResourceConsumptionList(rgResourceConsumptionList)) + d.Set("entry_count", rgResourceConsumptionList.EntryCount) + return nil +} + +func DataSourceRGResourceConsumptionList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceRGResourceConsumptionListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceRGResourceConsumptionListSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/rg/data_source_rg_usage.go b/internal/service/cloudbroker/rg/data_source_rg_usage.go new file mode 100644 index 0000000..94f8f19 --- /dev/null +++ b/internal/service/cloudbroker/rg/data_source_rg_usage.go @@ -0,0 +1,69 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 rg + +import ( + "context" + "strconv" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceRgUsageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + usage, err := utilityDataRgUsageCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + d.SetId(strconv.Itoa(d.Get("rg_id").(int))) + flattenRgUsageResource(d, *usage) + return nil +} + +func DataSourceRgUsage() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceRgUsageRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceRgUsageSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/rg/flattens.go b/internal/service/cloudbroker/rg/flattens.go new file mode 100644 index 0000000..4f379a0 --- /dev/null +++ b/internal/service/cloudbroker/rg/flattens.go @@ -0,0 +1,498 @@ +package rg + +import ( + log "github.com/sirupsen/logrus" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg" +) + +func flattenResgroup(d *schema.ResourceData, rgData *rg.RecordRG) { + log.Debugf("flattenResgroup: decoded RG name %q / ID %d, account ID %d", + rgData.Name, rgData.ID, rgData.AccountID) + + d.Set("account_id", rgData.AccountID) + d.Set("account_name", rgData.AccountName) + d.Set("acl", flattenRgAcl(rgData.ACL)) + d.Set("cpu_allocation_parameter", rgData.CPUAllocationParameter) + d.Set("cpu_allocation_ratio", rgData.CPUAllocationRatio) + d.Set("created_by", rgData.CreatedBy) + d.Set("created_time", rgData.CreatedTime) + d.Set("def_net_id", rgData.DefNetID) + d.Set("def_net_type", rgData.DefNetType) + d.Set("deleted_by", rgData.DeletedBy) + d.Set("deleted_time", rgData.DeletedTime) + d.Set("desc", rgData.Description) + d.Set("dirty", rgData.Dirty) + d.Set("gid", rgData.GID) + d.Set("guid", rgData.GUID) + d.Set("rg_id", rgData.ID) + d.Set("lock_status", rgData.LockStatus) + d.Set("milestones", rgData.Milestones) + d.Set("name", rgData.Name) + d.Set("register_computes", rgData.RegisterComputes) + d.Set("resource_limits", flattenRgResourceLimits(rgData.ResourceLimits)) + d.Set("resource_types", rgData.ResTypes) + d.Set("secret", rgData.Secret) + d.Set("status", rgData.Status) + d.Set("uniq_pools", rgData.UniqPools) + d.Set("updated_by", rgData.UpdatedBy) + d.Set("updated_time", rgData.UpdatedTime) + d.Set("vins", rgData.VINS) + d.Set("computes", rgData.VMs) +} + +func flattenRgAcl(rgACLs rg.ListACL) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(rgACLs)) + for _, acl := range rgACLs { + temp := map[string]interface{}{ + "explicit": acl.Explicit, + "guid": acl.GUID, + "right": acl.Right, + "status": acl.Status, + "type": acl.Type, + "user_group_id": acl.UserGroupID, + } + + res = append(res, temp) + } + + return res +} + +func flattenRgResourceLimits(rl rg.ResourceLimits) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "cu_c": rl.CUC, + "cu_d": rl.CuD, + "cu_dm": rl.CUDM, + "cu_i": rl.CUI, + "cu_m": rl.CUM, + "cu_np": rl.CUNP, + "gpu_units": rl.GPUUnits, + } + res = append(res, temp) + + return res + +} + +func flattenRgAudits(rgAudits rg.ListAudits) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(rgAudits)) + for _, rgAudit := range rgAudits { + temp := map[string]interface{}{ + "call": rgAudit.Call, + "responsetime": rgAudit.ResponseTime, + "statuscode": rgAudit.StatusCode, + "timestamp": rgAudit.Timestamp, + "user": rgAudit.User, + } + + res = append(res, temp) + } + + return res +} + +func flattenRgListGroups(list *rg.ListAffinityGroup) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(list.Data)) + for _, item := range list.Data { + for key, vals := range item { + for _, v := range vals { + temp := map[string]interface{}{ + "label": key, + "id": v.ID, + "node_id": v.NodeID, + } + res = append(res, temp) + } + } + } + + return res +} + +func flattenRgAffinityGroupComputes(list rg.ListAffinityGroupCompute) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(list)) + + for _, item := range list { + temp := map[string]interface{}{ + "compute_id": item.ComputeID, + "other_node": item.OtherNode, + "other_node_indirect": item.OtherNodeIndirect, + "other_node_indirect_soft": item.OtherNodeIndirectSoft, + "other_node_soft": item.OtherNodeSoft, + "same_node": item.SameNode, + "same_node_soft": item.SameNodeSoft, + } + res = append(res, temp) + } + + return res +} + +func flattenRGResourceConsumption(d *schema.ResourceData, rg *rg.ItemResourceConsumption) { + d.Set("consumed", flattenResource(rg.Consumed)) + d.Set("reserved", flattenResource(rg.Reserved)) + d.Set("resource_limits", flattenRgResourceLimits(rg.ResourceLimits)) + d.Set("rg_id", rg.RGID) +} + +func flattenRGResourceConsumptionList(rg *rg.ListResourceConsumption) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(rg.Data)) + for _, rc := range rg.Data { + temp := map[string]interface{}{ + "consumed": flattenResource(rc.Consumed), + "reserved": flattenResource(rc.Reserved), + "resource_limits": flattenRgResourceLimits(rc.ResourceLimits), + "rg_id": rc.RGID, + } + res = append(res, temp) + } + return res +} + +func flattenRgUsageResource(d *schema.ResourceData, usage rg.Reservation) { + d.Set("cpu", usage.CPU) + d.Set("disk_size", usage.DiskSize) + d.Set("disk_size_max", usage.DiskSizeMax) + d.Set("extips", usage.ExtIPs) + d.Set("exttraffic", usage.ExtTraffic) + d.Set("gpu", usage.GPU) + d.Set("ram", usage.RAM) + d.Set("seps", flattenRGSeps(usage.SEPs)) +} + +func flattenResource(resource rg.Reservation) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "cpu": resource.CPU, + "disk_size": resource.DiskSize, + "disk_size_max": resource.DiskSizeMax, + "extips": resource.ExtIPs, + "exttraffic": resource.ExtTraffic, + "gpu": resource.GPU, + "ram": resource.RAM, + "seps": flattenRGSeps(resource.SEPs), + } + + res = append(res, temp) + + return res +} + +func flattenRGSeps(seps map[string]map[string]rg.DiskUsage) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + for sepKey, sepVal := range seps { + for dataKey, dataVal := range sepVal { + temp := map[string]interface{}{ + "sep_id": sepKey, + "data_name": dataKey, + "disk_size": dataVal.DiskSize, + "disk_size_max": dataVal.DiskSizeMax, + } + res = append(res, temp) + } + } + + return res +} + +func flattenRgListComputes(lc *rg.ListComputes) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(lc.Data)) + for _, compute := range lc.Data { + temp := map[string]interface{}{ + "account_id": compute.AccountID, + "account_name": compute.AccountName, + "affinity_label": compute.AffinityLabel, + "affinity_rules": flattenRules(compute.AffinityRules), + "affinity_weight": compute.AffinityWeight, + "antiaffinity_rules": flattenRules(compute.AntiAffinityRules), + "cpus": compute.CPUs, + "created_by": compute.CreatedBy, + "created_time": compute.CreatedTime, + "deleted_by": compute.DeletedBy, + "deleted_time": compute.DeletedTime, + "id": compute.ID, + "name": compute.Name, + "ram": compute.RAM, + "registered": compute.Registered, + "rg_id": compute.RGID, + "rg_name": compute.RGName, + "status": compute.Status, + "tech_status": compute.TechStatus, + "total_disks_size": compute.TotalDisksSize, + "updated_by": compute.UpdatedBy, + "updated_time": compute.UpdatedTime, + "user_managed": compute.UserManaged, + "vins_connected": compute.VINSConnected, + } + + res = append(res, temp) + } + + return res +} + +func flattenRules(list rg.ListRules) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(list)) + for _, rule := range list { + temp := map[string]interface{}{ + "guid": rule.GUID, + "key": rule.Key, + "mode": rule.Mode, + "policy": rule.Policy, + "topology": rule.Topology, + "value": rule.Value, + } + + res = append(res, temp) + } + + return res +} + +func flattenRgListLb(listLb *rg.ListLB) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(listLb.Data)) + for _, lb := range listLb.Data { + temp := map[string]interface{}{ + "ha_mode": lb.HAMode, + "acl": lb.ACL, + "backends": flattenBackends(lb.Backends), + "created_by": lb.CreatedBy, + "created_time": lb.CreatedTime, + "deleted_by": lb.DeletedBy, + "deleted_time": lb.DeletedTime, + "desc": lb.Description, + "dp_api_user": lb.DPAPIUser, + "extnet_id": lb.ExtNetID, + "frontends": flattenFrontends(lb.Frontends), + "gid": lb.GID, + "guid": lb.GUID, + "id": lb.ID, + "image_id": lb.ImageID, + "milestones": lb.Milestones, + "name": lb.Name, + "primary_node": flattenNode(lb.PrimaryNode), + "rg_name": lb.RGName, + "secondary_node": flattenNode(lb.SecondaryNode), + "status": lb.Status, + "tech_status": lb.TechStatus, + "updated_by": lb.UpdatedBy, + "updated_time": lb.UpdatedTime, + "vins_id": lb.VINSID, + } + res = append(res, temp) + } + return res +} + +func flattenNode(node rg.RecordNode) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "backend_ip": node.BackendIP, + "compute_id": node.ComputeID, + "frontend_ip": node.FrontendIP, + "guid": node.GUID, + "mgmt_ip": node.MGMTIP, + "network_id": node.NetworkID, + } + res = append(res, temp) + return res +} + +func flattenFrontends(list rg.ListFrontends) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(list)) + for _, front := range list { + temp := map[string]interface{}{ + "backend": front.Backend, + "bindings": flattenBindings(front.Bindings), + "guid": front.GUID, + "name": front.Name, + } + res = append(res, temp) + } + + return res +} + +func flattenBindings(list rg.ListBindings) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(list)) + for _, bind := range list { + temp := map[string]interface{}{ + "address": bind.Address, + "guid": bind.GUID, + "name": bind.Name, + "port": bind.Port, + } + res = append(res, temp) + } + + return res +} + +func flattenBackends(b rg.ListBackends) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(b)) + for _, item := range b { + temp := map[string]interface{}{ + "algorithm": item.Algorithm, + "guid": item.GUID, + "name": item.Name, + "server_default_settings": flattenServerSettings(item.ServerDefaultSettings), + "servers": flattenListServers(item.Servers), + } + res = append(res, temp) + } + return res +} + +func flattenListServers(list rg.ListServers) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(list)) + for _, serv := range list { + temp := map[string]interface{}{ + "address": serv.Address, + "check": serv.Check, + "guid": serv.GUID, + "name": serv.Name, + "port": serv.Port, + "server_settings": flattenServerSettings(serv.ServerSettings), + } + res = append(res, temp) + } + + return res +} + +func flattenServerSettings(settings rg.ServerSettings) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "inter": settings.Inter, + "guid": settings.GUID, + "down_inter": settings.DownInter, + "rise": settings.Rise, + "fall": settings.Fall, + "slow_start": settings.SlowStart, + "max_conn": settings.MaxConn, + "max_queue": settings.MaxQueue, + "weight": settings.Weight, + } + res = append(res, temp) + return res +} + +func flattenRgList(rgl *rg.ListRG) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(rgl.Data)) + for _, rg := range rgl.Data { + temp := map[string]interface{}{ + "account_id": rg.AccountID, + "account_name": rg.AccountName, + "acl": flattenRgAcl(rg.ACL), + "cpu_allocation_parameter": rg.CPUAllocationParameter, + "cpu_allocation_ratio": rg.CPUAllocationRatio, + "created_by": rg.CreatedBy, + "created_time": rg.CreatedTime, + "def_net_id": rg.DefNetID, + "def_net_type": rg.DefNetType, + "deleted_by": rg.DeletedBy, + "deleted_time": rg.DeletedTime, + "desc": rg.Description, + "dirty": rg.Dirty, + "gid": rg.GID, + "guid": rg.GUID, + "rg_id": rg.ID, + "lock_status": rg.LockStatus, + "milestones": rg.Milestones, + "name": rg.Name, + "register_computes": rg.RegisterComputes, + "resource_limits": flattenRgResourceLimits(rg.ResourceLimits), + "secret": rg.Secret, + "status": rg.Status, + "updated_by": rg.UpdatedBy, + "updated_time": rg.UpdatedTime, + "vins": rg.VINS, + "vms": rg.VMs, + } + res = append(res, temp) + } + return res + +} + +func flattenRgListVins(lv *rg.ListVINS) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(lv.Data)) + for _, vins := range lv.Data { + temp := map[string]interface{}{ + "account_id": vins.AccountID, + "account_name": vins.AccountName, + "computes": vins.Computes, + "created_by": vins.CreatedBy, + "created_time": vins.CreatedTime, + "deleted_by": vins.DeletedBy, + "deleted_time": vins.DeletedTime, + "external_ip": vins.ExternalIP, + "id": vins.ID, + "name": vins.Name, + "network": vins.Network, + "pri_vnf_dev_id": vins.PriVNFDevID, + "rg_id": vins.RGID, + "rg_name": vins.RGName, + "status": vins.Status, + "updated_by": vins.UpdatedBy, + "updated_time": vins.UpdatedTime, + } + + res = append(res, temp) + } + + return res +} + +func flattenRgListPfw(listPfw *rg.ListPFW) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(listPfw.Data)) + for _, pfw := range listPfw.Data { + temp := map[string]interface{}{ + "public_port_end": pfw.PublicPortEnd, + "public_port_start": pfw.PublicPortStart, + "vm_id": pfw.VMID, + "vm_ip": pfw.VMIP, + "vm_name": pfw.VMName, + "vm_port": pfw.VMPort, + "vins_id": pfw.VINSID, + "vins_name": pfw.VINSName, + } + res = append(res, temp) + } + + return res +} + +func flattenResourceRG(d *schema.ResourceData, rgData *rg.RecordRG) { + d.Set("account_id", rgData.AccountID) + d.Set("gid", rgData.GID) + d.Set("rg_name", rgData.Name) + d.Set("resource_limits", flattenRgResourceLimits(rgData.ResourceLimits)) + d.Set("def_net_type", rgData.DefNetType) + d.Set("description", rgData.Description) + d.Set("register_computes", rgData.RegisterComputes) + d.Set("uniq_pools", rgData.UniqPools) + d.Set("cpu_allocation_parameter", rgData.CPUAllocationParameter) + d.Set("cpu_allocation_ratio", rgData.CPUAllocationRatio) + d.Set("acl", flattenRgAcl(rgData.ACL)) + d.Set("account_name", rgData.AccountName) + d.Set("created_by", rgData.CreatedBy) + d.Set("created_time", rgData.CreatedTime) + d.Set("def_net_id", rgData.DefNetID) + d.Set("deleted_by", rgData.DeletedBy) + d.Set("deleted_time", rgData.DeletedTime) + d.Set("guid", rgData.GUID) + d.Set("rg_id", rgData.ID) + d.Set("lock_status", rgData.LockStatus) + d.Set("milestones", rgData.Milestones) + d.Set("resource_types", rgData.ResTypes) + d.Set("secret", rgData.Secret) + d.Set("status", rgData.Status) + d.Set("updated_by", rgData.UpdatedBy) + d.Set("updated_time", rgData.UpdatedTime) + d.Set("vins", rgData.VINS) + d.Set("vms", rgData.VMs) +} diff --git a/internal/service/cloudbroker/rg/schema.go b/internal/service/cloudbroker/rg/schema.go new file mode 100644 index 0000000..4280e1b --- /dev/null +++ b/internal/service/cloudbroker/rg/schema.go @@ -0,0 +1,2487 @@ +package rg + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +func dataSourceRgSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "rg_id": { + Type: schema.TypeInt, + Required: true, + }, + "reason": { + Type: schema.TypeString, + Optional: true, + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "cpu_allocation_parameter": { + Type: schema.TypeString, + Computed: true, + }, + "cpu_allocation_ratio": { + Type: schema.TypeFloat, + Computed: true, + }, + "created_by": { + Type: schema.TypeString, + Computed: true, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + "def_net_id": { + Type: schema.TypeInt, + Computed: true, + }, + "def_net_type": { + Type: schema.TypeString, + Computed: true, + }, + "deleted_by": { + Type: schema.TypeString, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "dirty": { + Type: schema.TypeBool, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "lock_status": { + Type: schema.TypeString, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "register_computes": { + Type: schema.TypeBool, + Computed: true, + }, + "resource_limits": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cu_c": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_d": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_dm": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_i": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_m": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_np": { + Type: schema.TypeFloat, + Computed: true, + }, + "gpu_units": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + "resource_types": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "secret": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "uniq_pools": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "updated_by": { + Type: schema.TypeString, + Computed: true, + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + }, + "vins": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "computes": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + } +} + +func dataSourceRgAuditsSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "rg_id": { + Type: schema.TypeInt, + Required: true, + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "call": { + Type: schema.TypeString, + Computed: true, + }, + "responsetime": { + Type: schema.TypeFloat, + Computed: true, + }, + "statuscode": { + Type: schema.TypeInt, + Computed: true, + }, + "timestamp": { + Type: schema.TypeFloat, + Computed: true, + }, + "user": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + } +} + +func dataSourceRgAffinityGroupsListSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "rg_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the RG", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, + + "affinity_groups": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "label": { + Type: schema.TypeString, + Computed: true, + }, + "id": { + Type: schema.TypeInt, + Computed: true, + }, + "node_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } +} + +func dataSourceRgAffinityGroupsGetSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "rg_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the RG", + }, + "affinity_group": { + Type: schema.TypeString, + Required: true, + Description: "Affinity group label", + }, + + "ids": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + } + + return res +} + +func dataSourceRgAffinityGroupComputesSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "rg_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the RG", + }, + "affinity_group": { + Type: schema.TypeString, + Required: true, + Description: "Affinity group label", + }, + + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "compute_id": { + Type: schema.TypeInt, + Computed: true, + }, + "other_node": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "other_node_indirect": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "other_node_indirect_soft": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "other_node_soft": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "same_node": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "same_node_soft": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + }, + }, + }, + } + + return res +} + +func dataSourceRGResourceConsumptionGetSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "rg_id": { + Type: schema.TypeInt, + Required: true, + }, + "consumed": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeFloat, + Computed: true, + }, + "extips": { + Type: schema.TypeInt, + Computed: true, + }, + "exttraffic": { + Type: schema.TypeInt, + Computed: true, + }, + "gpu": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "seps": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeString, + Computed: true, + }, + "data_name": { + Type: schema.TypeString, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "reserved": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeFloat, + Computed: true, + }, + "extips": { + Type: schema.TypeInt, + Computed: true, + }, + "exttraffic": { + Type: schema.TypeInt, + Computed: true, + }, + "gpu": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "seps": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeString, + Computed: true, + }, + "data_name": { + Type: schema.TypeString, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "resource_limits": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cu_c": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_d": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_dm": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_i": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_m": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_np": { + Type: schema.TypeFloat, + Computed: true, + }, + "gpu_units": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + } + + return res +} + +func dataSourceRGResourceConsumptionListSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "consumed": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeFloat, + Computed: true, + }, + "extips": { + Type: schema.TypeInt, + Computed: true, + }, + "exttraffic": { + Type: schema.TypeInt, + Computed: true, + }, + "gpu": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "seps": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeString, + Computed: true, + }, + "data_name": { + Type: schema.TypeString, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "reserved": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeFloat, + Computed: true, + }, + "extips": { + Type: schema.TypeInt, + Computed: true, + }, + "exttraffic": { + Type: schema.TypeInt, + Computed: true, + }, + "gpu": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "seps": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeString, + Computed: true, + }, + "data_name": { + Type: schema.TypeString, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "resource_limits": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cu_c": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_d": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_dm": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_i": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_m": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_np": { + Type: schema.TypeFloat, + Computed: true, + }, + "gpu_units": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return res +} + +func dataSourceRgUsageSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "rg_id": { + Type: schema.TypeInt, + Required: true, + }, + "reason": { + Type: schema.TypeString, + Optional: true, + }, + + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_size": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeInt, + Computed: true, + }, + "extips": { + Type: schema.TypeInt, + Computed: true, + }, + "exttraffic": { + Type: schema.TypeInt, + Computed: true, + }, + "gpu": { + Type: schema.TypeInt, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "seps": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeString, + Computed: true, + }, + "data_name": { + Type: schema.TypeString, + Computed: true, + }, + "disk_size": { + Type: schema.TypeFloat, + Computed: true, + }, + "disk_size_max": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + } + + return res +} + +func dataSourceRgListComputesSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "rg_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the RG", + }, + "compute_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by compute ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by account ID", + }, + "tech_status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by tech. status", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by status", + }, + "ip_address": { + Type: schema.TypeString, + Optional: true, + Description: "FIlter by IP address", + }, + "extnet_name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by extnet name", + }, + "extnet_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by extnet ID", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, + + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Computed: true, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "affinity_label": { + Type: schema.TypeString, + Computed: true, + }, + "affinity_rules": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "key": { + Type: schema.TypeString, + Computed: true, + }, + "mode": { + Type: schema.TypeString, + Computed: true, + }, + "policy": { + Type: schema.TypeString, + Computed: true, + }, + "topology": { + Type: schema.TypeString, + Computed: true, + }, + "value": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "affinity_weight": { + Type: schema.TypeInt, + Computed: true, + }, + "antiaffinity_rules": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "key": { + Type: schema.TypeString, + Computed: true, + }, + "mode": { + Type: schema.TypeString, + Computed: true, + }, + "policy": { + Type: schema.TypeString, + Computed: true, + }, + "topology": { + Type: schema.TypeString, + Computed: true, + }, + "value": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "cpus": { + 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, + }, + "id": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + }, + "registered": { + Type: schema.TypeBool, + Computed: true, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + }, + "total_disks_size": { + Type: schema.TypeInt, + Computed: true, + }, + "updated_by": { + Type: schema.TypeString, + Computed: true, + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + }, + "user_managed": { + Type: schema.TypeBool, + Computed: true, + }, + "vins_connected": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + + return res +} + +func dataSourceRgListLbSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "rg_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the RG", + }, + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by account ID", + }, + "tech_status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by tech. status", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by status", + }, + "front_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by frontend IP", + }, + "back_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by backend IP", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, + + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ha_mode": { + Type: schema.TypeBool, + Computed: true, + }, + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "backends": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "algorithm": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "server_default_settings": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "inter": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "down_inter": { + Type: schema.TypeInt, + Computed: true, + }, + "rise": { + Type: schema.TypeInt, + Computed: true, + }, + "fall": { + Type: schema.TypeInt, + Computed: true, + }, + "slow_start": { + Type: schema.TypeInt, + Computed: true, + }, + "max_conn": { + Type: schema.TypeInt, + Computed: true, + }, + "max_queue": { + Type: schema.TypeInt, + Computed: true, + }, + "weight": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "servers": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "address": { + Type: schema.TypeString, + Computed: true, + }, + "check": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "port": { + Type: schema.TypeInt, + Computed: true, + }, + "server_settings": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "inter": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "down_inter": { + Type: schema.TypeInt, + Computed: true, + }, + "rise": { + Type: schema.TypeInt, + Computed: true, + }, + "fall": { + Type: schema.TypeInt, + Computed: true, + }, + "slow_start": { + Type: schema.TypeInt, + Computed: true, + }, + "max_conn": { + Type: schema.TypeInt, + Computed: true, + }, + "max_queue": { + Type: schema.TypeInt, + Computed: true, + }, + "weight": { + 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, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "dp_api_user": { + Type: schema.TypeString, + Computed: true, + }, + "extnet_id": { + Type: schema.TypeInt, + Computed: true, + }, + "frontends": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "backend": { + Type: schema.TypeString, + Computed: true, + }, + "bindings": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "address": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "port": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "id": { + Type: schema.TypeInt, + Computed: true, + }, + "image_id": { + Type: schema.TypeInt, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "primary_node": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "backend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "compute_id": { + Type: schema.TypeInt, + Computed: true, + }, + "frontend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "mgmt_ip": { + Type: schema.TypeString, + Computed: true, + }, + "network_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + }, + "secondary_node": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "backend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "compute_id": { + Type: schema.TypeInt, + Computed: true, + }, + "frontend_ip": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "mgmt_ip": { + Type: schema.TypeString, + Computed: true, + }, + "network_id": { + 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, + }, + "vins_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + + return res +} + +func dataSourceRgListDeletedSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by account ID", + }, + "account_name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by account name", + }, + "created_after": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter RGs created after certain point in time (unix timestamp)", + }, + "created_before": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter RGs created before certain point in time (unix timestamp)", + }, + "lock_status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by lock status", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + 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, + }, + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "cpu_allocation_parameter": { + Type: schema.TypeString, + Computed: true, + }, + "cpu_allocation_ratio": { + Type: schema.TypeFloat, + Computed: true, + }, + "created_by": { + Type: schema.TypeString, + Computed: true, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + "def_net_id": { + Type: schema.TypeInt, + Computed: true, + }, + "def_net_type": { + Type: schema.TypeString, + Computed: true, + }, + "deleted_by": { + Type: schema.TypeString, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "dirty": { + Type: schema.TypeBool, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "lock_status": { + Type: schema.TypeString, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "register_computes": { + Type: schema.TypeBool, + Computed: true, + }, + "resource_limits": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cu_c": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_d": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_dm": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_i": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_m": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_np": { + Type: schema.TypeFloat, + Computed: true, + }, + "gpu_units": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + "secret": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "updated_by": { + Type: schema.TypeString, + Computed: true, + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + }, + "vins": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "vms": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "resource_types": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "uniq_pools": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return res +} + +func dataSourceRgListSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by account ID", + }, + "account_name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by account name", + }, + "created_after": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter RGs created after certain point in time (unix timestamp)", + }, + "created_before": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter RGs created before certain point in time (unix timestamp)", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by status", + }, + "lock_status": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by lock status", + }, + "includedeleted": { + Type: schema.TypeBool, + Optional: true, + Description: "Include deleted", + }, + "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, + }, + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "cpu_allocation_parameter": { + Type: schema.TypeString, + Computed: true, + }, + "cpu_allocation_ratio": { + Type: schema.TypeFloat, + Computed: true, + }, + "created_by": { + Type: schema.TypeString, + Computed: true, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + "def_net_id": { + Type: schema.TypeInt, + Computed: true, + }, + "def_net_type": { + Type: schema.TypeString, + Computed: true, + }, + "deleted_by": { + Type: schema.TypeString, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "dirty": { + Type: schema.TypeBool, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "lock_status": { + Type: schema.TypeString, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "register_computes": { + Type: schema.TypeBool, + Computed: true, + }, + "resource_limits": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cu_c": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_d": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_dm": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_i": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_m": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_np": { + Type: schema.TypeFloat, + Computed: true, + }, + "gpu_units": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + "secret": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "updated_by": { + Type: schema.TypeString, + Computed: true, + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + }, + "vins": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "vms": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "resource_types": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "uniq_pools": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return res +} + +func dataSourceRgListVinsSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "rg_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the RG", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by account ID", + }, + "ext_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by external IP", + }, + "vins_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ViNS ID", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, + + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Computed: true, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "computes": { + 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, + }, + "external_ip": { + Type: schema.TypeString, + Computed: true, + }, + "id": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "network": { + Type: schema.TypeString, + Computed: true, + }, + "pri_vnf_dev_id": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "updated_by": { + Type: schema.TypeString, + Computed: true, + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + + return res +} + +func dataSourceRgListPfwSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "rg_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the RG", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "public_port_end": { + Type: schema.TypeInt, + Computed: true, + }, + "public_port_start": { + Type: schema.TypeInt, + Computed: true, + }, + "vm_id": { + Type: schema.TypeInt, + Computed: true, + }, + "vm_ip": { + Type: schema.TypeString, + Computed: true, + }, + "vm_name": { + Type: schema.TypeString, + Computed: true, + }, + "vm_port": { + Type: schema.TypeInt, + Computed: true, + }, + "vins_id": { + Type: schema.TypeInt, + Computed: true, + }, + "vins_name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + + return res +} + +func resourceRgSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntAtLeast(1), + Description: "Unique ID of the account, which this resource group belongs to.", + }, + + "gid": { + Type: schema.TypeInt, + Required: true, + Description: "Unique ID of the grid, where this resource group is deployed.", + }, + + "rg_name": { + Type: schema.TypeString, + Required: true, + Description: "Name of this resource group. Names are case sensitive and unique within the context of a account.", + }, + + "resource_limits": { + Type: schema.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cu_c": { + Type: schema.TypeFloat, + Optional: true, + Computed: true, + Description: "MaxCPUCapacity", + }, + "cu_d": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_dm": { + Type: schema.TypeFloat, + Optional: true, + Computed: true, + Description: "MaxVDiskCapacity", + }, + "cu_i": { + Type: schema.TypeFloat, + Optional: true, + Computed: true, + Description: "MaxNumPublicIP", + }, + "cu_m": { + Type: schema.TypeFloat, + Optional: true, + Computed: true, + Description: "MaxMemoryCapacity", + }, + "cu_np": { + Type: schema.TypeFloat, + Optional: true, + Computed: true, + Description: "MaxNetworkPeerTransfer", + }, + "gpu_units": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + + "owner": { + Type: schema.TypeString, + Optional: true, + Description: "username - owner of this RG. Leave blank to set current user as owner", + }, + + "def_net_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + // Default: "PRIVATE", + ValidateFunc: validation.StringInSlice([]string{"PRIVATE", "PUBLIC", "NONE"}, false), + Description: "Type of the network, which this resource group will use as default for its computes - PRIVATE or PUBLIC or NONE.", + }, + + "ipcidr": { + Type: schema.TypeString, + Optional: true, + Description: "Address of the netowrk inside the private network segment (aka ViNS) if def_net_type=PRIVATE", + }, + + "description": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "User-defined text description of this resource group.", + }, + + "reason": { + Type: schema.TypeString, + Optional: true, + }, + + "ext_net_id": { + Type: schema.TypeInt, + Optional: true, + Default: 0, + Description: "ID of the external network for default ViNS. Pass 0 if def_net_type=PUBLIC or no external connection required for the defult ViNS when def_net_type=PRIVATE", + }, + + "ext_ip": { + Type: schema.TypeString, + Optional: true, + Description: "IP address on the external netowrk to request when def_net_type=PRIVATE and ext_net_id is not 0", + }, + + "register_computes": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + // Default: false, + Description: "Register computes in registration system", + }, + + "uniq_pools": { + Type: schema.TypeList, + Computed: true, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + + "access": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "user": { + Type: schema.TypeString, + Required: true, + Description: "User or group name to grant access", + }, + "right": { + Type: schema.TypeString, + Required: true, + Description: "Access rights to set, one of 'R', 'RCX' or 'ARCXDU'", + }, + "reason": { + Type: schema.TypeString, + Optional: true, + Description: "Reason for action", + }, + }, + }, + }, + + "def_net": { + Type: schema.TypeSet, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "net_type": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{"PRIVATE", "PUBLIC"}, false), + Description: "Network type to set. Must be on of 'PRIVATE' or 'PUBLIC'.", + }, + "net_id": { + Type: schema.TypeInt, + Optional: true, + Default: 0, + Description: "Network segment ID. If netType is PUBLIC and netId is 0 then default external network segment will be selected. If netType is PRIVATE and netId=0, the first ViNS defined for this RG will be selected. Otherwise, netId identifies either existing external network segment or ViNS.", + }, + "reason": { + Type: schema.TypeString, + Optional: true, + Description: "Reason for action", + }, + }, + }, + }, + + "cpu_allocation_parameter": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "set cpu allocation parameter", + }, + + "cpu_allocation_ratio": { + Type: schema.TypeFloat, + Optional: true, + Computed: true, + Description: "set cpu allocation ratio", + }, + + "enable": { + Type: schema.TypeBool, + Optional: true, + Default: true, + Description: "enable/disable rg", + }, + "restore": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "restore deleted rg", + }, + + "force": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "flag to force deleting resource group", + }, + "permanently": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "flag to permanently delete resource group", + }, + + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "explicit": { + Type: schema.TypeBool, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "right": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "user_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + + "account_name": { + Type: schema.TypeString, + Computed: true, + Description: "Name of the account, which this resource group belongs to.", + }, + "created_by": { + Type: schema.TypeString, + Computed: true, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + + "def_net_id": { + Type: schema.TypeInt, + Computed: true, + Description: "ID of the default network for this resource group (if any).", + }, + + "deleted_by": { + Type: schema.TypeString, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "lock_status": { + Type: schema.TypeString, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "resource_types": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "secret": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "Current status of this resource group.", + }, + "updated_by": { + Type: schema.TypeString, + Computed: true, + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + }, + "vins": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Description: "List of VINs deployed in this resource group.", + }, + "vms": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Description: "List of VM ids in this resource group.", + }, + } + + return res +} diff --git a/internal/service/cloudbroker/rg/utility_rg_get_resource_consumption.go b/internal/service/cloudbroker/rg/utility_rg_get_resource_consumption.go new file mode 100644 index 0000000..f133ea5 --- /dev/null +++ b/internal/service/cloudbroker/rg/utility_rg_get_resource_consumption.go @@ -0,0 +1,58 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 rg + +import ( + "context" + + log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func utilityRGResourceConsumptionGetCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ItemResourceConsumption, error) { + c := m.(*controller.ControllerCfg) + req := rg.GetResourceConsumptionRequest{ + RGID: uint64(d.Get("rg_id").(int)), + } + + log.Debugf("utilityRGResourceConsumptionGetCheckPresence: load") + accountResourceConsumptionRec, err := c.CloudBroker().RG().GetResourceConsumption(ctx, req) + if err != nil { + return nil, err + } + + return accountResourceConsumptionRec, nil +} diff --git a/internal/service/cloudbroker/rg/utility_rg_list_computes.go b/internal/service/cloudbroker/rg/utility_rg_list_computes.go new file mode 100644 index 0000000..1d9ab4e --- /dev/null +++ b/internal/service/cloudbroker/rg/utility_rg_list_computes.go @@ -0,0 +1,95 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 rg + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityRgListComputesCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListComputes, error) { + c := m.(*controller.ControllerCfg) + req := rg.ListComputesRequest{ + RGID: uint64(d.Get("rg_id").(int)), + } + + if compute_id, ok := d.GetOk("compute_id"); ok { + req.ComputeID = uint64(compute_id.(int)) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if account_id, ok := d.GetOk("account_id"); ok { + req.AccountID = uint64(account_id.(int)) + } + + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } + + if tech_status, ok := d.GetOk("tech_status"); ok { + req.TechStatus = tech_status.(string) + } + + if ip_address, ok := d.GetOk("ip_address"); ok { + req.IPAddress = ip_address.(string) + } + + if extnet_name, ok := d.GetOk("extnet_name"); ok { + req.ExtNetName = extnet_name.(string) + } + + if extnet_id, ok := d.GetOk("extnet_id"); ok { + req.ExtNetID = uint64(extnet_id.(int)) + } + + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + + listComputes, err := c.CloudBroker().RG().ListComputes(ctx, req) + if err != nil { + return nil, err + } + + return listComputes, nil +} diff --git a/internal/service/cloudbroker/rg/utility_rg_list_deleted.go b/internal/service/cloudbroker/rg/utility_rg_list_deleted.go new file mode 100644 index 0000000..0b35472 --- /dev/null +++ b/internal/service/cloudbroker/rg/utility_rg_list_deleted.go @@ -0,0 +1,88 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 rg + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityRgListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListRG, error) { + c := m.(*controller.ControllerCfg) + req := rg.ListDeletedRequest{} + + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if account_id, ok := d.GetOk("account_id"); ok { + req.AccountID = uint64(account_id.(int)) + } + + if account_name, ok := d.GetOk("account_name"); ok { + req.AccountName = account_name.(string) + } + + if created_after, ok := d.GetOk("created_after"); ok { + req.CreatedAfter = uint64(created_after.(int)) + } + + if created_before, ok := d.GetOk("created_before"); ok { + req.CreatedBefore = uint64(created_before.(int)) + } + + if lock_status, ok := d.GetOk("lock_status"); ok { + req.LockStatus = lock_status.(string) + } + + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + + rgList, err := c.CloudBroker().RG().ListDeleted(ctx, req) + if err != nil { + return nil, err + } + + return rgList, nil +} diff --git a/internal/service/cloudbroker/rg/utility_rg_list_lb.go b/internal/service/cloudbroker/rg/utility_rg_list_lb.go new file mode 100644 index 0000000..79b0997 --- /dev/null +++ b/internal/service/cloudbroker/rg/utility_rg_list_lb.go @@ -0,0 +1,91 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 rg + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityRgListLbCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListLB, error) { + c := m.(*controller.ControllerCfg) + req := rg.ListLBRequest{ + RGID: uint64(d.Get("rg_id").(int)), + } + + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + + if account_id, ok := d.GetOk("account_id"); ok { + req.AccountID = uint64(account_id.(int)) + } + + if tech_status, ok := d.GetOk("tech_status"); ok { + req.TechStatus = tech_status.(string) + } + + if status, ok := d.GetOk("status"); ok { + req.Status = status.(string) + } + + if front_ip, ok := d.GetOk("front_ip"); ok { + req.FrontIP = front_ip.(string) + } + + if back_ip, ok := d.GetOk("back_ip"); ok { + req.BackIP = back_ip.(string) + } + + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + + listLb, err := c.CloudBroker().RG().ListLB(ctx, req) + if err != nil { + return nil, err + } + + return listLb, nil +} diff --git a/internal/service/cloudbroker/vins/api.go b/internal/service/cloudbroker/rg/utility_rg_list_pfw.go similarity index 64% rename from internal/service/cloudbroker/vins/api.go rename to internal/service/cloudbroker/rg/utility_rg_list_pfw.go index 79d9bcf..f82d7c5 100644 --- a/internal/service/cloudbroker/vins/api.go +++ b/internal/service/cloudbroker/rg/utility_rg_list_pfw.go @@ -1,44 +1,55 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, - -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 vins - -const VinsListAPI = "/restmachine/cloudbroker/vins/list" -const VinsGetAPI = "/restmachine/cloudbroker/vins/get" -const VinsSearchAPI = "/restmachine/cloudbroker/vins/search" - -const VinsCreateInAccountAPI = "/restmachine/cloudbroker/vins/createInAccount" -const VinsCreateInRgAPI = "/restmachine/cloudbroker/vins/createInRG" - -const VinsExtNetConnectAPI = "/restmachine/cloudbroker/vins/extNetConnect" -const VinsExtNetDisconnectAPI = "/restmachine/cloudbroker/vins/extNetDisconnect" - -const VinsDeleteAPI = "/restmachine/cloudbroker/vins/delete" +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 rg + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityRgListPfwCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListPFW, error) { + c := m.(*controller.ControllerCfg) + req := rg.ListPFWRequest{ + RGID: uint64(d.Get("rg_id").(int)), + } + + listPfw, err := c.CloudBroker().RG().ListPFW(ctx, req) + if err != nil { + return nil, err + } + + return listPfw, nil +} diff --git a/internal/service/cloudbroker/kvmvm/osusers_subresource.go b/internal/service/cloudbroker/rg/utility_rg_list_vins.go similarity index 52% rename from internal/service/cloudbroker/kvmvm/osusers_subresource.go rename to internal/service/cloudbroker/rg/utility_rg_list_vins.go index 258bf37..a138b26 100644 --- a/internal/service/cloudbroker/kvmvm/osusers_subresource.go +++ b/internal/service/cloudbroker/rg/utility_rg_list_vins.go @@ -3,6 +3,7 @@ Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Authors: Petr Krutov, Stanislav Solovev, +Kasim Baybikov, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -29,59 +30,50 @@ builds seamlessly. Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki */ -package kvmvm +package rg import ( - log "github.com/sirupsen/logrus" - "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute" + "context" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" ) -func parseOsUsers(logins compute.ListOSUsers) []interface{} { - var result = make([]interface{}, len(logins)) +func utilityRgListVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListVINS, error) { + c := m.(*controller.ControllerCfg) + req := rg.ListVINSRequest{ + RGID: uint64(d.Get("rg_id").(int)), + } - for index, value := range logins { - elem := make(map[string]interface{}) + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } - elem["guid"] = value.GUID - elem["login"] = value.Login - elem["password"] = value.Password - elem["public_key"] = value.PubKey - result[index] = elem - log.Debugf("parseOsUsers: parsed element %d - login %q", index, value.Login) + if account_id, ok := d.GetOk("account_id"); ok { + req.AccountID = uint64(account_id.(int)) } - return result -} + if ext_ip, ok := d.GetOk("ext_ip"); ok { + req.ExtIP = ext_ip.(string) + } + + if vins_id, ok := d.GetOk("vins_id"); ok { + req.VINSID = uint64(vins_id.(int)) + } + + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } -func osUsersSubresourceSchemaMake() map[string]*schema.Schema { - rets := map[string]*schema.Schema{ - "guid": { - Type: schema.TypeString, - Computed: true, - Description: "GUID of this guest OS user.", - }, - - "login": { - Type: schema.TypeString, - Computed: true, - Description: "Login name of this guest OS user.", - }, - - "password": { - Type: schema.TypeString, - Computed: true, - Sensitive: true, - Description: "Password of this guest OS user.", - }, - - "public_key": { - Type: schema.TypeString, - Computed: true, - Description: "SSH public key of this guest OS user.", - }, + listVins, err := c.CloudBroker().RG().ListVINS(ctx, req) + if err != nil { + return nil, err } - return rets + return listVins, nil } diff --git a/internal/service/cloudbroker/k8s/api.go b/internal/service/cloudbroker/rg/utility_rg_resource_consumption_list.go similarity index 60% rename from internal/service/cloudbroker/k8s/api.go rename to internal/service/cloudbroker/rg/utility_rg_resource_consumption_list.go index b075608..8d827f5 100644 --- a/internal/service/cloudbroker/k8s/api.go +++ b/internal/service/cloudbroker/rg/utility_rg_resource_consumption_list.go @@ -1,49 +1,55 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -/* -Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud -Orchestration Technology) with Terraform by Hashicorp. - -Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort - -Please see README.md to learn where to place source code so that it -builds seamlessly. - -Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki -*/ - -package k8s - -const K8sCreateAPI = "/restmachine/cloudbroker/k8s/create" -const K8sGetAPI = "/restmachine/cloudbroker/k8s/get" -const K8sUpdateAPI = "/restmachine/cloudbroker/k8s/update" -const K8sDeleteAPI = "/restmachine/cloudbroker/k8s/delete" - -const K8sWgCreateAPI = "/restmachine/cloudbroker/k8s/workersGroupAdd" -const K8sWgDeleteAPI = "/restmachine/cloudbroker/k8s/workersGroupDelete" - -const K8sWorkerAddAPI = "/restmachine/cloudbroker/k8s/workerAdd" -const K8sWorkerDeleteAPI = "/restmachine/cloudbroker/k8s/deleteWorkerFromGroup" - -const K8sGetConfigAPI = "/restmachine/cloudbroker/k8s/getConfig" - -const LbGetAPI = "/restmachine/cloudbroker/lb/get" - -const AsyncTaskGetAPI = "/restmachine/cloudbroker/tasks/get" +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 rg + +import ( + "context" + + log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func utilityRGResourceConsumptionListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListResourceConsumption, error) { + c := m.(*controller.ControllerCfg) + + log.Debugf("utilityRGResourceConsumptionListCheckPresence: load") + rgResourceConsumptionList, err := c.CloudBroker().RG().ListResourceConsumption(ctx) + if err != nil { + return nil, err + } + + return rgResourceConsumptionList, nil +} diff --git a/internal/service/cloudbroker/snapshot/utility_snapshot.go b/internal/service/cloudbroker/rg/utility_rg_usage.go similarity index 71% rename from internal/service/cloudbroker/snapshot/utility_snapshot.go rename to internal/service/cloudbroker/rg/utility_rg_usage.go index 50a0377..c56ab60 100644 --- a/internal/service/cloudbroker/snapshot/utility_snapshot.go +++ b/internal/service/cloudbroker/rg/utility_rg_usage.go @@ -1,64 +1,59 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, - -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 snapshot - -import ( - "context" - "errors" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute" -) - -func utilitySnapshotCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ItemSnapshot, error) { - snapShotList, err := utilitySnapshotListCheckPresence(ctx, d, m) - if err != nil { - return nil, err - } - - findId := "" - - if (d.Get("guid").(string)) != "" { - findId = d.Get("guid").(string) - } else { - findId = d.Id() - } - - for _, s := range snapShotList { - if s.GUID == findId { - return &s, nil - } - } - - return nil, errors.New("snapshot not found") - -} +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 rg + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityDataRgUsageCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.Reservation, error) { + c := m.(*controller.ControllerCfg) + req := rg.UsageRequest{ + RGID: uint64(d.Get("rg_id").(int)), + } + + if reason, ok := d.GetOk("reason"); ok { + req.Reason = reason.(string) + } + + usage, err := c.CloudBroker().RG().Usage(ctx, req) + if err != nil { + return nil, err + } + + return usage, nil +} diff --git a/internal/service/cloudbroker/sep/schema.go b/internal/service/cloudbroker/sep/schema.go new file mode 100644 index 0000000..94d0234 --- /dev/null +++ b/internal/service/cloudbroker/sep/schema.go @@ -0,0 +1,700 @@ +package sep + +import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + +func dataSourceSepCSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeInt, + Required: true, + Description: "sep type des id", + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + Description: "ckey", + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Description: "meta", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "config": { + Type: schema.TypeString, + Computed: true, + Description: "config", + }, + "consumed_by": { + Type: schema.TypeSet, + Computed: true, + Description: "consumed by", + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + Description: "description", + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "gid", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + Description: "milestones", + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "name", + }, + "obj_status": { + Type: schema.TypeString, + Computed: true, + Description: "object status", + }, + "provided_by": { + Type: schema.TypeList, + Computed: true, + Description: "provided by", + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "shared_with": { + Type: schema.TypeList, + Computed: true, + Description: "shared with", + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + Description: "tech status", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "type", + }, + } +} + +func dataSourceSepConfigSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeInt, + Required: true, + Description: "storage endpoint provider ID", + }, + "config": { + Type: schema.TypeString, + Computed: true, + Description: "sep config json string", + }, + } +} + +func dataSourceSepConsumptionSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeInt, + Required: true, + Description: "sep id", + }, + "by_pool": { + Type: schema.TypeList, + Computed: true, + Description: "consumption divided by pool", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + Description: "pool name", + }, + "disk_count": { + Type: schema.TypeInt, + Computed: true, + Description: "number of disks", + }, + "disk_usage": { + Type: schema.TypeInt, + Computed: true, + Description: "disk usage", + }, + "snapshot_count": { + Type: schema.TypeInt, + Computed: true, + Description: "number of snapshots", + }, + "snapshot_usage": { + Type: schema.TypeInt, + Computed: true, + Description: "snapshot usage", + }, + "usage": { + Type: schema.TypeInt, + Computed: true, + Description: "usage", + }, + "usage_limit": { + Type: schema.TypeInt, + Computed: true, + Description: "usage limit", + }, + }, + }, + }, + "total": { + Type: schema.TypeList, + Computed: true, + Description: "total consumption", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "capacity_limit": { + Type: schema.TypeInt, + Computed: true, + Description: "capacity limit", + }, + "disk_count": { + Type: schema.TypeInt, + Computed: true, + Description: "number of disks", + }, + "disk_usage": { + Type: schema.TypeInt, + Computed: true, + Description: "disk usage", + }, + "snapshot_count": { + Type: schema.TypeInt, + Computed: true, + Description: "number of snapshots", + }, + "snapshot_usage": { + Type: schema.TypeInt, + Computed: true, + Description: "snapshot usage", + }, + "usage": { + Type: schema.TypeInt, + Computed: true, + Description: "usage", + }, + "usage_limit": { + Type: schema.TypeInt, + Computed: true, + Description: "usage limit", + }, + }, + }, + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "sep type", + }, + } +} + +func dataSourceSepDiskListSchemaMake() map[string]*schema.Schema { + rets := map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeInt, + Required: true, + Description: "storage endpoint provider ID", + }, + "pool_name": { + Type: schema.TypeString, + Optional: true, + Description: "pool name", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Description: "sep disk list", + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + } + + return rets +} + +func dataSourceSepListSchemaMake() map[string]*schema.Schema { + rets := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "find by id", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "find by name", + }, + "gid": { + Type: schema.TypeInt, + Optional: true, + Description: "find by gid", + }, + "type": { + Type: schema.TypeString, + Optional: true, + Description: "find by sep type", + }, + "provided_by": { + Type: schema.TypeInt, + Optional: true, + Description: "find by provided physical node id", + }, + "tech_status": { + Type: schema.TypeString, + Optional: true, + Description: "find by techStatus", + }, + "consumed_by": { + Type: schema.TypeInt, + Optional: true, + Description: "find by consumed physical node id", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "page size", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Description: "sep list", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ckey": { + Type: schema.TypeString, + Computed: true, + Description: "ckey", + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Description: "meta", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "config": { + Description: "config", + Type: schema.TypeString, + Computed: true, + }, + "consumed_by": { + Type: schema.TypeSet, + Computed: true, + Description: "consumed by", + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + Description: "description", + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "gid", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "sep_id": { + Type: schema.TypeInt, + Computed: true, + Description: "sep id", + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + Description: "milestones", + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "name", + }, + "obj_status": { + Type: schema.TypeString, + Computed: true, + Description: "object status", + }, + "provided_by": { + Type: schema.TypeList, + Computed: true, + Description: "provided by", + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "shared_with": { + Type: schema.TypeList, + Computed: true, + Description: "shared with", + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + Description: "tech status", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "type", + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + Description: "entryCount", + }, + } + + return rets +} + +func dataSourceSepPoolSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeInt, + Required: true, + Description: "storage endpoint provider ID", + }, + "pool_name": { + Type: schema.TypeString, + Required: true, + Description: "pool name", + }, + "pool": { + Type: schema.TypeList, + Computed: true, + Description: "pool", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "access_account_ids": { + Type: schema.TypeList, + Computed: true, + Description: "access account ids", + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "access_res_group_ids": { + Type: schema.TypeList, + Computed: true, + Description: "access res group ids", + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "name", + }, + "pagecache_ratio": { + Type: schema.TypeInt, + Computed: true, + Description: "pagecache_ratio", + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + Description: "reference_id", + }, + "types": { + Type: schema.TypeList, + Computed: true, + Description: "types", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "uris": { + Type: schema.TypeSet, + Computed: true, + Description: "uris", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip": { + Type: schema.TypeString, + Computed: true, + Description: "ip", + }, + "port": { + Type: schema.TypeInt, + Computed: true, + Description: "port", + }, + }, + }, + }, + "usage_limit": { + Type: schema.TypeInt, + Computed: true, + Description: "usage limit", + }, + }, + }, + }, + } +} + +func resourceSepSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "gid": { + Type: schema.TypeInt, + Required: true, + Description: "grid (platform) ID", + }, + "name": { + Type: schema.TypeString, + Required: true, + Description: "SEP name", + }, + "type": { + Type: schema.TypeString, + Required: true, + Description: "type of storage", + }, + "access_to_pool": { + Type: schema.TypeSet, + MaxItems: 1, + Optional: true, + Computed: true, + Description: "grant or revoke access to pool", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "pool_name": { + Type: schema.TypeString, + Required: true, + Description: "pool name", + }, + "account_id_pool": { + Type: schema.TypeInt, + Optional: true, + Description: "account id to grant/revoke access to the specified pool sep", + }, + "rg_id": { + Type: schema.TypeInt, + Required: true, + Description: "resource group id to grant/revoke access to the specified pool sep", + }, + }, + }, + }, + "account_ids": { + Type: schema.TypeSet, + Optional: true, + Description: "lift of account ids to have access to sep", + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "clear_physically": { + Type: schema.TypeBool, + Optional: true, + Default: true, + Description: "clear disks and images physically", + }, + "decommission": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "unlink everything that exists from SEP", + }, + "enable": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "enable SEP after creation", + }, + "field_edit": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "field_name": { + Type: schema.TypeString, + Required: true, + Description: "field name", + }, + "field_value": { + Type: schema.TypeString, + Required: true, + Description: "field value", + }, + "field_type": { + Type: schema.TypeString, + Required: true, + Description: "field type", + }, + }, + }, + }, + "sep_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "sep type des id", + }, + "upd_capacity_limit": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Update SEP capacity limit", + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + Description: "ckey", + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Description: "meta", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "config": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "sep config string", + }, + "consumed_by": { + Type: schema.TypeSet, + Optional: true, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Description: "list of consumer nodes IDs", + }, + "desc": { + Type: schema.TypeString, + Computed: true, + Optional: true, + Description: "sep description", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + Description: "milestones", + }, + "obj_status": { + Type: schema.TypeString, + Computed: true, + Description: "object status", + }, + "provided_by": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Description: "list of provider nodes IDs", + }, + "shared_with": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Description: "list of shared with ids", + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + Description: "tech status", + }, + } +} + +func resourceSepConfigSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeInt, + Required: true, + Description: "sep id", + }, + "config": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "config json string", + }, + "field_edit": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "field_name": { + Type: schema.TypeString, + Required: true, + Description: "field name", + }, + "field_value": { + Type: schema.TypeString, + Required: true, + Description: "field value", + }, + "field_type": { + Type: schema.TypeString, + Required: true, + Description: "field type", + }, + }, + }, + }, + } +} diff --git a/internal/service/cloudbroker/snapshot/api.go b/internal/service/cloudbroker/snapshot/api.go deleted file mode 100644 index e311a8f..0000000 --- a/internal/service/cloudbroker/snapshot/api.go +++ /dev/null @@ -1,37 +0,0 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, - -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 snapshot - -const snapshotCreateAPI = "/restmachine/cloudbroker/compute/snapshotCreate" -const snapshotDeleteAPI = "/restmachine/cloudbroker/compute/snapshotDelete" -const snapshotRollbackAPI = "/restmachine/cloudbroker/compute/snapshotRollback" -const snapshotListAPI = "/restmachine/cloudbroker/compute/snapshotList" diff --git a/internal/service/cloudbroker/snapshot/data_source_snapshot_list.go b/internal/service/cloudbroker/snapshot/data_source_snapshot_list.go deleted file mode 100644 index 48f67bf..0000000 --- a/internal/service/cloudbroker/snapshot/data_source_snapshot_list.go +++ /dev/null @@ -1,132 +0,0 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, - -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 snapshot - -import ( - "context" - - "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute" - "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" -) - -func flattenSnapshotList(gl compute.ListSnapshots) []map[string]interface{} { - res := make([]map[string]interface{}, 0) - for _, item := range gl { - temp := map[string]interface{}{ - "label": item.Label, - "guid": item.GUID, - "disks": item.Disks, - "timestamp": item.Timestamp, - } - - res = append(res, temp) - } - return res -} - -func dataSourceSnapshotListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - snapshotList, err := utilitySnapshotListCheckPresence(ctx, d, m) - if err != nil { - return diag.FromErr(err) - } - id := uuid.New() - d.SetId(id.String()) - d.Set("items", flattenSnapshotList(snapshotList)) - - return nil -} - -func dataSourceSnapshotListSchemaMake() map[string]*schema.Schema { - rets := map[string]*schema.Schema{ - "compute_id": { - Type: schema.TypeInt, - Required: true, - ForceNew: true, - Description: "ID of the compute instance to create snapshot for.", - }, - "items": { - Type: schema.TypeList, - Computed: true, - Description: "snapshot list", - Elem: &schema.Resource{ - Schema: dataSourceSnapshotSchemaMake(), - }, - }, - } - - return rets -} - -func dataSourceSnapshotSchemaMake() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "label": { - Type: schema.TypeString, - Computed: true, - Description: "text label for snapshot. Must be unique among this compute snapshots.", - }, - "disks": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeInt, - }, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - Description: "guid of the snapshot", - }, - "timestamp": { - Type: schema.TypeInt, - Computed: true, - Description: "timestamp", - }, - } -} - -func DataSourceSnapshotList() *schema.Resource { - return &schema.Resource{ - SchemaVersion: 1, - - ReadContext: dataSourceSnapshotListRead, - - Timeouts: &schema.ResourceTimeout{ - Read: &constants.Timeout30s, - Default: &constants.Timeout60s, - }, - - Schema: dataSourceSnapshotListSchemaMake(), - } -} diff --git a/internal/service/cloudbroker/snapshot/resource_snapshot.go b/internal/service/cloudbroker/snapshot/resource_snapshot.go deleted file mode 100644 index 9eb27a3..0000000 --- a/internal/service/cloudbroker/snapshot/resource_snapshot.go +++ /dev/null @@ -1,191 +0,0 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Authors: -Petr Krutov, -Stanislav Solovev, - -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 snapshot - -import ( - "context" - "strings" - - "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/cloudbroker/compute" - "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" - "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" -) - -func resourceSnapshotCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Debugf("resourceSnapshotCreate: called for snapshot %s", d.Get("label").(string)) - - c := m.(*controller.ControllerCfg) - req := compute.SnapshotCreateRequest{ - Label: d.Get("label").(string), - ComputeID: uint64(d.Get("compute_id").(int)), - } - - snapshotId, err := c.CloudBroker().Compute().SnapshotCreate(ctx, req) - if err != nil { - return diag.FromErr(err) - } - - snapshotId = strings.ReplaceAll(snapshotId, "\"", "") - - d.SetId(snapshotId) - d.Set("guid", snapshotId) - - return resourceSnapshotRead(ctx, d, m) -} - -func resourceSnapshotRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - snapshot, err := utilitySnapshotCheckPresence(ctx, d, m) - if err != nil { - return diag.FromErr(err) - } - - d.Set("timestamp", snapshot.Timestamp) - d.Set("guid", snapshot.GUID) - d.Set("disks", snapshot.Disks) - d.Set("label", snapshot.Label) - - return nil -} - -func resourceSnapshotDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Debugf("resourceSnapshotDelete: called for %s, id: %s", d.Get("label").(string), d.Id()) - - c := m.(*controller.ControllerCfg) - req := compute.SnapshotDeleteRequest{ - ComputeID: uint64(d.Get("compute_id").(int)), - Label: d.Get("label").(string), - } - - _, err := c.CloudBroker().Compute().SnapshotDelete(ctx, req) - if err != nil { - return diag.FromErr(err) - } - - d.SetId("") - - return nil -} - -func resourceSnapshotUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - if d.HasChange("rollback") { - if d.Get("rollback").(bool) { - err := resourceSnapshotRollback(ctx, d, m) - if err != nil { - return diag.FromErr(err) - } - } - } - - return nil -} - -func resourceSnapshotRollback(ctx context.Context, d *schema.ResourceData, m interface{}) error { - c := m.(*controller.ControllerCfg) - req := compute.SnapshotRollbackRequest{ - ComputeID: uint64(d.Get("compute_id").(int)), - Label: d.Get("label").(string), - } - - _, err := c.CloudBroker().Compute().SnapshotRollback(ctx, req) - if err != nil { - return err - } - return nil -} - -func resourceSnapshotSchemaMake() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "compute_id": { - Type: schema.TypeInt, - Required: true, - ForceNew: true, - Description: "ID of the compute instance to create snapshot for.", - }, - "label": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - Description: "text label for snapshot. Must be unique among this compute snapshots.", - }, - "rollback": { - Type: schema.TypeBool, - Optional: true, - Default: false, - Description: "is rollback the snapshot", - }, - "disks": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeInt, - }, - }, - "guid": { - Type: schema.TypeString, - Computed: true, - Description: "guid of the snapshot", - }, - "timestamp": { - Type: schema.TypeInt, - Computed: true, - Description: "timestamp", - }, - } -} - -func ResourceSnapshot() *schema.Resource { - return &schema.Resource{ - SchemaVersion: 1, - - CreateContext: resourceSnapshotCreate, - ReadContext: resourceSnapshotRead, - UpdateContext: resourceSnapshotUpdate, - DeleteContext: resourceSnapshotDelete, - - Importer: &schema.ResourceImporter{ - StateContext: schema.ImportStatePassthroughContext, - }, - - Timeouts: &schema.ResourceTimeout{ - Create: &constants.Timeout60s, - Read: &constants.Timeout30s, - Update: &constants.Timeout60s, - Delete: &constants.Timeout60s, - Default: &constants.Timeout60s, - }, - - Schema: resourceSnapshotSchemaMake(), - } -} diff --git a/internal/service/cloudbroker/stack/schema.go b/internal/service/cloudbroker/stack/schema.go new file mode 100644 index 0000000..0c40a5a --- /dev/null +++ b/internal/service/cloudbroker/stack/schema.go @@ -0,0 +1,577 @@ +package stack + +import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + +func dataSourceStackSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "stack_id": { + Type: schema.TypeInt, + Required: true, + Description: "stack_id", + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + Description: "ckey", + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "meta", + }, + "api_url": { + Type: schema.TypeString, + Computed: true, + Description: "api_url", + }, + "api_key": { + Type: schema.TypeString, + Computed: true, + Description: "api_key", + }, + "app_id": { + Type: schema.TypeString, + Computed: true, + Description: "api_id", + }, + "cpu_allocation_ratio": { + Type: schema.TypeFloat, + Computed: true, + Description: "cpu_allocation_ratio", + }, + "description": { + Type: schema.TypeString, + Computed: true, + Description: "description", + }, + "descr": { + Type: schema.TypeString, + Computed: true, + Description: "descr", + }, + "drivers": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "drivers", + }, + "eco": { + Type: schema.TypeString, + Computed: true, + Description: "eco", + }, + "error": { + Type: schema.TypeInt, + Computed: true, + Description: "error", + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "gid", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "images": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Description: "images", + }, + "login": { + Type: schema.TypeString, + Computed: true, + Description: "login", + }, + "mem_allocation_ratio": { + Type: schema.TypeFloat, + Computed: true, + Description: "mem_allocation_ratio", + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "name", + }, + "packages": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "libvirt_bin": { + Type: schema.TypeList, + Computed: true, + Description: "libvirt_bin", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installed_size": { + Type: schema.TypeString, + Computed: true, + Description: "installed_size", + }, + "ver": { + Type: schema.TypeString, + Computed: true, + Description: "ver", + }, + }, + }, + }, + "libvirt_daemon": { + Type: schema.TypeList, + Computed: true, + Description: "libvirt_daemon", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installed_size": { + Type: schema.TypeString, + Computed: true, + Description: "installed_size", + }, + "ver": { + Type: schema.TypeString, + Computed: true, + Description: "ver", + }, + }, + }, + }, + "lvm2_lockd": { + Type: schema.TypeList, + Computed: true, + Description: "lvm2_lockd", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installed_size": { + Type: schema.TypeString, + Computed: true, + Description: "installed_size", + }, + "ver": { + Type: schema.TypeString, + Computed: true, + Description: "ver", + }, + }, + }, + }, + "openvswitch_common": { + Type: schema.TypeList, + Computed: true, + Description: "openvswitch_common", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installed_size": { + Type: schema.TypeString, + Computed: true, + Description: "installed_size", + }, + "ver": { + Type: schema.TypeString, + Computed: true, + Description: "ver", + }, + }, + }, + }, + "openvswitch_switch": { + Type: schema.TypeList, + Computed: true, + Description: "openvswitch_switch", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installed_size": { + Type: schema.TypeString, + Computed: true, + Description: "installed_size", + }, + "ver": { + Type: schema.TypeString, + Computed: true, + Description: "ver", + }, + }, + }, + }, + "qemu_system_x86": { + Type: schema.TypeList, + Computed: true, + Description: "qemu_system_x86", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installed_size": { + Type: schema.TypeString, + Computed: true, + Description: "installed_size", + }, + "ver": { + Type: schema.TypeString, + Computed: true, + Description: "ver", + }, + }, + }, + }, + "sanlock": { + Type: schema.TypeList, + Computed: true, + Description: "sanlock", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installed_size": { + Type: schema.TypeString, + Computed: true, + Description: "installed_size", + }, + "ver": { + Type: schema.TypeString, + Computed: true, + Description: "ver", + }, + }, + }, + }, + }, + }, + }, + "passwd": { + Type: schema.TypeString, + Computed: true, + Description: "password", + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + Description: "reference_id", + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "status", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "type", + }, + } +} + +func dataSourceStacksListSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "by_id", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "name", + }, + "type": { + Type: schema.TypeString, + Optional: true, + Description: "type", + }, + "status": { + Type: schema.TypeString, + Optional: true, + Description: "type", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "page size", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "stack_id": { + Type: schema.TypeInt, + Required: true, + Description: "stack_id", + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + Description: "ckey", + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "meta", + }, + "api_url": { + Type: schema.TypeString, + Computed: true, + Description: "api_url", + }, + "api_key": { + Type: schema.TypeString, + Computed: true, + Description: "api_key", + }, + "app_id": { + Type: schema.TypeString, + Computed: true, + Description: "api_id", + }, + "cpu_allocation_ratio": { + Type: schema.TypeFloat, + Computed: true, + Description: "cpu_allocation_ratio", + }, + "description": { + Type: schema.TypeString, + Computed: true, + Description: "description", + }, + "descr": { + Type: schema.TypeString, + Computed: true, + Description: "descr", + }, + "drivers": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "drivers", + }, + "eco": { + Type: schema.TypeString, + Computed: true, + Description: "eco", + }, + "error": { + Type: schema.TypeInt, + Computed: true, + Description: "error", + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "gid", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "images": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Description: "images", + }, + "login": { + Type: schema.TypeString, + Computed: true, + Description: "login", + }, + "mem_allocation_ratio": { + Type: schema.TypeFloat, + Computed: true, + Description: "mem_allocation_ratio", + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "name", + }, + "packages": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "libvirt_bin": { + Type: schema.TypeList, + Computed: true, + Description: "libvirt_bin", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installed_size": { + Type: schema.TypeString, + Computed: true, + Description: "installed_size", + }, + "ver": { + Type: schema.TypeString, + Computed: true, + Description: "ver", + }, + }, + }, + }, + "libvirt_daemon": { + Type: schema.TypeList, + Computed: true, + Description: "libvirt_daemon", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installed_size": { + Type: schema.TypeString, + Computed: true, + Description: "installed_size", + }, + "ver": { + Type: schema.TypeString, + Computed: true, + Description: "ver", + }, + }, + }, + }, + "lvm2_lockd": { + Type: schema.TypeList, + Computed: true, + Description: "lvm2_lockd", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installed_size": { + Type: schema.TypeString, + Computed: true, + Description: "installed_size", + }, + "ver": { + Type: schema.TypeString, + Computed: true, + Description: "ver", + }, + }, + }, + }, + "openvswitch_common": { + Type: schema.TypeList, + Computed: true, + Description: "openvswitch_common", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installed_size": { + Type: schema.TypeString, + Computed: true, + Description: "installed_size", + }, + "ver": { + Type: schema.TypeString, + Computed: true, + Description: "ver", + }, + }, + }, + }, + "openvswitch_switch": { + Type: schema.TypeList, + Computed: true, + Description: "openvswitch_switch", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installed_size": { + Type: schema.TypeString, + Computed: true, + Description: "installed_size", + }, + "ver": { + Type: schema.TypeString, + Computed: true, + Description: "ver", + }, + }, + }, + }, + "qemu_system_x86": { + Type: schema.TypeList, + Computed: true, + Description: "qemu_system_x86", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installed_size": { + Type: schema.TypeString, + Computed: true, + Description: "installed_size", + }, + "ver": { + Type: schema.TypeString, + Computed: true, + Description: "ver", + }, + }, + }, + }, + "sanlock": { + Type: schema.TypeList, + Computed: true, + Description: "sanlock", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "installed_size": { + Type: schema.TypeString, + Computed: true, + Description: "installed_size", + }, + "ver": { + Type: schema.TypeString, + Computed: true, + Description: "ver", + }, + }, + }, + }, + }, + }, + }, + "passwd": { + Type: schema.TypeString, + Computed: true, + Description: "password", + }, + "reference_id": { + Type: schema.TypeString, + Computed: true, + Description: "reference_id", + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "status", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "type", + }, + }, + }, + Description: "items of stacks list", + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + Description: "entry_count", + }, + } +} diff --git a/internal/service/cloudbroker/vins/data_source_vins_audits.go b/internal/service/cloudbroker/vins/data_source_vins_audits.go new file mode 100644 index 0000000..0ac2796 --- /dev/null +++ b/internal/service/cloudbroker/vins/data_source_vins_audits.go @@ -0,0 +1,70 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 vins + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceVinsAuditsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + audits, err := utilityVinsAuditsCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenVinsAudits(audits)) + + return nil +} + +func DataSourceVinsAudits() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceVinsAuditsRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + Schema: DataSourceVinsAuditsSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/vins/data_source_vins_ext_net_list.go b/internal/service/cloudbroker/vins/data_source_vins_ext_net_list.go new file mode 100644 index 0000000..f21257d --- /dev/null +++ b/internal/service/cloudbroker/vins/data_source_vins_ext_net_list.go @@ -0,0 +1,71 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 vins + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceVinsExtNetListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + extNetList, err := utilityVinsExtNetListCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenVinsExtNetList(extNetList)) + d.Set("entry_count", extNetList.EntryCount) + + return nil +} + +func DataSourceVinsExtNetList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceVinsExtNetListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + Schema: DataSourceVinsExtNetListchemaMake(), + } +} diff --git a/internal/service/cloudbroker/vins/data_source_vins_ip_list.go b/internal/service/cloudbroker/vins/data_source_vins_ip_list.go new file mode 100644 index 0000000..17641cf --- /dev/null +++ b/internal/service/cloudbroker/vins/data_source_vins_ip_list.go @@ -0,0 +1,71 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 vins + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceVinsIpListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + ips, err := utilityVinsIpListCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenVinsIpList(ips)) + d.Set("entry_count", ips.EntryCount) + + return nil +} + +func DataSourceVinsIpList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceVinsIpListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + Schema: DataSourceVinsIpListSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/vins/data_source_vins_list_deleted.go b/internal/service/cloudbroker/vins/data_source_vins_list_deleted.go new file mode 100644 index 0000000..780a208 --- /dev/null +++ b/internal/service/cloudbroker/vins/data_source_vins_list_deleted.go @@ -0,0 +1,72 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 vins + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceVinsListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + vinsList, err := utilityVinsListDeletedCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenVinsList(vinsList)) + d.Set("entry_count", vinsList.EntryCount) + + return nil +} + +func DataSourceVinsListDeleted() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceVinsListDeletedRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceVinsListDeletedSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/vins/data_source_vins_nat_rule_list.go b/internal/service/cloudbroker/vins/data_source_vins_nat_rule_list.go new file mode 100644 index 0000000..21c903c --- /dev/null +++ b/internal/service/cloudbroker/vins/data_source_vins_nat_rule_list.go @@ -0,0 +1,71 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 vins + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceVinsNatRuleListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + natRules, err := utilityVinsNatRuleListCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenVinsNatRuleList(natRules)) + d.Set("entry_count", natRules.EntryCount) + + return nil +} + +func DataSourceVinsNatRuleList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceVinsNatRuleListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + Schema: DataSourceVinsNatRuleListSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/vins/data_source_vins_static_route.go b/internal/service/cloudbroker/vins/data_source_vins_static_route.go new file mode 100644 index 0000000..c0f3d7b --- /dev/null +++ b/internal/service/cloudbroker/vins/data_source_vins_static_route.go @@ -0,0 +1,69 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 vins + +import ( + "context" + "strconv" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceStaticRouteRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + staticRoute, err := utilityDataStaticRouteCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + d.SetId(strconv.FormatUint(staticRoute.ID, 10)) + flattenStaticRouteData(d, staticRoute) + return nil +} + +func DataSourceStaticRoute() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceStaticRouteRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceStaticRouteSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/vins/data_source_vins_static_route_list.go b/internal/service/cloudbroker/vins/data_source_vins_static_route_list.go new file mode 100644 index 0000000..f6b5b47 --- /dev/null +++ b/internal/service/cloudbroker/vins/data_source_vins_static_route_list.go @@ -0,0 +1,72 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 vins + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" +) + +func dataSourceStaticRouteListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + staticRouteList, err := utilityStaticRouteListCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenStaticRouteList(staticRouteList)) + d.Set("entry_count", staticRouteList.EntryCount) + + return nil +} + +func DataSourceStaticRouteList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceStaticRouteListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceStaticRouteListSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/vins/flattens.go b/internal/service/cloudbroker/vins/flattens.go new file mode 100644 index 0000000..e4bd2d5 --- /dev/null +++ b/internal/service/cloudbroker/vins/flattens.go @@ -0,0 +1,582 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Sergey Kisil, + +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 vins + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens" +) + +func flattenVins(d *schema.ResourceData, vinsRecord *vins.RecordVINS) { + d.Set("vnf_dev", flattenVinsVNFDev(vinsRecord.VNFDev)) + d.Set("account_id", vinsRecord.AccountID) + d.Set("account_name", vinsRecord.AccountName) + d.Set("created_by", vinsRecord.CreatedBy) + d.Set("created_time", vinsRecord.CreatedTime) + d.Set("default_gw", vinsRecord.DefaultGW) + d.Set("default_qos", flattenVinsQOS(vinsRecord.DefaultQOS)) + d.Set("deleted_by", vinsRecord.DeletedBy) + d.Set("deleted_time", vinsRecord.DeletedTime) + d.Set("description", vinsRecord.Description) + d.Set("gid", vinsRecord.GID) + d.Set("guid", vinsRecord.GUID) + d.Set("vins_id", vinsRecord.ID) + d.Set("lock_status", vinsRecord.LockStatus) + d.Set("manager_id", vinsRecord.ManagerID) + d.Set("manager_type", vinsRecord.ManagerType) + d.Set("milestones", vinsRecord.Milestones) + d.Set("name", vinsRecord.Name) + d.Set("netmask", vinsRecord.NetMask) + d.Set("network", vinsRecord.Network) + d.Set("pre_reservations_num", vinsRecord.PreReservationsNum) + d.Set("redundant", vinsRecord.Redundant) + d.Set("rg_id", vinsRecord.RGID) + d.Set("rg_name", vinsRecord.RGName) + d.Set("sec_vnf_dev_id", vinsRecord.SecVNFDevID) + d.Set("status", vinsRecord.Status) + d.Set("updated_by", vinsRecord.UpdatedBy) + d.Set("updated_time", vinsRecord.UpdatedTime) + d.Set("user_managed", vinsRecord.UserManaged) + d.Set("vnfs", flattenVinsRecordVNFs(vinsRecord.VNFs)) + d.Set("vxlan_id", vinsRecord.VXLANID) + d.Set("nat_rule", flattenRuleBlock(vinsRecord.VNFs.NAT.Config.Rules)) +} + +func flattenVinsData(d *schema.ResourceData, vinsRecord *vins.RecordVINS) { + log.Debugf("flattenVins: decoded ViNS name: %s, ID : %d, account ID %d, RG ID %d", + vinsRecord.Name, vinsRecord.ID, vinsRecord.AccountID, vinsRecord.RGID) + + d.Set("vnf_dev", flattenVinsVNFDev(vinsRecord.VNFDev)) + d.Set("account_id", vinsRecord.AccountID) + d.Set("account_name", vinsRecord.AccountName) + d.Set("created_by", vinsRecord.CreatedBy) + d.Set("created_time", vinsRecord.CreatedTime) + d.Set("default_gw", vinsRecord.DefaultGW) + d.Set("default_qos", flattenVinsQOS(vinsRecord.DefaultQOS)) + d.Set("deleted_by", vinsRecord.DeletedBy) + d.Set("deleted_time", vinsRecord.DeletedTime) + d.Set("description", vinsRecord.Description) + d.Set("gid", vinsRecord.GID) + d.Set("guid", vinsRecord.GUID) + d.Set("vins_id", vinsRecord.ID) + d.Set("lock_status", vinsRecord.LockStatus) + d.Set("manager_id", vinsRecord.ManagerID) + d.Set("manager_type", vinsRecord.ManagerType) + d.Set("milestones", vinsRecord.Milestones) + d.Set("name", vinsRecord.Name) + d.Set("netmask", vinsRecord.NetMask) + d.Set("network", vinsRecord.Network) + d.Set("pre_reservations_num", vinsRecord.PreReservationsNum) + d.Set("redundant", vinsRecord.Redundant) + d.Set("rg_id", vinsRecord.RGID) + d.Set("rg_name", vinsRecord.RGName) + d.Set("sec_vnf_dev_id", vinsRecord.SecVNFDevID) + d.Set("status", vinsRecord.Status) + d.Set("updated_by", vinsRecord.UpdatedBy) + d.Set("updated_time", vinsRecord.UpdatedTime) + d.Set("user_managed", vinsRecord.UserManaged) + d.Set("vnfs", flattenVinsRecordVNFs(vinsRecord.VNFs)) + d.Set("vxlan_id", vinsRecord.VXLANID) +} + +func flattenVinsVNFDev(vd vins.VNFDev) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "ckey": vd.CKey, + "meta": flattens.FlattenMeta(vd.Meta), + "account_id": vd.AccountID, + "capabilities": vd.Capabilities, + "config": flattenVinsConfig(vd.Config), + "config_saved": vd.ConfigSaved, + "custom_precfg": vd.CustomPreConfig, + "description": vd.Description, + "gid": vd.GID, + "guid": vd.GUID, + "id": vd.ID, + "interfaces": flattenVinsListInterfaces(vd.Interfaces), + "lock_status": vd.LockStatus, + "milestones": vd.Milestones, + "name": vd.Name, + "status": vd.Status, + "tech_status": vd.TechStatus, + "type": vd.Type, + "vins": vd.VINS, + } + res = append(res, temp) + return res +} + +func flattenVinsRecordVNFs(rv vins.RecordVNFs) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "dhcp": flattenVinsRecordDHCP(rv.DHCP), + "gw": flattenVinsRecordGW(rv.GW), + "nat": flattenVinsRecordNAT(rv.NAT), + } + res = append(res, temp) + return res +} + +func flattenVinsRecordDHCP(rv vins.RecordDHCP) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "config": flattenVinsVNFsConfig(rv.Config), + "ckey": rv.CKey, + "meta": flattens.FlattenMeta(rv.Meta), + "account_id": rv.AccountID, + "created_time": rv.CreatedTime, + "devices": flattenVinsPrimaryDevices(rv.Devices), + "gid": rv.GID, + "guid": rv.GUID, + "id": rv.ID, + "lock_status": rv.LockStatus, + "milestones": rv.Milestones, + "owner_id": rv.OwnerID, + "owner_type": rv.OwnerType, + "pure_virtual": rv.PureVirtual, + "routes": flattenVinsRoutes(rv.Routes), + "status": rv.Status, + "tech_status": rv.TechStatus, + "type": rv.Type, + } + res = append(res, temp) + return res +} + +func flattenVinsRecordGW(rg vins.RecordGW) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "config": flattenVinsGWConfig(rg.Config), + "ckey": rg.CKey, + "meta": flattens.FlattenMeta(rg.Meta), + "account_id": rg.AccountID, + "created_time": rg.CreatedTime, + "devices": flattenVinsPrimaryDevices(rg.Devices), + "gid": rg.GID, + "guid": rg.GUID, + "id": rg.ID, + "lock_status": rg.LockStatus, + "milestones": rg.Milestones, + "owner_id": rg.OwnerID, + "owner_type": rg.OwnerType, + "pure_virtual": rg.PureVirtual, + "routes": flattenVinsRoutes(rg.Routes), + "status": rg.Status, + "tech_status": rg.TechStatus, + "type": rg.Type, + } + res = append(res, temp) + return res +} + +func flattenVinsRecordNAT(rn vins.RecordNAT) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "config": flattenVinsNATConfig(rn.Config), + "ckey": rn.CKey, + "meta": flattens.FlattenMeta(rn.Meta), + "account_id": rn.AccountID, + "created_time": rn.CreatedTime, + "devices": flattenVinsPrimaryDevices(rn.Devices), + "gid": rn.GID, + "guid": rn.GUID, + "id": rn.ID, + "lock_status": rn.LockStatus, + "milestones": rn.Milestones, + "owner_id": rn.OwnerID, + "owner_type": rn.OwnerType, + "pure_virtual": rn.PureVirtual, + "routes": flattenVinsRoutes(rn.Routes), + "status": rn.Status, + "tech_status": rn.TechStatus, + "type": rn.Type, + } + res = append(res, temp) + return res +} + +func flattenVinsVNFsConfig(vc vins.VNFsConfig) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "default_gw": vc.DefaultGW, + "dns": vc.DNS, + "ip_end": vc.IPEnd, + "ip_start": vc.IPStart, + "lease": vc.Lease, + "net_mask": vc.NetMask, + "network": vc.Network, + "reservations": flattenVinsListReservations(vc.Reservations), + } + res = append(res, temp) + return res +} + +func flattenVinsGWConfig(gc vins.GWConfig) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "default_gw": gc.DefaultGW, + "ext_net_id": gc.ExtNetID, + "ext_net_ip": gc.ExtNetIP, + "ext_netmask": gc.ExtNetMask, + "qos": flattenVinsQOS(gc.QOS), + } + res = append(res, temp) + return res +} + +func flattenVinsNATConfig(nc vins.NATConfig) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "net_mask": nc.NetMask, + "network": nc.Network, + "rules": flattenRulesItem(nc.Rules), + } + res = append(res, temp) + return res +} + +func flattenRuleBlock(rules []vins.ItemNATRule) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(rules)) + for _, rule := range rules { + tmp := map[string]interface{}{ + "int_ip": rule.LocalIP, + "int_port": rule.LocalPort, + "ext_port_start": rule.PublicPortStart, + "ext_port_end": rule.PublicPortEnd, + "proto": rule.Protocol, + "rule_id": rule.ID, + } + res = append(res, tmp) + } + return res +} + +func flattenRulesItem(rules []vins.ItemNATRule) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(rules)) + for _, rule := range rules { + tmp := map[string]interface{}{ + "rule_id": rule.ID, + "local_ip": rule.LocalIP, + "local_port": rule.LocalPort, + "protocol": rule.Protocol, + "public_port_end": rule.PublicPortEnd, + "public_port_start": rule.PublicPortStart, + "vm_id": rule.VMID, + "vm_name": rule.VMName, + } + res = append(res, tmp) + } + return res +} + +func flattenVinsPrimaryDevices(d vins.Devices) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "primary": flattenVinsDevices(d.Primary), + } + res = append(res, temp) + return res +} + +func flattenVinsDevices(d vins.Primary) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "dev_id": d.DevID, + "iface01": d.IFace01, + "iface02": d.IFace02, + } + res = append(res, temp) + return res +} + +func flattenVinsRoutes(r vins.ListRoutes) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(r)) + for _, v := range r { + temp := map[string]interface{}{ + "destination": v.Destination, + "netmask": v.Netmask, + "gateway": v.Gateway, + "compute_ids": v.ComputeIds, + "guid": v.GUID, + "route_id": v.ID, + } + res = append(res, temp) + } + return res +} + +func flattenVinsListReservations(li vins.ListReservations) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(li)) + for _, v := range li { + temp := map[string]interface{}{ + "client_type": v.ClientType, + "description": v.Description, + "domain_name": v.DomainName, + "host_name": v.Hostname, + "ip": v.IP, + "mac": v.MAC, + "type": v.Type, + "vm_id": v.VMID, + } + res = append(res, temp) + } + return res +} + +func flattenVinsConfig(c vins.Config) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "mgmt": flattenVinsMGMT(c.MGMT), + "resources": flattenVinsResources(c.Resources), + } + res = append(res, temp) + return res +} + +func flattenVinsMGMT(m vins.MGMT) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "ip_addr": m.IPAddress, + "password": m.Password, + "ssh_key": m.SSHKey, + "user": m.User, + } + res = append(res, temp) + return res +} + +func flattenVinsResources(r vins.Resources) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "cpu": r.CPU, + "ram": r.RAM, + "stack_id": r.StackID, + "uuid": r.UUID, + } + res = append(res, temp) + return res +} + +func flattenVinsListInterfaces(i vins.ListInterfaces) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(i)) + for _, v := range i { + temp := map[string]interface{}{ + "conn_id": v.ConnID, + "conn_type": v.ConnType, + "def_gw": v.DefGW, + "enabled": v.Enabled, + "flipgroup_id": v.FLIPGroupID, + "guid": v.GUID, + "ip_address": v.IPAddress, + "listen_ssh": v.ListenSSH, + "mac": v.MAC, + "name": v.Name, + "net_id": v.NetID, + "net_mask": v.NetMask, + "net_type": v.NetType, + "pci_slot": v.PCISlot, + "qos": flattenVinsQOS(v.QOS), + "target": v.Target, + "type": v.Type, + "vnfs": v.VNFs, + } + res = append(res, temp) + } + return res +} + +func flattenVinsList(vl *vins.ListVINS) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(vl.Data)) + for _, v := range vl.Data { + temp := map[string]interface{}{ + "account_id": v.AccountID, + "account_name": v.AccountName, + "created_by": v.CreatedBy, + "created_time": v.CreatedTime, + "default_gw": v.DefaultGW, + "default_qos": flattenVinsQOS(v.DefaultQOS), + "deleted_by": v.DeletedBy, + "deleted_time": v.DeletedTime, + "description": v.Description, + "external_ip": v.ExternalIP, + "gid": v.GID, + "guid": v.GUID, + "vins_id": v.ID, + "name": v.Name, + "lock_status": v.LockStatus, + "manager_id": v.ManagerID, + "manager_type": v.ManagerType, + "milestones": v.Milestones, + "netmask": v.NetMask, + "network": v.Network, + "pre_reservations_num": v.PreReservationsNum, + "pri_vnf_dev_id": v.PriVNFDevID, + "redundant": v.Redundant, + "rg_id": v.RGID, + "rg_name": v.RGName, + "sec_vnf_dev_id": v.SecVNFDevID, + "status": v.Status, + "updated_by": v.UpdatedBy, + "updated_time": v.UpdatedTime, + "user_managed": v.UserManaged, + "vnfs": flattenVinsVNFs(v.VNFs), + "vxlan_id": v.VXLANID, + } + res = append(res, temp) + } + return res +} + +func flattenVinsVNFs(iv vins.ItemVNFs) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "dhcp": iv.DHCP, + "dns": iv.DNS, + "fw": iv.FW, + "gw": iv.GW, + "nat": iv.NAT, + "vpn": iv.VPN, + } + res = append(res, temp) + return res +} + +func flattenVinsQOS(dq vins.QOS) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "e_rate": dq.ERate, + "guid": dq.GUID, + "in_burst": dq.InBurst, + "in_rate": dq.InRate, + } + res = append(res, temp) + return res +} + +func flattenVinsAudits(auidts vins.ListAudits) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(auidts)) + for _, audit := range auidts { + temp := map[string]interface{}{ + "call": audit.Call, + "response_time": audit.ResponseTime, + "status_code": audit.StatusCode, + "time_stamp": audit.Timestamp, + "user": audit.User, + } + res = append(res, temp) + } + + return res +} + +func flattenVinsExtNetList(extNetList *vins.ListExtNets) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(extNetList.Data)) + for _, extNet := range extNetList.Data { + temp := map[string]interface{}{ + "default_gw": extNet.DefaultGW, + "ext_net_id": extNet.ExtNetID, + "ip": extNet.IP, + "prefix_len": extNet.PrefixLen, + "status": extNet.Status, + "tech_status": extNet.TechStatus, + } + res = append(res, temp) + } + + return res +} + +func flattenVinsNatRuleList(natRules *vins.ListNATRules) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(natRules.Data)) + for _, natRule := range natRules.Data { + temp := map[string]interface{}{ + "id": natRule.ID, + "local_ip": natRule.LocalIP, + "local_port": natRule.LocalPort, + "protocol": natRule.Protocol, + "public_port_end": natRule.PublicPortEnd, + "public_port_start": natRule.PublicPortStart, + "vm_id": natRule.VMID, + "vm_name": natRule.VMName, + } + res = append(res, temp) + } + + return res +} + +func flattenVinsIpList(ips *vins.ListIPs) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(ips.Data)) + for _, ip := range ips.Data { + temp := map[string]interface{}{ + "client_type": ip.ClientType, + "domain_name": ip.DomainName, + "host_name": ip.Hostname, + "ip": ip.IP, + "mac": ip.MAC, + "type": ip.Type, + "vm_id": ip.VMID, + } + res = append(res, temp) + } + + return res +} + +func flattenStaticRouteList(sr *vins.ListStaticRoutes) []map[string]interface{} { + res := make([]map[string]interface{}, 0, len(sr.Data)) + for _, staticRoute := range sr.Data { + temp := map[string]interface{}{ + "route_id": staticRoute.ID, + "destination": staticRoute.Destination, + "gateway": staticRoute.Gateway, + "guid": staticRoute.GUID, + "netmask": staticRoute.Netmask, + "compute_ids": staticRoute.ComputeIds, + } + res = append(res, temp) + } + + return res +} + +func flattenStaticRouteData(d *schema.ResourceData, route *vins.ItemRoutes) { + d.Set("destination", route.Destination) + d.Set("gateway", route.Gateway) + d.Set("guid", route.GUID) + d.Set("netmask", route.Netmask) + d.Set("compute_ids", route.ComputeIds) + d.Set("route_id", route.ID) +} diff --git a/internal/service/cloudbroker/vins/resource_ckeck_input_value.go b/internal/service/cloudbroker/vins/resource_ckeck_input_value.go new file mode 100644 index 0000000..fa3e286 --- /dev/null +++ b/internal/service/cloudbroker/vins/resource_ckeck_input_value.go @@ -0,0 +1,131 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Sergey Kisil, + +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 vins + +import ( + "context" + "fmt" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/ic" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func checkParamsExistenceCreateInAcc(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) diag.Diagnostics { + var errs []error + + accountId := uint64(d.Get("account_id").(int)) + + if err := ic.ExistAccount(ctx, accountId, c); err != nil { + errs = append(errs, err) + } + + if gid, ok := d.GetOk("gid"); ok { + if err := ic.ExistGID(ctx, uint64(gid.(int)), c); err != nil { + errs = append(errs, err) + } + } + + return dc.ErrorsToDiagnostics(errs) +} + +func checkParamsExistenceCreateInRG(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) diag.Diagnostics { + var errs []error + + rgId := uint64(d.Get("rg_id").(int)) + + if err := ic.ExistGID(ctx, rgId, c); err != nil { + errs = append(errs, err) + } + + extNetID, ok := d.GetOk("ext_net_id") + if ok { + if err := ic.ExistExtNetInVins(ctx, extNetID.(int), c); err != nil { + errs = append(errs, err) + } + } + + if extIP, ok := d.GetOk("ext_ip"); ok { + if extNetID.(int) < 0 { + errs = append(errs, fmt.Errorf("external IP is related only for extNetId >= 0: ext_ip %d, extNetId %d", extIP, extNetID)) + } + } + + return nil +} + +func checkParamsExistenceUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) diag.Diagnostics { + var errs []error + + if rgId, ok := d.GetOk("rg_id"); ok { + err := ic.ExistRG(ctx, uint64(rgId.(int)), c) + if err != nil { + errs = append(errs, err) + } + } + + if extNetId, ok := d.GetOk("ext_net_id"); ok { + err := ic.ExistExtNetInVins(ctx, extNetId.(int), c) + if err != nil { + errs = append(errs, err) + } + } + + if accountId, ok := d.GetOk("account_id"); ok { + err := ic.ExistAccount(ctx, uint64(accountId.(int)), c) + if err != nil { + errs = append(errs, err) + } + } + + if gid, ok := d.GetOk("gid"); ok { + err := ic.ExistGID(ctx, uint64(gid.(int)), c) + if err != nil { + errs = append(errs, err) + } + } + + return dc.ErrorsToDiagnostics(errs) +} + +func checkParamsExistenceStaticRoute(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) diag.Diagnostics { + vinsId := uint64(d.Get("vins_id").(int)) + + if err := ic.ExistVins(ctx, vinsId, c); err != nil { + return diag.FromErr(err) + } + + return nil +} diff --git a/internal/service/cloudbroker/vins/resource_utility.go b/internal/service/cloudbroker/vins/resource_utility.go new file mode 100644 index 0000000..af2b4af --- /dev/null +++ b/internal/service/cloudbroker/vins/resource_utility.go @@ -0,0 +1,155 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Sergey Kisil, + +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 vins + +import ( + "context" + "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/cloudbroker/vins" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func createVinsInAcc(ctx context.Context, d *schema.ResourceData, m interface{}, accID uint64) (vins.CreateInAccountRequest, diag.Diagnostics) { + c := m.(*controller.ControllerCfg) + req := vins.CreateInAccountRequest{} + + if diags := checkParamsExistenceCreateInAcc(ctx, d, c); diags != nil { + return req, diags + } + + req.AccountID = accID + req.Name = d.Get("name").(string) + + if gid, ok := d.GetOk("gid"); ok { + req.GID = uint64(gid.(int)) + } + if IPCIDR, ok := d.GetOk("ipcidr"); ok { + req.IPCIDR = IPCIDR.(string) + } + if description, ok := d.GetOk("description"); ok { + req.Description = description.(string) + } + if preReservationsNum, ok := d.GetOk("pre_reservations_num"); ok { + req.PreReservationsNum = uint64(preReservationsNum.(int)) + } + if reason, ok := d.GetOk("reason"); ok { + req.Reason = reason.(string) + } + if routesList, ok := d.GetOk("routes"); ok { + var routes []vins.Route + var route vins.Route + for _, r := range routesList.([]map[string]interface{}) { + route.Netmask = r["netmask"].(string) + route.Destination = r["destination"].(string) + route.Gateway = r["gateway"].(string) + routes = append(routes, route) + } + req.Routes = routes + } + + return req, nil +} + +func createVinsInRG(ctx context.Context, d *schema.ResourceData, m interface{}, RGID uint64) (vins.CreateInRGRequest, diag.Diagnostics) { + c := m.(*controller.ControllerCfg) + req := vins.CreateInRGRequest{} + + if diags := checkParamsExistenceCreateInRG(ctx, d, c); diags != nil { + return req, diags + } + + req.RGID = RGID + req.Name = d.Get("name").(string) + + if IPCIDR, ok := d.GetOk("ipcidr"); ok { + req.IPCIDR = IPCIDR.(string) + } + + if extNetID, ok := d.GetOk("ext_net_id"); ok { + req.ExtNetID = uint64(extNetID.(int)) + } + + if extIP, ok := d.GetOk("ext_ip"); ok { + req.ExtIP = extIP.(string) + } + if description, ok := d.GetOk("description"); ok { + req.Description = description.(string) + } + if preReservationsNum, ok := d.GetOk("pre_reservations_num"); ok { + req.PreReservationsNum = uint64(preReservationsNum.(int)) + } + if reason, ok := d.GetOk("reason"); ok { + req.Reason = reason.(string) + } + if routesList, ok := d.GetOk("routes"); ok { + var routes []vins.Route + var route vins.Route + for _, r := range routesList.([]map[string]interface{}) { + route.Netmask = r["netmask"].(string) + route.Destination = r["destination"].(string) + route.Gateway = r["gateway"].(string) + routes = append(routes, route) + } + req.Routes = routes + } + + return req, nil +} + +func isContainsIp(els []interface{}, el interface{}) bool { + elConv := el.(map[string]interface{}) + for _, elOld := range els { + elOldConv := elOld.(map[string]interface{}) + if elOldConv["ip_addr"].(string) == elConv["ip_addr"].(string) && + elOldConv["type"].(string) == elConv["type"].(string) && + elOldConv["mac"].(string) == elConv["mac"].(string) && + elOldConv["compute_id"].(string) == elConv["compute_id"].(string) { + return true + } + } + return false +} + +func isContainsNatRule(els []interface{}, el interface{}) bool { + elConv := el.(map[string]interface{}) + for _, elOld := range els { + elOldConv := elOld.(map[string]interface{}) + if elOldConv["int_ip"].(string) == elConv["int_ip"].(string) && + elOldConv["int_port"].(int) == elConv["int_port"].(int) && + elOldConv["ext_port_start"].(int) == elConv["ext_port_start"].(int) { + return true + } + } + return false +} diff --git a/internal/service/cloudbroker/vins/resource_vins_static_route.go b/internal/service/cloudbroker/vins/resource_vins_static_route.go new file mode 100644 index 0000000..c8d7905 --- /dev/null +++ b/internal/service/cloudbroker/vins/resource_vins_static_route.go @@ -0,0 +1,249 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 vins + +import ( + "context" + "fmt" + "strconv" + "strings" + + log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins" + "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/dc" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func resourceStaticRouteCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("resourceStaticRouteCreate: called for vins_id %s", d.Get("vins_id")) + + c := m.(*controller.ControllerCfg) + + if diags := checkParamsExistenceStaticRoute(ctx, d, c); diags != nil { + return diags + } + + req := vins.StaticRouteAddRequest{ + VINSID: uint64(d.Get("vins_id").(int)), + Destination: d.Get("destination").(string), + Netmask: d.Get("netmask").(string), + Gateway: d.Get("gateway").(string), + } + + if computesIDS, ok := d.GetOk("compute_ids"); ok { + ids := computesIDS.([]interface{}) + + res := make([]uint64, 10) + + for _, id := range ids { + computeId := uint64(id.(int)) + res = append(res, computeId) + } + + req.ComputeIds = res + } + + _, err := c.CloudBroker().VINS().StaticRouteAdd(ctx, req) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + staticRouteData, err := getStaticRouteData(ctx, d, m) + if err != nil { + return diag.FromErr(err) + } + + d.SetId(fmt.Sprintf("%d#%d", req.VINSID, staticRouteData.ID)) + + return resourceStaticRouteRead(ctx, d, m) +} + +func resourceStaticRouteRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("resourceStaticRouteRead: called for route_id %s", d.Id()) + + staticRouteData, err := utilityDataStaticRouteCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + flattenStaticRouteData(d, staticRouteData) + + return nil +} + +func resourceStaticRouteUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("resourceStaticRouteUpdate: called for static route id %s", d.Id()) + + c := m.(*controller.ControllerCfg) + + if diags := checkParamsExistenceStaticRoute(ctx, d, c); diags != nil { + return diags + } + + staticRouteData, err := utilityDataStaticRouteCheckPresence(ctx, d, m) + if err != nil { + d.SetId("") + return diag.FromErr(err) + } + + warnings := dc.Warnings{} + if d.HasChange("compute_ids") { + if errs := resourceStaticRouteChangeComputeIds(ctx, d, m, staticRouteData); len(errs) != 0 { + for _, err := range errs { + warnings.Add(err) + } + } + } + + return append(warnings.Get(), resourceStaticRouteRead(ctx, d, m)...) +} + +func resourceStaticRouteDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + log.Debugf("resourceStaticRouteDelete: called for static route id %s", d.Id()) + + c := m.(*controller.ControllerCfg) + req := vins.StaticRouteDelRequest{} + + arr := strings.Split(d.Id(), "#") + if len(arr) != 2 { + return diag.Errorf("broken state id - %s", d.Id()) + } + + req.VINSID, _ = strconv.ParseUint(arr[0], 10, 64) + req.RouteId, _ = strconv.ParseUint(arr[1], 10, 64) + + _, err := c.CloudBroker().VINS().StaticRouteDel(ctx, req) + if err != nil { + return diag.FromErr(err) + } + + d.SetId("") + + return nil +} + +func resourceStaticRouteChangeComputeIds(ctx context.Context, d *schema.ResourceData, m interface{}, staticRouteData *vins.ItemRoutes) []error { + c := m.(*controller.ControllerCfg) + + var errs []error + + vinsId := uint64(d.Get("vins_id").(int)) + + deletedIds := make([]uint64, 0) + addedIds := make([]uint64, 0) + + oldComputeIds, newComputeIds := d.GetChange("compute_ids") + oldComputeIdsSlice := oldComputeIds.([]interface{}) + newComputeIdsSlice := newComputeIds.([]interface{}) + + for _, el := range oldComputeIdsSlice { + if !isContainsIds(newComputeIdsSlice, el) { + convertedEl := uint64(el.(int)) + deletedIds = append(deletedIds, convertedEl) + } + } + + for _, el := range newComputeIdsSlice { + if !isContainsIds(oldComputeIdsSlice, el) { + convertedEl := uint64(el.(int)) + addedIds = append(addedIds, convertedEl) + } + } + + if len(deletedIds) > 0 { + req := vins.StaticRouteAccessRevokeRequest{ + VINSID: vinsId, + RouteId: staticRouteData.ID, + ComputeIds: deletedIds, + } + + if _, err := c.CloudBroker().VINS().StaticRouteAccessRevoke(ctx, req); err != nil { + errs = append(errs, err) + } + } + + if len(addedIds) > 0 { + req := vins.StaticRouteAccessGrantRequest{ + VINSID: vinsId, + RouteId: staticRouteData.ID, + ComputeIds: addedIds, + } + + if _, err := c.CloudBroker().VINS().StaticRouteAccessGrant(ctx, req); err != nil { + errs = append(errs, err) + } + } + + return errs +} + +func isContainsIds(els []interface{}, el interface{}) bool { + convEl := el.(int) + for _, elOld := range els { + if convEl == elOld.(int) { + return true + } + } + return false +} + +func ResourceStaticRoute() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + CreateContext: resourceStaticRouteCreate, + ReadContext: resourceStaticRouteRead, + UpdateContext: resourceStaticRouteUpdate, + DeleteContext: resourceStaticRouteDelete, + + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: &constants.Timeout20m, + Read: &constants.Timeout600s, + Update: &constants.Timeout20m, + Delete: &constants.Timeout600s, + Default: &constants.Timeout600s, + }, + + Schema: resourceStaticRouteSchemaMake(), + } +} diff --git a/internal/service/cloudbroker/vins/schema.go b/internal/service/cloudbroker/vins/schema.go new file mode 100644 index 0000000..747d3f5 --- /dev/null +++ b/internal/service/cloudbroker/vins/schema.go @@ -0,0 +1,3281 @@ +package vins + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +func dataSourceVinsSchemaMake() map[string]*schema.Schema { + rets := map[string]*schema.Schema{ + "vins_id": { + Type: schema.TypeInt, + Required: true, + Description: "vins id", + }, + "reason": { + Type: schema.TypeString, + Optional: true, + Description: "reason for action", + }, + "vnf_dev": { + Type: schema.TypeList, + Computed: true, + Description: "vnf dev", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ckey": { + Type: schema.TypeString, + Computed: true, + Description: "ckey", + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Description: "meta", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + Description: "account id", + }, + "capabilities": { + Type: schema.TypeList, + Computed: true, + Description: "capabilities", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "config": { + Type: schema.TypeList, + Computed: true, + Description: "config", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "mgmt": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip_addr": { + Type: schema.TypeString, + Computed: true, + Description: "ip address", + }, + "password": { + Type: schema.TypeString, + Computed: true, + Description: "password", + }, + "ssh_key": { + Type: schema.TypeString, + Computed: true, + Description: "ssh key", + }, + "user": { + Type: schema.TypeString, + Computed: true, + Description: "user", + }, + }, + }, + }, + "resources": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + Description: "cpu", + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + Description: "ram", + }, + "stack_id": { + Type: schema.TypeInt, + Computed: true, + Description: "stack id", + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + Description: "uuid", + }, + }, + }, + }, + }, + }, + }, + "config_saved": { + Type: schema.TypeBool, + Computed: true, + Description: "is config saved", + }, + "custom_precfg": { + Type: schema.TypeBool, + Computed: true, + Description: "custom pre config", + }, + "description": { + Type: schema.TypeString, + Computed: true, + Description: "description", + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "gid", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "id": { + Type: schema.TypeInt, + Computed: true, + Description: "id", + }, + "interfaces": { + Type: schema.TypeList, + Computed: true, + Description: "interfaces", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "conn_id": { + Type: schema.TypeInt, + Computed: true, + Description: "connection id", + }, + "conn_type": { + Type: schema.TypeString, + Computed: true, + Description: "connection type", + }, + "def_gw": { + Type: schema.TypeString, + Computed: true, + Description: "default gw", + }, + "enabled": { + Type: schema.TypeBool, + Computed: true, + Description: "enabled", + }, + "flipgroup_id": { + Type: schema.TypeInt, + Computed: true, + Description: "flipgroup id", + }, + "guid": { + Type: schema.TypeString, + Computed: true, + Description: "guid", + }, + "ip_address": { + Type: schema.TypeString, + Computed: true, + Description: "ip address", + }, + "listen_ssh": { + Type: schema.TypeBool, + Computed: true, + Description: "listen ssh", + }, + "mac": { + Type: schema.TypeString, + Computed: true, + Description: "mac", + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "name", + }, + "net_id": { + Type: schema.TypeInt, + Computed: true, + Description: "net id", + }, + "net_mask": { + Type: schema.TypeInt, + Computed: true, + Description: "net mask", + }, + "net_type": { + Type: schema.TypeString, + Computed: true, + Description: "net type", + }, + "pci_slot": { + Type: schema.TypeInt, + Computed: true, + Description: "pci slot", + }, + "qos": { + Type: schema.TypeList, + Computed: true, + Description: "qos", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "e_rate": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "in_burst": { + Type: schema.TypeInt, + Computed: true, + }, + "in_rate": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "target": { + Type: schema.TypeString, + Computed: true, + Description: "target", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "type", + }, + "vnfs": { + Type: schema.TypeList, + Computed: true, + Description: "vnfs", + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + }, + }, + }, + "lock_status": { + Type: schema.TypeString, + Computed: true, + Description: "lock status", + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + Description: "milestones", + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "name", + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "status", + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + Description: "tech status", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "type", + }, + "vins": { + Type: schema.TypeList, + Computed: true, + Description: "vins", + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + }, + }, + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + Description: "account id", + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + Description: "account name", + }, + "created_by": { + Type: schema.TypeString, + Computed: true, + Description: "created by", + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + Description: "created time", + }, + "default_gw": { + Type: schema.TypeString, + Computed: true, + Description: "default gw", + }, + "default_qos": { + Type: schema.TypeList, + Computed: true, + Description: "default qoa", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "e_rate": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "in_burst": { + Type: schema.TypeInt, + Computed: true, + }, + "in_rate": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "deleted_by": { + Type: schema.TypeString, + Computed: true, + Description: "deleted by", + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + Description: "deleted time", + }, + "description": { + Type: schema.TypeString, + Computed: true, + Description: "description", + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "gid", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "lock_status": { + Type: schema.TypeString, + Computed: true, + Description: "lock status", + }, + "manager_id": { + Type: schema.TypeInt, + Computed: true, + Description: "manager id", + }, + "manager_type": { + Type: schema.TypeString, + Computed: true, + Description: "manager type", + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + Description: "milestones", + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "name", + }, + "netmask": { + Type: schema.TypeInt, + Computed: true, + Description: "net mask", + }, + "network": { + Type: schema.TypeString, + Computed: true, + Description: "network", + }, + "pre_reservations_num": { + Type: schema.TypeInt, + Computed: true, + Description: "pre reservations num", + }, + "redundant": { + Type: schema.TypeBool, + Computed: true, + Description: "redundant", + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + Description: "resource group id", + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + Description: "resource group name", + }, + "sec_vnf_dev_id": { + Type: schema.TypeInt, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "status", + }, + "updated_by": { + Type: schema.TypeString, + Computed: true, + Description: "updated by", + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + Description: "updated time", + }, + "user_managed": { + Type: schema.TypeBool, + Computed: true, + Description: "user managed", + }, + "vnfs": { + Type: schema.TypeList, + Computed: true, + Description: "vnfs", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dhcp": { + Type: schema.TypeList, + Computed: true, + Description: "dhcp", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ckey": { + Type: schema.TypeString, + Computed: true, + Description: "ckey", + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Description: "meta", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + Description: "account id", + }, + "config": { + Type: schema.TypeList, + Computed: true, + Description: "config", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "default_gw": { + Type: schema.TypeString, + Computed: true, + Description: "default gw", + }, + "dns": { + Type: schema.TypeList, + Computed: true, + Description: "list of dns", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "ip_end": { + Type: schema.TypeString, + Computed: true, + Description: "ip end", + }, + "ip_start": { + Type: schema.TypeString, + Computed: true, + Description: "ip start", + }, + "lease": { + Type: schema.TypeInt, + Computed: true, + Description: "lease", + }, + "net_mask": { + Type: schema.TypeInt, + Computed: true, + Description: "net mask", + }, + "network": { + Type: schema.TypeString, + Computed: true, + Description: "network", + }, + "reservations": { + Type: schema.TypeList, + Computed: true, + Description: "reservations", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "client_type": { + Type: schema.TypeString, + Computed: true, + Description: "client type", + }, + "description": { + Type: schema.TypeString, + Computed: true, + Description: "description", + }, + "domain_name": { + Type: schema.TypeString, + Computed: true, + Description: "domain name", + }, + "host_name": { + Type: schema.TypeString, + Computed: true, + Description: "host name", + }, + "ip": { + Type: schema.TypeString, + Computed: true, + Description: "ip", + }, + "mac": { + Type: schema.TypeString, + Computed: true, + Description: "mac", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "type", + }, + "vm_id": { + Type: schema.TypeInt, + Computed: true, + Description: "vm id", + }, + }, + }, + }, + }, + }, + }, + + "created_time": { + Type: schema.TypeInt, + Computed: true, + Description: "created time", + }, + "devices": { + Type: schema.TypeList, + Computed: true, + Description: "devices list", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "primary": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dev_id": { + Type: schema.TypeInt, + Computed: true, + }, + "iface01": { + Type: schema.TypeString, + Computed: true, + }, + "iface02": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "gid", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "id": { + Type: schema.TypeInt, + Computed: true, + Description: "id", + }, + "lock_status": { + Type: schema.TypeString, + Computed: true, + Description: "lock status", + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + Description: "milestones", + }, + "owner_id": { + Type: schema.TypeInt, + Computed: true, + Description: "owner id", + }, + "owner_type": { + Type: schema.TypeString, + Computed: true, + Description: "owner type", + }, + "pure_virtual": { + Type: schema.TypeBool, + Computed: true, + Description: "prune virtual", + }, + "routes": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "compute_ids": { + Type: schema.TypeList, + Computed: true, + Description: "compute ids", + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "route_id": { + Type: schema.TypeInt, + Computed: true, + Description: "route id", + }, + "guid": { + Type: schema.TypeString, + Computed: true, + Description: "guid", + }, + "destination": { + Type: schema.TypeString, + Computed: true, + Description: "destination", + }, + "netmask": { + Type: schema.TypeString, + Computed: true, + Description: "net mask", + }, + "gateway": { + Type: schema.TypeString, + Computed: true, + Description: "gateway", + }, + }, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "status", + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + Description: "tech status", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "type", + }, + }, + }, + }, + "gw": { + Type: schema.TypeList, + Computed: true, + Description: "gw", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ckey": { + Type: schema.TypeString, + Computed: true, + Description: "ckey", + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Description: "meta", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + Description: "account id", + }, + "config": { + Type: schema.TypeList, + Computed: true, + Description: "config", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "default_gw": { + Type: schema.TypeString, + Computed: true, + Description: "default gw", + }, + "ext_net_id": { + Type: schema.TypeInt, + Computed: true, + Description: "extnet id", + }, + "ext_net_ip": { + Type: schema.TypeString, + Computed: true, + Description: "extnet ip", + }, + "ext_netmask": { + Type: schema.TypeInt, + Computed: true, + Description: "extnet mask", + }, + "qos": { + Type: schema.TypeList, + Computed: true, + Description: "qos", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "e_rate": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "in_burst": { + Type: schema.TypeInt, + Computed: true, + }, + "in_rate": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + Description: "created time", + }, + "devices": { + Type: schema.TypeList, + Computed: true, + Description: "devices list", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "primary": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dev_id": { + Type: schema.TypeInt, + Computed: true, + }, + "iface01": { + Type: schema.TypeString, + Computed: true, + }, + "iface02": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "gid", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "id": { + Type: schema.TypeInt, + Computed: true, + Description: "id", + }, + "lock_status": { + Type: schema.TypeString, + Computed: true, + Description: "losk status", + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + Description: "milestones", + }, + "owner_id": { + Type: schema.TypeInt, + Computed: true, + Description: "owner id", + }, + "owner_type": { + Type: schema.TypeString, + Computed: true, + Description: "owner type", + }, + "pure_virtual": { + Type: schema.TypeBool, + Computed: true, + Description: "pure virtual", + }, + "routes": { + Type: schema.TypeList, + Computed: true, + Description: "routes", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "compute_ids": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "route_id": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "destination": { + Type: schema.TypeString, + Computed: true, + }, + "netmask": { + Type: schema.TypeString, + Computed: true, + }, + "gateway": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "status", + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + Description: "tech status", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "type", + }, + }, + }, + }, + "nat": { + Type: schema.TypeList, + Computed: true, + Description: "nat", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ckey": { + Type: schema.TypeString, + Computed: true, + Description: "ckey", + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Description: "meta", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + Description: "account id", + }, + "config": { + Type: schema.TypeList, + Computed: true, + Description: "config", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "net_mask": { + Type: schema.TypeInt, + Computed: true, + Description: "net mask", + }, + "network": { + Type: schema.TypeString, + Computed: true, + Description: "network", + }, + "rules": { + Type: schema.TypeList, + Computed: true, + Description: "nat rules", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "rule_id": { + Type: schema.TypeInt, + Computed: true, + Description: "nat rule id", + }, + "local_ip": { + Type: schema.TypeString, + Computed: true, + Description: "local ip", + }, + "local_port": { + Type: schema.TypeInt, + Computed: true, + Description: "local port", + }, + "protocol": { + Type: schema.TypeString, + Computed: true, + Description: "protocol", + }, + "public_port_end": { + Type: schema.TypeInt, + Computed: true, + Description: "public port end", + }, + "public_port_start": { + Type: schema.TypeInt, + Computed: true, + Description: "public port start", + }, + "vm_id": { + Type: schema.TypeInt, + Computed: true, + Description: "vm id", + }, + "vm_name": { + Type: schema.TypeString, + Computed: true, + Description: "vm name", + }, + }, + }, + }, + }, + }, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + Description: "created time", + }, + "devices": { + Type: schema.TypeList, + Computed: true, + Description: "devices list", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "primary": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dev_id": { + Type: schema.TypeInt, + Computed: true, + }, + "iface01": { + Type: schema.TypeString, + Computed: true, + }, + "iface02": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "gid", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "id": { + Type: schema.TypeInt, + Computed: true, + Description: "id", + }, + "lock_status": { + Type: schema.TypeString, + Computed: true, + Description: "lock status", + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + Description: "milestones", + }, + "owner_id": { + Type: schema.TypeInt, + Computed: true, + Description: "owner id", + }, + "owner_type": { + Type: schema.TypeString, + Computed: true, + Description: "owner type", + }, + "pure_virtual": { + Type: schema.TypeBool, + Computed: true, + Description: "pure virtual", + }, + "routes": { + Type: schema.TypeList, + Computed: true, + Description: "routes", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "compute_ids": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "route_id": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "destination": { + Type: schema.TypeString, + Computed: true, + }, + "netmask": { + Type: schema.TypeString, + Computed: true, + }, + "gateway": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "status", + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + Description: "tech status", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "type", + }, + }, + }, + }, + }, + }, + }, + "vxlan_id": { + Type: schema.TypeInt, + Computed: true, + Description: "vxlan id", + }, + } + + return rets +} + +func dataSourceVinsListSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by id", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by account id", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Find by rg id", + }, + "ext_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Find by ext ip", + }, + "include_deleted": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "include deleted computes", + }, + "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, + }, + "created_by": { + Type: schema.TypeString, + Computed: true, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + "default_gw": { + Type: schema.TypeString, + Computed: true, + }, + "default_qos": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "e_rate": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "in_burst": { + Type: schema.TypeInt, + Computed: true, + }, + "in_rate": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "deleted_by": { + Type: schema.TypeString, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + }, + "external_ip": { + Type: schema.TypeString, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "vins_id": { + Type: schema.TypeInt, + Computed: true, + }, + "lock_status": { + Type: schema.TypeString, + Computed: true, + }, + "manager_id": { + Type: schema.TypeInt, + Computed: true, + }, + "manager_type": { + Type: schema.TypeString, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "netmask": { + Type: schema.TypeInt, + Computed: true, + }, + "network": { + Type: schema.TypeString, + Computed: true, + }, + "pre_reservations_num": { + Type: schema.TypeInt, + Computed: true, + }, + "pri_vnf_dev_id": { + Type: schema.TypeInt, + Computed: true, + }, + "redundant": { + Type: schema.TypeBool, + Computed: true, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + }, + "sec_vnf_dev_id": { + Type: schema.TypeInt, + Computed: true, + }, + "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, + }, + "vnfs": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dhcp": { + Type: schema.TypeInt, + Computed: true, + }, + "dns": { + Type: schema.TypeInt, + Computed: true, + }, + "fw": { + Type: schema.TypeInt, + Computed: true, + }, + "gw": { + Type: schema.TypeInt, + Computed: true, + }, + "nat": { + Type: schema.TypeInt, + Computed: true, + }, + "vpn": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "vxlan_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Optional: true, + Description: "entry count", + }, + } + return res +} + +func dataSourceVinsListDeletedSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "by_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by ID", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by account ID", + }, + "rg_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Filter by resgroup ID", + }, + "ext_ip": { + Type: schema.TypeString, + Optional: true, + Description: "Filter by external IP", + }, + "page": { + Type: schema.TypeInt, + Optional: true, + Description: "Page number", + }, + "size": { + Type: schema.TypeInt, + Optional: true, + Description: "Page size", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Computed: true, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "created_by": { + Type: schema.TypeString, + Computed: true, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + }, + "default_gw": { + Type: schema.TypeString, + Computed: true, + }, + "default_qos": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "e_rate": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "in_burst": { + Type: schema.TypeInt, + Computed: true, + }, + "in_rate": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "deleted_by": { + Type: schema.TypeString, + Computed: true, + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + }, + "external_ip": { + Type: schema.TypeString, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "vins_id": { + Type: schema.TypeInt, + Computed: true, + }, + "lock_status": { + Type: schema.TypeString, + Computed: true, + }, + "manager_id": { + Type: schema.TypeInt, + Computed: true, + }, + "manager_type": { + Type: schema.TypeString, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "netmask": { + Type: schema.TypeInt, + Computed: true, + }, + "network": { + Type: schema.TypeString, + Computed: true, + }, + "pre_reservations_num": { + Type: schema.TypeInt, + Computed: true, + }, + "pri_vnf_dev_id": { + Type: schema.TypeInt, + Computed: true, + }, + "redundant": { + Type: schema.TypeBool, + Computed: true, + }, + "rg_id": { + Type: schema.TypeInt, + Computed: true, + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + }, + "sec_vnf_dev_id": { + Type: schema.TypeInt, + Computed: true, + }, + "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, + }, + "vnfs": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dhcp": { + Type: schema.TypeInt, + Computed: true, + }, + "dns": { + Type: schema.TypeInt, + Computed: true, + }, + "fw": { + Type: schema.TypeInt, + Computed: true, + }, + "gw": { + Type: schema.TypeInt, + Computed: true, + }, + "nat": { + Type: schema.TypeInt, + Computed: true, + }, + "vpn": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "vxlan_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return res +} + +func DataSourceVinsAuditsSchemaMake() map[string]*schema.Schema { + rets := map[string]*schema.Schema{ + "vins_id": { + Type: schema.TypeInt, + Required: true, + Description: "Unique ID of the ViNS. If ViNS ID is specified, then ViNS name, rg_id and account_id are ignored.", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "call": { + Type: schema.TypeString, + Computed: true, + }, + "response_time": { + Type: schema.TypeFloat, + Computed: true, + }, + "status_code": { + Type: schema.TypeInt, + Computed: true, + }, + "time_stamp": { + Type: schema.TypeFloat, + Computed: true, + }, + "user": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + } + return rets +} + +func DataSourceVinsExtNetListchemaMake() map[string]*schema.Schema { + rets := map[string]*schema.Schema{ + "vins_id": { + Type: schema.TypeInt, + Required: true, + Description: "Unique ID of the ViNS. If ViNS ID is specified, then ViNS name, rg_id and account_id are ignored.", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "default_gw": { + Type: schema.TypeString, + Computed: true, + }, + "ext_net_id": { + Type: schema.TypeInt, + Computed: true, + }, + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "prefix_len": { + Type: schema.TypeInt, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return rets +} + +func DataSourceVinsIpListSchemaMake() map[string]*schema.Schema { + rets := map[string]*schema.Schema{ + "vins_id": { + Type: schema.TypeInt, + Required: true, + Description: "Unique ID of the ViNS", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "client_type": { + Type: schema.TypeString, + Computed: true, + }, + "domain_name": { + Type: schema.TypeString, + Computed: true, + }, + "host_name": { + Type: schema.TypeString, + Computed: true, + }, + "ip": { + Type: schema.TypeString, + Computed: true, + }, + "mac": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "vm_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return rets +} + +func DataSourceVinsNatRuleListSchemaMake() map[string]*schema.Schema { + rets := map[string]*schema.Schema{ + "vins_id": { + Type: schema.TypeInt, + Required: true, + Description: "Unique ID of the ViNS. If ViNS ID is specified, then ViNS name, rg_id and account_id are ignored.", + }, + "reason": { + Type: schema.TypeString, + Optional: true, + Description: "reason for action", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeInt, + Computed: true, + }, + "local_ip": { + Type: schema.TypeString, + Computed: true, + }, + "local_port": { + Type: schema.TypeInt, + Computed: true, + }, + "protocol": { + Type: schema.TypeString, + Computed: true, + }, + "public_port_end": { + Type: schema.TypeInt, + Computed: true, + }, + "public_port_start": { + Type: schema.TypeInt, + Computed: true, + }, + "vm_id": { + Type: schema.TypeInt, + Computed: true, + }, + "vm_name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return rets +} + +func dataSourceStaticRouteListSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "vins_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of VINS", + }, + "items": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "compute_ids": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "destination": { + Type: schema.TypeString, + Computed: true, + }, + "gateway": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "netmask": { + Type: schema.TypeString, + Computed: true, + }, + "route_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "entry_count": { + Type: schema.TypeInt, + Computed: true, + }, + } + return res +} + +func resourceVinsSchemaMake() map[string]*schema.Schema { + rets := map[string]*schema.Schema{ + // parameters from CreateInAccount + "name": { + Type: schema.TypeString, + Required: true, + Description: "name", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "ipcidr": { + Type: schema.TypeString, + Optional: true, + }, + "description": { + Type: schema.TypeString, + Optional: true, + Default: "", + Description: "Optional user-defined text description of this ViNS.", + }, + "pre_reservations_num": { + Type: schema.TypeInt, + Optional: true, + Default: 32, + }, + "routes": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "compute_ids": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "route_id": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "destination": { + Type: schema.TypeString, + Computed: true, + }, + "netmask": { + Type: schema.TypeString, + Computed: true, + }, + "gateway": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "reason": { + Type: schema.TypeString, + Optional: true, + }, + + // Additional parameters from CreateInRG + "rg_id": { + Type: schema.TypeInt, + Computed: true, + Optional: true, + }, + "ext_net_id": { + Type: schema.TypeInt, + Optional: true, + Default: -1, + }, + "ext_ip": { + Type: schema.TypeString, + Optional: true, + Default: "", + }, + + // Enable, delete parameters + "enable": { + Type: schema.TypeBool, + Optional: true, + Default: true, + Description: "enable for enable/disable requests", + }, + "force": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "force for delete request", + }, + "permanently": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "permanently for delete request", + }, + + // IP release, IP reserve parameters + "ip": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "type": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{"DHCP", "VIP", "EXCLUDE"}, false), + }, + "ip_addr": { + Type: schema.TypeString, + Optional: true, + }, + "mac": { + Type: schema.TypeString, + Optional: true, + }, + "compute_id": { + Type: schema.TypeInt, + Optional: true, + }, + "reason": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + + // NAT rule add parameters + "nat_rule": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "int_ip": { + Type: schema.TypeString, + Required: true, + }, + "int_port": { + Type: schema.TypeInt, + Required: true, + }, + "ext_port_start": { + Type: schema.TypeInt, + Required: true, + }, + "ext_port_end": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "proto": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"tcp", "udp"}, false), + Computed: true, + }, + "rule_id": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + + // vnf dev start, stop, restart, reset, redeploy parameters + "vnfdev_start": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "true to start vnfdev, false to stop vnfdev", + }, + "vnfdev_reset": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "vnfdev_restart": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "vnfdev_redeploy": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + + // default_qos + "default_qos": { + Type: schema.TypeList, + Computed: true, + Optional: true, + Description: "default qoa", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "e_rate": { + Type: schema.TypeInt, + Computed: true, + Optional: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "in_burst": { + Type: schema.TypeInt, + Computed: true, + Optional: true, + }, + "in_rate": { + Type: schema.TypeInt, + Computed: true, + Optional: true, + }, + }, + }, + }, + + // other resource fields + "vins_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "vins id", + }, + "vnf_dev": { + Type: schema.TypeList, + Computed: true, + Description: "vnf dev", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ckey": { + Type: schema.TypeString, + Computed: true, + Description: "ckey", + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Description: "meta", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + Description: "account id", + }, + "capabilities": { + Type: schema.TypeList, + Computed: true, + Description: "capabilities", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "config": { + Type: schema.TypeList, + Computed: true, + Description: "config", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "mgmt": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip_addr": { + Type: schema.TypeString, + Computed: true, + Description: "ip address", + }, + "password": { + Type: schema.TypeString, + Computed: true, + Description: "password", + }, + "ssh_key": { + Type: schema.TypeString, + Computed: true, + Description: "ssh key", + }, + "user": { + Type: schema.TypeString, + Computed: true, + Description: "user", + }, + }, + }, + }, + "resources": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + Description: "cpu", + }, + "ram": { + Type: schema.TypeInt, + Computed: true, + Description: "ram", + }, + "stack_id": { + Type: schema.TypeInt, + Computed: true, + Description: "stack id", + }, + "uuid": { + Type: schema.TypeString, + Computed: true, + Description: "uuid", + }, + }, + }, + }, + }, + }, + }, + "config_saved": { + Type: schema.TypeBool, + Computed: true, + Description: "is config saved", + }, + "custom_precfg": { + Type: schema.TypeBool, + Computed: true, + Description: "custom pre config", + }, + "description": { + Type: schema.TypeString, + Computed: true, + Description: "description", + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "gid", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "id": { + Type: schema.TypeInt, + Computed: true, + Description: "id", + }, + "interfaces": { + Type: schema.TypeList, + Computed: true, + Description: "interfaces", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "conn_id": { + Type: schema.TypeInt, + Computed: true, + Description: "connection id", + }, + "conn_type": { + Type: schema.TypeString, + Computed: true, + Description: "connection type", + }, + "def_gw": { + Type: schema.TypeString, + Computed: true, + Description: "default gw", + }, + "enabled": { + Type: schema.TypeBool, + Computed: true, + Description: "enabled", + }, + "flipgroup_id": { + Type: schema.TypeInt, + Computed: true, + Description: "flipgroup id", + }, + "guid": { + Type: schema.TypeString, + Computed: true, + Description: "guid", + }, + "ip_address": { + Type: schema.TypeString, + Computed: true, + Description: "ip address", + }, + "listen_ssh": { + Type: schema.TypeBool, + Computed: true, + Description: "listen ssh", + }, + "mac": { + Type: schema.TypeString, + Computed: true, + Description: "mac", + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "name", + }, + "net_id": { + Type: schema.TypeInt, + Computed: true, + Description: "net id", + }, + "net_mask": { + Type: schema.TypeInt, + Computed: true, + Description: "net mask", + }, + "net_type": { + Type: schema.TypeString, + Computed: true, + Description: "net type", + }, + "pci_slot": { + Type: schema.TypeInt, + Computed: true, + Description: "pci slot", + }, + "qos": { + Type: schema.TypeList, + Computed: true, + Description: "qos", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "e_rate": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "in_burst": { + Type: schema.TypeInt, + Computed: true, + }, + "in_rate": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "target": { + Type: schema.TypeString, + Computed: true, + Description: "target", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "type", + }, + "vnfs": { + Type: schema.TypeList, + Computed: true, + Description: "vnfs", + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + }, + }, + }, + "lock_status": { + Type: schema.TypeString, + Computed: true, + Description: "lock status", + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + Description: "milestones", + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "name", + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "status", + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + Description: "tech status", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "type", + }, + "vins": { + Type: schema.TypeList, + Computed: true, + Description: "vins", + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + }, + }, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + Description: "account name", + }, + "created_by": { + Type: schema.TypeString, + Computed: true, + Description: "created by", + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + Description: "created time", + }, + "default_gw": { + Type: schema.TypeString, + Computed: true, + Description: "default gw", + }, + "deleted_by": { + Type: schema.TypeString, + Computed: true, + Description: "deleted by", + }, + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + Description: "deleted time", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "lock_status": { + Type: schema.TypeString, + Computed: true, + Description: "lock status", + }, + "manager_id": { + Type: schema.TypeInt, + Computed: true, + Description: "manager id", + }, + "manager_type": { + Type: schema.TypeString, + Computed: true, + Description: "manager type", + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + Description: "milestones", + }, + "netmask": { + Type: schema.TypeInt, + Computed: true, + Description: "net mask", + }, + "network": { + Type: schema.TypeString, + Computed: true, + Description: "network", + }, + "redundant": { + Type: schema.TypeBool, + Computed: true, + Description: "redundant", + }, + "rg_name": { + Type: schema.TypeString, + Computed: true, + Description: "resource group name", + }, + "sec_vnf_dev_id": { + Type: schema.TypeInt, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "status", + }, + "updated_by": { + Type: schema.TypeString, + Computed: true, + Description: "updated by", + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + Description: "updated time", + }, + "user_managed": { + Type: schema.TypeBool, + Computed: true, + Description: "user managed", + }, + "vnfs": { + Type: schema.TypeList, + Computed: true, + Description: "vnfs", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dhcp": { + Type: schema.TypeList, + Computed: true, + Description: "dhcp", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ckey": { + Type: schema.TypeString, + Computed: true, + Description: "ckey", + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Description: "meta", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + Description: "account id", + }, + "config": { + Type: schema.TypeList, + Computed: true, + Description: "config", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "default_gw": { + Type: schema.TypeString, + Computed: true, + Description: "default gw", + }, + "dns": { + Type: schema.TypeList, + Computed: true, + Description: "list of dns", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "ip_end": { + Type: schema.TypeString, + Computed: true, + Description: "ip end", + }, + "ip_start": { + Type: schema.TypeString, + Computed: true, + Description: "ip start", + }, + "lease": { + Type: schema.TypeInt, + Computed: true, + Description: "lease", + }, + "net_mask": { + Type: schema.TypeInt, + Computed: true, + Description: "net mask", + }, + "network": { + Type: schema.TypeString, + Computed: true, + Description: "network", + }, + "reservations": { + Type: schema.TypeList, + Computed: true, + Description: "reservations", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "client_type": { + Type: schema.TypeString, + Computed: true, + Description: "client type", + }, + "description": { + Type: schema.TypeString, + Computed: true, + Description: "description", + }, + "domain_name": { + Type: schema.TypeString, + Computed: true, + Description: "domain name", + }, + "host_name": { + Type: schema.TypeString, + Computed: true, + Description: "host name", + }, + "ip": { + Type: schema.TypeString, + Computed: true, + Description: "ip", + }, + "mac": { + Type: schema.TypeString, + Computed: true, + Description: "mac", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "type", + }, + "vm_id": { + Type: schema.TypeInt, + Computed: true, + Description: "vm id", + }, + }, + }, + }, + }, + }, + }, + + "created_time": { + Type: schema.TypeInt, + Computed: true, + Description: "created time", + }, + "devices": { + Type: schema.TypeList, + Computed: true, + Description: "devices list", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "primary": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dev_id": { + Type: schema.TypeInt, + Computed: true, + }, + "iface01": { + Type: schema.TypeString, + Computed: true, + }, + "iface02": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "gid", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "id": { + Type: schema.TypeInt, + Computed: true, + Description: "id", + }, + "lock_status": { + Type: schema.TypeString, + Computed: true, + Description: "lock status", + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + Description: "milestones", + }, + "owner_id": { + Type: schema.TypeInt, + Computed: true, + Description: "owner id", + }, + "owner_type": { + Type: schema.TypeString, + Computed: true, + Description: "owner type", + }, + "pure_virtual": { + Type: schema.TypeBool, + Computed: true, + Description: "prune virtual", + }, + "routes": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "compute_ids": { + Type: schema.TypeList, + Computed: true, + Description: "compute ids", + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "route_id": { + Type: schema.TypeInt, + Computed: true, + Description: "route id", + }, + "guid": { + Type: schema.TypeString, + Computed: true, + Description: "guid", + }, + "destination": { + Type: schema.TypeString, + Computed: true, + Description: "destination", + }, + "netmask": { + Type: schema.TypeString, + Computed: true, + Description: "net mask", + }, + "gateway": { + Type: schema.TypeString, + Computed: true, + Description: "gateway", + }, + }, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "status", + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + Description: "tech status", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "type", + }, + }, + }, + }, + "gw": { + Type: schema.TypeList, + Computed: true, + Description: "gw", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ckey": { + Type: schema.TypeString, + Computed: true, + Description: "ckey", + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Description: "meta", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + Description: "account id", + }, + "config": { + Type: schema.TypeList, + Computed: true, + Description: "config", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "default_gw": { + Type: schema.TypeString, + Computed: true, + Description: "default gw", + }, + "ext_net_id": { + Type: schema.TypeInt, + Computed: true, + Description: "extnet id", + }, + "ext_net_ip": { + Type: schema.TypeString, + Computed: true, + Description: "extnet ip", + }, + "ext_netmask": { + Type: schema.TypeInt, + Computed: true, + Description: "extnet mask", + }, + "qos": { + Type: schema.TypeList, + Computed: true, + Description: "qos", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "e_rate": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "in_burst": { + Type: schema.TypeInt, + Computed: true, + }, + "in_rate": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + Description: "created time", + }, + "devices": { + Type: schema.TypeList, + Computed: true, + Description: "devices list", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "primary": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dev_id": { + Type: schema.TypeInt, + Computed: true, + }, + "iface01": { + Type: schema.TypeString, + Computed: true, + }, + "iface02": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "gid", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "id": { + Type: schema.TypeInt, + Computed: true, + Description: "id", + }, + "lock_status": { + Type: schema.TypeString, + Computed: true, + Description: "losk status", + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + Description: "milestones", + }, + "owner_id": { + Type: schema.TypeInt, + Computed: true, + Description: "owner id", + }, + "owner_type": { + Type: schema.TypeString, + Computed: true, + Description: "owner type", + }, + "pure_virtual": { + Type: schema.TypeBool, + Computed: true, + Description: "pure virtual", + }, + "routes": { + Type: schema.TypeList, + Computed: true, + Description: "routes", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "compute_ids": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "route_id": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "destination": { + Type: schema.TypeString, + Computed: true, + }, + "netmask": { + Type: schema.TypeString, + Computed: true, + }, + "gateway": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "status", + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + Description: "tech status", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "type", + }, + }, + }, + }, + "nat": { + Type: schema.TypeList, + Computed: true, + Description: "nat", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ckey": { + Type: schema.TypeString, + Computed: true, + Description: "ckey", + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Description: "meta", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + Description: "account id", + }, + "config": { + Type: schema.TypeList, + Computed: true, + Description: "config", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "net_mask": { + Type: schema.TypeInt, + Computed: true, + Description: "net mask", + }, + "network": { + Type: schema.TypeString, + Computed: true, + Description: "network", + }, + "rules": { + Type: schema.TypeList, + Computed: true, + Description: "nat rules", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "rule_id": { + Type: schema.TypeInt, + Computed: true, + Description: "nat rule id", + }, + "local_ip": { + Type: schema.TypeString, + Computed: true, + Description: "local ip", + }, + "local_port": { + Type: schema.TypeInt, + Computed: true, + Description: "local port", + }, + "protocol": { + Type: schema.TypeString, + Computed: true, + Description: "protocol", + }, + "public_port_end": { + Type: schema.TypeInt, + Computed: true, + Description: "public port end", + }, + "public_port_start": { + Type: schema.TypeInt, + Computed: true, + Description: "public port start", + }, + "vm_id": { + Type: schema.TypeInt, + Computed: true, + Description: "vm id", + }, + "vm_name": { + Type: schema.TypeString, + Computed: true, + Description: "vm name", + }, + }, + }, + }, + }, + }, + }, + "created_time": { + Type: schema.TypeInt, + Computed: true, + Description: "created time", + }, + "devices": { + Type: schema.TypeList, + Computed: true, + Description: "devices list", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "primary": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dev_id": { + Type: schema.TypeInt, + Computed: true, + }, + "iface01": { + Type: schema.TypeString, + Computed: true, + }, + "iface02": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "gid", + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + Description: "guid", + }, + "id": { + Type: schema.TypeInt, + Computed: true, + Description: "id", + }, + "lock_status": { + Type: schema.TypeString, + Computed: true, + Description: "lock status", + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + Description: "milestones", + }, + "owner_id": { + Type: schema.TypeInt, + Computed: true, + Description: "owner id", + }, + "owner_type": { + Type: schema.TypeString, + Computed: true, + Description: "owner type", + }, + "pure_virtual": { + Type: schema.TypeBool, + Computed: true, + Description: "pure virtual", + }, + "routes": { + Type: schema.TypeList, + Computed: true, + Description: "routes", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "compute_ids": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "route_id": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "destination": { + Type: schema.TypeString, + Computed: true, + }, + "netmask": { + Type: schema.TypeString, + Computed: true, + }, + "gateway": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "status", + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + Description: "tech status", + }, + "type": { + Type: schema.TypeString, + Computed: true, + Description: "type", + }, + }, + }, + }, + }, + }, + }, + "vxlan_id": { + Type: schema.TypeInt, + Computed: true, + Description: "vxlan id", + }, + } + + return rets +} + +func dataSourceStaticRouteSchemaMake() map[string]*schema.Schema { + rets := map[string]*schema.Schema{ + "vins_id": { + Type: schema.TypeInt, + Required: true, + Description: "Unique ID of the ViNS", + }, + "route_id": { + Type: schema.TypeInt, + Required: true, + Description: "Unique ID of the static route", + }, + "compute_ids": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "destination": { + Type: schema.TypeString, + Computed: true, + }, + "gateway": { + Type: schema.TypeString, + Computed: true, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "netmask": { + Type: schema.TypeString, + Computed: true, + }, + } + return rets +} + +func resourceStaticRouteSchemaMake() map[string]*schema.Schema { + rets := map[string]*schema.Schema{ + "destination": { + Type: schema.TypeString, + Required: true, + }, + "gateway": { + Type: schema.TypeString, + Required: true, + }, + "netmask": { + Type: schema.TypeString, + Required: true, + }, + "vins_id": { + Type: schema.TypeInt, + Required: true, + Description: "Unique ID of the ViNS", + }, + + "guid": { + Type: schema.TypeString, + Computed: true, + }, + "route_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Unique ID of the static route", + }, + "compute_ids": { + Type: schema.TypeList, + Computed: true, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + } + + return rets +} diff --git a/internal/service/cloudbroker/vins/utility_vins_audits.go b/internal/service/cloudbroker/vins/utility_vins_audits.go new file mode 100644 index 0000000..98bfa22 --- /dev/null +++ b/internal/service/cloudbroker/vins/utility_vins_audits.go @@ -0,0 +1,63 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Sergey Kisil, + +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 vins + +import ( + "context" + "strconv" + + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func utilityVinsAuditsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (vins.ListAudits, error) { + c := m.(*controller.ControllerCfg) + + req := vins.AuditsRequest{} + + if d.Id() != "" { + id, _ := strconv.ParseUint(d.Id(), 10, 64) + req.VINSID = id + } else { + req.VINSID = uint64(d.Get("vins_id").(int)) + } + + audits, err := c.CloudBroker().VINS().Audits(ctx, req) + if err != nil { + return nil, err + } + + return audits, nil +} diff --git a/internal/service/cloudbroker/vins/utility_vins_ext_net_list.go b/internal/service/cloudbroker/vins/utility_vins_ext_net_list.go new file mode 100644 index 0000000..5328204 --- /dev/null +++ b/internal/service/cloudbroker/vins/utility_vins_ext_net_list.go @@ -0,0 +1,61 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 vins + +import ( + "context" + "strconv" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityVinsExtNetListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListExtNets, error) { + c := m.(*controller.ControllerCfg) + req := vins.ExtNetListRequest{} + + if d.Id() != "" { + id, _ := strconv.ParseUint(d.Id(), 10, 64) + req.VINSID = id + } else { + req.VINSID = uint64(d.Get("vins_id").(int)) + } + + extNetList, err := c.CloudBroker().VINS().ExtNetList(ctx, req) + if err != nil { + return nil, err + } + + return extNetList, nil +} diff --git a/internal/service/cloudbroker/vins/utility_vins_ip_list.go b/internal/service/cloudbroker/vins/utility_vins_ip_list.go new file mode 100644 index 0000000..7933a92 --- /dev/null +++ b/internal/service/cloudbroker/vins/utility_vins_ip_list.go @@ -0,0 +1,61 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 vins + +import ( + "context" + "strconv" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityVinsIpListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListIPs, error) { + c := m.(*controller.ControllerCfg) + req := vins.IPListRequest{} + + if d.Id() != "" { + id, _ := strconv.ParseUint(d.Id(), 10, 64) + req.VINSID = id + } else { + req.VINSID = uint64(d.Get("vins_id").(int)) + } + + ips, err := c.CloudBroker().VINS().IPList(ctx, req) + if err != nil { + return nil, err + } + + return ips, nil +} diff --git a/internal/service/cloudbroker/vins/utility_vins_list_deleted.go b/internal/service/cloudbroker/vins/utility_vins_list_deleted.go new file mode 100644 index 0000000..f815e9e --- /dev/null +++ b/internal/service/cloudbroker/vins/utility_vins_list_deleted.go @@ -0,0 +1,77 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 vins + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityVinsListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListVINS, error) { + c := m.(*controller.ControllerCfg) + req := vins.ListDeletedRequest{} + + if by_id, ok := d.GetOk("by_id"); ok { + req.ByID = uint64(by_id.(int)) + } + if name, ok := d.GetOk("name"); ok { + req.Name = name.(string) + } + if account_id, ok := d.GetOk("account_id"); ok { + req.AccountID = uint64(account_id.(int)) + } + if rg_id, ok := d.GetOk("rg_id"); ok { + req.RGID = uint64(rg_id.(int)) + } + if ext_ip, ok := d.GetOk("ext_ip"); ok { + req.ExtIP = ext_ip.(string) + } + if page, ok := d.GetOk("page"); ok { + req.Page = uint64(page.(int)) + } + if size, ok := d.GetOk("size"); ok { + req.Size = uint64(size.(int)) + } + + log.Debugf("utilityVinsListDeletedCheckPresence") + vinsList, err := c.CloudBroker().VINS().ListDeleted(ctx, req) + if err != nil { + return nil, err + } + + return vinsList, nil +} diff --git a/internal/service/cloudbroker/vins/utility_vins_nat_rule_list.go b/internal/service/cloudbroker/vins/utility_vins_nat_rule_list.go new file mode 100644 index 0000000..71dcaf1 --- /dev/null +++ b/internal/service/cloudbroker/vins/utility_vins_nat_rule_list.go @@ -0,0 +1,65 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 vins + +import ( + "context" + "strconv" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" +) + +func utilityVinsNatRuleListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListNATRules, error) { + c := m.(*controller.ControllerCfg) + req := vins.NATRuleListRequest{} + + if d.Id() != "" { + id, _ := strconv.ParseUint(d.Id(), 10, 64) + req.VINSID = id + } else { + req.VINSID = uint64(d.Get("vins_id").(int)) + } + + if reason, ok := d.GetOk("reason"); ok { + req.Reason = reason.(string) + } + + natRuleList, err := c.CloudBroker().VINS().NATRuleList(ctx, req) + if err != nil { + return nil, err + } + + return natRuleList, nil +} diff --git a/internal/service/cloudbroker/vins/utility_vins_static_route.go b/internal/service/cloudbroker/vins/utility_vins_static_route.go new file mode 100644 index 0000000..b487de6 --- /dev/null +++ b/internal/service/cloudbroker/vins/utility_vins_static_route.go @@ -0,0 +1,107 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 vins + +import ( + "context" + "fmt" + "strconv" + "strings" + + log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func utilityDataStaticRouteCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ItemRoutes, error) { + c := m.(*controller.ControllerCfg) + req := vins.StaticRouteListRequest{} + var routeId uint64 + + if d.Id() != "" { + arr := strings.Split(d.Id(), "#") + if len(arr) != 2 { + return nil, fmt.Errorf("broken state id") + } + + req.VINSID, _ = strconv.ParseUint(arr[0], 10, 64) + routeId, _ = strconv.ParseUint(arr[1], 10, 64) + } else { + req.VINSID = uint64(d.Get("vins_id").(int)) + routeId = uint64(d.Get("route_id").(int)) + } + + log.Debugf("utilityStaticRouteCheckPresence, vins_id: %v", req.VINSID) + staticRouteList, err := c.CloudBroker().VINS().StaticRouteList(ctx, req) + if err != nil { + return nil, err + } + + log.Debugf("utilityStaticRouteCheckPresence: ROUTE ID %v", routeId) + + staticRoute := &vins.ItemRoutes{} + for _, route := range staticRouteList.Data { + if routeId == route.ID { + staticRoute = &route + return staticRoute, nil + } + } + + return nil, fmt.Errorf("static route not found") +} + +func getStaticRouteData(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ItemRoutes, error) { + c := m.(*controller.ControllerCfg) + req := vins.StaticRouteListRequest{} + req.VINSID = uint64(d.Get("vins_id").(int)) + + staticRouteList, err := c.CloudBroker().VINS().StaticRouteList(ctx, req) + if err != nil { + return nil, err + } + + destination := d.Get("destination").(string) + gateway := d.Get("gateway").(string) + + staticRoute := &vins.ItemRoutes{} + for _, route := range staticRouteList.Data { + if destination == route.Destination && gateway == route.Gateway { + staticRoute = &route + return staticRoute, nil + } + } + + return nil, fmt.Errorf("static route not found") +} diff --git a/internal/service/cloudbroker/vins/utility_vins_static_route_list.go b/internal/service/cloudbroker/vins/utility_vins_static_route_list.go new file mode 100644 index 0000000..6fe7ce7 --- /dev/null +++ b/internal/service/cloudbroker/vins/utility_vins_static_route_list.go @@ -0,0 +1,58 @@ +/* +Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, +Kasim Baybikov, + +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 vins + +import ( + "context" + + log "github.com/sirupsen/logrus" + "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins" + "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func utilityStaticRouteListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListStaticRoutes, error) { + c := m.(*controller.ControllerCfg) + req := vins.StaticRouteListRequest{} + + req.VINSID = uint64(d.Get("vins_id").(int)) + + log.Debugf("utilityStaticRouteListCheckPresence") + staticRouteList, err := c.CloudBroker().VINS().StaticRouteList(ctx, req) + if err != nil { + return nil, err + } + + return staticRouteList, nil +} diff --git a/samples/cloudbroker/data_account_deleted_list/main.tf b/samples/cloudbroker/data_account_list_deleted/main.tf similarity index 94% rename from samples/cloudbroker/data_account_deleted_list/main.tf rename to samples/cloudbroker/data_account_list_deleted/main.tf index a8e72b5..ba78cdd 100644 --- a/samples/cloudbroker/data_account_deleted_list/main.tf +++ b/samples/cloudbroker/data_account_list_deleted/main.tf @@ -26,7 +26,7 @@ provider "decort" { allow_unverified_ssl = true } -data "decort_cb_account_deleted_list" "adl" { +data "decort_cb_account_list_deleted" "adl" { #номер страницы для отображения #опциональный параметр #тип - число @@ -57,5 +57,5 @@ data "decort_cb_account_deleted_list" "adl" { } output "test" { - value = data.decort_cb_account_deleted_list.adl + value = data.decort_cb_account_list_deleted.adl } diff --git a/samples/cloudbroker/data_audit/main.tf b/samples/cloudbroker/data_audit/main.tf new file mode 100644 index 0000000..25d62d5 --- /dev/null +++ b/samples/cloudbroker/data_audit/main.tf @@ -0,0 +1,38 @@ +/* +Пример использования +Получение аудита по guid +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_audit" "audit" { + #guid аудита + #обязательный параметр + #тип - строка + audit_guid = "abcdefg" +} + +output "test" { + value = data.decort_cb_audit.audit +} diff --git a/samples/cloudbroker/data_audit_linked_jobs/main.tf b/samples/cloudbroker/data_audit_linked_jobs/main.tf new file mode 100644 index 0000000..fe05812 --- /dev/null +++ b/samples/cloudbroker/data_audit_linked_jobs/main.tf @@ -0,0 +1,38 @@ +/* +Пример использования +Получение списка заданий, связанных с указанный событием. +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_audit_linked_jobs" "jobs" { + #guid аудита + #обязательный параметр + #тип - строка + audit_guid = "abcdefg" +} + +output "test" { + value = data.decort_cb_audit_linked_jobs.jobs +} diff --git a/samples/cloudbroker/data_audit_list/main.tf b/samples/cloudbroker/data_audit_list/main.tf new file mode 100644 index 0000000..60d931d --- /dev/null +++ b/samples/cloudbroker/data_audit_list/main.tf @@ -0,0 +1,68 @@ +/* +Пример использования +Получение списка аудитов +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_audit_list" "al" { + #фильтр по аудитам с временной меткой после указанного значения + #опциональный параметр + #тип - число + #timestamp_at = 123456 + + #фильтр по аудитам с временной меткой до указанного значения + #опциональный параметр + #тип - число + #timestamp_to = 123456 + + #фильтр по пользователю (Mongo RegExp поддерживаются) + #опциональный параметр + #тип - строка + #user = "username" + + #фильтр по api endpoint (Mongo RegExp поддерживаются) + #опциональный параметр + #тип - строка + #call = "/restmachine/cloudbroker/audit/list" + + #фильтр по HTTP статус-коду + #опциональный параметр + #тип - число + #status_code = 200 + + #номер страницы для отображения + #опциональный параметр + #тип - число + #page = 2 + + #размер страницы + #опциональный параметр + #тип - число + #size = 3 +} + +output "test" { + value = data.decort_cb_audit_list.al +} diff --git a/samples/cloudbroker/data_disk_list_deleted/main.tf b/samples/cloudbroker/data_disk_list_deleted/main.tf new file mode 100644 index 0000000..2c26a8a --- /dev/null +++ b/samples/cloudbroker/data_disk_list_deleted/main.tf @@ -0,0 +1,79 @@ +/* +Пример использования +Получение списка удаленных дисков +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_disk_list_deleted" "dld" { + #фильтр по id диска + #опциональный параметр + #тип - число + #by_id = 11111 + + #фильтр по имени диска + #опциональный параметр + #тип - строка + #name = "disk name" + + #фильтр по имени аккаунта + #опциональный параметр + #тип - строка + #account_name = "account name" + + #фильтр по максимальному размеру диска + #опциональный параметр + #тип - число + #disk_max_size = 3 + + #фильтр по полю shared + #опциональный параметр + #тип - булев + #shared = true + + #id аккаунта для получения списка дисков + #опциональный параметр + #тип - число + #account_id = 11111 + + #тип диска + #опциональный параметр + #тип - строка + #возможные типы: "b" - boot_disk, "d" - data_disk + #type = "d" + + #кол-во страниц для вывода + #опицональный параметр + #тип - число + #page = 1 + + #размер страницы + #опицональный параметр + #тип - число + #size = 1 +} + +output "test" { + value = data.decort_cb_disk_list_deleted.dld +} diff --git a/samples/cloudbroker/data_disk_list_types/main.tf b/samples/cloudbroker/data_disk_list_types/main.tf new file mode 100644 index 0000000..1aa6b4d --- /dev/null +++ b/samples/cloudbroker/data_disk_list_types/main.tf @@ -0,0 +1,44 @@ +/* +Пример использования +Получение списка типов дисков (недетализированное) +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_disk_list_types" "dlt" { + #номер страницы для отображения + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #page = 2 + + #размер страницы + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #size = 3 +} + +output "test" { + value = data.decort_cb_disk_list_types.dlt +} diff --git a/samples/cloudbroker/data_disk_list_types_detailed/main.tf b/samples/cloudbroker/data_disk_list_types_detailed/main.tf new file mode 100644 index 0000000..99af944 --- /dev/null +++ b/samples/cloudbroker/data_disk_list_types_detailed/main.tf @@ -0,0 +1,46 @@ +/* +Пример использования +Получение списка типов дисков, но детально +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + + +data "decort_cb_disk_list_types_detailed" "dltd" { + #номер страницы для отображения + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #page = 2 + + #размер страницы + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #size = 3 +} + +output "test" { + value = data.decort_cb_disk_list_types_detailed.dltd +} diff --git a/samples/cloudbroker/data_disk_list_unattached/main.tf b/samples/cloudbroker/data_disk_list_unattached/main.tf new file mode 100644 index 0000000..4120e84 --- /dev/null +++ b/samples/cloudbroker/data_disk_list_unattached/main.tf @@ -0,0 +1,85 @@ +/* +Пример использования +Получение списка доступных неприсоединенных дисков +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_disk_list_unattached" "dlu" { + #фильтр по id диска + #опциональный параметр + #тип - число + #by_id = 100 + + #фильтр по имени аккаунта + #опциональный параметр + #тип - строка + #account_name = "user" + + #фильтр по максимальному размеру диска + #опциональный параметр + #тип - число + #disk_max_size = 100 + + #фильтр по статусу + #опциональный параметр + #тип - строка + #status = "ENABLED" + + #фильтр по типу + #опциональный параметр + #тип - строка + #возможные типы: "b" - boot_disk, "d" - data_disk + #type = "d" + + #фильтр по id аккаунта + #опциональный параметр + #тип - число + #account_id = 100 + + #фильтр по id sep + #опциональный параметр + #тип - число + #sep_id = 1 + + #фильтр по имени pool + #опциональный параметр + #тип - строка + #pool = "test" + + #номер страницы для отображения + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #page = 2 + + #размер страницы + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #size = 3 +} + +output "test" { + value = data.decort_cb_disk_list_unattached.dlu +} diff --git a/samples/cloudbroker/data_disk_snapshot/main.tf b/samples/cloudbroker/data_disk_snapshot/main.tf new file mode 100644 index 0000000..2428fac --- /dev/null +++ b/samples/cloudbroker/data_disk_snapshot/main.tf @@ -0,0 +1,42 @@ +/* +Пример использования +Получение конкретного снапшота +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_disk_snapshot" "ds" { + #Номер диска + #обязательный параметр + #тип - число + disk_id = 20100 + + #Ярлык диска + #обязательный параметр + #тип - строка + label = "label" +} + +output "test" { + value = data.decort_cb_disk_snapshot.ds +} diff --git a/samples/cloudbroker/data_disk_snapshot_list/main.tf b/samples/cloudbroker/data_disk_snapshot_list/main.tf new file mode 100644 index 0000000..64cdb20 --- /dev/null +++ b/samples/cloudbroker/data_disk_snapshot_list/main.tf @@ -0,0 +1,37 @@ +/* +Пример использования +Получение списка снапшотов диска +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_disk_snapshot_list" "ds" { + #Номер диска + #обязательный параметр + #тип - число + disk_id = 20100 +} + +output "test" { + value = data.decort_cb_disk_snapshot_list.ds +} diff --git a/samples/cloudbroker/data_flipgroup/main.tf b/samples/cloudbroker/data_flipgroup/main.tf new file mode 100644 index 0000000..3e26c92 --- /dev/null +++ b/samples/cloudbroker/data_flipgroup/main.tf @@ -0,0 +1,37 @@ +/* +Пример использования +Получение flipgroup по id +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + source = "basis/decort/decort" + version = "" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + oauth2_url = "https://sso-alpha.dev.decs.online" + controller_url = "https://alpha.dev.decs.online" + app_id = "" + app_secret = "" +} + +data "decort_cb_flipgroup" "fg" { + # ID флипгруппы + # Обязательный параметр + # int + flipgroup_id = 999 +} + +output "fg_out" { + value = data.decort_cb_flipgroup.fg +} diff --git a/samples/cloudbroker/data_flipgroup_list/main.tf b/samples/cloudbroker/data_flipgroup_list/main.tf new file mode 100644 index 0000000..9bce6c1 --- /dev/null +++ b/samples/cloudbroker/data_flipgroup_list/main.tf @@ -0,0 +1,79 @@ +/* +Пример использования +Получение списка flipgroup +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + source = "basis/decort/decort" + version = "" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + oauth2_url = "https://sso-alpha.dev.decs.online" + controller_url = "https://alpha.dev.decs.online" + app_id = "" + app_secret = "" +} + +data "decort_cb_flipgroup_list" "fg" { + #фильтр по id flipgroup + #опциональный параметр + #тип - число + #by_id = 100 + + #фильтр по имени flipgroup + #опциональный параметр + #тип - строка + #name = "test" + + #фильтр по id vins + #опциональный параметр + #тип - число + #vins_id = 100 + + #фильтр по имени vins + #опциональный параметр + #тип - строка + #vins_name = "test" + + #фильтр по id extnet + #опциональный параметр + #тип - число + #extnet_id = 100 + + #фильтр по IP + #опциональный параметр + #тип - строка + #by_ip = "1.1.1.1.1" + + #фильтр по id ресурсной группы + #опциональный параметр + #тип - число + #rg_id = 11111 + + #номер страницы для отображения + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #page = 2 + + #размер страницы + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #size = 3 +} + +output "fg_out" { + value = data.decort_cb_flipgroup_list.fg +} diff --git a/samples/cloudbroker/data_grid_get_consumption/main.tf b/samples/cloudbroker/data_grid_get_consumption/main.tf new file mode 100644 index 0000000..a6c3294 --- /dev/null +++ b/samples/cloudbroker/data_grid_get_consumption/main.tf @@ -0,0 +1,38 @@ +/* +Пример использования +Получение информации и потребленных и зарезервированных ресурсах grid по id +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_grid_get_consumption" "cons" { + #id grid для получения информации + #обязательный параметр + #тип - число + grid_id = 215 +} + +output "test" { + value = data.decort_cb_grid_get_consumption.cons +} diff --git a/samples/cloudbroker/data_grid_get_post_diagnosis/main.tf b/samples/cloudbroker/data_grid_get_post_diagnosis/main.tf new file mode 100644 index 0000000..14c7022 --- /dev/null +++ b/samples/cloudbroker/data_grid_get_post_diagnosis/main.tf @@ -0,0 +1,50 @@ +/* +Пример использования +Получение снимка платформы с дополнительной диагностической информацией +(журналы и т. д.). +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_grid_get_diagnosis" "gd" { + #id grid для получения информации + #обязательный параметр + #тип - число + gid = 215 +} + +data "decort_cb_grid_post_diagnosis" "pd" { + #id grid для получения информации + #обязательный параметр + #тип - число + gid = 215 +} + +output "test-gd" { + value = data.decort_cb_grid_get_diagnosis.gd +} + +output "test-pd" { + value = data.decort_cb_grid_post_diagnosis.pd +} diff --git a/samples/cloudbroker/data_grid_get_post_status/main.tf b/samples/cloudbroker/data_grid_get_post_status/main.tf new file mode 100644 index 0000000..6c4cdd4 --- /dev/null +++ b/samples/cloudbroker/data_grid_get_post_status/main.tf @@ -0,0 +1,43 @@ +/* +Пример использования +Проверка статуса активности текущей среды. +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_grid_get_status" "gs" { + #нет входящих параметров +} + +data "decort_cb_grid_post_status" "ps" { + #нет входящих параметров +} + +output "test-gs" { + value = data.decort_cb_grid_get_status.gs +} + +output "test-ps" { + value = data.decort_cb_grid_post_status.ps +} diff --git a/samples/cloudbroker/data_grid_list_consumption/main.tf b/samples/cloudbroker/data_grid_list_consumption/main.tf new file mode 100644 index 0000000..8076c5f --- /dev/null +++ b/samples/cloudbroker/data_grid_list_consumption/main.tf @@ -0,0 +1,35 @@ +/* +Пример использования +Получение информации и потребленных и зарезервированных ресурсах во всех grid +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_grid_list_consumption" "lc" { + #нет входящих параметров +} + +output "test" { + value = data.decort_cb_grid_list_consumption.lc +} diff --git a/samples/cloudbroker/data_grid_list_emails/main.tf b/samples/cloudbroker/data_grid_list_emails/main.tf new file mode 100644 index 0000000..ab12204 --- /dev/null +++ b/samples/cloudbroker/data_grid_list_emails/main.tf @@ -0,0 +1,43 @@ +/* +Пример использования +Получение списка email-адресов пользователей. +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_grid_list_emails" "gle" { + #номер страницы для отображения + #опциональный параметр, тип - число + #если не задан - выводятся все доступные данные + #page = 2 + + #размер страницы + #опциональный параметр, тип - число + #если не задан - выводятся все доступные данные + #size = 3 +} + +output "test" { + value = data.decort_cb_grid_list_emails.gle +} diff --git a/samples/cloudbroker/data_k8ci/main.tf b/samples/cloudbroker/data_k8ci/main.tf new file mode 100644 index 0000000..dad04d8 --- /dev/null +++ b/samples/cloudbroker/data_k8ci/main.tf @@ -0,0 +1,40 @@ +/* +Пример использования +Получение информации о k8ci + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true + } + + +data "decort_cb_k8ci" "k8ci" { + #id k8ci + #обязательный параметр + #тип - число + k8ci_id = 111 +} + +output "test" { + value = data.decort_cb_k8ci.k8ci +} diff --git a/samples/cloudbroker/data_k8ci_list/main.tf b/samples/cloudbroker/data_k8ci_list/main.tf new file mode 100644 index 0000000..193443e --- /dev/null +++ b/samples/cloudbroker/data_k8ci_list/main.tf @@ -0,0 +1,80 @@ +/* +Пример использования +Получение списка k8ci + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true + } + + +data "decort_cb_k8ci_list" "k8cil" { + #фильтр по id k8ci + #опциональный параметр + #тип - число + #by_id = 111 + + #фильтр по имени k8ci + #опциональный параметр + #тип - строка + #name = "name" + + #фильтр по статусу k8ci + #опциональный параметр + #тип - строка + #status = "status" + + #фильтр по worker driver + #опциональный параметр + #тип - строка + #worker_driver = "KVM_X86" + + #фильтр по master driver + #опциональный параметр + #тип - строка + #master_driver = "KVM_X86" + + #фильтр по network plugin + #опциональный параметр + #тип - строка + #network_plugin = "flannel" + + #исключить из результата недоступные k8ci + #опциональный параметр + #тип - булево значение + #include_disabled = "true" + + #номер страницы для отображения + #опциональный параметр + #тип - число + #page = 2 + + #размер страницы + #опциональный параметр + #тип - число + #size = 3 +} + +output "test" { + value = data.decort_cb_k8ci_list.k8cil +} diff --git a/samples/cloudbroker/data_k8ci_list_deleted/main.tf b/samples/cloudbroker/data_k8ci_list_deleted/main.tf new file mode 100644 index 0000000..b566e01 --- /dev/null +++ b/samples/cloudbroker/data_k8ci_list_deleted/main.tf @@ -0,0 +1,70 @@ +/* +Пример использования +Получение списка удаленных k8ci + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true + } + + +data "decort_cb_k8ci_list_deleted" "k8cild" { + #фильтр по id k8ci + #опциональный параметр + #тип - число + #by_id = 111 + + #фильтр по имени k8ci + #опциональный параметр + #тип - строка + #name = "name" + + #фильтр по worker driver + #опциональный параметр + #тип - строка + #worker_driver = "KVM_X86" + + #фильтр по master driver + #опциональный параметр + #тип - строка + #master_driver = "KVM_X86" + + #фильтр по network plugin + #опциональный параметр + #тип - строка + #network_plugin = "flannel" + + #номер страницы для отображения + #опциональный параметр + #тип - число + #page = 2 + + #размер страницы + #опциональный параметр + #тип - число + #size = 3 +} + +output "test" { + value = data.decort_cb_k8ci_list_deleted.k8cild +} diff --git a/samples/cloudbroker/data_k8s/main.tf b/samples/cloudbroker/data_k8s/main.tf new file mode 100644 index 0000000..df2df33 --- /dev/null +++ b/samples/cloudbroker/data_k8s/main.tf @@ -0,0 +1,37 @@ +/* +Пример использования +Получение информации о k8s кластере +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} + + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_k8s" "k8s" { + #id кластера + #обязательный параметр + #тип - число + k8s_id = 49304 +} + +output "output_k8s" { + value = data.decort_cb_k8s.k8s +} diff --git a/samples/cloudbroker/data_k8s_computes/main.tf b/samples/cloudbroker/data_k8s_computes/main.tf new file mode 100644 index 0000000..402c16f --- /dev/null +++ b/samples/cloudbroker/data_k8s_computes/main.tf @@ -0,0 +1,31 @@ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + source = "basis/decort/decort" + version = "" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + oauth2_url = "https://sso.digitalenergy.online" + controller_url = "https://mr4.digitalenergy.online" + app_id = "" + app_secret = "" +} + +data "decort_cb_k8s_computes" "computes" { + # ID кластера + # Обязательный параметр + k8s_id = 999 +} + +output "computes_out" { + value = data.decort_cb_k8s_computes.computes +} diff --git a/samples/cloudbroker/data_k8s_list/main.tf b/samples/cloudbroker/data_k8s_list/main.tf new file mode 100644 index 0000000..2f6d419 --- /dev/null +++ b/samples/cloudbroker/data_k8s_list/main.tf @@ -0,0 +1,90 @@ +/* +Пример использования +Получение списка доступных кластеров +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} + + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_k8s_list" "k8s_list" { + #фильтр по id кластера + #опциональный параметр + #тип - число + #by_id = 100 + + #фильтр по имени кластера + #опциональный параметр + #тип - строка + #name = "test" + + #фильтр по ip + #опциональный параметр + #тип - строка + #ip_address = "test" + + #фильтр по id ресурсной группы + #опциональный параметр + #тип - число + #rg_id = 100 + + #фильтр по id балансировщика нагрузки + #опциональный параметр + #тип - число + #lb_id = 100 + + #фильтр по id ресурсной группы + #опциональный параметр + #тип - число + #bservice_id = 100 + + #фильтр по статусу + #опциональный параметр + #тип - строка + #status = "ENABLED" + + #фильтр по техническому статусу + #опциональный параметр + #тип - строка + #tech_status = "STOPPED" + + #включение удаленных k8s в результат + #опциональный параметр + #тип - булев тип + #если не задан - выводятся все неудаленные данные + # include_deleted = true + + #номер страницы для отображения + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + # page = 1 + + #размер страницы + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + # size = 1 +} + +output "output_k8s_list" { + value = data.decort_cb_k8s_list.k8s_list +} diff --git a/samples/cloudbroker/data_k8s_list_deleted/main.tf b/samples/cloudbroker/data_k8s_list_deleted/main.tf new file mode 100644 index 0000000..0f020bf --- /dev/null +++ b/samples/cloudbroker/data_k8s_list_deleted/main.tf @@ -0,0 +1,80 @@ +/* +Пример использования +Получение списка удаленных кластеров +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} + + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_k8s_list_deleted" "k8s_list_deleted" { + #фильтр по id кластера + #опциональный параметр + #тип - число + #by_id = 100 + + #фильтр по имени кластера + #опциональный параметр + #тип - строка + #name = "test" + + #фильтр по ip + #опциональный параметр + #тип - строка + #ip_address = "test" + + #фильтр по id ресурсной группы + #опциональный параметр + #тип - число + #rg_id = 100 + + #фильтр по id балансировщика нагрузки + #опциональный параметр + #тип - число + #lb_id = 100 + + #фильтр по id ресурсной группы + #опциональный параметр + #тип - число + #bservice_id = 100 + + #фильтр по техническому статусу + #опциональный параметр + #тип - строка + #tech_status = "STOPPED" + + #номер страницы для отображения + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #page = 1 + + #размер страницы + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #size = 1 +} + +output "output_k8s_list_deleted" { + value = data.decort_cb_k8s_list_deleted.k8s_list_deleted +} + diff --git a/samples/cloudbroker/data_k8s_wg/main.tf b/samples/cloudbroker/data_k8s_wg/main.tf new file mode 100644 index 0000000..e9039b1 --- /dev/null +++ b/samples/cloudbroker/data_k8s_wg/main.tf @@ -0,0 +1,42 @@ +/* +Пример использования +Получение информации о k8s кластере +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} + + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_k8s_wg" "k8s_wg" { + #id кластера + #обязательный параметр + #тип - число + k8s_id = 49304 + + #id группы воркеров + #обязательный параметр + #тип - число + wg_id = 43329 +} + +output "output_k8s_wg" { + value = data.decort_cb_k8s_wg.k8s_wg +} diff --git a/samples/cloudbroker/data_k8s_wg_cloud_init/main.tf b/samples/cloudbroker/data_k8s_wg_cloud_init/main.tf new file mode 100644 index 0000000..e9583e5 --- /dev/null +++ b/samples/cloudbroker/data_k8s_wg_cloud_init/main.tf @@ -0,0 +1,45 @@ +/* +Пример использования +Получение информации о мета данных рабочей группы k8s кластера +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} + + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_k8s_wg_cloud_init" "wg_cloud_init" { + #id кластера + #обязательный параметр + #тип - число + k8s_id = 977 + + #id группы воркеров + #обязательный параметр + #тип - число + wg_id = 2110 +} + +output "wg_cloud_init" { + value = data.decort_cb_k8s_wg_cloud_init.wg_cloud_init +} + + + diff --git a/samples/cloudbroker/data_k8s_wg_list/main.tf b/samples/cloudbroker/data_k8s_wg_list/main.tf new file mode 100644 index 0000000..364ea52 --- /dev/null +++ b/samples/cloudbroker/data_k8s_wg_list/main.tf @@ -0,0 +1,37 @@ +/* +Пример использования +Получение списка доступных групп воркеров в кластере +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} + + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_k8s_wg_list" "k8s_wg_list" { + #id кластера + #обязательный параметр + #тип - число + k8s_id = 49304 +} + +output "output_k8s_wg_list" { + value = data.decort_cb_k8s_wg_list.k8s_wg_list +} diff --git a/samples/cloudbroker/data_kvmvm/main.tf b/samples/cloudbroker/data_kvmvm/main.tf new file mode 100644 index 0000000..ff768b3 --- /dev/null +++ b/samples/cloudbroker/data_kvmvm/main.tf @@ -0,0 +1,44 @@ +/* +Пример использования +Получение данных о compute (виртуальной машине). +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_kvmvm" "comp" { + #получение информации по идентификатору машины - compute_id + + # id виртуальной машины + # обязательный параметр + # тип - число + compute_id = 11346 + + # прична запроса + # опциональный параметр + # тип - строка + reason = "test" +} + +output "test" { + value = data.decort_cb_kvmvm.comp +} diff --git a/samples/cloudbroker/data_kvmvm_affinity_relations/main.tf b/samples/cloudbroker/data_kvmvm_affinity_relations/main.tf new file mode 100644 index 0000000..c8ce004 --- /dev/null +++ b/samples/cloudbroker/data_kvmvm_affinity_relations/main.tf @@ -0,0 +1,39 @@ +/* +Пример использования +Получение словаря ВМ (виртуальных машин), разделенного по правилам affinity и anti-affinity. +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* + +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_kvmvm_affinity_relations" "aff_rel" { + #id виртуальной машины + #обязательный параметр + #тип - число + compute_id = 48 +} + +output "output" { + value = data.decort_cb_kvmvm_affinity_relations.aff_rel +} diff --git a/samples/cloudbroker/data_kvmvm_audits/main.tf b/samples/cloudbroker/data_kvmvm_audits/main.tf new file mode 100644 index 0000000..ddca0a2 --- /dev/null +++ b/samples/cloudbroker/data_kvmvm_audits/main.tf @@ -0,0 +1,38 @@ +/* +Пример использования +Получение данных об аудитах compute (виртулаьной машине) +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_kvmvm_audits" "kvmvm_audits" { + #id виртуальной машины + #обязательный параметр + #тип - число + compute_id = 10154 +} + +output "output" { + value = data.decort_cb_kvmvm_audits.kvmvm_audits +} diff --git a/samples/cloudbroker/data_kvmvm_boot_order_get/main.tf b/samples/cloudbroker/data_kvmvm_boot_order_get/main.tf new file mode 100644 index 0000000..aa1017e --- /dev/null +++ b/samples/cloudbroker/data_kvmvm_boot_order_get/main.tf @@ -0,0 +1,39 @@ +/* +Пример использования +Получение информации о текущем порядке загрузки ВМ (виртуальной машины). +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* + +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_kvmvm_boot_order_get" "boot_order" { + #id виртуальной машины + #обязательный параметр + #тип - число + compute_id = 48 +} + +output "output" { + value = data.decort_cb_kvmvm_boot_order_get.boot_order +} diff --git a/samples/cloudbroker/data_kvmvm_get_audits/main.tf b/samples/cloudbroker/data_kvmvm_get_audits/main.tf new file mode 100644 index 0000000..f55b58d --- /dev/null +++ b/samples/cloudbroker/data_kvmvm_get_audits/main.tf @@ -0,0 +1,44 @@ +/* +Пример использования +Получение данных об аудитах compute (виртулаьной машине) +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_kvmvm_get_audits" "kvmvm_get_audits" { + #id виртуальной машины + #обязательный параметр + #тип - число + compute_id = 10154 + + #причина запроса + #опциональный параметр + #тип - строка + #reason = "test" +} + +output "output" { + value = data.decort_cb_kvmvm_get_audits.kvmvm_get_audits +} diff --git a/samples/cloudbroker/data_kvmvm_get_console_url/main.tf b/samples/cloudbroker/data_kvmvm_get_console_url/main.tf new file mode 100644 index 0000000..9c95022 --- /dev/null +++ b/samples/cloudbroker/data_kvmvm_get_console_url/main.tf @@ -0,0 +1,38 @@ +/* +Пример использования +Получение url compute (виртулаьной машины) +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_kvmvm_get_console_url" "kvmvm_get_console_url" { + #id виртуальной машины + #обязательный параметр + #тип - число + compute_id = 10154 +} + +output "output" { + value = data.decort_cb_kvmvm_get_console_url.kvmvm_get_console_url +} diff --git a/samples/cloudbroker/data_kvmvm_get_log/main.tf b/samples/cloudbroker/data_kvmvm_get_log/main.tf new file mode 100644 index 0000000..a889e61 --- /dev/null +++ b/samples/cloudbroker/data_kvmvm_get_log/main.tf @@ -0,0 +1,43 @@ +/* +Пример использования +Получение логов compute (виртуальной машины) +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_kvmvm_get_log" "kvmvm_get_log" { + #id виртуальной машины + #обязательный параметр + #тип - число + compute_id = 10154 + + #путь до log файла + #обязательный параметр + #тип - строка + path = "/var/log/file.log" +} + +output "output" { + value = data.decort_cb_kvmvm_get_log.kvmvm_get_log +} diff --git a/samples/cloudbroker/data_kvmvm_list/main.tf b/samples/cloudbroker/data_kvmvm_list/main.tf new file mode 100644 index 0000000..5c94a7e --- /dev/null +++ b/samples/cloudbroker/data_kvmvm_list/main.tf @@ -0,0 +1,106 @@ +/* +Пример использования +Получение данных об списке compute (виртуальных машин) +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_kvmvm_list" "compute_list" { + #фильтр по id ВМ + #опциональный параметр + #тип - число + #by_id = 100 + + #фильтр по имени ВМ + #опциональный параметр + #тип - строка + #name = "test" + + #id аккаунта для получения списка ВМ + #опциональный параметр + #тип - число + #account_id = 11111 + + #фильтр по имени ресурсной группы + #опциональный параметр + #тип - строка + #rg_name = "test" + + #фильтр по id ресурсной группы + #опциональный параметр + #тип - число + #rg_id = 100 + + #фильтр по техническому статусу + #опциональный параметр + #тип - строка + #tech_status = "STOPPED" + + #фильтр по статусу + #опциональный параметр + #тип - строка + #status = "ENABLED" + + #фильтр по ip + #опциональный параметр + #тип - строка + #ip_address = "test" + + #фильтр по имени extnet + #опциональный параметр + #тип - строка + #extnet_name = "test" + + #фильтр по id extnet + #опциональный параметр + #тип - число + #extnet_id = 100 + + #флаг влючения в результат удаленных балансироващиков нагрузки + #опциональный параметр + #тип - булев тип + #значение по-умолчанию - false + #если не задан - выводятся все доступные неудаленные балансировщики + #includedeleted = true + + #номер страницы для отображения + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #page = 1 + + #размер страницы + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #size = 1 + + #Включить в список вывода ВМ, принадлежащие k8s кластерам (при значении параметра true) + #опциональный параметр + #bool (default = false) + #ignore_k8s = true +} + +output "output" { + value = data.decort_cb_kvmvm_list.compute_list +} diff --git a/samples/cloudbroker/data_kvmvm_list_deleted/main.tf b/samples/cloudbroker/data_kvmvm_list_deleted/main.tf new file mode 100644 index 0000000..0c38124 --- /dev/null +++ b/samples/cloudbroker/data_kvmvm_list_deleted/main.tf @@ -0,0 +1,95 @@ +/* +Пример использования +Получение данных о списке удаленных compute (виртуальных машин) +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_kvmvm_list_deleted" "compute_list" { + #фильтр по id виртуальной машины + #опциональный параметр + #тип - число + #by_id = 100 + + #фильтр по имени виртуальной машины + #опциональный параметр + #тип - строка + #name = "test" + + #фильтр по id аккаунта + #опциональный параметр + #тип - число + #account_id = 100 + + #фильтр по имени ресурсной группы + #опциональный параметр + #тип - строка + #rg_name = "test" + + #фильтр по id ресурсной группы + #опциональный параметр + #тип - число + #rg_id = 100 + + #фильтр по техническому статусу + #опциональный параметр + #тип - строка + #tech_status = "some" + + #фильтр по ip + #опциональный параметр + #тип - строка + #ip_address = "test" + + #фильтр по имени extNet + #опциональный параметр + #тип - строка + #extnet_name = "test" + + #фильтр по id extNet + #опциональный параметр + #тип - число + #extnet_id = 100 + + #номер страницы для отображения + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #page = 1 + + #размер страницы + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #size = 1 + + #Включить в список вывода ВМ, принадлежащие k8s кластерам (при значении параметра true) + #опциональный параметр + #bool (default = false) + #ignore_k8s = true +} + +output "output" { + value = data.decort_cb_kvmvm_list_deleted.compute_list +} diff --git a/samples/cloudbroker/data_kvmvm_migrate_storage_info/main.tf b/samples/cloudbroker/data_kvmvm_migrate_storage_info/main.tf new file mode 100644 index 0000000..44dad89 --- /dev/null +++ b/samples/cloudbroker/data_kvmvm_migrate_storage_info/main.tf @@ -0,0 +1,39 @@ +/* +Пример использования +Получение информации о последней (включая текущую) миграции хранилища. +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* + +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_kvmvm_migrate_storage_info" "info" { + #id виртуальной машины + #обязательный параметр + #тип - число + compute_id = 48 +} + +output "output" { + value = data.decort_cb_kvmvm_migrate_storage_info.info +} diff --git a/samples/cloudbroker/data_kvmvm_pci_device_list/main.tf b/samples/cloudbroker/data_kvmvm_pci_device_list/main.tf new file mode 100644 index 0000000..0bdba2f --- /dev/null +++ b/samples/cloudbroker/data_kvmvm_pci_device_list/main.tf @@ -0,0 +1,66 @@ +/* +Пример использования +Получение данных о списке подключенных устройств (PCI) +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_kvmvm_pci_device_list" "pci_device_list" { + #id виртуальной машины + #обязательный параметр + #тип - число + compute_id = 100 + + #фильтр по id ресурсной группы + #опциональный параметр + #тип - число + #rg_id = 100 + + #фильтр по id устройства + #опциональный параметр + #тип - число + #device_id = 100 + + #фильтр по статусу + #опциональный параметр + #тип - строка + #status = "ENABLED" + + #номер страницы для отображения + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #page = 1 + + #размер страницы + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #size = 1 +} + +output "output" { + value = data.decort_cb_kvmvm_pci_device_list.pci_device_list +} diff --git a/samples/cloudbroker/data_kvmvm_pfw_list/main.tf b/samples/cloudbroker/data_kvmvm_pfw_list/main.tf new file mode 100644 index 0000000..f9d1622 --- /dev/null +++ b/samples/cloudbroker/data_kvmvm_pfw_list/main.tf @@ -0,0 +1,44 @@ +/* +Пример использования +Получение данных об списке port forwarding compute (виртулаьных машин) +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* + +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_kvmvm_pfw_list" "kvmvm_pfw_list" { + #id виртуальной машины + #обязательный параметр + #тип - число + compute_id = 48 + + #причина запроса + #опциональный параметр + #тип - строка + reason = "test" +} + +output "output" { + value = data.decort_cb_kvmvm_pfw_list.kvmvm_pfw_list +} diff --git a/samples/cloudbroker/data_kvmvm_snapshot_list/main.tf b/samples/cloudbroker/data_kvmvm_snapshot_list/main.tf new file mode 100644 index 0000000..f090001 --- /dev/null +++ b/samples/cloudbroker/data_kvmvm_snapshot_list/main.tf @@ -0,0 +1,39 @@ +/* +Пример использования +Получение списка моментальных снимков ВМ (виртуальных машин). +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* + +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_kvmvm_snapshot_list" "kvmvm_snapshot_list" { + #id виртуальной машины + #обязательный параметр + #тип - число + compute_id = 48 +} + +output "output" { + value = data.decort_cb_kvmvm_snapshot_list.kvmvm_snapshot_list +} diff --git a/samples/cloudbroker/data_kvmvm_snapshot_usage/main.tf b/samples/cloudbroker/data_kvmvm_snapshot_usage/main.tf new file mode 100644 index 0000000..8348ff1 --- /dev/null +++ b/samples/cloudbroker/data_kvmvm_snapshot_usage/main.tf @@ -0,0 +1,44 @@ +/* +Пример использования +Получение настояего размера снимка ВМ (виртуальной машины) в хранилище. +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* + +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_kvmvm_snapshot_usage" "snp_usage" { + #id виртуальной машины + #обязательный параметр + #тип - число + compute_id = 48 + + #label снимка + #опциональный параметр + #тип - строка + label = "test" +} + +output "output" { + value = data.decort_cb_kvmvm_snapshot_usage.snp_usage +} diff --git a/samples/cloudbroker/data_kvmvm_user_list/main.tf b/samples/cloudbroker/data_kvmvm_user_list/main.tf new file mode 100644 index 0000000..c72565f --- /dev/null +++ b/samples/cloudbroker/data_kvmvm_user_list/main.tf @@ -0,0 +1,39 @@ +/* +Пример использования +Получение данных об юзерах compute (виртулаьной машины) +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* + +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_kvmvm_user_list" "kvmvm_user_list" { + #id виртуальной машины + #обязательный параметр + #тип - число + compute_id = 10154 +} + +output "output" { + value = data.decort_cb_kvmvm_user_list.kvmvm_user_list +} diff --git a/samples/cloudbroker/data_kvmvm_vgpu_list/main.tf b/samples/cloudbroker/data_kvmvm_vgpu_list/main.tf new file mode 100644 index 0000000..0ee676a --- /dev/null +++ b/samples/cloudbroker/data_kvmvm_vgpu_list/main.tf @@ -0,0 +1,70 @@ +/* +Пример использования +Получение данных о списке подключенных графических процессоров +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* + +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_kvmvm_vgpu_list" "vgpu_list" { + #id виртуальной машины + #обязательный параметр + #тип - число + compute_id = 100 + + #фильтр по id графического процессора + #опциональный параметр + #тип - число + #gpu_id = 100 + + #фильтр по типу графического процессора + #опциональный параметр + #тип - строка + #type = "NVIDIA" + + #фильтр по статусу + #опциональный параметр + #тип - строка + #status = "ENABLED" + + #фильтр "включая удаленные графические процессоры" + #опциональный параметр + #тип - булев тип + #includedeleted = "false" + + #номер страницы для отображения + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #page = 1 + + #размер страницы + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #size = 1 +} + +output "output" { + value = data.decort_cb_kvmvm_vgpu_list.vgpu_list +} diff --git a/samples/cloudbroker/data_lb/main.tf b/samples/cloudbroker/data_lb/main.tf new file mode 100644 index 0000000..a1c1c33 --- /dev/null +++ b/samples/cloudbroker/data_lb/main.tf @@ -0,0 +1,37 @@ +/* +Пример использования +Получение информации о load balancer (балансировщик нагрузок) +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_lb" "lb" { + #id балансировщика нагрузок + #обязательный параметр + #тип - число + lb_id = 238 +} + +output "test" { + value = data.decort_cb_lb.lb +} diff --git a/samples/cloudbroker/data_lb_list/main.tf b/samples/cloudbroker/data_lb_list/main.tf new file mode 100644 index 0000000..c9cfa0b --- /dev/null +++ b/samples/cloudbroker/data_lb_list/main.tf @@ -0,0 +1,91 @@ +/* +Пример использования +Получение списка load balancer (балансировщиков нагрузки) +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_lb_list" "lbl" { + #фильтр по id балансировщика нагрузки + #опциональный параметр + #тип - число + #by_id = 100 + + #фильтр по имени балансировщика нагрузки + #опциональный параметр + #тип - строка + #name = "test" + + #id аккаунта для получения списка балансировщиков нагрузки + #опциональный параметр + #тип - число + #account_id = 11111 + + #фильтр по id ресурсной группы + #опциональный параметр + #тип - число + #rg_id = 100 + + #фильтр по техническому статусу + #опциональный параметр + #тип - строка + #tech_status = "STOPPED" + + #фильтр по статусу + #опциональный параметр + #тип - строка + #status = "ENABLED" + + #фильтр по IP front + #опциональный параметр + #тип - строка + #front_ip = "ENABLED" + + #фильтр по IP back + #опциональный параметр + #тип - строка + #back_ip = "ENABLED" + + #флаг влючения в результат удаленных балансироващиков нагрузки + #опциональный параметр + #тип - булев тип + #значение по-умолчанию - false + #если не задан - выводятся все доступные неудаленные балансировщики + #includedeleted = true + + #номер страницы для отображения + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #page = 1 + + #размер страницы + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #size = 1 +} + +output "test" { + value = data.decort_cb_lb_list.lbl +} diff --git a/samples/cloudbroker/data_lb_list_deleted/main.tf b/samples/cloudbroker/data_lb_list_deleted/main.tf new file mode 100644 index 0000000..925f972 --- /dev/null +++ b/samples/cloudbroker/data_lb_list_deleted/main.tf @@ -0,0 +1,80 @@ +/* +Пример использования +Получение списка удаленных load balancer (балансировщиков нагрузок) + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_lb_list_deleted" "lbld" { + #фильтр по id балансировщика нагрузки + #опциональный параметр + #тип - число + #by_id = 100 + + #фильтр по имени балансировщика нагрузки + #опциональный параметр + #тип - строка + #name = "test" + + #id аккаунта для получения списка балансировщиков нагрузки + #опциональный параметр + #тип - число + #account_id = 11111 + + #фильтр по id ресурсной группы + #опциональный параметр + #тип - число + #rg_id = 100 + + #фильтр по техническому статусу + #опциональный параметр + #тип - строка + #tech_status = "STOPPED" + + #фильтр по IP front + #опциональный параметр + #тип - строка + #front_ip = "ENABLED" + + #фильтр по IP back + #опциональный параметр + #тип - строка + #back_ip = "ENABLED" + + #номер страницы для отображения + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #page = 1 + + #размер страницы + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #size = 1 +} + +output "test" { + value = data.decort_cb_lb_list_deleted.lbld +} diff --git a/samples/cloudbroker/data_rg/main.tf b/samples/cloudbroker/data_rg/main.tf new file mode 100644 index 0000000..79e2d95 --- /dev/null +++ b/samples/cloudbroker/data_rg/main.tf @@ -0,0 +1,43 @@ +/* +Пример использования +Получение информации о ресурсной группе RG +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_rg" "rg" { + #id ресурсной группы + #обязательный параметр + #тип - число + rg_id = 1022 + + #причина для выполняния действия + #необязятельный параметр + #тип - строка + reason = "TEST" +} + +output "output" { + value = data.decort_cb_rg.rg +} diff --git a/samples/cloudbroker/data_rg_affinity_group_computes/main.tf b/samples/cloudbroker/data_rg_affinity_group_computes/main.tf new file mode 100644 index 0000000..4c0ce7a --- /dev/null +++ b/samples/cloudbroker/data_rg_affinity_group_computes/main.tf @@ -0,0 +1,41 @@ +/* +Пример использования +Получение информации о специальной группе компьютов +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +/* terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} */ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_rg_affinity_group_computes" "lc" { + #id ресурсной группы + #обязательный параметр + #тип - число + rg_id = 123 + + #название специальной группы компьютов + #обязательное поле + #тип - строка + affinity_group = "TEST" +} + +output "output" { + value = data.decort_cb_rg_affinity_group_computes.lc +} diff --git a/samples/cloudbroker/data_rg_affinity_groups_get/main.tf b/samples/cloudbroker/data_rg_affinity_groups_get/main.tf new file mode 100644 index 0000000..1a2fc90 --- /dev/null +++ b/samples/cloudbroker/data_rg_affinity_groups_get/main.tf @@ -0,0 +1,42 @@ +/* +Пример использования +Получение информации о списке компьютов из определенной группы +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +/* terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} */ + + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_rg_affinity_groups_get" "get_groups" { + #id ресурсной группы + #обязательный параметр + #тип - число + rg_id = 123 + + #название специальной группы компьютов + #обязательное поле + #тип - строка + affinity_group = "TEST" +} + +output "output" { + value = data.decort_cb_rg_affinity_groups_get.get_groups +} diff --git a/samples/cloudbroker/data_rg_affinity_groups_list/main.tf b/samples/cloudbroker/data_rg_affinity_groups_list/main.tf new file mode 100644 index 0000000..647c4d3 --- /dev/null +++ b/samples/cloudbroker/data_rg_affinity_groups_list/main.tf @@ -0,0 +1,48 @@ +/* +Пример использования +Получение информации о списке специальных групп компьютов +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +/* terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} */ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_rg_affinity_groups_list" "list_groups" { + #id ресурсной группы + #обязательный параметр + #тип - число + rg_id = 123 + + #номер страницы для отображения + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #page = 1 + + #размер страницы + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #size = 1 +} + +output "output" { + value = data.decort_cb_rg_affinity_groups_list.list_groups +} diff --git a/samples/cloudbroker/data_rg_audits/main.tf b/samples/cloudbroker/data_rg_audits/main.tf new file mode 100644 index 0000000..bdfe145 --- /dev/null +++ b/samples/cloudbroker/data_rg_audits/main.tf @@ -0,0 +1,36 @@ +/* +Пример использования +Получение информации о списке аудитов ресурсной группы +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +/* terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} */ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_rg_audits" "rg_audits" { + #id ресурсной группы + #обязательный параметр + #тип - число + rg_id = 1022 +} + +output "output" { + value = data.decort_cb_rg_audits.rg_audits +} diff --git a/samples/cloudbroker/data_rg_get_resource_consumption/main.tf b/samples/cloudbroker/data_rg_get_resource_consumption/main.tf new file mode 100644 index 0000000..078fd9e --- /dev/null +++ b/samples/cloudbroker/data_rg_get_resource_consumption/main.tf @@ -0,0 +1,37 @@ +/* +Получение списка текущего потребления ресурсов ресурсной группы +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://alpha.dev.decs.online" + #oauth2_url = + oauth2_url = "https://sso-alpha.dev.decs.online" + allow_unverified_ssl = true +} + +data "decort_cb_rg_resource_consumption_get" "rc_get" { + #id ресурсной группы + #обязательный параметр + #тип - число + rg_id = 111 +} + +output "test" { + value = data.decort_cb_rg_resource_consumption_get.rc_get +} + diff --git a/samples/cloudbroker/data_rg_list/main.tf b/samples/cloudbroker/data_rg_list/main.tf new file mode 100644 index 0000000..142d2d8 --- /dev/null +++ b/samples/cloudbroker/data_rg_list/main.tf @@ -0,0 +1,82 @@ +/* +Пример использования +Получение информации о списке всех ресурсных группах к которым есть доступ +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +/* terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} */ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_rg_list" "rg_list" { + #фильтр по id ресурсной группы + #опциональный параметр + #тип - число + #by_id = 100 + + #фильтр по имени ресурсной группы + #опциональный параметр + #тип - строка + #name = "test" + + #id аккаунта для получения списка ресурсных групп + #опциональный параметр + #тип - число + #account_id = 11111 + + #фильтр по имени аккаунта + #опциональный параметр + #тип - строка + #account_name = "test" + + #фильтр по времени создания (после указанного времени) + #опциональный параметр + #тип - число + #created_after = 123 + + #фильтр по времени создания (перед указанным временем) + #опциональный параметр + #тип - число + #created_before = 123 + + #фильтр по статусу + #опциональный параметр + #тип - строка + #status = "ENABLED" + + #отображать удаленные ресурсные группы или нет + #необязательный параметр + #тип - булевый + #значение по умолчанию - false + #includedeleted = false + + #номер страницы + #необязательный параметр + #тип - число + #page = 1 + + #размер страницы + #необязательный параметр + #тип - число + #size = 2 +} + +output "output" { + value = data.decort_cb_rg_list.rg_list +} diff --git a/samples/cloudbroker/data_rg_list_computes/main.tf b/samples/cloudbroker/data_rg_list_computes/main.tf new file mode 100644 index 0000000..5946694 --- /dev/null +++ b/samples/cloudbroker/data_rg_list_computes/main.tf @@ -0,0 +1,88 @@ +/* +Пример использования +Получение информации о списке компьютов в ресурсной группе +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +/* terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} */ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_rg_list_computes" "list_computes" { + #id ресурсной группы + #обязательный параметр + #тип - число + rg_id = 123 + + #фильтр по id compute + #опциональный параметр + #тип - число + #compute_id = 100 + + #фильтр по имени compute + #опциональный параметр + #тип - строка + #name = "test" + + #фильтр по id аккаунта + #опциональный параметр + #тип - число + #account_id = 100 + + #фильтр по техническому статусу + #опциональный параметр + #тип - строка + #tech_status = "STARTED" + + #фильтр по статусу + #опциональный параметр + #тип - строка + #status = "ENABLED" + + #фильтр по ip address + #опциональный параметр + #тип - строка + #ip_address = "1.1.1.1.1" + + #фильтр по имени внешней сети + #опциональный параметр + #тип - строка + #extnet_name = "test" + + #фильтр по id внешней сети + #опциональный параметр + #тип - число + #extnet_id = 100 + + #номер страницы для отображения + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #page = 1 + + #размер страницы + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #size = 1 +} + +output "output" { + value = data.decort_cb_rg_list_computes.list_computes +} diff --git a/samples/cloudbroker/data_rg_list_deleted/main.tf b/samples/cloudbroker/data_rg_list_deleted/main.tf new file mode 100644 index 0000000..e6a2c09 --- /dev/null +++ b/samples/cloudbroker/data_rg_list_deleted/main.tf @@ -0,0 +1,76 @@ +/* +Пример использования +Получение информации о списке удаленных ресурсных групп +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +/* terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} */ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_rg_list_deleted" "list_deleted" { + #фильтр по id ресурсной группы + #опциональный параметр + #тип - число + #by_id = 100 + + #фильтр по имени ресурсной группы + #опциональный параметр + #тип - строка + #name = "test" + + #id аккаунта для получения списка ресурсных групп + #опциональный параметр + #тип - число + #account_id = 11111 + + #фильтр по имени аккаунта + #опциональный параметр + #тип - строка + #account_name = "test" + + #фильтр по времени создания (после указанного времени) + #опциональный параметр + #тип - число + #created_after = 123 + + #фильтр по времени создания (перед указанным временем) + #опциональный параметр + #тип - число + #created_before = 123 + + #фильтр по lock status + #опциональный параметр + #тип - строка + #lock_status = "UNLOCKED" + + #номер страницы + #необязательный параметр + #тип - число + #page = 1 + + #размер страницы + #необязательный параметр + #тип - число + #size = 2 +} + +output "output" { + value = data.decort_cb_rg_list_deleted.list_deleted +} diff --git a/samples/cloudbroker/data_rg_list_lb/main.tf b/samples/cloudbroker/data_rg_list_lb/main.tf new file mode 100644 index 0000000..2a9318e --- /dev/null +++ b/samples/cloudbroker/data_rg_list_lb/main.tf @@ -0,0 +1,83 @@ +/* +Пример использования +Получение информации о списке балансировщиков в ресурсной группе +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +/* terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} */ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_rg_list_lb" "list_lb" { + #id ресурсной группы + #обязательный параметр + #тип - число + rg_id = 123 + + #фильтр по id балансировщика нагрузки + #опциональный параметр + #тип - число + #by_id = 100 + + #фильтр по имени балансировщика нагрузки + #опциональный параметр + #тип - строка + #name = "test" + + #id аккаунта для получения списка балансировщиков нагрузки + #опциональный параметр + #тип - число + #account_id = 11111 + + #фильтр по техническому статусу + #опциональный параметр + #тип - строка + #tech_status = "STOPPED" + + #фильтр по статусу + #опциональный параметр + #тип - строка + #status = "ENABLED" + + #фильтр по IP front + #опциональный параметр + #тип - строка + #front_ip = "1.1.1.1" + + #фильтр по IP back + #опциональный параметр + #тип - строка + #back_ip = "1.1.1.1" + + #номер страницы для отображения + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #page = 1 + + #размер страницы + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #size = 1 +} + +output "output" { + value = data.decort_cb_rg_list_lb.list_lb +} diff --git a/samples/cloudbroker/data_rg_list_pfw/main.tf b/samples/cloudbroker/data_rg_list_pfw/main.tf new file mode 100644 index 0000000..7bd8aff --- /dev/null +++ b/samples/cloudbroker/data_rg_list_pfw/main.tf @@ -0,0 +1,36 @@ +/* +Пример использования +Получение информации о списке правил переадресации портов для ресурсной группы. +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +/* terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} */ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_rg_list_pfw" "list_pfw" { + #id ресурсной группы + #обязательный параметр + #тип - число + rg_id = 123 +} + +output "output" { + value = data.decort_cb_rg_list_pfw.list_pfw +} diff --git a/samples/cloudbroker/data_rg_list_vins/main.tf b/samples/cloudbroker/data_rg_list_vins/main.tf new file mode 100644 index 0000000..c9dd5f5 --- /dev/null +++ b/samples/cloudbroker/data_rg_list_vins/main.tf @@ -0,0 +1,68 @@ +/* +Пример использования +Получение информации о списке винсов в ресурсной группе +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +/* terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} */ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_rg_list_vins" "list_vins" { + #id ресурсной группы + #обязательный параметр + #тип - число + rg_id = 123 + + # фильтр по id vins + # опциональный параметр + # тип - число + # vins_id = 100 + + # фильтр по имени vins + # опциональный параметр + # тип - строка + # name = "test" + + # id аккаунта для получения списка балансировщиков нагрузки + # опциональный параметр + # тип - число + # account_id = 11111 + + # фильтр по IP внешней сети + # опциональный параметр + # тип - строка + # ext_ip = "test" + + # номер страницы для отображения + # опциональный параметр + # тип - число + # если не задан - выводятся все доступные данные + # page = 2 + + # размер страницы + # опциональный параметр + # тип - число + # если не задан - выводятся все доступные данные + # size = 3 +} + +output "output" { + value = data.decort_cb_rg_list_vins.list_vins +} diff --git a/samples/cloudbroker/data_rg_resource_consumption_list/main.tf b/samples/cloudbroker/data_rg_resource_consumption_list/main.tf new file mode 100644 index 0000000..591af4a --- /dev/null +++ b/samples/cloudbroker/data_rg_resource_consumption_list/main.tf @@ -0,0 +1,34 @@ +/* +Получение списка текущего потребления ресурсов +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://alpha.dev.decs.online" + #oauth2_url = + oauth2_url = "https://sso-alpha.dev.decs.online" + allow_unverified_ssl = true +} + +data "decort_cb_rg_resource_consumption_list" "rc_list" { + #Нет входных параметров +} + +output "test" { + value = data.decort_cb_rg_resource_consumption_list.rc_list +} + diff --git a/samples/cloudbroker/data_rg_usage/main.tf b/samples/cloudbroker/data_rg_usage/main.tf new file mode 100644 index 0000000..b99862d --- /dev/null +++ b/samples/cloudbroker/data_rg_usage/main.tf @@ -0,0 +1,41 @@ +/* +Пример использования +Получение информации об использовании ресурсов на ресурсной группе +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +/* terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} */ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_rg_usage" "rg_usage" { + #id ресурсной группы + #обязательный параметр + #тип - число + rg_id = 123 + + #причина для действия + #необязательный параметр + #тип - строка + #reason = "TEST" +} + +output "output" { + value = data.decort_cb_rg_usage.rg_usage +} diff --git a/samples/cloudbroker/data_stack/main.tf b/samples/cloudbroker/data_stack/main.tf new file mode 100644 index 0000000..4296c32 --- /dev/null +++ b/samples/cloudbroker/data_stack/main.tf @@ -0,0 +1,38 @@ +/* +Пример использования +Получение стека по id +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_stack" "stack" { + #id стека + #обязательный параметр + #тип - число + stack_id = 1 +} + +output "test" { + value = data.decort_cb_stack.stack +} diff --git a/samples/cloudbroker/data_stack_list/main.tf b/samples/cloudbroker/data_stack_list/main.tf new file mode 100644 index 0000000..ad8c568 --- /dev/null +++ b/samples/cloudbroker/data_stack_list/main.tf @@ -0,0 +1,63 @@ +/* +Пример использования +Получение списка стеков +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_stack_list" "sl" { + #фильтр стеков по id + #опциональный параметр + #тип - число + #by_id = 111 + + #фильтр по имени стека + #опциональный параметр + #тип - строка + #name = "name" + + #фильтр по типу + #опциональный параметр + #тип - строка + #type = "type" + + #фильтр по статусу + #опциональный параметр + #тип - строка + #status = "status" + + #номер страницы для отображения + #опциональный параметр + #тип - число + #page = 2 + + #размер страницы + #опциональный параметр + #тип - число + #size = 3 +} + +output "test" { + value = data.decort_cb_stack_list.sl +} diff --git a/samples/cloudbroker/data_vins/main.tf b/samples/cloudbroker/data_vins/main.tf new file mode 100644 index 0000000..f796a3b --- /dev/null +++ b/samples/cloudbroker/data_vins/main.tf @@ -0,0 +1,42 @@ +/* +Пример использования +Получение данных о vins +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_vins" "vins" { + #обязательный параметр + #id желаемого vins + #тип - число + vins_id = 10101 + + #необязательный параметр + #причина запроса + #тип - строка + #reason = "report" +} + +output "test" { + value = data.decort_cb_vins.vins +} diff --git a/samples/cloudbroker/data_vins_audits/main.tf b/samples/cloudbroker/data_vins_audits/main.tf new file mode 100644 index 0000000..9a9a426 --- /dev/null +++ b/samples/cloudbroker/data_vins_audits/main.tf @@ -0,0 +1,37 @@ +/* +Пример использования +Получение списка vins audits +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_vins_audits" "vins_audits" { + #обязательный параметр + #id желаемого vins + #тип - число + vins_id = 10101 +} + +output "test" { + value = data.decort_cb_vins_audits.vins_audits +} diff --git a/samples/cloudbroker/data_vins_ext_net_list/main.tf b/samples/cloudbroker/data_vins_ext_net_list/main.tf new file mode 100644 index 0000000..5d443d4 --- /dev/null +++ b/samples/cloudbroker/data_vins_ext_net_list/main.tf @@ -0,0 +1,37 @@ +/* +Пример использования +Получение списка vins extnet +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_vins_ext_net_list" "vins_ext_net_list" { + #обязательный параметр + #id желаемого vins + #тип - число + vins_id = 10101 +} + +output "test" { + value = data.decort_cb_vins_ext_net_list.vins_ext_net_list +} diff --git a/samples/cloudbroker/data_vins_ip_list/main.tf b/samples/cloudbroker/data_vins_ip_list/main.tf new file mode 100644 index 0000000..c8c99cb --- /dev/null +++ b/samples/cloudbroker/data_vins_ip_list/main.tf @@ -0,0 +1,38 @@ +/* +Пример использования +Получение списка vins_ip +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_vins_ip_list" "vins_ip_list" { + #обязательный параметр + #id желаемого vins + #тип - число + vins_id = 10101 +} + +output "test" { + value = data.decort_cb_vins_ip_list.vins_ip_list +} + diff --git a/samples/cloudbroker/data_vins_list/main.tf b/samples/cloudbroker/data_vins_list/main.tf new file mode 100644 index 0000000..8410c4d --- /dev/null +++ b/samples/cloudbroker/data_vins_list/main.tf @@ -0,0 +1,75 @@ +/* +Пример использования +Получение списка vins +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_vins_list" "vl" { + #фильтр по id vins + #опциональный параметр + #тип - число + #by_id = 100 + + #фильтр по имени vins + #опциональный параметр + #тип - строка + #name = "test" + + #id аккаунта для получения списка vins + #опциональный параметр + #тип - число + #account_id = 11111 + + #фильтр по id ресурсной группы + #опциональный параметр + #тип - число + #rg_id = 100 + + #фильтр по IP внешней сети + #опциональный параметр + #тип - строка + #ext_ip = "test" + + #включение удаленных vins в результат + #опциональный параметр + #тип - булев тип + #если не задан - выводятся все неудаленные данные + #include_deleted = true + + #номер страницы для отображения + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #page = 1 + + #размер страницы + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #size = 1 +} + +output "test" { + value = data.decort_cb_vins_list.vl +} diff --git a/samples/cloudbroker/data_vins_list_deleted/main.tf b/samples/cloudbroker/data_vins_list_deleted/main.tf new file mode 100644 index 0000000..4f16906 --- /dev/null +++ b/samples/cloudbroker/data_vins_list_deleted/main.tf @@ -0,0 +1,67 @@ +/* +Пример использования +Получение списка удаленных vins +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_vins_list_deleted" "vins_list_deleted" { + #фильтр по id vins + #опциональный параметр + #тип - число + #by_id = 100 + + #фильтр по имени vins + #опциональный параметр + #тип - строка + #name = "test" + + #id аккаунта для получения списка vins + #опциональный параметр + #тип - число + #account_id = 11111 + + #фильтр по id ресурсной группы + #опциональный параметр + #тип - число + #rg_id = 100 + + #фильтр по IP внешней сети + #опциональный параметр + #тип - строка + #ext_ip = "test" + + #кол-во страниц для вывода + #опицональный параметр + #тип - число + #page = 1 + + #размер страницы + #опицональный параметр + #тип - число + #size = 1 +} + +output "test" { + value = data.decort_cb_vins_list_deleted.vins_list_deleted +} diff --git a/samples/cloudbroker/data_vins_nat_rule_list/main.tf b/samples/cloudbroker/data_vins_nat_rule_list/main.tf new file mode 100644 index 0000000..245493a --- /dev/null +++ b/samples/cloudbroker/data_vins_nat_rule_list/main.tf @@ -0,0 +1,43 @@ +/* +Пример использования +Получение списка natRule vins +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_vins_nat_rule_list" "vins_nat_rule_list" { + #обязательный параметр + #id желаемого vins + #тип - число + vins_id = 10101 + + #необязательный параметр + #причина вызова + #тип - строка + #reason = "test" +} + +output "test" { + value = data.decort_cb_vins_nat_rule_list.vins_nat_rule_list +} + diff --git a/samples/cloudbroker/data_vins_static_route/main.tf b/samples/cloudbroker/data_vins_static_route/main.tf new file mode 100644 index 0000000..fd55cf8 --- /dev/null +++ b/samples/cloudbroker/data_vins_static_route/main.tf @@ -0,0 +1,44 @@ +/* +Пример использования +vins static route +Получение информации о static route в данном Vins +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://mr4.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_vins_static_route" "route" { + #обязательный параметр + #id vins в котором добавлены routes + #тип - число + vins_id = 1111 + + #обязательный параметр + #id route + #тип - число + route_id = 1 +} + +output "route" { + value = data.decort_cb_vins_static_route.route +} diff --git a/samples/cloudbroker/data_vins_static_route_list/main.tf b/samples/cloudbroker/data_vins_static_route_list/main.tf new file mode 100644 index 0000000..1583450 --- /dev/null +++ b/samples/cloudbroker/data_vins_static_route_list/main.tf @@ -0,0 +1,39 @@ +/* +Пример использования +vins static route list +Получение информации о всех static routes в данном Vins +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://mr4.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_cb_vins_static_route_list" "route" { + #обязательный параметр + #id vins в котором добавлены routes + #тип - число + vins_id = 111 +} + +output "route" { + value = data.decort_cb_vins_static_route_list.route +} diff --git a/samples/cloudbroker/resource_disk_snapshot/main.tf b/samples/cloudbroker/resource_disk_snapshot/main.tf new file mode 100644 index 0000000..d1a199a --- /dev/null +++ b/samples/cloudbroker/resource_disk_snapshot/main.tf @@ -0,0 +1,53 @@ +/* +Пример использования +Ресурс снапшота диска +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +resource "decort_cb_disk_snapshot" "ds" { + #Номер диска + #обязательный параметр + #тип - число + disk_id = 20100 + + #Ярлык диска + #обязательный параметр + #тип - строка + label = "label" + + #флаг rollback + #опциональный параметр + #тип - bool + #значение по умолчанию - false + #rollback = true + + #timestamp + #опциональный параметр + #тип - число + #применимо совместно с rollback = true + #timestamp = 15 +} + +output "test" { + value = decort_cb_disk_snapshot.ds +} diff --git a/samples/cloudbroker/resource_flipgroup/main.tf b/samples/cloudbroker/resource_flipgroup/main.tf new file mode 100644 index 0000000..5c34c80 --- /dev/null +++ b/samples/cloudbroker/resource_flipgroup/main.tf @@ -0,0 +1,72 @@ +/* +Пример использования +ресурса флипгруппы +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + source = "basis/decort/decort" + version = "" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + oauth2_url = "https://sso-alpha.dev.decs.online" + controller_url = "https://alpha.dev.decs.online" + app_id = "" + app_secret = "" +} + +resource "decort_cb_flipgroup" "fg" { + # ID аккаунта + # Обязательный параметр + # int + account_id = 999 + + # Наименование Flipgroup + # Обязательный параметр + # string + name = "flipgroup_name" + + # Тип сети (EXTNET, VINS) + # Обязательный параметр + # string + net_type = "EXTNET" + + # ID сети + # Обязательный параметр + # int + net_id = 13 + + # Тип клиентов (в данный момент поддерживается только тип 'compute') + # Обязательный параметр + # string + client_type = "compute" + + # IP-адрес + # Опциональный параметр + # string + #ip = "127.0.0.1" + + # Список клиентов, прикрепленных к флипгруппе + # Опциональный параметр + # []int + #client_ids = [11269] + + # Описание флипгруппы + # Опциональный параметр + # string + #desc = "CHANGED" +} + +output "fg_out" { + value = decort_cb_flipgroup.fg +} diff --git a/samples/cloudbroker/resource_k8ci/main.tf b/samples/cloudbroker/resource_k8ci/main.tf new file mode 100644 index 0000000..472c299 --- /dev/null +++ b/samples/cloudbroker/resource_k8ci/main.tf @@ -0,0 +1,103 @@ +/* +Пример использования +Ресурса k8ci +Ресурс позволяет: +1. Создавать k8ci +2. Редактировать k8ci +3. Удалять k8ci + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +resource "decort_cb_k8ci" "k8ci" { + #имя k8ci + #обязательный параметр + #тип - строка + name = "test" + + #тег версии + #обязательный параметр + #тип - строка + version = "1.1.1" + + #тип master driver + #обязательный параметр + #тип - строка + master_driver = "KVM_X86" + + #тип worker driver + #обязательный параметр + #тип - строка + worker_driver = "KVM_X86" + + #максимальное число master компутов + #обязательный параметр + #тип - число + max_master_count = 1 + + #максимальное число worker компутов + #обязательный параметр + #тип - число + max_worker_count = 1 + + #id образа для master + #обязательный параметр + #тип - число + master_image_id = 4 + + #id образа для worker + #обязательный параметр + #тип - число + worker_image_id = 4 + + #network plugins + #обязательный параметр + #тип - список строк + network_plugins = ["flannel"] + + #доступность k8ci + #опциональный параметр + #тип - булево значение + #enabled = false + + #флаг для моментального удаления k8ci + #опциональный параметр + #тип - булевый + #permanently = true + + #описание + #опциональный параметр + #тип - строка + #desc = "some" + + #доступность k8ci другим аккаунтам + #опциональный параметр + #тип - список чисел + #shared_with = [1111] +} + +output "test" { + value = decort_cb_k8ci.k8ci +} diff --git a/samples/cloudbroker/resource_k8s_cp/main.tf b/samples/cloudbroker/resource_k8s_cp/main.tf new file mode 100644 index 0000000..f287963 --- /dev/null +++ b/samples/cloudbroker/resource_k8s_cp/main.tf @@ -0,0 +1,169 @@ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + source = "basis/decort/decort" + version = "" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + oauth2_url = "https://sso.digitalenergy.online" + controller_url = "https://mr4.digitalenergy.online" + app_id = "" + app_secret = "" +} + +resource "decort_cb_k8s_cp" "cp" { + # Название кластера + # Обязательный параметр + # string + name = "k8s-cp" + + # K8sCI ID + # Обязательный параметр + # int + k8sci_id = 55 + + # Плагин сети (flannel, weavenet или calico) + # Обязательный параметр + # string + network_plugin = "flannel" + + # ID ресурсной группы + # Обязательный параметр + # int + rg_id = 1387 + + # Кол-во ядер мастер-узла + # Опциональный параметр + # int + cpu = 2 + + # Объем RAM мастер-узла + # Опциональный параметр + # int + ram = 2048 + + # Кол-во ВМ мастер-узла (1 или 3) + # Опциональный параметр + # int + num = 1 + + # Размер диска мастер-узла + # Опциональный параметр + # int + disk = 10 + + # Описание кластера + # Опциональный параметр + # string + desc = "" + + # id extnet + #опциональный параметр + #тип - число + extnet_id = 0 + + # id vins + # опциональный параметр + # тип - число + vins_id = 1234 + + # Storage Endpoint ID + # Опциональный параметр + # id + sep_id = 0 + + # SEP Pool + # Опциональный параметр + # string + sep_pool = "pool" + + # Старт/Стоп кластера + # Опциональный параметр + # bool + start = true + + # Включить/отключить кластер + # Опциональный параметр + # bool + enabled = true + + # Удалить кластер безвозвратно + # Опциональный параметр + # bool + permanently = true + + # Восстановить кластер из корзины + # Опциональный параметр + # bool + restore = true + + # Создать кластер с/без балансировщика нагрузки + # Опциональный параметр + # bool + with_lb = true + + # позволяет создать схему отказоустройчивой LB + # опциональный параметр + # тип - булев тип + ha_mode = true + + # дополнительные SAN (Subject Alternative Names) для использования в процессе автоматического выписывания сертификата Кластера Kubernetes; + # возможность взаимодействовать с кластером по FQDN + # параметр получает список строк – IP-адреса и/или DNS (по формату RFC 1123 c поддержкой wildcard) + # опциональный параметр + # тип - массив строк + additional_sans = ["192.168.201.0","192.168.201.1"] + + # используется для определения настроек и действий, которые должны быть выполнены перед запуском любого другого компонента в кластере + # это позволяет вам настраивать такие вещи, как регистрация node, настройка network и другие задачи инициализации + # опциональный параметр + # тип - строка + init_config = "{JSON string}" + + # используется для определения глобальных настроек и конфигураций для всего кластера + # он включает в себя такие параметры, как имя кластера, настройки DNS, методы аутентификации и другие конфигурации в масштабах кластера + # опциональный параметр + # тип - строка + cluster_config = "{JSON string}" + + # используется для настройки поведения и параметров Kubelet, который является агентом primary node, запускаемым на каждом node кластера + # он включает в себя такие параметры, как IP-адрес node, распределение ресурсов, политики удаления модулей и другие конфигурации, специфичные для Kubelet + # опциональный параметр + # тип - строка + kubelet_config = "{JSON string}" + + # используется для настройки поведения и параметров присоединения node к кластеру + # он включает в себя такие параметры, как режим прокси-сервера, диапазоны IP-адресов кластера и другие конфигурации, специфичные для Kube-proxy + # опциональный параметр + # тип - строка + kube_proxy_config = "{JSON string}" + + # используется для настройки поведения и параметров присоединения node к кластеру + # он включает в себя такие параметры, как cluster's control plane endpoint, токен и ключ сертификата + # опциональный параметр + # тип - строка + join_config = "{JSON string}" + + # при создании кластре использовать подключение только к сети ExtNet + # опциональный параметр + # тип - булев тип + extnet_only = true + + # добавить ssl-сертификат в формате x509 pem + # необязательный параметр + # тип - файл + oidc_cert = file("ca.crt") +} + +output "cp_out" { + value = decort_cb_k8s_cp.cp +} diff --git a/samples/cloudbroker/resource_k8s_wg/initconfig.tftpl b/samples/cloudbroker/resource_k8s_wg/initconfig.tftpl new file mode 100644 index 0000000..06df7c0 --- /dev/null +++ b/samples/cloudbroker/resource_k8s_wg/initconfig.tftpl @@ -0,0 +1,9 @@ +--- +users: +- groups: users, wheel + name: user + plain_text_passwd: examplePassword + primary_group: user + ssh_authorized_keys: + - ssh-rsa EXAMPLE%id_rsa.pub + sudo: ALL=(ALL) NOPASSWD:ALL diff --git a/samples/cloudbroker/resource_k8s_wg/main.tf b/samples/cloudbroker/resource_k8s_wg/main.tf new file mode 100644 index 0000000..a904a9a --- /dev/null +++ b/samples/cloudbroker/resource_k8s_wg/main.tf @@ -0,0 +1,96 @@ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + source = "basis/decort/decort" + version = "" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + oauth2_url = "https://sso.digitalenergy.online" + controller_url = "https://mr4.digitalenergy.online" + app_id = "" + app_secret = "" +} + + +resource "decort_cb_k8s_wg" "wg" { + #id экземпляра k8s + #обязательный параметр + #тип - число + k8s_id = 1234 //это значение должно быть и результат вызова decort_cb_k8s.cluster.k8s_id + + #имя worker group + #обязательный параметр + #тип - строка + name = "workers-2" + + #количество worker node для создания + #опциональный параметр + #тип - число + #по - умолчанию - 1 + num = 2 + + #количество cpu для 1 worker node + #опциональный параметр + #тип - число + #по - умолчанию - 1 + cpu = 1 + + #количество RAM для одной worker node в Мбайтах + #опциональный параметр + #тип - число + #по-умолчанию - 1024 + ram = 1024 + + #размер загрузочного диска для worker node, в Гбайтах + #опциональный параметр + #тип - число + #по - умолчанию - 0 + #если установлен параметр 0, то размер диска будет равен размеру образа + disk = 10 + + #список строк с labels для worker группы, в формате: ["label1=value1", "label2=value2"] + #опциональный параметр + #тип - массив строк + labels = ["label1=value1", "label2=value2"] + + #Список строк с annotations для worker группы, в формате: ["key1=value1", "key2=value2"] + #опциональный параметр + #тип - массив строк + annotations = ["key1=value1", "key2=value2"] + + #Список строк с taints для worker группы, в формате: ["key1=value1:NoSchedule", "key2=value2:NoExecute"] + #опциональный параметр + #тип - массив строк + taints = ["key1=value1", "key2=value2"] + + #ID СХД для создания загрузочных дисков для Worker-групп по умолчанию. Использует sepId образа, если не указан. + #опциональный параметр + #тип - число + worker_sep_id = 1 + + #Пул для хранения Workers. Если не заполнить, будет выбран системой + #опциональный параметр + #тип - число + worker_sep_pool = "worker_pool" + + #Перечень аргументов для cloud-init для виртуальных машин worker групп + #опциональный параметр + #тип - файл + #используется при создании и обновлении ресурса + cloud_init = file("initconfig.tftpl") +} + + +output "test_wg" { + value = decort_cb_k8s_wg.wg +} diff --git a/samples/cloudbroker/resource_kvmvm/initconfig.tftpl b/samples/cloudbroker/resource_kvmvm/initconfig.tftpl new file mode 100644 index 0000000..587b59c --- /dev/null +++ b/samples/cloudbroker/resource_kvmvm/initconfig.tftpl @@ -0,0 +1,14 @@ +{ +"users": [ + { + "groups": "users, wheel", + "name": "user", + "plain_text_passwd": "examplePassword", + "primary_group": "user", + "ssh_authorized_keys": [ + "ssh-rsa EXAMPLE%id_rsa.pub" + ], + "sudo": "ALL=(ALL) NOPASSWD:ALL" + } +] +} diff --git a/samples/cloudbroker/resource_kvmvm/main.tf b/samples/cloudbroker/resource_kvmvm/main.tf new file mode 100644 index 0000000..5779779 --- /dev/null +++ b/samples/cloudbroker/resource_kvmvm/main.tf @@ -0,0 +1,423 @@ +/* +Пример использования +Работа с ресурсом kvmvm (compute) +Ресурс позволяет: +1. Создавать compute +2. Редактировать compute +3. Удалять compute +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +resource "decort_cb_kvmvm" "comp" { + #имя compute + #обязательный параметр + #мб изменен + #тип - строка + name = "test-tf-compute-update-new" + + #id resource group + #обязательный параметр + #тип - число + rg_id = 1111 + + #тип драйвера для compute + #обязательный параметр + #тип - строка + driver = "KVM_X86" + + #число cpu + #обязательный параметр + #тип - число + cpu = 1 + + #кол-во оперативной памяти, МБ + #обязательный параметр + #тип - число + ram = 2048 + + #id образа диска для создания compute + #обязательный параметр + #тип - число + image_id = 111 + + #размер загрузочного диска + #опциональный параметр + #тип - число + boot_disk_size = 20 + + #ID сепа для boot диска + #опциональный параметр + #тип - число + sep_id = 1 + + #Название пула + #опциональный параметр + #тип - строка + pool = "data02" + + #конфигурация cloud init + #опциональный параметр + #тип - файл в формате JSON/YAML + cloud_init = file("initconfig.tftpl") + + #описание compute + #опциональный параметр + #тип - строка + description = "test update description in tf words update" + + #stack id + #опциональный параметр + #тип - число + stack_id = 1 + + #id образа CD-ROM для загрузки + #используется при изменении ресурса, при повторном старте вм + #опциональный параметр + #тип - число + alt_boot_id = 1 + + #Создание и добавление диска дял compute + #опциональный параметр + #тип - список дисков + disks { + #Имя диска + #Обязательный для диска параметр + #Тип - строка + disk_name = "disk_name" + + #Размер диска + #Обязательный для диска параметр + #Тип - число + size = 5 + + #Тип диска + #опциональный параметр + #тип - строка + disk_type = "D" + + #опциональный параметр + #тип - число + sep_id = 1 + + #Название пула + #опциональный параметр + #тип - строка + pool = "data01" + + #Описание диска + #опциональный параметр + #тип - строка + desc = "" + + #Айди образа + #опциональный параметр + image_id = 378 + + #Флаг для удаления диска + #опциональный параметр + #тип - bool + permanently = false + } + + #правила affinity + #опциональный параметр + #может быть один, несколько или ни одного блока + #тип - блок + affinity_rules { + #тип правила + #возможные значения - compute или node + #обязательный параметр + #тип - строка + topology = "compute" + + #строгость правила + #возможные значения - RECOMMENDED и REQUIRED + #обязательный параметр + #тип - строка + policy = "RECOMMENDED" + + #режим проверки + #возможные значения - ANY, EQ, NE + #обязательный параметр + #тип - строка + mode = "ANY" + + #ключ правила + #обязательный параметр + #тип строка + key = "testkey" + + #ключ правила + #обязательный параметр + #тип строка + value = "testvalue" + } + + #правила anti-affinity + #опциональный параметр + #может быть один, несколько или ни одного блока + #тип - блок + anti_affinity_rules { + #тип правила + #возможные значения - compute или node + #обязательный параметр + #тип - строка + topology = "compute" + + #строгость правила + #возможные значения - RECOMMENDED и REQUIRED + #обязательный параметр + #тип - строка + policy = "RECOMMENDED" + + #режим проверки + #возможные значения - ANY, EQ, NE + #обязательный параметр + #тип - строка + mode = "ANY" + + #ключ правила + #обязательный параметр + #тип строка + key = "testkey" + + #ключ правила + #обязательный параметр + #тип строка + value = "testvalue" + } + + #установка метки для вм + #опциональный параметр + #тип - строка + affinity_label = "test4" + + + #наименование системы + #опциональный параметр + #используется при создании вм + #по умолчанию - не задан + #тип - строка + is="" + + #назначение вм + #опциональный параметр + #используется при создании вм + #по умолчанию - не задан + #тип - строка + ipa_type = "" + + #Id экстра дисков + #опциональный параметр + #тип - список чисел + extra_disks = [1234, 4322, 1344] + + #Управление XML виртуальной машины + #опциональный параметр + #тип - строка (json-encoded) + custom_fields = "{`key`:`value`}" + + #Описание необходимости выполнения действия + #опциональный параметр + #тип - строка + reason = "need" + + #Присоеденения сетей и удаление сетей в компьюте + #опциональный параметр + #тип - блок + network { + #Тип сети VINS/EXTNET + #Обязательный параметр + #тип - строка + net_type = "VINS" + + #ID сети + #Обязательный параметр + #тип - число + net_id = 1234 + + #IP адрес входящий в сеть + #опциональный параметр + #тип - строка + ip_address = "127.0.0.1" + } + + #добавление и удаление тэгов + #опциональный параметр + #тип - блок + tags { + #Ключ для тэга + #Обязательный параметр + #тип - строка + key = "key" + + #Значения тэга + #Обязательный параметр + #тип - строка + value = "value" + } + + #добавление и удаление port forwarding + #опциональный параметр + #тип - блок + port_forwarding { + #номер внешнего начального порта для правила + #Обязательный параметр + #тип - число + public_port_start = 2023 + + #номер внешнего последнего порта для правила + #опциональный параметр + #тип - число + #по умолчанию - -1 + public_port_end = 2023 + + #номер внутреннего базового порта + #Обязательный параметр + #тип - число + local_port = 80 + + #сетевой протокол + #Обязательный параметр + #тип - строка + proto = "tcp" + } + + #предоставить/забрать пользователю доступ к компьюту + #опциональный параметр + #тип - блок + user_access { + #Имя юзера, которому предоставляем доступ + #Обязательный параметр + #тип - строка + username = "some@decs3o" + + #Права: 'R' - только на чтение, 'RCX' - чтение/запись, 'ARCXDU' - админ + #Обязательный параметр + #тип - строка + access_type = "ARCXDU" + } + + #Создать/удалить снапшот компьюта + #опциональный параметр + #тип - блок + snapshot { + #Лейбл снапшота + #Обязательный параметр + #тип - строка + label = "label1" + } + + #Rollback на нужный снапшот + #опциональный параметр + #Не имеет смысла при отсутсвии снапшотов + #тип - блок + rollback { + #Лейбл снапшота + #Обязательный параметр + #тип - строка + label = "label1" + } + + #Вставить/удалить СD rom + #опциональный параметр + #Максимальное кол-во - 1 + #тип - блок + cd { + #ID образа диска CD rom + #Обязательный параметр + #тип - число + cdrom_id = 344 + } + + #Добавить компьют на стэк + #опциональный параметр + #тип - булев + pin_to_stack = true + + #id stack для добавления компьюта на этот стэк + #опциональный параметр + #тип - число + target_stack_id = 1 + + #Флаг для принужительного добавления компьюта на стэк + #опциональный параметр + #тип - булев + force_pin = true + + #Флаг доступности компьюта для проведения с ним операций + #опциональный параметр + #тип - булев + enabled = true + + #pause/resume компьюта + #опциональный параметр + #тип - булев + pause = true + + #сделать компьют заново + #опциональный параметр + #тип - булев + reset = true + + #восстановить удаленный компьют из корзины + #опциональный параметр + #тип - булев + restore = true + + #флаг для редеплоя компьюта + #опциональный параметр + #тип - булев + auto_start = true + + #флаг для редеплоя компьюта + #опциональный параметр + #тип - булев + force_stop = true + + #поле для редеплоя компьюта + #опциональный параметр + #тип - строка + data_disks = "KEEP" + + #запуск/стоп компьюта + #опциональный параметр + #тип - булев + started = true + + #detach диска при удалении компьюта + #опциональный параметр + #тип - булев + detach_disks = true + + #Флаг для удаления компьюта + #опциональный параметр + #тип - bool + permanently = false +} + +output "test" { + value = decort_cb_kvmvm.comp +} diff --git a/samples/cloudbroker/resource_lb/main.tf b/samples/cloudbroker/resource_lb/main.tf new file mode 100644 index 0000000..077479d --- /dev/null +++ b/samples/cloudbroker/resource_lb/main.tf @@ -0,0 +1,107 @@ +/* +Пример использования +Ресурса load balancer +Ресурс позволяет: +1. Создавать load balancer +2. Редактировать load balancer +3. Удалять load balancer + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +resource "decort_cb_lb" "lb" { + #id ресурсной группы для создания балансировщика + #обязательный параметр + #тип - число + rg_id = 1111 + + #наименование load balancer + #обязательный параметр + #тип - строка + name = "tf-test-lb" + + #id внешней сети и id виртуальной сети не могут быть одновременно = 0 + + #id внешней сети + #опциональный параметр + #тип - число + extnet_id = 6 + + #id виртуальной сети + #опциональный параметр + #тип - число + vins_id = 758 + + #флаг запуска load balancer + #обязательный параметр + #тип - булев тип + #по умолчанию - true + #если load balancer был в статусе "stopped" (start = false), + #то для успешного старта, он должен быть доступен (enable = true) + start = true + + # позволяет создать схему отказоустройчивой LB + # опциональный параметр + # тип - булев тип + #ha_mode = true + + #описание + #опциональный параметр + #тип - строка + #desc = "temp super lb for testing tf provider" + + #флаг доступности load balancer + #необязательный параметр + #тип - булев тип + #enable = true + + #флаг перезапуска load balancer + #необязательный параметр + #тип - булев тип + #перезагрузка срабатывает только при изменении флага с false на true + #restart = false + + #флаг сброса конфигурации load balancer + #необязательный параметр + #тип - булев тип + #сброс срабатывает только при изменении флага с false на true + #config_reset = false + + #флаг моментального удаления load balancer + #необязательный параметр + #тип - булев тип + #по умолчанию - false + #применяется при выполнении команды terraform destroy + #permanently = false + + #флаг восстановления load balancer + #необязательный параметр + #тип - булев тип + #восстановить можно load balancer, удаленным с флагом permanently = false + #restore = true +} + +output "test" { + value = decort_cb_lb.lb +} diff --git a/samples/cloudbroker/resource_lb_backend/main.tf b/samples/cloudbroker/resource_lb_backend/main.tf new file mode 100644 index 0000000..898b3e2 --- /dev/null +++ b/samples/cloudbroker/resource_lb_backend/main.tf @@ -0,0 +1,108 @@ +/* +Пример использования +Ресурса load balancer backend +Ресурс позволяет: +1. Создавать backend +2. Редактировать backend +3. Удалять backend + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +resource "decort_cb_lb_backend" "lb" { + #id балансировщика нагрузок + #обязательный параметр + #тип - число + lb_id = 668 + + #имя бекенда для создания сервера + #обязательный параметр + #тип - строка + name = "testBackend" + + #алгоритм балансировки + #опицональный параметр + #тип - строка + #по умолчанию - "roundrobin" + #доступные значения - "roundrobin", "static-rr", "leastconn" + #algorithm = "roundrobin" + + #------------------- + #настройки для серверов по умолчанию + #------------------- + + #интервал между проверками, в миллисекундах + #опицональный параметр + #тип - число + #по умолчанию - 5000 + #inter = 5000 + + #интервал между проверками доступности сервера после восстановления, в миллисекундах + #опицональный параметр + #тип - число + #по умолчанию - 10000 + #downinter = 1000 + + #кол-во проверок, которые сервер должен успешно пройти + #опицональный параметр + #тип - число + #по умолчанию - 2 + #rise = 2 + + #кол-во проверок, которые сервер может не пройти и после этого получить статус "unavailable" + #опицональный параметр + #тип - число + #по умолчанию - 2 + #fall = 2 + + #кол-во миллисекунд - время между получением сервера статуса "available" и открытием соединений + #опицональный параметр + #тип - число + #по умолчанию - 60000 + #slowstart = 60000 + + #максимальное кол-во соединений сервера, при достижении этого кол-ва, сервер выходит из схемы балансирования + #опицональный параметр + #тип - число + #по умолчанию - 250 + #maxconn = 250 + + #максимальное кол-во соединений в очереди серевера, при достижении этого кол-ва, соединения будут перенаправлены на другой сервер + #опицональный параметр + #тип - число + #по умолчанию - 256 + #maxqueue = 256 + + #вес сервера для балансировки + #опицональный параметр + #тип - число + #мин - 0 + #макс - 255 + #по умолчанию - 100 + #weight = 100 +} + +output "test" { + value = decort_cb_lb_backend.lb +} diff --git a/samples/cloudbroker/resource_lb_backend_server/main.tf b/samples/cloudbroker/resource_lb_backend_server/main.tf new file mode 100644 index 0000000..26218c5 --- /dev/null +++ b/samples/cloudbroker/resource_lb_backend_server/main.tf @@ -0,0 +1,119 @@ +/* +Пример использования +Ресурса load balancer backend server +Ресурс позволяет: +1. Создавать server +2. Редактировать server +3. Удалять server + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +resource "decort_cb_lb_backend_server" "lb" { + #id балансировщика нагрузок + #обязательный параметр + #тип - число + lb_id = 668 + + #имя бекенда для создания сервера + #обязательный параметр + #тип - строка + backend_name = "testBackend" + + #имя сервера + #обязательный параметр + #тип - строка + name = "testServer" + + #ip адрес сервера + #обязательный параметр + #тип - строка + address = "192.168.5.33" + + #порт сервера + #обязательный параметр + #тип - число + port = 6553 + + #проверка доступности сервера + #опицональный параметр + #тип - строка + #по умолчанию - "enabled" + #доступные значения - "disabled", "enabled" + #check = "enabled" + + #интервал между проверками, в миллисекундах + #опицональный параметр + #тип - число + #по умолчанию - 5000 + #inter = 5000 + + #интервал между проверками доступности сервера после восстановления, в миллисекундах + #опицональный параметр + #тип - число + #по умолчанию - 10000 + #downinter = 1000 + + #кол-во проверок, которые сервер должен успешно пройти + #опицональный параметр + #тип - число + #по умолчанию - 2 + #rise = 2 + + #кол-во проверок, которые сервер может не пройти и после этого получить статус "unavailable" + #опицональный параметр + #тип - число + #по умолчанию - 2 + #fall = 2 + + #кол-во миллисекунд - время между получением сервера статуса "available" и открытием соединений + #опицональный параметр + #тип - число + #по умолчанию - 60000 + #slowstart = 60000 + + #максимальное кол-во соединений сервера, при достижении этого кол-ва, сервер выходит из схемы балансирования + #опицональный параметр + #тип - число + #по умолчанию - 250 + #maxconn = 250 + + #максимальное кол-во соединений в очереди серевера, при достижении этого кол-ва, соединения будут перенаправлены на другой сервер + #опицональный параметр + #тип - число + #по умолчанию - 256 + #maxqueue = 256 + + #вес сервера для балансировки + #опицональный параметр + #тип - число + #мин - 0 + #макс - 255 + #по умолчанию - 100 + #weight = 100 +} + +output "test" { + value = decort_cb_lb_backend_server.lb +} diff --git a/samples/cloudbroker/resource_lb_frontend/main.tf b/samples/cloudbroker/resource_lb_frontend/main.tf new file mode 100644 index 0000000..fb11c5a --- /dev/null +++ b/samples/cloudbroker/resource_lb_frontend/main.tf @@ -0,0 +1,51 @@ +/* +Пример использования +Ресурса load balancer frontend +Ресурс позволяет: +1. Создавать frontend +2. Удалять frontend + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +resource "decort_cb_lb_frontend" "lb" { + #id балансировщика нагрузок + #обязательный параметр + #тип - число + lb_id = 668 + + #имя бекенда для создания фронтенда + #обязательный параметр + #тип - строка + backend_name = "testBackend" + + #имя фронтенда + #обязательный параметр + #тип - строка + name = "testFrontend" +} + +output "test" { + value = decort_cb_lb_frontend.lb +} diff --git a/samples/cloudbroker/resource_lb_frontend_bind/main.tf b/samples/cloudbroker/resource_lb_frontend_bind/main.tf new file mode 100644 index 0000000..b65fd17 --- /dev/null +++ b/samples/cloudbroker/resource_lb_frontend_bind/main.tf @@ -0,0 +1,62 @@ +/* +Пример использования +Ресурса load balancer frontend bind (привязка фронтенда балансировщика нагрузок) +Ресурс позволяет: +1. Создавать привязку +2. Редактировать привязку +3. Удалять привязку + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +resource "decort_cb_lb_frontend_bind" "lb" { + #id балансировщика нагрузок + #обязательный параметр + #тип - число + lb_id = 668 + + #имя фронтенда для создания привязки + #обязательный параметр + #тип - строка + frontend_name = "testFrontend" + + #наименование привязки + #обязательный параметр + #тип - строка + name = "testBinding" + + #адрес привязки фронтенда + #обязательный параметр + #тип - строка + address = "111.111.111.111" + + #порт для привязки фронтенда + #обязательный параметр + #тип - число + port = 1111 +} + +output "test" { + value = decort_cb_lb_frontend_bind.lb +} diff --git a/samples/cloudbroker/resource_rg/main.tf b/samples/cloudbroker/resource_rg/main.tf new file mode 100644 index 0000000..195b12b --- /dev/null +++ b/samples/cloudbroker/resource_rg/main.tf @@ -0,0 +1,208 @@ +/* +Пример использования +Ресурсов RG +Ресурс позволяет: +1. Создавать +2. Редактировать +3. Удалять +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +resource "decort_cb_rg" "rg" { + #имя ресурсной группы + #обязательный параметр + #тип - строка + rg_name = "testing_rg_1" + + #id аккаунта которому будет принадлежать ресурсная группа + #обязательный параметр + #тип - число + account_id = 123 + + #id сети + #обязательный параметр + #тип - число + gid = 1234 + + #лимиты ресурсов + #опциональные параметры + #тип - блок + #resource_limits { + #max number of cpu cores + #опциональный праметр при использовании блока + #тип - число + #cu_c = 12 + + #max size of aggregated vdisks in GB + #опциональный праметр при использовании блока + #тип - число + #cu_dm = 12 + + #max number of assigned public IPs + #опциональный праметр при использовании блока + #тип - число + #cu_i = 12 + + #max size of memory in MB + #опциональный праметр при использовании блока + #тип - число + #cu_m = 12 + + #max sent/received network transfer peering + #опциональный праметр при использовании блока + #тип - число + #cu_np = 12 + #} + + #имя владельца ресурсной группы + #опциональный параметр + #тип - строка + #owner = "owner name" + + #тип сети по умолчанию для этой ресурсной группы. + #виртуальные машины, созданные в этой RG, по умолчанию будут подключены к этой сети. + #Допустимые значения: PRIVATE, PUBLIC, NONE. + #необязательный параметр + #тип - строка + #def_net_type = "NONE" + + #ip cidr частной сети, если сеть по умолчанию PRIVATE + #необязательный параметр + #тип - строка + #ipcidr = "1.1.1.1" + + #описание + #необязательный параметр + #тип - строка + #description = "qwerty" + + #id внешней сети + #необязательный параметр + #тип - число + #ext_net_id = 123 + + #ip внешней сети + #необязательный параметр + #тип - строка + #ext_ip = "1.1.1.1" + + #причина выполнения + #необязательный параметр + #тип - строка + #reason = "TEST" + + #зарегистрировать компьюты в регистрационной системе + #необязательный параметр + #тип - булев + #register_computes = true + + #список названий pools + #необязательный параметр + #тип - массив строк + #uniq_pools = ["sep1_poolName1", "sep2_poolName2"] + + #блок для предоставления прав на ресурсную группу + #необязательный параметр + #тип - блок + access { + #имя юзера предоставляемому права + #обязательный праметр при использовании блока + #тип - строка + user = "kasim_baybikov_1@decs3o" + + #тип прав + #обязательный параметр + #тип - строка + #разрешенные значения: "R", "RCX" or "ARCXDU" + right = "RCX" + + #причина запроса + #необязательный параметр + #тип - строка + reason = "test" + } + + #Установить сеть по умолчанию + #необязательный параметр + #тип - блок + #при добавлении блока, удалять его нельзя + def_net { + #тип сети + #обязательный параметр при использовании блока + #тип - строка + net_type = "PUBLIC" + + #id сети + #идентификатор сегмента сети. Если net_type — PUBLIC, а net_id — 0, + #то будет выбран сегмент внешней сети по умолчанию. Если net_type + #имеет значение PRIVATE и net_id=0, будет выбран первый vins, определенный для этой ресурсной группы. + #В противном случае net_id идентифицирует либо существующий сегмент внешней сети, либо vins. + #необязательный параметр + #тип - число + net_id = 1234 + + #причина выполнения + #необязательный параметр + #тип - строка + reason = "TEST" + } + + #может ли запуститься ВМ, если ресурсов CPU недостаточно + #необязательный параметр + #Допустимые значения: strict, loose. + #тип - строка + cpu_allocation_parameter = "loose" + + #CPU allocation ratio + #необязательный параметр + #one pCPU = ratio*vCPU (zero or positive value) + #тип - число + cpu_allocation_ratio = 1 + + #флаг доступности ресурсной группы + #необязательный параметр + #тип - булевый + enable = true + + #флаг для восстановления удаленной ресурсной группы + #необязательный параметр + #тип - булевый + #restore = false + + #флаг для принудительного удаления ресурсной группы + #необязательный параметр + #тип - булевый + #перед удалением следует перевести ресурсную группу в статус disabled, выставив enable = false + force = true + + #флаг для моментального удаления ресурсной группы + #необязательный параметр + #тип - булевый + permanently = true +} + + +output "output" { + value = decort_cb_rg.rg +} diff --git a/samples/cloudbroker/resource_vins/main.tf b/samples/cloudbroker/resource_vins/main.tf new file mode 100644 index 0000000..7329c63 --- /dev/null +++ b/samples/cloudbroker/resource_vins/main.tf @@ -0,0 +1,242 @@ +/* +Пример использования +Ресурса vins +Ресурс позволяет: +1. Создавать vins +2. Удалять vins +3. Восстанвливать vins +4. Добавлять и убирать подключение к внешней сети +5. Резервировать и освобождать ip для vins +6. Добавлять и удалять natrule +7. Перезапускать и редеплоить vnfdev + +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://mr4.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +resource "decort_cb_vins" "vins" { + # Параметры для создания vins + + #обязательный параметр + #имя создаваемого ресурса + #тип - строка + name = "Test_name" + + #опциональный параметр + #id аккаунта для создаения ресурса + #тип - число + #внимание, для создания ресурса обязательно должен быть указан или rg_id, или account_id + account_id = 2023 + + #опциональный параметр + #id ресурсной группы для создаения ресурса + #тип - число + #внимание, для создания ресурса обязательно должен быть указан или rg_id, или account_id + rg_id = 10101 + + #опциональный параметр + #id внешней сети для подключения к ней ресурса + #тип - число + #ext_net_id = 2222 + + #опциональный параметр + #ip внешней сети для подключения к нему ресурса + #тип - строка + #ext_ip = "1.1.1.1" + + #опциональный параметр + #private network IP CIDR + #тип - строка + #ipcidr = "192.168.0.1" + + #опциональный параметр + #количество зарезервированных адресов на момент создания + #тип - число + #значение по умолчанию 32 + #pre_reservations_num = 2 + + #опциональный параметр + #grid (platform) ID + #тип - число + #gid = 2002 + + #опциональный параметр + #Description + #тип - строка + #description = "Description" + + #опциональный параметр + #Причина запроса + #тип - строка + #reason = "test" + + #опциональный параметр + #блок для указания списка routes + #тип - блок + #routes = [{ + #опциональный параметр + #destination network + #тип - строка + #destination = "DHCP" + + #опциональный параметр + #destination network mask in 255.255.255.255 format + #тип - строка + #netmask = "192.168.5.5" + + #опциональный параметр + #next hop host, IP address from ViNS ID free IP pool + #тип - строка + #gateway = "192.168.5.5" + #}] + + # Default qos + + #опциональный параметр + #блок для указания default_qos + #тип - блок + #default_qos = { + #опциональный параметр + #ingress rate + #тип - число + #in_rate = 1 + + #опциональный параметр + #ingress burst + #тип - число + #in_burst = 1 + + #опциональный параметр + #egress rate + #тип - число + #e_rate = 1 + #} + + # Enable, delete parameters + + #опциональный параметр + #ручное подключение и отключение ресурса + #тип - булев тип + #enable = true + + #опциональный параметр + #удаление навсегда + #тип - булев тип + #permanently = true + + #опциональный параметр + #удаляет за собой все зависимые ресурсы + #тип - булев тип + #force = true + + # IP release, IP reserve parameters + + #опциональный параметр + #блок для резервирования ip + #тип - блок + #ip { + #обязательный параметр + #тип подключения + #тип - строка + # type = "DHCP" + + #опциональный параметр + #ip который необходимо зарезервировать + #тип - строка + #ip_addr = "192.168.5.5" + + #опциональный параметр + #mac который необходимо зарезервировать + #тип - строка + #mac = "ff:ff:ff:ff:ff:ff" + + #опциональный параметр + #compute_id, ассоциируемый с типом DHCP + #тип - число + #compute_id = 1234 + + #опциональный параметр + #причина запроса + #тип - строка + #reason = "one more reason" + #} + + # Добавление и удаление NAT Rules + + #опциональный параметр + #блок для добавления natRule + #тип - блок + #nat_rule { + #обязательный параметр + #ip внутренний + #тип - строка + # int_ip = "192.168.0.28" + + #обязательный параметр + #внутренний порт + #тип - число + # int_port = 80 + + #обязательный параметр + #начало диапазона внешних портов + #тип - число + # ext_port_start = 8001 + + #опциональный параметр + #конец диапазона внешних портов + #тип - число + #ext_port_end = 8001 + + #опциональный параметр + #протокол natRule: разрешенные значения "tcp", "udp" + #тип - строка + #proto = "tcp" + #} + + # vnf dev start, stop, restart, reset, redeploy parameters + + #опциональный параметр + #true: старт vnfDev; false: стоп vnfDev + #тип - булев тип + #vnfdev_start = true + + #опциональный параметр + #перезапуск vnfDev + #тип - булев тип + #vnfdev_restart = true + + #опциональный параметр + #ресет vnfDev + #тип - булев тип + #vnfdev_reset = true + + #опциональный параметр + #редеплой vnfDev + #тип - булев тип + #vnfdev_redeploy = true +} + +output "test" { + value = decort_cb_vins.vins +} diff --git a/samples/cloudbroker/resource_vins_static_route/main.tf b/samples/cloudbroker/resource_vins_static_route/main.tf new file mode 100644 index 0000000..ba32d35 --- /dev/null +++ b/samples/cloudbroker/resource_vins_static_route/main.tf @@ -0,0 +1,63 @@ +/* +Пример использования +Ресурса vins static routes +Ресурс позволяет: +1. Создавать static routes +2. Удалять static routes +3. Предоставлять доступ виртуальным машинам к static routes +4. Удалять доступ виртуальным машинам к static routes +*/ + +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "" + source = "basis/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "decs3o" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +resource "decort_cb_vins_static_route" "sr" { + #id Vins + #обязательный параметр + #тип - число + vins_id = 385 + + #destination network + #обязательный параметр + #тип - строка + destination = "192.168.201.0" + + #destination network mask + #обязательный параметр + #тип - строка + netmask = "255.255.255.255" + + #IP-адрес из пула свободных IP-адресов ViNS ID + #обязательный параметр + #тип - строка + gateway = "192.168.201.40" + + #список виртуальных машин, которым будет предоставлен доступ к роуту + #опциональный параметр + #тип - массив чисел + #compute_ids = [111,222] +} + +output "sr" { + value = decort_cb_vins_static_route.sr +}