diff --git a/decort/data_source_account.go b/decort/data_source_account.go index 735384f..39ef95c 100644 --- a/decort/data_source_account.go +++ b/decort/data_source_account.go @@ -1,6 +1,6 @@ /* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -25,108 +25,393 @@ Visit https://github.com/rudecs/terraform-provider-decort for full source code p package decort import ( - "encoding/json" - "fmt" - // "net/url" - - log "github.com/sirupsen/logrus" - + "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func flattenAccount(d *schema.ResourceData, acc_facts string) error { - // NOTE: this function modifies ResourceData argument - as such it should never be called - // from resourceAccountExists(...) method - - // log.Debugf("flattenAccount: ready to decode response body from %q", CloudspacesGetAPI) - details := AccountRecord{} - err := json.Unmarshal([]byte(acc_facts), &details) +func dataSourceAccountRead(d *schema.ResourceData, m interface{}) error { + acc, err := utilityAccountCheckPresence(d, m) if err != nil { return err } - log.Debugf("flattenAccount: decoded Account name %q / ID %d, status %q", details.Name, details.ID, details.Status) - - d.SetId(fmt.Sprintf("%d", details.ID)) - d.Set("name", details.Name) - d.Set("status", details.Status) - + id := uuid.New() + d.SetId(id.String()) + d.Set("dc_location", acc.DCLocation) + d.Set("resources", flattenAccResources(acc.Resources)) + d.Set("ckey", acc.CKey) + d.Set("meta", flattenMeta(acc.Meta)) + d.Set("acl", flattenAccAcl(acc.Acl)) + d.Set("company", acc.Company) + d.Set("companyurl", acc.CompanyUrl) + d.Set("created_by", acc.CreatedBy) + d.Set("created_time", acc.CreatedTime) + d.Set("deactivation_time", acc.DeactiovationTime) + d.Set("deleted_by", acc.DeletedBy) + d.Set("deleted_time", acc.DeletedTime) + d.Set("displayname", acc.DisplayName) + d.Set("guid", acc.GUID) + d.Set("account_id", acc.ID) + d.Set("account_name", acc.Name) + d.Set("resource_limits", flattenRgResourceLimits(acc.ResourceLimits)) + d.Set("send_access_emails", acc.SendAccessEmails) + d.Set("service_account", acc.ServiceAccount) + d.Set("status", acc.Status) + d.Set("updated_time", acc.UpdatedTime) + d.Set("version", acc.Version) + d.Set("vins", acc.Vins) + d.Set("vinses", acc.Vinses) + d.Set("computes", flattenAccComputes(acc.Computes)) + d.Set("machines", flattenAccMachines(acc.Machines)) return nil } -func dataSourceAccountRead(d *schema.ResourceData, m interface{}) error { - acc_facts, err := utilityAccountCheckPresence(d, m) - if acc_facts == "" { - // if empty string is returned from utilityAccountCheckPresence then there is no - // such account and err tells so - just return it to the calling party - d.SetId("") // ensure ID is empty in this case - return err +func flattenAccComputes(acs Computes) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "started": acs.Started, + "stopped": acs.Stopped, } + res = append(res, temp) + return res +} - return flattenAccount(d, acc_facts) +func flattenAccMachines(ams Machines) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "running": ams.Running, + "halted": ams.Halted, + } + res = append(res, temp) + return res } -func dataSourceAccount() *schema.Resource { - return &schema.Resource{ - SchemaVersion: 1, +func flattenAccAcl(acls []AccountAclRecord) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + for _, acls := range acls { + temp := map[string]interface{}{ + "can_be_deleted": acls.CanBeDeleted, + "explicit": acls.IsExplicit, + "guid": acls.Guid, + "right": acls.Rights, + "status": acls.Status, + "type": acls.Type, + "user_group_id": acls.UgroupID, + } + res = append(res, temp) + } + return res +} - Read: dataSourceAccountRead, +func flattenAccResources(r Resources) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "current": flattenAccResource(r.Current), + "reserved": flattenAccResource(r.Reserved), + } + res = append(res, temp) + return res +} - Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, - }, +func flattenAccResource(r Resource) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "cpu": r.CPU, + "disksize": r.Disksize, + "extips": r.Extips, + "exttraffic": r.Exttraffic, + "gpu": r.GPU, + "ram": r.RAM, + } + res = append(res, temp) + return res +} - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Optional: true, - Description: "Name of the account. Names are case sensitive and unique.", +func dataSourceAccountSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Required: true, + }, + "dc_location": { + Type: schema.TypeString, + Computed: true, + }, + "resources": { + Type: schema.TypeList, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "current": { + Type: schema.TypeList, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disksize": { + 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, + }, + }, + }, + }, + "reserved": { + Type: schema.TypeList, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disksize": { + 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, + }, + }, + }, + }, + }, }, - - "account_id": { - Type: schema.TypeInt, - Optional: true, - Description: "Unique ID of the account. If account ID is specified, then account name is ignored.", + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, }, - - "status": { - Type: schema.TypeString, - Computed: true, - Description: "Current status of the account.", + }, + "acl": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "can_be_deleted": { + Type: schema.TypeBool, + Computed: true, + }, + "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, + }, + }, }, - - /* We keep the following attributes commented out, as we are not implementing account - management with Terraform plugin, so we do not need this extra info. - - "quota": { - Type: schema.TypeList, - Optional: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: quotaRgSubresourceSchema(), // this is a dictionary + }, + "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, + }, + "account_name": { + Type: schema.TypeString, + Computed: true, + }, + "resource_limits": { + Type: schema.TypeList, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cu_c": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_d": { + 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, + }, }, - Description: "Quotas on the resources for this account and all its resource groups.", }, - - "resource_groups": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema { - Type: schema.TypeInt, + }, + "send_access_emails": { + Type: schema.TypeBool, + Computed: true, + }, + "service_account": { + Type: schema.TypeBool, + Computed: true, + }, + "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, + }, + }, + "computes": { + Type: schema.TypeList, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "started": { + Type: schema.TypeInt, + Computed: true, + }, + "stopped": { + Type: schema.TypeInt, + Computed: true, + }, }, - Description: "IDs of resource groups in this account." }, - - "vins": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema { - Type: schema.TypeInt, + }, + "machines": { + Type: schema.TypeList, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "halted": { + Type: schema.TypeInt, + Computed: true, + }, + "running": { + Type: schema.TypeInt, + Computed: true, + }, }, - Description: "IDs of VINSes created at the account level." }, - */ }, + "vinses": { + Type: schema.TypeInt, + Computed: true, + }, + } + return res +} + +func dataSourceAccount() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + Read: dataSourceAccountRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &Timeout30s, + Default: &Timeout60s, + }, + + Schema: dataSourceAccountSchemaMake(), } } diff --git a/decort/data_source_account_audits_list.go b/decort/data_source_account_audits_list.go new file mode 100644 index 0000000..c31e947 --- /dev/null +++ b/decort/data_source_account_audits_list.go @@ -0,0 +1,114 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func flattenAccountAuditsList(aal AccountAuditsList) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + for _, aa := range aal { + temp := map[string]interface{}{ + "call": aa.Call, + "responsetime": aa.ResponseTime, + "statuscode": aa.StatusCode, + "timestamp": aa.Timestamp, + "user": aa.User, + } + res = append(res, temp) + } + return res + +} + +func dataSourceAccountAuditsListRead(d *schema.ResourceData, m interface{}) error { + accountAuditsList, err := utilityAccountAuditsListCheckPresence(d, m) + if err != nil { + return err + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenAccountAuditsList(accountAuditsList)) + + return nil +} + +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 dataSourceAccountAuditsList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + Read: dataSourceAccountAuditsListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &Timeout30s, + Default: &Timeout60s, + }, + + Schema: dataSourceAccountAuditsListSchemaMake(), + } +} diff --git a/decort/data_source_account_computes_list.go b/decort/data_source_account_computes_list.go new file mode 100644 index 0000000..8a7ba77 --- /dev/null +++ b/decort/data_source_account_computes_list.go @@ -0,0 +1,189 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func flattenAccountComputesList(acl AccountComputesList) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + for _, acc := range acl { + temp := map[string]interface{}{ + "account_id": acc.AccountId, + "account_name": acc.AccountName, + "cpus": acc.CPUs, + "created_by": acc.CreatedBy, + "created_time": acc.CreatedTime, + "deleted_by": acc.DeletedBy, + "deleted_time": acc.DeletedTime, + "compute_id": acc.ComputeId, + "compute_name": acc.ComputeName, + "ram": acc.RAM, + "registered": acc.Registered, + "rg_id": acc.RgId, + "rg_name": acc.RgName, + "status": acc.Status, + "tech_status": acc.TechStatus, + "total_disks_size": acc.TotalDisksSize, + "updated_by": acc.UpdatedBy, + "updated_time": acc.UpdatedTime, + "user_managed": acc.UserManaged, + "vins_connected": acc.VinsConnected, + } + res = append(res, temp) + } + return res + +} + +func dataSourceAccountComputesListRead(d *schema.ResourceData, m interface{}) error { + accountComputesList, err := utilityAccountComputesListCheckPresence(d, m) + if err != nil { + return err + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenAccountComputesList(accountComputesList)) + + return nil +} + +func dataSourceAccountComputesListSchemaMake() 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{ + "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, + }, + }, + }, + }, + } + return res +} + +func dataSourceAccountComputesList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + Read: dataSourceAccountComputesListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &Timeout30s, + Default: &Timeout60s, + }, + + Schema: dataSourceAccountComputesListSchemaMake(), + } +} diff --git a/decort/data_source_account_consumed_units.go b/decort/data_source_account_consumed_units.go new file mode 100644 index 0000000..6723e17 --- /dev/null +++ b/decort/data_source_account_consumed_units.go @@ -0,0 +1,98 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func dataSourceAccountConsumedUnitsRead(d *schema.ResourceData, m interface{}) error { + accountConsumedUnits, err := utilityAccountConsumedUnitsCheckPresence(d, m) + if err != nil { + return err + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("cu_c", accountConsumedUnits.CUC) + d.Set("cu_d", accountConsumedUnits.CUD) + d.Set("cu_i", accountConsumedUnits.CUI) + d.Set("cu_m", accountConsumedUnits.CUM) + d.Set("cu_np", accountConsumedUnits.CUNP) + d.Set("gpu_units", accountConsumedUnits.GpuUnits) + + return nil +} + +func dataSourceAccountConsumedUnitsSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the account", + }, + "cu_c": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_d": { + 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 dataSourceAccountConsumedUnits() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + Read: dataSourceAccountConsumedUnitsRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &Timeout30s, + Default: &Timeout60s, + }, + + Schema: dataSourceAccountConsumedUnitsSchemaMake(), + } +} diff --git a/decort/data_source_account_consumed_units_by_type.go b/decort/data_source_account_consumed_units_by_type.go new file mode 100644 index 0000000..4b9ccd6 --- /dev/null +++ b/decort/data_source_account_consumed_units_by_type.go @@ -0,0 +1,78 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func dataSourceAccountConsumedUnitsByTypeRead(d *schema.ResourceData, m interface{}) error { + result, err := utilityAccountConsumedUnitsByTypeCheckPresence(d, m) + if err != nil { + return err + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("cu_result", result) + + return nil +} + +func dataSourceAccountConsumedUnitsByTypeSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the account", + }, + "cu_type": { + Type: schema.TypeString, + Required: true, + Description: "cloud unit resource type", + }, + "cu_result": { + Type: schema.TypeFloat, + Computed: true, + }, + } + return res +} + +func dataSourceAccountConsumedUnitsByType() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + Read: dataSourceAccountConsumedUnitsByTypeRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &Timeout30s, + Default: &Timeout60s, + }, + + Schema: dataSourceAccountConsumedUnitsByTypeSchemaMake(), + } +} diff --git a/decort/data_source_account_deleted_list.go b/decort/data_source_account_deleted_list.go new file mode 100644 index 0000000..d2a57c5 --- /dev/null +++ b/decort/data_source_account_deleted_list.go @@ -0,0 +1,58 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func dataSourceAccountDeletedListRead(d *schema.ResourceData, m interface{}) error { + accountDeletedList, err := utilityAccountDeletedListCheckPresence(d, m) + if err != nil { + return err + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenAccountList(accountDeletedList)) + + return nil +} + +func dataSourceAccountDeletedList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + Read: dataSourceAccountDeletedListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &Timeout30s, + Default: &Timeout60s, + }, + + Schema: dataSourceAccountListSchemaMake(), + } +} diff --git a/decort/data_source_account_disks_list.go b/decort/data_source_account_disks_list.go new file mode 100644 index 0000000..def9676 --- /dev/null +++ b/decort/data_source_account_disks_list.go @@ -0,0 +1,119 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func flattenAccountDisksList(adl AccountDisksList) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + for _, ad := range adl { + temp := map[string]interface{}{ + "disk_id": ad.ID, + "disk_name": ad.Name, + "pool": ad.Pool, + "sep_id": ad.SepId, + "size_max": ad.SizeMax, + "type": ad.Type, + } + res = append(res, temp) + } + return res + +} + +func dataSourceAccountDisksListRead(d *schema.ResourceData, m interface{}) error { + accountDisksList, err := utilityAccountDisksListCheckPresence(d, m) + if err != nil { + return err + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenAccountDisksList(accountDisksList)) + + return nil +} + +func dataSourceAccountDisksListSchemaMake() 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{ + "disk_id": { + Type: schema.TypeInt, + Computed: true, + }, + "disk_name": { + Type: schema.TypeString, + Computed: true, + }, + "pool": { + Type: schema.TypeString, + Computed: true, + }, + "sep_id": { + Type: schema.TypeInt, + Computed: true, + }, + "size_max": { + Type: schema.TypeInt, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + } + return res +} + +func dataSourceAccountDisksList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + Read: dataSourceAccountDisksListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &Timeout30s, + Default: &Timeout60s, + }, + + Schema: dataSourceAccountDisksListSchemaMake(), + } +} diff --git a/decort/data_source_account_flipgroups_list.go b/decort/data_source_account_flipgroups_list.go new file mode 100644 index 0000000..dd83716 --- /dev/null +++ b/decort/data_source_account_flipgroups_list.go @@ -0,0 +1,194 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func flattenAccountFlipGroupsList(afgl AccountFlipGroupsList) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + for _, afg := range afgl { + temp := map[string]interface{}{ + "account_id": afg.AccountId, + "client_type": afg.ClientType, + "conn_type": afg.ConnType, + "created_by": afg.CreatedBy, + "created_time": afg.CreatedTime, + "default_gw": afg.DefaultGW, + "deleted_by": afg.DeletedBy, + "deleted_time": afg.DeletedTime, + "desc": afg.Desc, + "gid": afg.GID, + "guid": afg.GUID, + "fg_id": afg.ID, + "ip": afg.IP, + "milestones": afg.Milestones, + "fg_name": afg.Name, + "net_id": afg.NetID, + "net_type": afg.NetType, + "netmask": afg.NetMask, + "status": afg.Status, + "updated_by": afg.UpdatedBy, + "updated_time": afg.UpdatedTime, + } + res = append(res, temp) + } + return res + +} + +func dataSourceAccountFlipGroupsListRead(d *schema.ResourceData, m interface{}) error { + accountFlipGroupsList, err := utilityAccountFlipGroupsListCheckPresence(d, m) + if err != nil { + return err + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenAccountFlipGroupsList(accountFlipGroupsList)) + + return nil +} + +func dataSourceAccountFlipGroupsListSchemaMake() 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{ + "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, + }, + }, + }, + }, + } + return res +} + +func dataSourceAccountFlipGroupsList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + Read: dataSourceAccountFlipGroupsListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &Timeout30s, + Default: &Timeout60s, + }, + + Schema: dataSourceAccountFlipGroupsListSchemaMake(), + } +} diff --git a/decort/data_source_account_list.go b/decort/data_source_account_list.go new file mode 100644 index 0000000..b587bda --- /dev/null +++ b/decort/data_source_account_list.go @@ -0,0 +1,306 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func flattenAccountList(al AccountCloudApiList) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + for _, acc := range al { + temp := map[string]interface{}{ + "acl": flattenRgAcl(acc.Acl), + "created_time": acc.CreatedTime, + "deleted_time": acc.DeletedTime, + "account_id": acc.ID, + "account_name": acc.Name, + "status": acc.Status, + "updated_time": acc.UpdatedTime, + } + res = append(res, temp) + } + return res +} + +/*uncomment for cloudbroker +func flattenAccountList(al AccountList) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + for _, acc := range al { + temp := map[string]interface{}{ + "dc_location": acc.DCLocation, + "ckey": acc.CKey, + "meta": flattenMeta(acc.Meta), + + "acl": flattenRgAcl(acc.Acl), + + "company": acc.Company, + "companyurl": acc.CompanyUrl, + "created_by": acc.CreatedBy, + + "created_time": acc.CreatedTime, + + "deactivation_time": acc.DeactiovationTime, + "deleted_by": acc.DeletedBy, + + "deleted_time": acc.DeletedTime, + + "displayname": acc.DisplayName, + "guid": acc.GUID, + + "account_id": acc.ID, + "account_name": acc.Name, + + "resource_limits": flattenRgResourceLimits(acc.ResourceLimits), + "send_access_emails": acc.SendAccessEmails, + "service_account": acc.ServiceAccount, + + "status": acc.Status, + "updated_time": acc.UpdatedTime, + + "version": acc.Version, + "vins": acc.Vins, + + } + res = append(res, temp) + } + return res +} +*/ + +func dataSourceAccountListRead(d *schema.ResourceData, m interface{}) error { + accountList, err := utilityAccountListCheckPresence(d, m) + if err != nil { + return err + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenAccountList(accountList)) + + return nil +} + +func dataSourceAccountListSchemaMake() 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.Resource{ + Schema: map[string]*schema.Schema{ + /*uncomment for cloudbroker + "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, + }, + }, + }, + }, + /*uncomment for cloudbroker + "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, + }, + /*uncomment for cloudbroker + "deactivation_time": { + Type: schema.TypeFloat, + Computed: true, + }, + "deleted_by": { + Type: schema.TypeString, + Computed: true, + }, + */ + "deleted_time": { + Type: schema.TypeInt, + Computed: true, + }, + /*uncomment for cloudbroker + "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, + }, + /*uncomment for cloudbroker + "resource_limits": { + Type: schema.TypeList, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cu_c": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_d": { + 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, + }, + }, + }, + }, + "send_access_emails": { + Type: schema.TypeBool, + Computed: true, + }, + "service_account": { + Type: schema.TypeBool, + Computed: true, + }, + */ + "status": { + Type: schema.TypeString, + Computed: true, + }, + "updated_time": { + Type: schema.TypeInt, + Computed: true, + }, + /*uncomment for cloudbroker + "version": { + Type: schema.TypeInt, + Computed: true, + }, + "vins": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + */ + }, + }, + }, + } + return res +} + +func dataSourceAccountList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + Read: dataSourceAccountListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &Timeout30s, + Default: &Timeout60s, + }, + + Schema: dataSourceAccountListSchemaMake(), + } +} diff --git a/decort/data_source_account_reserved_units.go b/decort/data_source_account_reserved_units.go new file mode 100644 index 0000000..b4d48c9 --- /dev/null +++ b/decort/data_source_account_reserved_units.go @@ -0,0 +1,98 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func dataSourceAccountReservedUnitsRead(d *schema.ResourceData, m interface{}) error { + accountReservedUnits, err := utilityAccountReservedUnitsCheckPresence(d, m) + if err != nil { + return err + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("cu_c", accountReservedUnits.CUC) + d.Set("cu_d", accountReservedUnits.CUD) + d.Set("cu_i", accountReservedUnits.CUI) + d.Set("cu_m", accountReservedUnits.CUM) + d.Set("cu_np", accountReservedUnits.CUNP) + d.Set("gpu_units", accountReservedUnits.GpuUnits) + + return nil +} + +func dataSourceAccountReservedUnitsSchemaMake() map[string]*schema.Schema { + res := map[string]*schema.Schema{ + "account_id": { + Type: schema.TypeInt, + Required: true, + Description: "ID of the account", + }, + "cu_c": { + Type: schema.TypeFloat, + Computed: true, + }, + "cu_d": { + 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 dataSourceAccountReservedUnits() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + Read: dataSourceAccountReservedUnitsRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &Timeout30s, + Default: &Timeout60s, + }, + + Schema: dataSourceAccountReservedUnitsSchemaMake(), + } +} diff --git a/decort/data_source_account_rg_list.go b/decort/data_source_account_rg_list.go new file mode 100644 index 0000000..40e2284 --- /dev/null +++ b/decort/data_source_account_rg_list.go @@ -0,0 +1,294 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func flattenAccountRGList(argl AccountRGList) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + for _, arg := range argl { + temp := map[string]interface{}{ + "computes": flattenAccRGComputes(arg.Computes), + "resources": flattenAccRGResources(arg.Resources), + "created_by": arg.CreatedBy, + "created_time": arg.CreatedTime, + "deleted_by": arg.DeletedBy, + "deleted_time": arg.DeletedTime, + "rg_id": arg.RGID, + "milestones": arg.Milestones, + "rg_name": arg.RGName, + "status": arg.Status, + "updated_by": arg.UpdatedBy, + "updated_time": arg.UpdatedTime, + "vinses": arg.Vinses, + } + res = append(res, temp) + } + return res + +} + +func flattenAccRGComputes(argc AccountRGComputes) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "started": argc.Started, + "stopped": argc.Stopped, + } + res = append(res, temp) + return res +} + +func flattenAccRGResources(argr AccountRGResources) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "consumed": flattenAccResource(argr.Consumed), + "limits": flattenAccResource(argr.Limits), + "reserved": flattenAccResource(argr.Reserved), + } + res = append(res, temp) + return res +} + +func dataSourceAccountRGListRead(d *schema.ResourceData, m interface{}) error { + accountRGList, err := utilityAccountRGListCheckPresence(d, m) + if err != nil { + return err + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenAccountRGList(accountRGList)) + + return nil +} + +func dataSourceAccountRGListSchemaMake() 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{ + "computes": { + Type: schema.TypeList, + MaxItems: 1, + 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, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "consumed": { + Type: schema.TypeList, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disksize": { + 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, + }, + }, + }, + }, + + "limits": { + Type: schema.TypeList, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disksize": { + 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, + }, + }, + }, + }, + "reserved": { + Type: schema.TypeList, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disksize": { + 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, + }, + }, + }, + }, + }, + }, + }, + + "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, + }, + }, + }, + }, + } + return res +} + +func dataSourceAccountRGList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + Read: dataSourceAccountRGListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &Timeout30s, + Default: &Timeout60s, + }, + + Schema: dataSourceAccountRGListSchemaMake(), + } +} diff --git a/decort/data_source_account_templates_list.go b/decort/data_source_account_templates_list.go new file mode 100644 index 0000000..4071088 --- /dev/null +++ b/decort/data_source_account_templates_list.go @@ -0,0 +1,139 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func flattenAccountTemplatesList(atl AccountTemplatesList) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + for _, at := range atl { + temp := map[string]interface{}{ + "unc_path": at.UNCPath, + "account_id": at.AccountId, + "desc": at.Desc, + "template_id": at.ID, + "template_name": at.Name, + "public": at.Public, + "size": at.Size, + "status": at.Status, + "type": at.Type, + "username": at.Username, + } + res = append(res, temp) + } + return res + +} + +func dataSourceAccountTemplatesListRead(d *schema.ResourceData, m interface{}) error { + accountTemplatesList, err := utilityAccountTemplatesListCheckPresence(d, m) + if err != nil { + return err + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenAccountTemplatesList(accountTemplatesList)) + + return nil +} + +func dataSourceAccountTemplatesListSchemaMake() 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{ + "unc_path": { + Type: schema.TypeString, + Computed: true, + }, + "account_id": { + Type: schema.TypeInt, + Computed: true, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "template_id": { + Type: schema.TypeInt, + Computed: true, + }, + "template_name": { + Type: schema.TypeString, + Computed: true, + }, + "public": { + Type: schema.TypeBool, + Computed: true, + }, + "size": { + Type: schema.TypeInt, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "username": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + } + return res +} + +func dataSourceAccountTemplatessList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + Read: dataSourceAccountTemplatesListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &Timeout30s, + Default: &Timeout60s, + }, + + Schema: dataSourceAccountTemplatesListSchemaMake(), + } +} diff --git a/decort/data_source_account_vins_list.go b/decort/data_source_account_vins_list.go new file mode 100644 index 0000000..e9d50e7 --- /dev/null +++ b/decort/data_source_account_vins_list.go @@ -0,0 +1,174 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func flattenAccountVinsList(avl AccountVinsList) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + for _, av := range avl { + temp := map[string]interface{}{ + "account_id": av.AccountId, + "account_name": av.AccountName, + "computes": av.Computes, + "created_by": av.CreatedBy, + "created_time": av.CreatedTime, + "deleted_by": av.DeletedBy, + "deleted_time": av.DeletedTime, + "external_ip": av.ExternalIP, + "vin_id": av.ID, + "vin_name": av.Name, + "network": av.Network, + "pri_vnf_dev_id": av.PriVnfDevId, + "rg_id": av.RgId, + "rg_name": av.RgName, + "status": av.Status, + "updated_by": av.UpdatedBy, + "updated_time": av.UpdatedTime, + } + res = append(res, temp) + } + return res + +} + +func dataSourceAccountVinsListRead(d *schema.ResourceData, m interface{}) error { + accountVinsList, err := utilityAccountVinsListCheckPresence(d, m) + if err != nil { + return err + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenAccountVinsList(accountVinsList)) + + return nil +} + +func dataSourceAccountVinsListSchemaMake() 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{ + "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, + }, + }, + }, + }, + } + return res +} + +func dataSourceAccountVinsList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + Read: dataSourceAccountVinsListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &Timeout30s, + Default: &Timeout60s, + }, + + Schema: dataSourceAccountVinsListSchemaMake(), + } +} diff --git a/decort/data_source_rg_list.go b/decort/data_source_rg_list.go index 9220693..73afce5 100644 --- a/decort/data_source_rg_list.go +++ b/decort/data_source_rg_list.go @@ -1,6 +1,6 @@ /* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/decort/models_api.go b/decort/models_api.go index b3e6f86..119f11e 100644 --- a/decort/models_api.go +++ b/decort/models_api.go @@ -51,12 +51,13 @@ type UserAclRecord struct { } type AccountAclRecord struct { - IsExplicit bool `json:"explicit"` - Guid string `json:"guid"` - Rights string `json:"right"` - Status string `json:"status"` - Type string `json:"type"` - UgroupID string `json:"userGroupId"` + IsExplicit bool `json:"explicit"` + Guid string `json:"guid"` + Rights string `json:"right"` + Status string `json:"status"` + Type string `json:"type"` + UgroupID string `json:"userGroupId"` + CanBeDeleted bool `json:"canBeDeleted"` } type ResourceLimits struct { @@ -987,3 +988,241 @@ type SepConfig map[string]interface{} type SepList []Sep type SepPool map[string]interface{} + +/////////////////////// +///// ACCOUNTS //// +/////////////////////// + +const accountAddUserAPI = "/restmachine/cloudapi/account/addUser" +const accountAuditsAPI = "/restmachine/cloudapi/account/audits" +const accountCreateAPI = "/restmachine/cloudapi/account/create" +const accountDeleteAPI = "/restmachine/cloudapi/account/delete" +const accountDeleteUserAPI = "/restmachine/cloudapi/account/deleteUser" +const accountDisableAPI = "/restmachine/cloudapi/account/disable" +const accountEnableAPI = "/restmachine/cloudapi/account/enable" +const accountGetAPI = "/restmachine/cloudapi/account/get" +const accountGetConsumedUnitsAPI = "/restmachine/cloudapi/account/getConsumedAccountUnits" +const accountGetConsumedUnitsByTypeAPI = "/restmachine/cloudapi/account/getConsumedCloudUnitsByType" +const accountGetReservedUnitsAPI = "/restmachine/cloudapi/account/getReservedAccountUnits" +const accountListAPI = "/restmachine/cloudapi/account/list" +const accountListComputesAPI = "/restmachine/cloudapi/account/listComputes" +const accountListDeletedAPI = "/restmachine/cloudapi/account/listDeleted" +const accountListDisksAPI = "/restmachine/cloudapi/account/listDisks" +const accountListFlipGroupsAPI = "/restmachine/cloudapi/account/listFlipGroups" +const accountListRGAPI = "/restmachine/cloudapi/account/listRG" +const accountListTemplatesAPI = "/restmachine/cloudapi/account/listTemplates" +const accountListVinsAPI = "/restmachine/cloudapi/account/listVins" +const accountRestoreAPI = "/restmachine/cloudapi/account/restore" +const accountUpdateAPI = "/restmachine/cloudapi/account/update" +const accountUpdateUserAPI = "/restmachine/cloudapi/account/updateUser" + +////Structs + +type Account struct { + DCLocation string `json:"DCLocation"` + CKey string `jspn:"_ckey"` + Meta []interface{} `json:"_meta"` + Acl []AccountAclRecord `json:"acl"` + Company string `json:"company"` + CompanyUrl string `json:"companyurl"` + CreatedBy string `jspn:"createdBy"` + CreatedTime int `json:"createdTime"` + DeactiovationTime float64 `json:"deactivationTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime int `json:"deletedTime"` + DisplayName string `json:"displayname"` + GUID int `json:"guid"` + ID int `json:"id"` + Name string `json:"name"` + ResourceLimits ResourceLimits `json:"resourceLimits"` + SendAccessEmails bool `json:"sendAccessEmails"` + ServiceAccount bool `json:"serviceAccount"` + Status string `json:"status"` + UpdatedTime int `json:"updatedTime"` + Version int `json:"version"` + Vins []int `json:"vins"` +} + +type AccountList []Account + +type AccountCloudApi struct { + Acl []AccountAclRecord `json:"acl"` + CreatedTime int `json:"createdTime"` + DeletedTime int `json:"deletedTime"` + ID int `json:"id"` + Name string `json:"name"` + Status string `json:"status"` + UpdatedTime int `json:"updatedTime"` +} + +type AccountCloudApiList []AccountCloudApi + +type Resource struct { + CPU int `json:"cpu"` + Disksize int `json:"disksize"` + Extips int `json:"extips"` + Exttraffic int `json:"exttraffic"` + GPU int `json:"gpu"` + RAM int `json:"ram"` +} + +type Resources struct { + Current Resource `json:"Current"` + Reserved Resource `json:"Reserved"` +} + +type Computes struct { + Started int `json:"started"` + Stopped int `json:"stopped"` +} + +type Machines struct { + Running int `json:"running"` + Halted int `json:"halted"` +} + +type AccountWithResources struct { + Account + Resources Resources `json:"Resources"` + Computes Computes `json:"computes"` + Machines Machines `json:"machines"` + Vinses int `json:"vinses"` +} + +type AccountCompute struct { + AccountId int `json:"accountId"` + AccountName string `json:"accountName"` + CPUs int `json:"cpus"` + CreatedBy string `json:"createdBy"` + CreatedTime int `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime int `json:"deletedTime"` + ComputeId int `json:"id"` + ComputeName string `json:"name"` + RAM int `json:"ram"` + Registered bool `json:"registered"` + RgId int `json:"rgId"` + RgName string `json:"rgName"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + TotalDisksSize int `json:"totalDisksSize"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime int `json:"updatedTime"` + UserManaged bool `json:"userManaged"` + VinsConnected int `json:"vinsConnected"` +} + +type AccountComputesList []AccountCompute + +type AccountDisk struct { + ID int `json:"id"` + Name string `json:"name"` + Pool string `json:"pool"` + SepId int `json:"sepId"` + SizeMax int `json:"sizeMax"` + Type string `json:"type"` +} + +type AccountDisksList []AccountDisk + +type AccountVin struct { + AccountId int `json:"accountId"` + AccountName string `json:"accountName"` + Computes int `json:"computes"` + CreatedBy string `json:"createdBy"` + CreatedTime int `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime int `json:"deletedTime"` + ExternalIP string `json:"externalIP"` + ID int `json:"id"` + Name string `json:"name"` + Network string `json:"network"` + PriVnfDevId int `json:"priVnfDevId"` + RgId int `json:"rgId"` + RgName string `json:"rgName"` + Status string `json:"status"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime int `json:"updatedTime"` +} + +type AccountVinsList []AccountVin + +type AccountAudit struct { + Call string `json:"call"` + ResponseTime float64 `json:"responsetime"` + StatusCode int `json:"statuscode"` + Timestamp float64 `json:"timestamp"` + User string `json:"user"` +} + +type AccountAuditsList []AccountAudit + +type AccountRGComputes struct { + Started int `json:"Started"` + Stopped int `json:"Stopped"` +} + +type AccountRGResources struct { + Consumed Resource `json:"Consumed"` + Limits Resource `json:"Limits"` + Reserved Resource `json:"Reserved"` +} + +type AccountRG struct { + Computes AccountRGComputes `json:"Computes"` + Resources AccountRGResources `json:"Resources"` + CreatedBy string `json:"createdBy"` + CreatedTime int `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime int `json:"deletedTime"` + RGID int `json:"id"` + Milestones int `json:"milestones"` + RGName string `json:"name"` + Status string `json:"status"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime int `json:"updatedTime"` + Vinses int `json:"vinses"` +} + +type AccountRGList []AccountRG + +type AccountTemplate struct { + UNCPath string `json:"UNCPath"` + AccountId int `json:"accountId"` + Desc string `json:"desc"` + ID int `json:"id"` + Name string `json:"name"` + Public bool `json:"public"` + Size int `json:"size"` + Status string `json:"status"` + Type string `json:"type"` + Username string `json:"username"` +} + +type AccountTemplatesList []AccountTemplate + +type AccountFlipGroup struct { + AccountId int `json:"accountId"` + ClientType string `json:"clientType"` + ConnType string `json:"connType"` + CreatedBy string `json:"createdBy"` + CreatedTime int `json:"createdTime"` + DefaultGW string `json:"defaultGW"` + DeletedBy string `json:"deletedBy"` + DeletedTime int `json:"deletedTime"` + Desc string `json:"desc"` + GID int `json:"gid"` + GUID int `json:"guid"` + ID int `json:"id"` + IP string `json:"ip"` + Milestones int `json:"milestones"` + Name string `json:"name"` + NetID int `json:"netId"` + NetType string `json:"netType"` + NetMask int `json:"netmask"` + Status string `json:"status"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime int `json:"updatedTime"` +} + +type AccountFlipGroupsList []AccountFlipGroup diff --git a/decort/provider.go b/decort/provider.go index 00af955..030b263 100644 --- a/decort/provider.go +++ b/decort/provider.go @@ -114,31 +114,44 @@ func Provider() *schema.Provider { "decort_pcidevice": resourcePcidevice(), "decort_sep": resourceSep(), "decort_sep_config": resourceSepConfig(), + "decort_account": resourceAccount(), }, DataSourcesMap: map[string]*schema.Resource{ - "decort_account": dataSourceAccount(), - "decort_resgroup": dataSourceResgroup(), - "decort_kvmvm": dataSourceCompute(), - "decort_image": dataSourceImage(), - "decort_disk": dataSourceDisk(), - "decort_vins": dataSourceVins(), - "decort_grid": dataSourceGrid(), - "decort_grid_list": dataSourceGridList(), - "decort_image_list": dataSourceImageList(), - "decort_image_list_stacks": dataSourceImageListStacks(), - "decort_snapshot_list": dataSourceSnapshotList(), - "decort_vgpu": dataSourceVGPU(), - "decort_pcidevice": dataSourcePcidevice(), - "decort_pcidevice_list": dataSourcePcideviceList(), - "decort_sep_list": dataSourceSepList(), - "decort_sep": dataSourceSep(), - "decort_sep_consumption": dataSourceSepConsumption(), - "decort_sep_disk_list": dataSourceSepDiskList(), - "decort_sep_config": dataSourceSepConfig(), - "decort_sep_pool": dataSourceSepPool(), - "decort_disk_list": dataSourceDiskList(), - "decort_rg_list": dataSourceRgList(), + "decort_account": dataSourceAccount(), + "decort_resgroup": dataSourceResgroup(), + "decort_kvmvm": dataSourceCompute(), + "decort_image": dataSourceImage(), + "decort_disk": dataSourceDisk(), + "decort_vins": dataSourceVins(), + "decort_grid": dataSourceGrid(), + "decort_grid_list": dataSourceGridList(), + "decort_image_list": dataSourceImageList(), + "decort_image_list_stacks": dataSourceImageListStacks(), + "decort_snapshot_list": dataSourceSnapshotList(), + "decort_vgpu": dataSourceVGPU(), + "decort_pcidevice": dataSourcePcidevice(), + "decort_pcidevice_list": dataSourcePcideviceList(), + "decort_sep_list": dataSourceSepList(), + "decort_sep": dataSourceSep(), + "decort_sep_consumption": dataSourceSepConsumption(), + "decort_sep_disk_list": dataSourceSepDiskList(), + "decort_sep_config": dataSourceSepConfig(), + "decort_sep_pool": dataSourceSepPool(), + "decort_disk_list": dataSourceDiskList(), + "decort_rg_list": dataSourceRgList(), + "decort_account_list": dataSourceAccountList(), + "decort_account_computes_list": dataSourceAccountComputesList(), + "decort_account_disks_list": dataSourceAccountDisksList(), + "decort_account_vins_list": dataSourceAccountVinsList(), + "decort_account_audits_list": dataSourceAccountAuditsList(), + "decort_account_rg_list": dataSourceAccountRGList(), + "decort_account_consumed_units": dataSourceAccountConsumedUnits(), + "decort_account_consumed_units_by_type": dataSourceAccountConsumedUnitsByType(), + "decort_account_reserved_units": dataSourceAccountReservedUnits(), + "decort_account_templates_list": dataSourceAccountTemplatessList(), + "decort_account_deleted_list": dataSourceAccountDeletedList(), + "decort_account_flipgroups_list": dataSourceAccountFlipGroupsList(), // "decort_pfw": dataSourcePfw(), }, diff --git a/decort/resource_account.go b/decort/resource_account.go new file mode 100644 index 0000000..a113092 --- /dev/null +++ b/decort/resource_account.go @@ -0,0 +1,794 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "errors" + "net/url" + "strconv" + "strings" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + log "github.com/sirupsen/logrus" +) + +func resourceAccountCreate(d *schema.ResourceData, m interface{}) error { + log.Debugf("resourceAccountCreate") + + if accountId, ok := d.GetOk("account_id"); ok { + if exists, err := resourceAccountExists(d, m); exists { + if err != nil { + return err + } + d.SetId(strconv.Itoa(accountId.(int))) + err = resourceAccountRead(d, m) + if err != nil { + return err + } + + return nil + } + return errors.New("provided sep id does not exist") + } + + controller := m.(*ControllerCfg) + urlValues := &url.Values{} + + urlValues.Add("name", d.Get("account_name").(string)) + urlValues.Add("username", d.Get("username").(string)) + + if emailaddress, ok := d.GetOk("emailaddress"); ok { + urlValues.Add("emailaddress", emailaddress.(string)) + } + if sendAccessEmails, ok := d.GetOk("send_access_emails"); ok { + urlValues.Add("sendAccessEmails", strconv.FormatBool(sendAccessEmails.(bool))) + } + if resLimits, ok := d.GetOk("resource_limits"); ok { + resLimit := resLimits.([]interface{})[0] + resLimitConv := resLimit.(map[string]interface{}) + if resLimitConv["cu_m"] != nil { + maxMemCap := int(resLimitConv["cu_m"].(float64)) + if maxMemCap == 0 { + urlValues.Add("maxMemoryCapacity", strconv.Itoa(-1)) + } else { + urlValues.Add("maxMemoryCapacity", strconv.Itoa(maxMemCap)) + } + } + if resLimitConv["cu_d"] != nil { + maxDiskCap := int(resLimitConv["cu_d"].(float64)) + if maxDiskCap == 0 { + urlValues.Add("maxVDiskCapacity", strconv.Itoa(-1)) + } else { + urlValues.Add("maxVDiskCapacity", strconv.Itoa(maxDiskCap)) + } + } + if resLimitConv["cu_c"] != nil { + maxCPUCap := int(resLimitConv["cu_c"].(float64)) + if maxCPUCap == 0 { + urlValues.Add("maxCPUCapacity", strconv.Itoa(-1)) + } else { + urlValues.Add("maxCPUCapacity", strconv.Itoa(maxCPUCap)) + } + + } + if resLimitConv["cu_i"] != nil { + maxNumPublicIP := int(resLimitConv["cu_i"].(float64)) + if maxNumPublicIP == 0 { + urlValues.Add("maxNumPublicIP", strconv.Itoa(-1)) + } else { + urlValues.Add("maxNumPublicIP", strconv.Itoa(maxNumPublicIP)) + } + + } + if resLimitConv["cu_np"] != nil { + maxNP := int(resLimitConv["cu_np"].(float64)) + if maxNP == 0 { + urlValues.Add("maxNetworkPeerTransfer", strconv.Itoa(-1)) + } else { + urlValues.Add("maxNetworkPeerTransfer", strconv.Itoa(maxNP)) + } + + } + if resLimitConv["gpu_units"] != nil { + gpuUnits := int(resLimitConv["gpu_units"].(float64)) + if gpuUnits == 0 { + urlValues.Add("gpu_units", strconv.Itoa(-1)) + } else { + urlValues.Add("gpu_units", strconv.Itoa(gpuUnits)) + } + } + } + + accountId, err := controller.decortAPICall("POST", accountCreateAPI, urlValues) + if err != nil { + return err + } + + id := uuid.New() + d.SetId(accountId) + d.Set("account_id", accountId) + + err = resourceAccountRead(d, m) + if err != nil { + return err + } + + d.SetId(id.String()) + + return nil +} + +func resourceAccountRead(d *schema.ResourceData, m interface{}) error { + log.Debugf("resourceSepRead") + + acc, err := utilityAccountCheckPresence(d, m) + if acc == nil { + d.SetId("") + return err + } + + d.Set("dc_location", acc.DCLocation) + d.Set("resources", flattenAccResources(acc.Resources)) + d.Set("ckey", acc.CKey) + d.Set("meta", flattenMeta(acc.Meta)) + d.Set("acl", flattenAccAcl(acc.Acl)) + d.Set("company", acc.Company) + d.Set("companyurl", acc.CompanyUrl) + d.Set("created_by", acc.CreatedBy) + d.Set("created_time", acc.CreatedTime) + d.Set("deactivation_time", acc.DeactiovationTime) + d.Set("deleted_by", acc.DeletedBy) + d.Set("deleted_time", acc.DeletedTime) + d.Set("displayname", acc.DisplayName) + d.Set("guid", acc.GUID) + d.Set("account_id", acc.ID) + d.Set("account_name", acc.Name) + d.Set("resource_limits", flattenRgResourceLimits(acc.ResourceLimits)) + d.Set("send_access_emails", acc.SendAccessEmails) + d.Set("service_account", acc.ServiceAccount) + d.Set("status", acc.Status) + d.Set("updated_time", acc.UpdatedTime) + d.Set("version", acc.Version) + d.Set("vins", acc.Vins) + d.Set("vinses", acc.Vinses) + d.Set("computes", flattenAccComputes(acc.Computes)) + d.Set("machines", flattenAccMachines(acc.Machines)) + + return nil +} + +func resourceAccountDelete(d *schema.ResourceData, m interface{}) error { + log.Debugf("resourceAccountDelete") + + account, err := utilityAccountCheckPresence(d, m) + if account == nil { + if err != nil { + return err + } + return nil + } + + controller := m.(*ControllerCfg) + urlValues := &url.Values{} + urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) + urlValues.Add("permanently", strconv.FormatBool(d.Get("permanently").(bool))) + + _, err = controller.decortAPICall("POST", accountDeleteAPI, urlValues) + if err != nil { + return err + } + d.SetId("") + + return nil +} + +func resourceAccountExists(d *schema.ResourceData, m interface{}) (bool, error) { + log.Debugf("resourceAccountExists") + + account, err := utilityAccountCheckPresence(d, m) + if account == nil { + if err != nil { + return false, err + } + return false, nil + } + + return true, nil +} + +func resourceAccountEdit(d *schema.ResourceData, m interface{}) error { + log.Debugf("resourceAccountEdit") + c := m.(*ControllerCfg) + + urlValues := &url.Values{} + if d.HasChange("enable") { + api := accountDisableAPI + enable := d.Get("enable").(bool) + if enable { + api = accountEnableAPI + } + urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) + + _, err := c.decortAPICall("POST", api, urlValues) + if err != nil { + return err + } + + urlValues = &url.Values{} + } + + if d.HasChange("account_name") { + urlValues.Add("name", d.Get("account_name").(string)) + urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) + _, err := c.decortAPICall("POST", accountUpdateAPI, urlValues) + if err != nil { + return err + } + + urlValues = &url.Values{} + } + if d.HasChange("resource_limits") { + resLimit := d.Get("resource_limits").([]interface{})[0] + resLimitConv := resLimit.(map[string]interface{}) + + if resLimitConv["cu_m"] != nil { + maxMemCap := int(resLimitConv["cu_m"].(float64)) + if maxMemCap == 0 { + urlValues.Add("maxMemoryCapacity", strconv.Itoa(-1)) + } else { + urlValues.Add("maxMemoryCapacity", strconv.Itoa(maxMemCap)) + } + } + if resLimitConv["cu_d"] != nil { + maxDiskCap := int(resLimitConv["cu_d"].(float64)) + if maxDiskCap == 0 { + urlValues.Add("maxVDiskCapacity", strconv.Itoa(-1)) + } else { + urlValues.Add("maxVDiskCapacity", strconv.Itoa(maxDiskCap)) + } + } + if resLimitConv["cu_c"] != nil { + maxCPUCap := int(resLimitConv["cu_c"].(float64)) + if maxCPUCap == 0 { + urlValues.Add("maxCPUCapacity", strconv.Itoa(-1)) + } else { + urlValues.Add("maxCPUCapacity", strconv.Itoa(maxCPUCap)) + } + + } + if resLimitConv["cu_i"] != nil { + maxNumPublicIP := int(resLimitConv["cu_i"].(float64)) + if maxNumPublicIP == 0 { + urlValues.Add("maxNumPublicIP", strconv.Itoa(-1)) + } else { + urlValues.Add("maxNumPublicIP", strconv.Itoa(maxNumPublicIP)) + } + + } + if resLimitConv["cu_np"] != nil { + maxNP := int(resLimitConv["cu_np"].(float64)) + if maxNP == 0 { + urlValues.Add("maxNetworkPeerTransfer", strconv.Itoa(-1)) + } else { + urlValues.Add("maxNetworkPeerTransfer", strconv.Itoa(maxNP)) + } + + } + if resLimitConv["gpu_units"] != nil { + gpuUnits := int(resLimitConv["gpu_units"].(float64)) + if gpuUnits == 0 { + urlValues.Add("gpu_units", strconv.Itoa(-1)) + } else { + urlValues.Add("gpu_units", strconv.Itoa(gpuUnits)) + } + } + + urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) + _, err := c.decortAPICall("POST", accountUpdateAPI, urlValues) + if err != nil { + return err + } + + urlValues = &url.Values{} + } + + if d.HasChange("send_access_emails") { + urlValues.Add("sendAccessEmails", strconv.FormatBool(d.Get("send_access_emails").(bool))) + urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) + _, err := c.decortAPICall("POST", accountUpdateAPI, urlValues) + if err != nil { + return err + } + + urlValues = &url.Values{} + } + + if d.HasChange("restore") { + restore := d.Get("restore").(bool) + if restore { + urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) + _, err := c.decortAPICall("POST", accountRestoreAPI, urlValues) + if err != nil { + return err + } + + urlValues = &url.Values{} + } + } + + if d.HasChange("users") { + deletedUsers := make([]interface{}, 0) + addedUsers := make([]interface{}, 0) + updatedUsers := make([]interface{}, 0) + + old, new := d.GetChange("users") + oldConv := old.([]interface{}) + newConv := new.([]interface{}) + for _, el := range oldConv { + if !isContainsUser(newConv, el) { + deletedUsers = append(deletedUsers, el) + } + } + for _, el := range newConv { + if !isContainsUser(oldConv, el) { + addedUsers = append(addedUsers, el) + } else { + if isChangedUser(oldConv, el) { + updatedUsers = append(updatedUsers, el) + } + } + } + + if len(deletedUsers) > 0 { + for _, user := range deletedUsers { + userConv := user.(map[string]interface{}) + urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) + urlValues.Add("userId", userConv["user_id"].(string)) + urlValues.Add("recursivedelete", strconv.FormatBool(userConv["recursive_delete"].(bool))) + _, err := c.decortAPICall("POST", accountDeleteUserAPI, urlValues) + if err != nil { + return err + } + + urlValues = &url.Values{} + } + } + + if len(addedUsers) > 0 { + for _, user := range addedUsers { + userConv := user.(map[string]interface{}) + urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) + urlValues.Add("userId", userConv["user_id"].(string)) + urlValues.Add("accesstype", strings.ToUpper(userConv["access_type"].(string))) + _, err := c.decortAPICall("POST", accountAddUserAPI, urlValues) + if err != nil { + return err + } + + urlValues = &url.Values{} + } + } + + if len(updatedUsers) > 0 { + for _, user := range updatedUsers { + userConv := user.(map[string]interface{}) + urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) + urlValues.Add("userId", userConv["user_id"].(string)) + urlValues.Add("accesstype", strings.ToUpper(userConv["access_type"].(string))) + _, err := c.decortAPICall("POST", accountUpdateUserAPI, urlValues) + if err != nil { + return err + } + + urlValues = &url.Values{} + } + } + + } + + return nil +} + +func isContainsUser(els []interface{}, el interface{}) bool { + for _, elOld := range els { + elOldConv := elOld.(map[string]interface{}) + elConv := el.(map[string]interface{}) + if elOldConv["user_id"].(string) == elConv["user_id"].(string) { + return true + } + } + return false +} + +func isChangedUser(els []interface{}, el interface{}) bool { + for _, elOld := range els { + elOldConv := elOld.(map[string]interface{}) + elConv := el.(map[string]interface{}) + if elOldConv["user_id"].(string) == elConv["user_id"].(string) && + (strings.ToUpper(elOldConv["access_type"].(string)) != strings.ToUpper(elConv["access_type"].(string)) || + elOldConv["recursive_delete"].(bool) != elConv["recursive_delete"].(bool)) { + return true + } + } + return false +} + +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", + }, + "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, + }, + }, + }, + }, + "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, + 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, + 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, + }, + "resources": { + Type: schema.TypeList, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "current": { + Type: schema.TypeList, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disksize": { + 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, + }, + }, + }, + }, + "reserved": { + Type: schema.TypeList, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cpu": { + Type: schema.TypeInt, + Computed: true, + }, + "disksize": { + 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, + }, + }, + }, + }, + }, + }, + }, + "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{ + "can_be_deleted": { + Type: schema.TypeBool, + Computed: true, + }, + "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, + }, + "service_account": { + Type: schema.TypeBool, + Computed: true, + }, + "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, + }, + }, + "computes": { + Type: schema.TypeList, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "started": { + Type: schema.TypeInt, + Computed: true, + }, + "stopped": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "machines": { + Type: schema.TypeList, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "halted": { + Type: schema.TypeInt, + Computed: true, + }, + "running": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, + }, + "vinses": { + Type: schema.TypeInt, + Computed: true, + }, + } +} + +func resourceAccount() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + Create: resourceAccountCreate, + Read: resourceAccountRead, + Update: resourceAccountEdit, + Delete: resourceAccountDelete, + Exists: resourceAccountExists, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: &Timeout60s, + Read: &Timeout30s, + Update: &Timeout60s, + Delete: &Timeout60s, + Default: &Timeout60s, + }, + + Schema: resourceAccountSchemaMake(), + } +} diff --git a/decort/resource_rg.go b/decort/resource_rg.go index 4a07cb6..5528bb4 100644 --- a/decort/resource_rg.go +++ b/decort/resource_rg.go @@ -39,10 +39,6 @@ func resourceResgroupCreate(d *schema.ResourceData, m interface{}) error { // Valid account ID is required to create new resource group // obtain Account ID by account name - it should not be zero on success - validated_account_id, err := utilityGetAccountIdBySchema(d, m) - if err != nil { - return err - } rg_name, arg_set := d.GetOk("name") if !arg_set { @@ -62,7 +58,7 @@ func resourceResgroupCreate(d *schema.ResourceData, m interface{}) error { // all required parameters are set in the schema - we can continue with RG creation log.Debugf("resourceResgroupCreate: called for RG name %s, account ID %d", - rg_name.(string), validated_account_id) + rg_name.(string), d.Get("account_id").(int)) // quota settings are optional set_quota := false @@ -77,10 +73,10 @@ func resourceResgroupCreate(d *schema.ResourceData, m interface{}) error { controller := m.(*ControllerCfg) log.Debugf("resourceResgroupCreate: called by user %q for RG name %s, account ID %d", controller.getDecortUsername(), - rg_name.(string), validated_account_id) + rg_name.(string), d.Get("account_id").(int)) url_values := &url.Values{} - url_values.Add("accountId", fmt.Sprintf("%d", validated_account_id)) + url_values.Add("accountId", fmt.Sprintf("%d", d.Get("account_id").(int))) url_values.Add("name", rg_name.(string)) url_values.Add("gid", fmt.Sprintf("%d", DefaultGridID)) // use default Grid ID, similar to disk resource mgmt convention url_values.Add("owner", controller.getDecortUsername()) diff --git a/decort/utility_account.go b/decort/utility_account.go index f1eaf34..136a939 100644 --- a/decort/utility_account.go +++ b/decort/utility_account.go @@ -1,6 +1,6 @@ /* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: Stanislav Solovev, , Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -26,131 +26,35 @@ package decort import ( "encoding/json" - "fmt" "net/url" + "strconv" log "github.com/sirupsen/logrus" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - // "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) -func utilityAccountCheckPresence(d *schema.ResourceData, m interface{}) (string, error) { +func utilityAccountCheckPresence(d *schema.ResourceData, m interface{}) (*AccountWithResources, error) { + account := &AccountWithResources{} controller := m.(*ControllerCfg) urlValues := &url.Values{} - accId, argSet := d.GetOk("account_id") - if argSet { - // get Account right away by its ID - log.Debugf("utilityAccountCheckPresence: locating Account by its ID %d", accId.(int)) - urlValues.Add("accountId", fmt.Sprintf("%d", accId.(int))) - apiResp, err := controller.decortAPICall("POST", AccountsGetAPI, urlValues) - if err != nil { - return "", err - } - return apiResp, nil + if (strconv.Itoa(d.Get("account_id").(int))) != "0" { + urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) + } else { + urlValues.Add("accountId", d.Id()) } - accName, argSet := d.GetOk("name") - if !argSet { - // neither ID nor name - no account for you! - return "", fmt.Errorf("Cannot check account presence if name is empty and no account ID specified") - } - - apiResp, err := controller.decortAPICall("POST", AccountsListAPI, urlValues) - if err != nil { - return "", err - } - // log.Debugf("%s", apiResp) - // log.Debugf("utilityAccountCheckPresence: ready to decode response body from %q", AccountsListAPI) - accList := AccountsListResp{} - err = json.Unmarshal([]byte(apiResp), &accList) + log.Debugf("utilityAccountCheckPresence: load account") + accountRaw, err := controller.decortAPICall("POST", accountGetAPI, urlValues) if err != nil { - return "", err - } - - log.Debugf("utilityAccountCheckPresence: traversing decoded Json of length %d", len(accList)) - for index, item := range accList { - // match by account name - if item.Name == accName.(string) { - log.Debugf("utilityAccountCheckPresence: match account name %q / ID %d at index %d", - item.Name, item.ID, index) - - // NB: unlike accounts/get API, accounts/list API returns abridged set of account info, - // for instance it does not return quotas - - reencodedItem, err := json.Marshal(item) - if err != nil { - return "", err - } - return string(reencodedItem[:]), nil - } + return nil, err } - return "", fmt.Errorf("Cannot find account name %q", accName.(string)) -} - -func utilityGetAccountIdBySchema(d *schema.ResourceData, m interface{}) (int, error) { - /* - This function expects schema that contains the following two elements: - - "account_name": &schema.Schema{ - Type: schema.TypeString, - Required: Optional, - Description: "Name of the account, ....", - }, - - "account_id": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - Description: "Unique ID of the account, ....", - }, - - Then it will check, which argument is set, and if account name is present, it will - initiate API calls to the DECORT cloud controller and try to match relevant account - by the name. - - NOTE that for some resources (most notably, Resource Group) "account_name" attribute is - marked as "Computed: true", so the only way to fully identify Resource Group is to specify - "account_id", which is marked as "Required: true" - - */ - - accId, argSet := d.GetOk("account_id") - if argSet { - if accId.(int) > 0 { - return accId.(int), nil - } - return 0, fmt.Errorf("Account ID must be positive") - } - - accName, argSet := d.GetOk("account_name") - if !argSet { - return 0, fmt.Errorf("Either non-empty account name or valid account ID must be specified") - } - - controller := m.(*ControllerCfg) - urlValues := &url.Values{} - apiResp, err := controller.decortAPICall("POST", AccountsListAPI, urlValues) - if err != nil { - return 0, err - } - - model := AccountsListResp{} - err = json.Unmarshal([]byte(apiResp), &model) + err = json.Unmarshal([]byte(accountRaw), &account) if err != nil { - return 0, err - } - - log.Debugf("utilityGetAccountIdBySchema: traversing decoded Json of length %d", len(model)) - for index, item := range model { - // need to match Account by name - if item.Name == accName.(string) { - log.Debugf("utilityGetAccountIdBySchema: match Account name %q / ID %d at index %d", - item.Name, item.ID, index) - return item.ID, nil - } + return nil, err } - return 0, fmt.Errorf("Cannot find account %q for the current user. Check account name and your access rights", accName.(string)) + return account, nil } diff --git a/decort/utility_account_audits_list.go b/decort/utility_account_audits_list.go new file mode 100644 index 0000000..283c513 --- /dev/null +++ b/decort/utility_account_audits_list.go @@ -0,0 +1,56 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "encoding/json" + "net/url" + "strconv" + + log "github.com/sirupsen/logrus" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func utilityAccountAuditsListCheckPresence(d *schema.ResourceData, m interface{}) (AccountAuditsList, error) { + accountAuditsList := AccountAuditsList{} + controller := m.(*ControllerCfg) + urlValues := &url.Values{} + + urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) + + log.Debugf("utilityAccountAuditsListCheckPresence: load account list") + accountAuditsListRaw, err := controller.decortAPICall("POST", accountAuditsAPI, urlValues) + if err != nil { + return nil, err + } + + err = json.Unmarshal([]byte(accountAuditsListRaw), &accountAuditsList) + if err != nil { + return nil, err + } + + return accountAuditsList, nil +} diff --git a/decort/utility_account_computes_list.go b/decort/utility_account_computes_list.go new file mode 100644 index 0000000..6c92590 --- /dev/null +++ b/decort/utility_account_computes_list.go @@ -0,0 +1,56 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "encoding/json" + "net/url" + "strconv" + + log "github.com/sirupsen/logrus" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func utilityAccountComputesListCheckPresence(d *schema.ResourceData, m interface{}) (AccountComputesList, error) { + accountComputesList := AccountComputesList{} + controller := m.(*ControllerCfg) + urlValues := &url.Values{} + + urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) + + log.Debugf("utilityAccountComputesListCheckPresence: load account list") + accountComputesListRaw, err := controller.decortAPICall("POST", accountListComputesAPI, urlValues) + if err != nil { + return nil, err + } + + err = json.Unmarshal([]byte(accountComputesListRaw), &accountComputesList) + if err != nil { + return nil, err + } + + return accountComputesList, nil +} diff --git a/decort/utility_account_consumed_units.go b/decort/utility_account_consumed_units.go new file mode 100644 index 0000000..b5cdd1e --- /dev/null +++ b/decort/utility_account_consumed_units.go @@ -0,0 +1,56 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "encoding/json" + "net/url" + "strconv" + + log "github.com/sirupsen/logrus" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func utilityAccountConsumedUnitsCheckPresence(d *schema.ResourceData, m interface{}) (*ResourceLimits, error) { + accountConsumedUnits := &ResourceLimits{} + controller := m.(*ControllerCfg) + urlValues := &url.Values{} + + urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) + + log.Debugf("utilityAccountConsumedUnitsCheckPresence: load account list") + accountConsumedUnitsRaw, err := controller.decortAPICall("POST", accountGetConsumedUnitsAPI, urlValues) + if err != nil { + return nil, err + } + + err = json.Unmarshal([]byte(accountConsumedUnitsRaw), accountConsumedUnits) + if err != nil { + return nil, err + } + + return accountConsumedUnits, nil +} diff --git a/decort/utility_account_consumed_units_by_type.go b/decort/utility_account_consumed_units_by_type.go new file mode 100644 index 0000000..d0d65f2 --- /dev/null +++ b/decort/utility_account_consumed_units_by_type.go @@ -0,0 +1,55 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "net/url" + "strconv" + "strings" + + log "github.com/sirupsen/logrus" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func utilityAccountConsumedUnitsByTypeCheckPresence(d *schema.ResourceData, m interface{}) (float64, error) { + controller := m.(*ControllerCfg) + urlValues := &url.Values{} + + urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) + urlValues.Add("cutype", strings.ToUpper(d.Get("cu_type").(string))) + + log.Debugf("utilityAccountConsumedUnitsByTypeCheckPresence") + resultRaw, err := controller.decortAPICall("POST", accountGetConsumedUnitsByTypeAPI, urlValues) + if err != nil { + return 0, err + } + result, err := strconv.ParseFloat(resultRaw, 64) + if err != nil { + return 0, err + } + + return result, nil +} diff --git a/decort/utility_account_deleted_list.go b/decort/utility_account_deleted_list.go new file mode 100644 index 0000000..7c82750 --- /dev/null +++ b/decort/utility_account_deleted_list.go @@ -0,0 +1,61 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "encoding/json" + "net/url" + "strconv" + + log "github.com/sirupsen/logrus" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func utilityAccountDeletedListCheckPresence(d *schema.ResourceData, m interface{}) (AccountCloudApiList, error) { + accountDeletedList := AccountCloudApiList{} + controller := m.(*ControllerCfg) + urlValues := &url.Values{} + + if page, ok := d.GetOk("page"); ok { + urlValues.Add("page", strconv.Itoa(page.(int))) + } + if size, ok := d.GetOk("size"); ok { + urlValues.Add("size", strconv.Itoa(size.(int))) + } + + log.Debugf("utilityAccountDeletedListCheckPresence: load") + accountDeletedListRaw, err := controller.decortAPICall("POST", accountListDeletedAPI, urlValues) + if err != nil { + return nil, err + } + + err = json.Unmarshal([]byte(accountDeletedListRaw), &accountDeletedList) + if err != nil { + return nil, err + } + + return accountDeletedList, nil +} diff --git a/decort/utility_account_disks_list.go b/decort/utility_account_disks_list.go new file mode 100644 index 0000000..941a2bc --- /dev/null +++ b/decort/utility_account_disks_list.go @@ -0,0 +1,56 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "encoding/json" + "net/url" + "strconv" + + log "github.com/sirupsen/logrus" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func utilityAccountDisksListCheckPresence(d *schema.ResourceData, m interface{}) (AccountDisksList, error) { + accountDisksList := AccountDisksList{} + controller := m.(*ControllerCfg) + urlValues := &url.Values{} + + urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) + + log.Debugf("utilityAccountDisksListCheckPresence: load account list") + accountDisksListRaw, err := controller.decortAPICall("POST", accountListDisksAPI, urlValues) + if err != nil { + return nil, err + } + + err = json.Unmarshal([]byte(accountDisksListRaw), &accountDisksList) + if err != nil { + return nil, err + } + + return accountDisksList, nil +} diff --git a/decort/utility_account_flip_groups.go b/decort/utility_account_flip_groups.go new file mode 100644 index 0000000..df2c36b --- /dev/null +++ b/decort/utility_account_flip_groups.go @@ -0,0 +1,56 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "encoding/json" + "net/url" + "strconv" + + log "github.com/sirupsen/logrus" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func utilityAccountFlipGroupsListCheckPresence(d *schema.ResourceData, m interface{}) (AccountFlipGroupsList, error) { + accountFlipGroupsList := AccountFlipGroupsList{} + controller := m.(*ControllerCfg) + urlValues := &url.Values{} + + urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) + + log.Debugf("utilityAccountFlipGroupsListCheckPresence") + accountFlipGroupsListRaw, err := controller.decortAPICall("POST", accountListFlipGroupsAPI, urlValues) + if err != nil { + return nil, err + } + + err = json.Unmarshal([]byte(accountFlipGroupsListRaw), &accountFlipGroupsList) + if err != nil { + return nil, err + } + + return accountFlipGroupsList, nil +} diff --git a/decort/utility_account_list.go b/decort/utility_account_list.go new file mode 100644 index 0000000..0dd3514 --- /dev/null +++ b/decort/utility_account_list.go @@ -0,0 +1,89 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "encoding/json" + "net/url" + "strconv" + + log "github.com/sirupsen/logrus" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func utilityAccountListCheckPresence(d *schema.ResourceData, m interface{}) (AccountCloudApiList, error) { + accountList := AccountCloudApiList{} + controller := m.(*ControllerCfg) + urlValues := &url.Values{} + + if page, ok := d.GetOk("page"); ok { + urlValues.Add("page", strconv.Itoa(page.(int))) + } + if size, ok := d.GetOk("size"); ok { + urlValues.Add("size", strconv.Itoa(size.(int))) + } + + log.Debugf("utilityAccountListCheckPresence: load account list") + accountListRaw, err := controller.decortAPICall("POST", accountListAPI, urlValues) + if err != nil { + return nil, err + } + + err = json.Unmarshal([]byte(accountListRaw), &accountList) + if err != nil { + return nil, err + } + + return accountList, nil +} + +/*uncomment for cloudbroker +func utilityAccountListCheckPresence(d *schema.ResourceData, m interface{}) (AccountList, error) { + accountList := AccountList{} + controller := m.(*ControllerCfg) + urlValues := &url.Values{} + + if page, ok := d.GetOk("page"); ok { + urlValues.Add("page", strconv.Itoa(page.(int))) + } + if size, ok := d.GetOk("size"); ok { + urlValues.Add("size", strconv.Itoa(size.(int))) + } + + log.Debugf("utilityAccountListCheckPresence: load account list") + accountListRaw, err := controller.decortAPICall("POST", accountListAPI, urlValues) + if err != nil { + return nil, err + } + + err = json.Unmarshal([]byte(accountListRaw), &accountList) + if err != nil { + return nil, err + } + + return accountList, nil +} +*/ diff --git a/decort/utility_account_reserved_units.go b/decort/utility_account_reserved_units.go new file mode 100644 index 0000000..31bd4b9 --- /dev/null +++ b/decort/utility_account_reserved_units.go @@ -0,0 +1,56 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "encoding/json" + "net/url" + "strconv" + + log "github.com/sirupsen/logrus" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func utilityAccountReservedUnitsCheckPresence(d *schema.ResourceData, m interface{}) (*ResourceLimits, error) { + accountReservedUnits := &ResourceLimits{} + controller := m.(*ControllerCfg) + urlValues := &url.Values{} + + urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) + + log.Debugf("utilityAccountReservedUnitsCheckPresence: load units") + accountReservedUnitsRaw, err := controller.decortAPICall("POST", accountGetReservedUnitsAPI, urlValues) + if err != nil { + return nil, err + } + + err = json.Unmarshal([]byte(accountReservedUnitsRaw), accountReservedUnits) + if err != nil { + return nil, err + } + + return accountReservedUnits, nil +} diff --git a/decort/utility_account_rg_list.go b/decort/utility_account_rg_list.go new file mode 100644 index 0000000..0145b3a --- /dev/null +++ b/decort/utility_account_rg_list.go @@ -0,0 +1,56 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "encoding/json" + "net/url" + "strconv" + + log "github.com/sirupsen/logrus" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func utilityAccountRGListCheckPresence(d *schema.ResourceData, m interface{}) (AccountRGList, error) { + accountRGList := AccountRGList{} + controller := m.(*ControllerCfg) + urlValues := &url.Values{} + + urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) + + log.Debugf("utilityAccountRGListCheckPresence: load account list") + accountRGListRaw, err := controller.decortAPICall("POST", accountListRGAPI, urlValues) + if err != nil { + return nil, err + } + + err = json.Unmarshal([]byte(accountRGListRaw), &accountRGList) + if err != nil { + return nil, err + } + + return accountRGList, nil +} diff --git a/decort/utility_account_templates_list.go b/decort/utility_account_templates_list.go new file mode 100644 index 0000000..2dd3a2e --- /dev/null +++ b/decort/utility_account_templates_list.go @@ -0,0 +1,56 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "encoding/json" + "net/url" + "strconv" + + log "github.com/sirupsen/logrus" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func utilityAccountTemplatesListCheckPresence(d *schema.ResourceData, m interface{}) (AccountTemplatesList, error) { + accountTemplatesList := AccountTemplatesList{} + controller := m.(*ControllerCfg) + urlValues := &url.Values{} + + urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) + + log.Debugf("utilityAccountTemplatesListCheckPresence: load") + accountTemplatesListRaw, err := controller.decortAPICall("POST", accountListTemplatesAPI, urlValues) + if err != nil { + return nil, err + } + + err = json.Unmarshal([]byte(accountTemplatesListRaw), &accountTemplatesList) + if err != nil { + return nil, err + } + + return accountTemplatesList, nil +} diff --git a/decort/utility_account_vins_list.go b/decort/utility_account_vins_list.go new file mode 100644 index 0000000..31291ff --- /dev/null +++ b/decort/utility_account_vins_list.go @@ -0,0 +1,56 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Author: 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. +*/ + +/* +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +Technology platfom. + +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +*/ + +package decort + +import ( + "encoding/json" + "net/url" + "strconv" + + log "github.com/sirupsen/logrus" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func utilityAccountVinsListCheckPresence(d *schema.ResourceData, m interface{}) (AccountVinsList, error) { + accountVinsList := AccountVinsList{} + controller := m.(*ControllerCfg) + urlValues := &url.Values{} + + urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) + + log.Debugf("utilityAccountVinsListCheckPresence: load account list") + accountVinsListRaw, err := controller.decortAPICall("POST", accountListVinsAPI, urlValues) + if err != nil { + return nil, err + } + + err = json.Unmarshal([]byte(accountVinsListRaw), &accountVinsList) + if err != nil { + return nil, err + } + + return accountVinsList, nil +} diff --git a/decort/utility_disk.go b/decort/utility_disk.go index 1422c03..c9a8605 100644 --- a/decort/utility_disk.go +++ b/decort/utility_disk.go @@ -16,16 +16,15 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration +This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration Technology platfom. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. */ package decort import ( - "encoding/json" "fmt" "net/url" @@ -36,16 +35,15 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) - func utilityDiskCheckPresence(d *schema.ResourceData, m interface{}) (string, error) { - // This function tries to locate Disk by one of the following algorithms depending on + // This function tries to locate Disk by one of the following algorithms depending on // the parameters passed: // - if disk ID is specified -> by disk ID // - if disk name is specifeid -> by disk name and either account ID or account name // // NOTE: disk names are not unique, so the first occurence of this name in the account will // be returned. There is no such ambiguity when locating disk by its ID. - // + // // If succeeded, it returns non empty string that contains JSON formatted facts about the disk // as returned by disks/get API call. // Otherwise it returns empty string and meaningful error. @@ -64,7 +62,7 @@ func utilityDiskCheckPresence(d *schema.ResourceData, m interface{}) (string, er if err != nil || theId <= 0 { diskId, argSet := d.GetOk("disk_id") if argSet { - theId =diskId.(int) + theId = diskId.(int) idSet = true } } else { @@ -92,18 +90,14 @@ func utilityDiskCheckPresence(d *schema.ResourceData, m interface{}) (string, er // Valid account ID is required to locate disks // obtain Account ID by account name - it should not be zero on success - validatedAccountId, err := utilityGetAccountIdBySchema(d, m) - if err != nil { - return "", err - } - urlValues.Add("accountId", fmt.Sprintf("%d", validatedAccountId)) + urlValues.Add("accountId", fmt.Sprintf("%d", d.Get("account_id").(int))) diskFacts, err := controller.decortAPICall("POST", DisksListAPI, urlValues) if err != nil { return "", err } - log.Debugf("utilityDiskCheckPresence: ready to unmarshal string %s", diskFacts) + log.Debugf("utilityDiskCheckPresence: ready to unmarshal string %s", diskFacts) disksList := DisksListResp{} err = json.Unmarshal([]byte(diskFacts), &disksList) @@ -119,25 +113,25 @@ func utilityDiskCheckPresence(d *schema.ResourceData, m interface{}) (string, er log.Debugf("utilityDiskCheckPresence: index %d, matched disk name %q", index, item.Name) // we found the disk we need - not get detailed information via API call to disks/get /* - // TODO: this may not be optimal as it initiates one extra call to the DECORT controller - // in spite of the fact that we already have all required information about the disk in - // item variable - // - get_urlValues := &url.Values{} - get_urlValues.Add("diskId", fmt.Sprintf("%d", item.ID)) - diskFacts, err = controller.decortAPICall("POST", DisksGetAPI, get_urlValues) - if err != nil { - return "", err - } - return diskFacts, nil + // TODO: this may not be optimal as it initiates one extra call to the DECORT controller + // in spite of the fact that we already have all required information about the disk in + // item variable + // + get_urlValues := &url.Values{} + get_urlValues.Add("diskId", fmt.Sprintf("%d", item.ID)) + diskFacts, err = controller.decortAPICall("POST", DisksGetAPI, get_urlValues) + if err != nil { + return "", err + } + return diskFacts, nil */ reencodedItem, err := json.Marshal(item) if err != nil { return "", err } - return string(reencodedItem[:]), nil + return string(reencodedItem[:]), nil } } return "", nil // there should be no error if disk does not exist -} \ No newline at end of file +} diff --git a/decort/utility_rg.go b/decort/utility_rg.go index 371e678..6a62ebd 100644 --- a/decort/utility_rg.go +++ b/decort/utility_rg.go @@ -104,7 +104,7 @@ func utilityResgroupCheckPresence(d *schema.ResourceData, m interface{}) (string } else { idSet = true } - + if idSet { // go straight for the RG by its ID log.Debugf("utilityResgroupCheckPresence: locating RG by its ID %d", theId) @@ -124,10 +124,6 @@ func utilityResgroupCheckPresence(d *schema.ResourceData, m interface{}) (string // Valid account ID is required to locate a resource group // obtain Account ID by account name - it should not be zero on success - validatedAccountId, err := utilityGetAccountIdBySchema(d, m) - if err != nil { - return "", err - } urlValues.Add("includedeleted", "false") apiResp, err := controller.decortAPICall("POST", ResgroupListAPI, urlValues) @@ -145,7 +141,7 @@ func utilityResgroupCheckPresence(d *schema.ResourceData, m interface{}) (string log.Debugf("utilityResgroupCheckPresence: traversing decoded Json of length %d", len(model)) for index, item := range model { // match by RG name & account ID - if item.Name == rgName.(string) && item.AccountID == validatedAccountId { + if item.Name == rgName.(string) && item.AccountID == d.Get("account_id").(int) { log.Debugf("utilityResgroupCheckPresence: match RG name %s / ID %d, account ID %d at index %d", item.Name, item.ID, item.AccountID, index) @@ -163,7 +159,7 @@ func utilityResgroupCheckPresence(d *schema.ResourceData, m interface{}) (string } } - return "", fmt.Errorf("Cannot find RG name %s owned by account ID %d", rgName, validatedAccountId) + return "", fmt.Errorf("Cannot find RG name %s owned by account ID %d", rgName, d.Get("account_id").(int)) } func utilityResgroupGetDefaultGridID() (interface{}, error) { @@ -172,4 +168,4 @@ func utilityResgroupGetDefaultGridID() (interface{}, error) { } return "", fmt.Errorf("utilityResgroupGetDefaultGridID: invalid default Grid ID %d", DefaultGridID) - } +} diff --git a/samples/README.md b/samples/README.md index 6761a86..db5b79e 100644 --- a/samples/README.md +++ b/samples/README.md @@ -20,6 +20,18 @@ - vgpu - disk_list - rg_list + - account_list + - account_computes_list + - account_disks_list + - account_vins_list + - account_audits_list + - account + - account_rg_list + - account_counsumed_units + - account_counsumed_units_by_type + - account_reserved_units + - account_templates_list + - account_deleted_list - resources: - image - virtual_image @@ -31,6 +43,7 @@ - pcidevice - sep - sep_config + - account ## Как пользоваться примерами 1. Установить terraform diff --git a/samples/data_account/main.tf b/samples/data_account/main.tf new file mode 100644 index 0000000..1cc63dc --- /dev/null +++ b/samples/data_account/main.tf @@ -0,0 +1,39 @@ +/* +Пример использования +Получение информации об аккаунте + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "1.1" + source = "digitalenergy.online/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "oauth2" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_account" "a" { + #id аккаунта + #обязательный параметр + #тип - число + account_id = 28096 + +} + +output "test" { + value = data.decort_account.a +} diff --git a/samples/data_account_audits_list/main.tf b/samples/data_account_audits_list/main.tf new file mode 100644 index 0000000..a30b152 --- /dev/null +++ b/samples/data_account_audits_list/main.tf @@ -0,0 +1,40 @@ +/* +Пример использования +Получение информации об использовании аккаунта + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "1.1" + source = "digitalenergy.online/decort/decort" + } + } +} +*/ + + +provider "decort" { + authenticator = "oauth2" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_account_audits_list" "aal" { + #id аккаунта + #обязательный параметр + #тип - число + account_id = 28096 + +} + +output "test" { + value = data.decort_account_audits_list.aal +} diff --git a/samples/data_account_computes_list/main.tf b/samples/data_account_computes_list/main.tf new file mode 100644 index 0000000..26edae2 --- /dev/null +++ b/samples/data_account_computes_list/main.tf @@ -0,0 +1,39 @@ +/* +Пример использования +Получение списка computes, используемых аккаунтом + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "1.1" + source = "digitalenergy.online/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "oauth2" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_account_computes_list" "acl" { + #id аккаунта + #обязательный параметр + #тип - число + account_id = 1111 + +} + +output "test" { + value = data.decort_account_computes_list.acl +} diff --git a/samples/data_account_consumed_units/main.tf b/samples/data_account_consumed_units/main.tf new file mode 100644 index 0000000..b12b1df --- /dev/null +++ b/samples/data_account_consumed_units/main.tf @@ -0,0 +1,37 @@ +/* +Пример использования +Получение информации о расходуемых ресурсах аккаута +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "1.1" + source = "digitalenergy.online/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "oauth2" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_account_consumed_units" "acu" { + #id аккаунта + #обязательный параметр + #тип - число + account_id = 88366 +} + +output "test" { + value = data.decort_account_consumed_units.acu +} diff --git a/samples/data_account_consumed_units_by_type/main.tf b/samples/data_account_consumed_units_by_type/main.tf new file mode 100644 index 0000000..67d3043 --- /dev/null +++ b/samples/data_account_consumed_units_by_type/main.tf @@ -0,0 +1,54 @@ +/* +Пример использования +Ресурса cdrom image +Ресурс позволяет: +1. Создавать образ +2. Редактировать образ +3. Удалять образ + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "1.1" + source = "digitalenergy.online/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "oauth2" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_account_consumed_units_by_type" "acubt" { + #id аккаунта + #обязательный параметр + #тип - число + account_id = 88366 + + #тип вычислительной еденицы + #обязательный параметр + #тип - строка + #значения: + #cu_c - кол-во виртуальных cpu ядер + #cu_m - кол-во RAM в МБ + #cu_d - кол-в используемой дисковой памяти, в ГБ + #cu_i - кол-во публичных ip адресов + #cu_np - кол-во полученного/отданного трафика, в ГБ + #gpu_units - кол-во gpu ядер + cu_type = "cu_a" +} + +output "test" { + value = data.decort_account_consumed_units_by_type.acubt +} diff --git a/samples/data_account_deleted_list/main.tf b/samples/data_account_deleted_list/main.tf new file mode 100644 index 0000000..7309fcd --- /dev/null +++ b/samples/data_account_deleted_list/main.tf @@ -0,0 +1,45 @@ +/* +Пример использования +Получение информации об удаленных аккаунтах +Информация предоставляется только по аккаунтам, удаленным без флага permanently +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "1.1" + source = "digitalenergy.online/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "oauth2" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_account_deleted_list" "adl" { + #номер страницы для отображения + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #page = 2 + + #размер страницы + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #size = 3 +} + +output "test" { + value = data.decort_account_deleted_list.adl +} diff --git a/samples/data_account_disks_list/main.tf b/samples/data_account_disks_list/main.tf new file mode 100644 index 0000000..ff6b4fa --- /dev/null +++ b/samples/data_account_disks_list/main.tf @@ -0,0 +1,39 @@ +/* +Пример использования +Получение информации о дисках, которые использует аккаунт + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "1.1" + source = "digitalenergy.online/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "oauth2" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_account_disks_list" "adl" { + #id аккаунта + #обязательный параметр + #тип - число + account_id = 28096 + +} + +output "test" { + value = data.decort_account_disks_list.adl +} diff --git a/samples/data_account_flipgroups_list/main.tf b/samples/data_account_flipgroups_list/main.tf new file mode 100644 index 0000000..134d621 --- /dev/null +++ b/samples/data_account_flipgroups_list/main.tf @@ -0,0 +1,38 @@ +/* +Пример использования +Получение информации о flipgroups, используемых аккаунтом + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "1.1" + source = "digitalenergy.online/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "oauth2" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_account_flipgroups_list" "afgl" { + #id аккаунта + #обязательный параметр + #тип - число + account_id = 1111 +} + +output "test" { + value = data.decort_account_flipgroups_list.afgl +} diff --git a/samples/data_account_list/main.tf b/samples/data_account_list/main.tf new file mode 100644 index 0000000..722077a --- /dev/null +++ b/samples/data_account_list/main.tf @@ -0,0 +1,45 @@ +/* +Пример использования +Получение списка доступных аккаунтов + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "1.1" + source = "digitalenergy.online/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "oauth2" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_account_list" "al" { + #номер страницы для отображения + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #page = 2 + + #размер страницы + #опциональный параметр + #тип - число + #если не задан - выводятся все доступные данные + #size = 3 +} + +output "test" { + value = data.decort_account_list.al +} diff --git a/samples/data_account_reserved_units/main.tf b/samples/data_account_reserved_units/main.tf new file mode 100644 index 0000000..f86a3dc --- /dev/null +++ b/samples/data_account_reserved_units/main.tf @@ -0,0 +1,38 @@ +/* +Пример использования +Получение информии о зарезервированных вычислительных мощностях + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "1.1" + source = "digitalenergy.online/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "oauth2" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_account_reserved_units" "aru" { + #id аккаунта + #обязательный параметр + #тип - число + account_id = 88366 +} + +output "test" { + value = data.decort_account_reserved_units.aru +} diff --git a/samples/data_account_rg_list/main.tf b/samples/data_account_rg_list/main.tf new file mode 100644 index 0000000..48d5418 --- /dev/null +++ b/samples/data_account_rg_list/main.tf @@ -0,0 +1,37 @@ +/* +Пример использования +Получение информации о ресурных группах, используемых аккаунтом +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "1.1" + source = "digitalenergy.online/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "oauth2" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_account_rg_list" "argl" { + #id аккаунта + #обязательный параметр + #тип - число + account_id = 88366 +} + +output "test" { + value = data.decort_account_rg_list.argl +} diff --git a/samples/data_account_templates_list/main.tf b/samples/data_account_templates_list/main.tf new file mode 100644 index 0000000..276fe68 --- /dev/null +++ b/samples/data_account_templates_list/main.tf @@ -0,0 +1,38 @@ +/* +Пример использования +Получение информации о шаблонах, используемых аккаунтом + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером + +terraform { + required_providers { + decort = { + version = "1.1" + source = "digitalenergy.online/decort/decort" + } + } +} + + +provider "decort" { + authenticator = "oauth2" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_account_templates_list" "atl" { + #id аккаунта + #обязательный параметр + #тип - число + account_id = 11111 +} + +output "test" { + value = data.decort_account_templates_list.atl +} diff --git a/samples/data_account_vins_list/main.tf b/samples/data_account_vins_list/main.tf new file mode 100644 index 0000000..da28996 --- /dev/null +++ b/samples/data_account_vins_list/main.tf @@ -0,0 +1,39 @@ +/* +Пример использования +Получение списка vins, используемых аккаунтом + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "1.1" + source = "digitalenergy.online/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "oauth2" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +data "decort_account_vins_list" "avl" { + #id аккаунта + #обязательный параметр + #тип - число + account_id = 28096 + +} + +output "test" { + value = data.decort_account_vins_list.avl +} diff --git a/samples/resource_account/main.tf b/samples/resource_account/main.tf new file mode 100644 index 0000000..f8bcf72 --- /dev/null +++ b/samples/resource_account/main.tf @@ -0,0 +1,159 @@ +/* +Пример использования +Ресурса account +Ресурс позволяет: +1. Создавать аккаунт +2. Редактировать аккаунт +3. Удалять аккаунт + +*/ +#Расскомментируйте этот код, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером +/* +terraform { + required_providers { + decort = { + version = "1.1" + source = "digitalenergy.online/decort/decort" + } + } +} +*/ + +provider "decort" { + authenticator = "oauth2" + #controller_url = + controller_url = "https://ds1.digitalenergy.online" + #oauth2_url = + oauth2_url = "https://sso.digitalenergy.online" + allow_unverified_ssl = true +} + +resource "decort_account" "a" { + #имя аккаунта + #обязательный параметр + #тип - строка + #используется при создании и редактировании аккаунта + account_name = "new_my_account" + + #имя пользователя - создателя аккаунта + #обязательный параметр + #тип - строка + username = "username@decs3o" + + #доступность аккаунта + #необязательный параметр + #тип - будев тип + #может применяться при редактировании аккаунта + enable = true + + #id аккаунта, позволяет сформировать .tfstate, если аккаунт имеет в платформе + #необязательный параметр + #тип - число + account_id = 11111 + + #электронная почта, на которую будет отправлена информация о доступе + #необязательный параметр + #тип - строка + #применяется при создании аккаунта + emailaddress = "fff@fff.ff" + + #отправлять ли на электронную почту письмо о доступе + #необязательный параметр + #тип - булев тип + #применяется при создании аккаунта и редактировании аккаунта + send_access_emails = true + + #добавление/редактирование/удаление пользователей, к которым привязан аккаунт + #необязательный параметр + #тип - объект, кол-во таких объектов не ограничено + /*users { + #id пользователя + #обязательный параметр + #тип - строка + user_id = "username_2@decs3o" + + #тип доступа пользователя + #обязательный параметр + #тип - строка + #возможные параметры: + #R - чтение + #RCX - запись + #ARCXDU - админ + access_type = "R" + + #рекурсивное удаление пользователя из всех ресурсов аккаунтов + #необязательный параметр + #тип - булев тип + #по-умолчанию - false + #применяется при удалении пользователя из аккаунта + recursive_delete = true + } + users { + user_id = "username_1@decs3o" + access_type = "R" + }*/ + + #ограничение используемых ресурсов + #необязательный параметр + #тип - объект + #используется при создании и редактировании + resource_limits { + #кол-во используемых ядер cpu + #необязательный параметр + #тип - ичсло + #если установлена -1 - кол-во неограичено + cu_c = 2 + + #кол-во используемой RAM в МБ + #необязательный параметр + #тип - ичсло + #если установлена -1 - кол-во неограичено + cu_m = 1024 + + #размер дисков, в ГБ + #необязательный параметр + #тип - ичсло + #если установлена -1 - размер неограичен + cu_d = 23 + + #кол-во используемых публичных IP + #необязательный параметр + #тип - ичсло + #если установлена -1 - кол-во неограичено + cu_i = 2 + + #ограничения на кол-во передачи данных, в ГБ + #необязательный параметр + #тип - ичсло + #если установлена -1 - кол-во неограичено + cu_np = 2 + + #кол-во графических процессоров + #необязательный параметр + #тип - ичсло + #если установлена -1 - кол-во неограичено + gpu_units = 2 + } + + #восстановление аккаунта + #необязательный параметр + #тип - булев тип + #применяется к удаленным аккаунтам + #по-умолчанию - false + #retore = false + + #мгновеное удаление аккаунта, если да - то аккаунт невозможно будет восстановить + #необязательный параметр + #тип - булев тип + #используется при удалении аккаунта + #по-умолчанию - false + #permanently = true + + +} + +output "test" { + value = decort_account.a +}