diff --git a/decort/data_account_deleted_list.go b/decort/data_account_deleted_list.go new file mode 100644 index 0000000..d2a57c5 --- /dev/null +++ b/decort/data_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/models_api.go b/decort/models_api.go index cbdf434..7e893eb 100644 --- a/decort/models_api.go +++ b/decort/models_api.go @@ -997,7 +997,6 @@ 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 accountDeleteAccountsAPI = "/cloudapi/account/deleteAccounts" const accountDeleteUserAPI = "/restmachine/cloudapi/account/deleteUser" const accountDisableAPI = "/restmachine/cloudapi/account/disable" const accountEnableAPI = "/restmachine/cloudapi/account/enable" @@ -1008,7 +1007,7 @@ const accountGetReservedUnitsAPI = "/restmachine/cloudapi/account/getReservedAcc const accountListAPI = "/restmachine/cloudapi/account/list" const accountListComputesAPI = "/restmachine/cloudapi/account/listComputes" const accountListCSAPI = "/cloudapi/account/listCS" -const accountListDeletedAPI = "/cloudapi/account/listDeleted" +const accountListDeletedAPI = "/restmachine/cloudapi/account/listDeleted" const accountListDisksAPI = "/restmachine/cloudapi/account/listDisks" const accountListFlipGroupsAPI = "/cloudapi/account/listFlipGroups" const accountListRGAPI = "/restmachine/cloudapi/account/listRG" diff --git a/decort/provider.go b/decort/provider.go index 0e48ce6..22c365e 100644 --- a/decort/provider.go +++ b/decort/provider.go @@ -150,6 +150,7 @@ func Provider() *schema.Provider { "decort_account_consumed_units_by_type": dataSourceAccountConsumedUnitsByType(), "decort_account_reserved_units": dataSourceAccountReservedUnits(), "decort_account_templates_list": dataSourceAccountTemplatessList(), + "decort_account_deleted_list": dataSourceAccountDeletedList(), // "decort_pfw": dataSourcePfw(), }, 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/samples/README.md b/samples/README.md index 291ac14..db5b79e 100644 --- a/samples/README.md +++ b/samples/README.md @@ -31,6 +31,7 @@ - account_counsumed_units_by_type - account_reserved_units - account_templates_list + - account_deleted_list - resources: - image - virtual_image 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 +}