Add data for account consumed units by type
This commit is contained in:
78
decort/data_account_consumed_units_by_type.go
Normal file
78
decort/data_account_consumed_units_by_type.go
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
|
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1003,6 +1003,7 @@ const accountDisableAPI = "/restmachine/cloudapi/account/disable"
|
|||||||
const accountEnableAPI = "/restmachine/cloudapi/account/enable"
|
const accountEnableAPI = "/restmachine/cloudapi/account/enable"
|
||||||
const accountGetAPI = "/restmachine/cloudapi/account/get"
|
const accountGetAPI = "/restmachine/cloudapi/account/get"
|
||||||
const accountGetConsumedUnitsAPI = "/restmachine/cloudapi/account/getConsumedAccountUnits"
|
const accountGetConsumedUnitsAPI = "/restmachine/cloudapi/account/getConsumedAccountUnits"
|
||||||
|
const accountGetConsumedUnitsByTypeAPI = "/restmachine/cloudapi/account/getConsumedCloudUnitsByType"
|
||||||
const accountListAPI = "/restmachine/cloudapi/account/list"
|
const accountListAPI = "/restmachine/cloudapi/account/list"
|
||||||
const accountListComputesAPI = "/restmachine/cloudapi/account/listComputes"
|
const accountListComputesAPI = "/restmachine/cloudapi/account/listComputes"
|
||||||
const accountListCSAPI = "/cloudapi/account/listCS"
|
const accountListCSAPI = "/cloudapi/account/listCS"
|
||||||
|
|||||||
@@ -147,6 +147,7 @@ func Provider() *schema.Provider {
|
|||||||
"decort_account_audits_list": dataSourceAccountAuditsList(),
|
"decort_account_audits_list": dataSourceAccountAuditsList(),
|
||||||
"decort_account_rg_list": dataSourceAccountRGList(),
|
"decort_account_rg_list": dataSourceAccountRGList(),
|
||||||
"decort_account_consumed_units": dataSourceAccountConsumedUnits(),
|
"decort_account_consumed_units": dataSourceAccountConsumedUnits(),
|
||||||
|
"decort_account_consumed_units_by_type": dataSourceAccountConsumedUnitsByType(),
|
||||||
// "decort_pfw": dataSourcePfw(),
|
// "decort_pfw": dataSourcePfw(),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
55
decort/utility_account_consumed_units_by_type.go
Normal file
55
decort/utility_account_consumed_units_by_type.go
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
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 (
|
||||||
|
"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
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
- account
|
- account
|
||||||
- account_rg_list
|
- account_rg_list
|
||||||
- account_counsumed_units
|
- account_counsumed_units
|
||||||
|
- account_counsumed_units_by_type
|
||||||
- resources:
|
- resources:
|
||||||
- image
|
- image
|
||||||
- virtual_image
|
- virtual_image
|
||||||
|
|||||||
54
samples/data_account_consumed_units_by_type/main.tf
Normal file
54
samples/data_account_consumed_units_by_type/main.tf
Normal file
@@ -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 = <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_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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user