Add a account disks list
This commit is contained in:
119
decort/data_source_account_disks_list.go
Normal file
119
decort/data_source_account_disks_list.go
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
|
Author: Sergey Shubin, <sergey.shubin@digitalenergy.online>, <svs1370@gmail.com>
|
||||||
|
|
||||||
|
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 _, acc := range adl {
|
||||||
|
temp := map[string]interface{}{
|
||||||
|
"disk_id": acc.ID,
|
||||||
|
"disk_name": acc.Name,
|
||||||
|
"pool": acc.Pool,
|
||||||
|
"sep_id": acc.SepId,
|
||||||
|
"size_max": acc.SizeMax,
|
||||||
|
"type": acc.Type,
|
||||||
|
}
|
||||||
|
res = append(res, temp)
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func dataSourceAccountDiskssListRead(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: dataSourceAccountDiskssListRead,
|
||||||
|
|
||||||
|
Timeouts: &schema.ResourceTimeout{
|
||||||
|
Read: &Timeout30s,
|
||||||
|
Default: &Timeout60s,
|
||||||
|
},
|
||||||
|
|
||||||
|
Schema: dataSourceAccountDisksListSchemaMake(),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1015,7 +1015,9 @@ const accountListAPI = "/restmachine/cloudbroker/account/list"
|
|||||||
const accountListComputesAPI = "/restmachine/cloudbroker/account/listComputes"
|
const accountListComputesAPI = "/restmachine/cloudbroker/account/listComputes"
|
||||||
const accountListCSAPI = "/cloudapi/account/listCS"
|
const accountListCSAPI = "/cloudapi/account/listCS"
|
||||||
const accountListDeletedAPI = "/cloudapi/account/listDeleted"
|
const accountListDeletedAPI = "/cloudapi/account/listDeleted"
|
||||||
const accountListDisksAPI = "/cloudapi/account/listDisks"
|
|
||||||
|
//const accountListDisksAPI = "/restmachine/cloudapi/account/listDisks"
|
||||||
|
const accountListDisksAPI = "/restmachine/cloudbroker/account/listDisks"
|
||||||
const accountListFlipGroupsAPI = "/cloudapi/account/listFlipGroups"
|
const accountListFlipGroupsAPI = "/cloudapi/account/listFlipGroups"
|
||||||
const accountListRGAPI = "/cloudapi/account/listRG"
|
const accountListRGAPI = "/cloudapi/account/listRG"
|
||||||
const accountListTemplatesAPI = "/cloudapi/account/listTemplates"
|
const accountListTemplatesAPI = "/cloudapi/account/listTemplates"
|
||||||
@@ -1097,3 +1099,14 @@ type AccountCompute struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AccountComputesList []AccountCompute
|
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
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ func Provider() *schema.Provider {
|
|||||||
"decort_rg_list": dataSourceRgList(),
|
"decort_rg_list": dataSourceRgList(),
|
||||||
"decort_account_list": dataSourceAccountList(),
|
"decort_account_list": dataSourceAccountList(),
|
||||||
"decort_account_computes_list": dataSourceAccountComputesList(),
|
"decort_account_computes_list": dataSourceAccountComputesList(),
|
||||||
|
"decort_account_disks_list": dataSourceAccountDisksList(),
|
||||||
// "decort_pfw": dataSourcePfw(),
|
// "decort_pfw": dataSourcePfw(),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
56
decort/utility_account_disks_list.go
Normal file
56
decort/utility_account_disks_list.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
|
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
39
samples/account_disks_list/main.tf
Normal file
39
samples/account_disks_list/main.tf
Normal file
@@ -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 = <DECORT_CONTROLLER_URL>
|
||||||
|
controller_url = "https://ds1.digitalenergy.online"
|
||||||
|
#oauth2_url = <DECORT_SSO_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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user