From 2f2fa2a544123d1c8f644dbfc23823de7805659e Mon Sep 17 00:00:00 2001 From: stSolo Date: Wed, 4 May 2022 20:56:56 +0300 Subject: [PATCH] Add resource, data, samples --- README.md | 3 +- README_EN.md | 3 +- decort/data_source_sep.go | 145 +++++++ ...ep_tatlin.go => data_source_sep_config.go} | 64 +-- decort/data_source_sep_consumption.go | 107 ++--- decort/data_source_sep_des.go | 380 ------------------ decort/data_source_sep_des_config.go | 238 ----------- decort/data_source_sep_des_pool.go | 129 ------ decort/data_source_sep_dorado.go | 348 ---------------- decort/data_source_sep_dorado_config.go | 268 ------------ decort/data_source_sep_hitachi.go | 329 --------------- decort/data_source_sep_hitachi_config.go | 261 ------------ decort/data_source_sep_hitachi_pool.go | 127 ------ decort/data_source_sep_list.go | 33 +- ...dorado_pool.go => data_source_sep_pool.go} | 51 +-- decort/data_source_sep_tatlin.go | 352 ---------------- decort/data_source_sep_tatlin_config.go | 270 ------------- decort/data_source_sep_tatlin_pool.go | 98 ----- decort/models_api.go | 257 ++---------- decort/provider.go | 46 +-- .../{resource_sep_des.go => resource_sep.go} | 293 +++++--------- decort/resource_sep_config.go | 197 +++++++++ decort/{utility_sep_des.go => utility_sep.go} | 17 +- ...ep_des_config.go => utility_sep_config.go} | 12 +- decort/utility_sep_dorado.go | 67 --- decort/utility_sep_dorado_config.go | 57 --- decort/utility_sep_dorado_pool.go | 58 --- decort/utility_sep_hitachi.go | 67 --- decort/utility_sep_hitachi_config.go | 57 --- decort/utility_sep_hitachi_pool.go | 58 --- ...ty_sep_des_pool.go => utility_sep_pool.go} | 10 +- decort/utility_sep_tatlin_config.go | 57 --- decort/utility_sep_tatlin_pool.go | 58 --- samples/README.md | 8 + samples/{data_sep_des => data_sep}/main.tf | 33 +- .../main.tf | 32 +- samples/data_sep_consumption/main.tf | 31 +- samples/data_sep_des_config/main.tf | 42 -- samples/data_sep_des_pool/main.tf | 43 -- samples/data_sep_disk_list/main.tf | 36 +- samples/data_sep_dorado_pool/main.tf | 43 -- samples/data_sep_hitachi/main.tf | 41 -- samples/data_sep_hitachi_pool/main.tf | 43 -- samples/data_sep_list/main.tf | 27 +- .../main.tf | 35 +- samples/data_sep_tatlin_pool/main.tf | 43 -- samples/resource_sep/main.tf | 124 ++++++ samples/resource_sep_config/main.tf | 73 ++++ samples/resource_sep_des/main.tf | 51 --- 49 files changed, 931 insertions(+), 4291 deletions(-) create mode 100644 decort/data_source_sep.go rename decort/{utility_sep_tatlin.go => data_source_sep_config.go} (52%) delete mode 100644 decort/data_source_sep_des.go delete mode 100644 decort/data_source_sep_des_config.go delete mode 100644 decort/data_source_sep_des_pool.go delete mode 100644 decort/data_source_sep_dorado.go delete mode 100644 decort/data_source_sep_dorado_config.go delete mode 100644 decort/data_source_sep_hitachi.go delete mode 100644 decort/data_source_sep_hitachi_config.go delete mode 100644 decort/data_source_sep_hitachi_pool.go rename decort/{data_source_sep_dorado_pool.go => data_source_sep_pool.go} (56%) delete mode 100644 decort/data_source_sep_tatlin.go delete mode 100644 decort/data_source_sep_tatlin_config.go delete mode 100644 decort/data_source_sep_tatlin_pool.go rename decort/{resource_sep_des.go => resource_sep.go} (60%) create mode 100644 decort/resource_sep_config.go rename decort/{utility_sep_des.go => utility_sep.go} (73%) rename decort/{utility_sep_des_config.go => utility_sep_config.go} (75%) delete mode 100644 decort/utility_sep_dorado.go delete mode 100644 decort/utility_sep_dorado_config.go delete mode 100644 decort/utility_sep_dorado_pool.go delete mode 100644 decort/utility_sep_hitachi.go delete mode 100644 decort/utility_sep_hitachi_config.go delete mode 100644 decort/utility_sep_hitachi_pool.go rename decort/{utility_sep_des_pool.go => utility_sep_pool.go} (79%) delete mode 100644 decort/utility_sep_tatlin_config.go delete mode 100644 decort/utility_sep_tatlin_pool.go rename samples/{data_sep_des => data_sep}/main.tf (50%) rename samples/{data_sep_tatlin => data_sep_config}/main.tf (50%) delete mode 100644 samples/data_sep_des_config/main.tf delete mode 100644 samples/data_sep_des_pool/main.tf delete mode 100644 samples/data_sep_dorado_pool/main.tf delete mode 100644 samples/data_sep_hitachi/main.tf delete mode 100644 samples/data_sep_hitachi_pool/main.tf rename samples/{data_sep_dorado => data_sep_pool}/main.tf (50%) delete mode 100644 samples/data_sep_tatlin_pool/main.tf create mode 100644 samples/resource_sep/main.tf create mode 100644 samples/resource_sep_config/main.tf delete mode 100644 samples/resource_sep_des/main.tf diff --git a/README.md b/README.md index 2982579..ced7576 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,8 @@ Terraform provider для платформы Digital Energy Cloud Orchestration - Работа с VINS, - Работа с pfw, - Работа с accounts, -- Работа с snapshots. +- Работа с snapshots, +- Работа с sep. Вики проекта: https://github.com/rudecs/terraform-provider-decort/wiki diff --git a/README_EN.md b/README_EN.md index 6fd0964..34e3625 100644 --- a/README_EN.md +++ b/README_EN.md @@ -14,7 +14,8 @@ NOTE: provider rc-1.25 is designed for DECORT API 3.7.x. For older API versions - Work with VINS, - Work with pfw, - Work with accounts, -- Work with snapshots. +- Work with snapshots, +- Work with sep. This provider supports Import operations on pre-existing resources. diff --git a/decort/data_source_sep.go b/decort/data_source_sep.go new file mode 100644 index 0000000..4dab665 --- /dev/null +++ b/decort/data_source_sep.go @@ -0,0 +1,145 @@ +/* +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" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func dataSourceSepRead(d *schema.ResourceData, m interface{}) error { + desSep, err := utilitySepCheckPresence(d, m) + if err != nil { + return err + } + id := uuid.New() + d.SetId(id.String()) + + d.Set("ckey", desSep.Ckey) + d.Set("meta", flattenMeta(desSep.Meta)) + d.Set("consumed_by", desSep.ConsumedBy) + d.Set("desc", desSep.Desc) + d.Set("gid", desSep.Gid) + d.Set("guid", desSep.Guid) + d.Set("sep_id", desSep.Id) + d.Set("milestones", desSep.Milestones) + d.Set("name", desSep.Name) + d.Set("obj_status", desSep.ObjStatus) + d.Set("provided_by", desSep.ProvidedBy) + d.Set("tech_status", desSep.TechStatus) + d.Set("type", desSep.Type) + data, _ := json.Marshal(desSep.Config) + d.Set("config", string(data)) + + return nil +} + +func dataSourceSepCSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeInt, + Required: true, + Description: "sep type des id", + }, + "ckey": { + Type: schema.TypeString, + Computed: true, + }, + "meta": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "consumed_by": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "desc": { + Type: schema.TypeString, + Computed: true, + }, + "gid": { + Type: schema.TypeInt, + Computed: true, + }, + "guid": { + Type: schema.TypeInt, + Computed: true, + }, + "milestones": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "obj_status": { + Type: schema.TypeString, + Computed: true, + }, + "provided_by": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "config": { + Type: schema.TypeString, + Computed: true, + }, + } +} + +func dataSourceSep() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + Read: dataSourceSepRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &Timeout30s, + Default: &Timeout60s, + }, + + Schema: dataSourceSepCSchemaMake(), + } +} diff --git a/decort/utility_sep_tatlin.go b/decort/data_source_sep_config.go similarity index 52% rename from decort/utility_sep_tatlin.go rename to decort/data_source_sep_config.go index 7fbc7e8..dcf1ec0 100644 --- a/decort/utility_sep_tatlin.go +++ b/decort/data_source_sep_config.go @@ -26,42 +26,52 @@ package decort import ( "encoding/json" - "errors" - "net/url" - "strconv" - "strings" - - log "github.com/sirupsen/logrus" + "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func utilitySepTatlinCheckPresence(d *schema.ResourceData, m interface{}) (*SepTatlin, error) { - controller := m.(*ControllerCfg) - urlValues := &url.Values{} +func dataSourceSepConfigRead(d *schema.ResourceData, m interface{}) error { + sepConfig, err := utilitySepConfigCheckPresence(d, m) + if err != nil { + return err + } - sepTatlin := &SepTatlin{} + id := uuid.New() + d.SetId(id.String()) - if d.Get("sep_id").(int) == 0 { - urlValues.Add("sep_id", d.Id()) - } else { - urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) - } + data, _ := json.Marshal(sepConfig) + d.Set("config", string(data)) - log.Debugf("utilitySepTatlinCheckPresence: load sep") - sepTatlinRaw, err := controller.decortAPICall("POST", sepGetAPI, urlValues) - if err != nil { - return nil, err - } + return nil +} - err = json.Unmarshal([]byte(sepTatlinRaw), sepTatlin) - if err != nil { - return nil, err +func dataSourceSepConfigSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeInt, + Required: true, + Description: "storage endpoint provider ID", + }, + "config": { + Type: schema.TypeString, + Computed: true, + Description: "sep config json string", + }, } +} - if strings.ToLower(sepTatlin.Type) != "tatlin" { - return nil, errors.New("Invalid sep type") - } +func dataSourceSepConfig() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, - return sepTatlin, nil + Read: dataSourceSepConfigRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &Timeout30s, + Default: &Timeout60s, + }, + + Schema: dataSourceSepConfigSchemaMake(), + } } diff --git a/decort/data_source_sep_consumption.go b/decort/data_source_sep_consumption.go index b0956c4..bd2c898 100644 --- a/decort/data_source_sep_consumption.go +++ b/decort/data_source_sep_consumption.go @@ -25,8 +25,6 @@ Visit https://github.com/rudecs/terraform-provider-decort for full source code p package decort import ( - "strconv" - "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) @@ -41,10 +39,7 @@ func dataSourceSepConsumptionRead(d *schema.ResourceData, m interface{}) error { d.Set("type", sepCons.Type) d.Set("total", flattenSepConsumption(sepCons.Total)) - err = d.Set("by_pool", flattenSepConsumptionPools(sepCons.ByPool)) - if err != nil { - return err - } + d.Set("by_pool", flattenSepConsumptionPools(sepCons.ByPool)) return nil } @@ -66,16 +61,19 @@ func flattenSepConsumptionPools(mp map[string]SepConsumptionInd) []map[string]in return sh } -func flattenSepConsumption(sc SepConsumptionTotal) map[string]interface{} { - return map[string]interface{}{ - "capacity_limit": strconv.Itoa(sc.CapacityLimit), - "disk_count": strconv.Itoa(sc.DiskCount), - "disk_usage": strconv.Itoa(sc.DiskUsage), - "snapshot_count": strconv.Itoa(sc.SnapshotCount), - "snapshot_usage": strconv.Itoa(sc.SnapshotUsage), - "usage": strconv.Itoa(sc.Usage), - "usage_limit": strconv.Itoa(sc.UsageLimit), +func flattenSepConsumption(sc SepConsumptionTotal) []map[string]interface{} { + sh := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "capacity_limit": sc.CapacityLimit, + "disk_count": sc.DiskCount, + "disk_usage": sc.DiskUsage, + "snapshot_count": sc.SnapshotCount, + "snapshot_usage": sc.SnapshotUsage, + "usage": sc.Usage, + "usage_limit": sc.UsageLimit, } + sh = append(sh, temp) + return sh } func dataSourceSepConsumptionSchemaMake() map[string]*schema.Schema { @@ -83,7 +81,7 @@ func dataSourceSepConsumptionSchemaMake() map[string]*schema.Schema { "sep_id": { Type: schema.TypeInt, Required: true, - Description: "sep type des id", + Description: "sep id", }, "by_pool": { Type: schema.TypeList, @@ -91,75 +89,92 @@ func dataSourceSepConsumptionSchemaMake() map[string]*schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "name": { - Type: schema.TypeString, - Computed: true, + Type: schema.TypeString, + Computed: true, + Description: "pool name", }, "disk_count": { - Type: schema.TypeInt, - Computed: true, + Type: schema.TypeInt, + Computed: true, + Description: "number of disks", }, "disk_usage": { - Type: schema.TypeInt, - Computed: true, + Type: schema.TypeInt, + Computed: true, + Description: "disk usage", }, "snapshot_count": { - Type: schema.TypeInt, - Computed: true, + Type: schema.TypeInt, + Computed: true, + Description: "number of snapshots", }, "snapshot_usage": { - Type: schema.TypeInt, - Computed: true, + Type: schema.TypeInt, + Computed: true, + Description: "snapshot usage", }, "usage": { - Type: schema.TypeInt, - Computed: true, + Type: schema.TypeInt, + Computed: true, + Description: "usage", }, "usage_limit": { - Type: schema.TypeInt, - Computed: true, + Type: schema.TypeInt, + Computed: true, + Description: "usage limit", }, }, }, + Description: "consumption divided by pool", }, "total": { - Type: schema.TypeMap, + Type: schema.TypeList, Computed: true, + MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "capacity_limit": { - Type: schema.TypeString, + Type: schema.TypeInt, Computed: true, }, "disk_count": { - Type: schema.TypeString, - Computed: true, + Type: schema.TypeInt, + Computed: true, + Description: "number of disks", }, "disk_usage": { - Type: schema.TypeString, - Computed: true, + Type: schema.TypeInt, + Computed: true, + Description: "disk usage", }, "snapshot_count": { - Type: schema.TypeString, - Computed: true, + Type: schema.TypeInt, + Computed: true, + Description: "number of snapshots", }, "snapshot_usage": { - Type: schema.TypeString, - Computed: true, + Type: schema.TypeInt, + Computed: true, + Description: "snapshot usage", }, "usage": { - Type: schema.TypeString, - Computed: true, + Type: schema.TypeInt, + Computed: true, + Description: "usage", }, "usage_limit": { - Type: schema.TypeString, - Computed: true, + Type: schema.TypeInt, + Computed: true, + Description: "usage limit", }, }, }, + Description: "total consumption", }, "type": { - Type: schema.TypeString, - Computed: true, + Type: schema.TypeString, + Computed: true, + Description: "sep type", }, } } diff --git a/decort/data_source_sep_des.go b/decort/data_source_sep_des.go deleted file mode 100644 index 0a654c1..0000000 --- a/decort/data_source_sep_des.go +++ /dev/null @@ -1,380 +0,0 @@ -/* -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" - - "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -func dataSourceSepDesRead(d *schema.ResourceData, m interface{}) error { - desSep, err := utilitySepDesCheckPresence(d, m) - if err != nil { - return err - } - id := uuid.New() - d.SetId(id.String()) - - d.Set("ckey", desSep.Ckey) - - d.Set("meta", flattenMeta(desSep.Meta)) - d.Set("consumed_by", desSep.ConsumedBy) - d.Set("desc", desSep.Desc) - d.Set("gid", desSep.Gid) - d.Set("guid", desSep.Guid) - d.Set("sep_id", desSep.Id) - d.Set("milestones", desSep.Milestones) - d.Set("name", desSep.Name) - d.Set("obj_status", desSep.ObjStatus) - d.Set("provided_by", desSep.ProvidedBy) - d.Set("tech_status", desSep.TechStatus) - d.Set("type", desSep.Type) - data, _ := json.Marshal(desSep.Config) - d.Set("config_string", string(data)) - err = d.Set("config", flattenSepDesConfig(desSep.Config)) - if err != nil { - return err - } - - return nil -} - -func flattenSepDesConfig(sc DesConfigSep) []interface{} { - return []interface{}{ - map[string]interface{}{ - "api_ips": sc.ApiIps, - "protocol": sc.Protocol, - "capacity_limit": sc.CapacityLimit, - "decs3o_app_secret": sc.Decs3oAppSecret, - "decs3o_app_id": sc.Decs3oAppId, - "format": sc.Format, - "edgeuser_password": sc.EdgeuserPassword, - "edgeuser_name": sc.EdgeuserName, - "transport": sc.Transport, - "ovs_settings": []interface{}{ - map[string]interface{}{ - "vpool_data_metadatacache": sc.OVSSettings.VPoolDataMetadataCache, - "vpool_vmstor_metadatacache": sc.OVSSettings.VPoolVMstorMetadataCache, - }, - }, - "housekeeping_settings": []interface{}{ - map[string]interface{}{ - "disk_del_queue": []interface{}{ - map[string]interface{}{ - "purgatory_id": sc.HousekeepingSettings.DiskDelQueue.PurgatoryId, - "chunk_max_size": sc.HousekeepingSettings.DiskDelQueue.ChunkMaxSize, - "disk_count_max": sc.HousekeepingSettings.DiskDelQueue.DiskCountMax, - "enabled": sc.HousekeepingSettings.DiskDelQueue.Enabled, - "normal_time_to_sleep": sc.HousekeepingSettings.DiskDelQueue.NormalTimeToSleep, - "one_minute_la_threshold": sc.HousekeepingSettings.DiskDelQueue.OneMinuteLaThreshold, - "oversize_time_to_sleep": sc.HousekeepingSettings.DiskDelQueue.OversizeTimeToSleep, - "purge_attempts_threshold": sc.HousekeepingSettings.DiskDelQueue.PurgeAttemptsThreshold, - }, - }, - }, - }, - "pools": flattenSepDesPools(sc.Pools), - }, - } -} - -func flattenSepDesPools(pools DesConfigPoolList) []map[string]interface{} { - temp := make([]map[string]interface{}, 0) - for _, pool := range pools { - t := map[string]interface{}{ - "types": pool.Types, - "reference_id": pool.ReferenceId, - "name": pool.Name, - "pagecache_ratio": pool.PagecacheRatio, - "uris": flattenDesSepPoolUris(pool.URIS), - } - temp = append(temp, t) - } - return temp -} - -func flattenDesSepPoolUris(uris URIList) []map[string]interface{} { - temp := make([]map[string]interface{}, 0) - for _, uri := range uris { - t := map[string]interface{}{ - "ip": uri.IP, - "port": uri.Port, - } - temp = append(temp, t) - } - return temp -} - -func dataSourceSepDesSchemaMake(sh map[string]*schema.Schema) map[string]*schema.Schema { - sh["config"] = &schema.Schema{ - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "api_ips": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "capacity_limit": { - Type: schema.TypeInt, - Computed: true, - }, - "protocol": { - Type: schema.TypeString, - Computed: true, - }, - "decs3o_app_secret": { - Type: schema.TypeString, - Computed: true, - }, - "format": { - Type: schema.TypeString, - Computed: true, - }, - "edgeuser_password": { - Type: schema.TypeString, - Computed: true, - }, - "edgeuser_name": { - Type: schema.TypeString, - Computed: true, - }, - "decs3o_app_id": { - Type: schema.TypeString, - Computed: true, - }, - "transport": { - Type: schema.TypeString, - Computed: true, - }, - "ovs_settings": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "vpool_data_metadatacache": { - Type: schema.TypeInt, - Computed: true, - }, - "vpool_vmstor_metadatacache": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - - "pools": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "types": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "reference_id": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "pagecache_ratio": { - Type: schema.TypeInt, - Computed: true, - }, - "uris": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "ip": { - Type: schema.TypeString, - Computed: true, - }, - "port": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - }, - }, - }, - "housekeeping_settings": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "disk_del_queue": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "chunk_max_size": { - Type: schema.TypeInt, - Computed: true, - }, - "disk_count_max": { - Type: schema.TypeInt, - Computed: true, - }, - "enabled": { - Type: schema.TypeBool, - Computed: true, - }, - "normal_time_to_sleep": { - Type: schema.TypeInt, - Computed: true, - }, - "one_minute_la_threshold": { - Type: schema.TypeInt, - Computed: true, - }, - "oversize_time_to_sleep": { - Type: schema.TypeInt, - Computed: true, - }, - "purge_attempts_threshold": { - Type: schema.TypeInt, - Computed: true, - }, - "purgatory_id": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - }, - }, - }, - }, - }, - } - - return sh -} - -func dataSourceSepSchemaMake() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "sep_id": { - Type: schema.TypeInt, - Required: true, - Description: "sep type des id", - }, - "ckey": { - Type: schema.TypeString, - Computed: true, - }, - "meta": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "consumed_by": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeInt, - }, - }, - "desc": { - Type: schema.TypeString, - Computed: true, - }, - "gid": { - Type: schema.TypeInt, - Computed: true, - }, - "guid": { - Type: schema.TypeInt, - Computed: true, - }, - "milestones": { - Type: schema.TypeInt, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "obj_status": { - Type: schema.TypeString, - Computed: true, - }, - "provided_by": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeInt, - }, - }, - "tech_status": { - Type: schema.TypeString, - Computed: true, - }, - "type": { - Type: schema.TypeString, - Computed: true, - }, - "config_string": { - Type: schema.TypeString, - Computed: true, - }, - } -} - -func dataSourceSepDes() *schema.Resource { - return &schema.Resource{ - SchemaVersion: 1, - - Read: dataSourceSepDesRead, - - Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, - }, - - Schema: dataSourceSepDesSchemaMake(dataSourceSepSchemaMake()), - } -} diff --git a/decort/data_source_sep_des_config.go b/decort/data_source_sep_des_config.go deleted file mode 100644 index 4522b07..0000000 --- a/decort/data_source_sep_des_config.go +++ /dev/null @@ -1,238 +0,0 @@ -/* -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" - - "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -func dataSourceSepConfigDesRead(d *schema.ResourceData, m interface{}) error { - desConfigSep, err := utilitySepConfigDesCheckPresence(d, m) - if err != nil { - return err - } - id := uuid.New() - d.SetId(id.String()) - - data, _ := json.Marshal(&desConfigSep) - d.Set("config_string", string(data)) - err = d.Set("config", flattenSepDesConfig(*desConfigSep)) - if err != nil { - return err - } - - return nil -} - -func dataSourceSepConfigDesSchemaMake() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "sep_id": { - Type: schema.TypeInt, - Required: true, - Description: "storage endpoint provider ID", - }, - "config_string": { - Type: schema.TypeString, - Computed: true, - }, - "config": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "api_ips": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "capacity_limit": { - Type: schema.TypeInt, - Computed: true, - }, - "protocol": { - Type: schema.TypeString, - Computed: true, - }, - "decs3o_app_secret": { - Type: schema.TypeString, - Computed: true, - }, - "format": { - Type: schema.TypeString, - Computed: true, - }, - "edgeuser_password": { - Type: schema.TypeString, - Computed: true, - }, - "edgeuser_name": { - Type: schema.TypeString, - Computed: true, - }, - "decs3o_app_id": { - Type: schema.TypeString, - Computed: true, - }, - "transport": { - Type: schema.TypeString, - Computed: true, - }, - "ovs_settings": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "vpool_data_metadatacache": { - Type: schema.TypeInt, - Computed: true, - }, - "vpool_vmstor_metadatacache": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - - "pools": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "types": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "reference_id": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "pagecache_ratio": { - Type: schema.TypeInt, - Computed: true, - }, - "uris": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "ip": { - Type: schema.TypeString, - Computed: true, - }, - "port": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - }, - }, - }, - "housekeeping_settings": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "disk_del_queue": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "chunk_max_size": { - Type: schema.TypeInt, - Computed: true, - }, - "disk_count_max": { - Type: schema.TypeInt, - Computed: true, - }, - "enabled": { - Type: schema.TypeBool, - Computed: true, - }, - "normal_time_to_sleep": { - Type: schema.TypeInt, - Computed: true, - }, - "one_minute_la_threshold": { - Type: schema.TypeInt, - Computed: true, - }, - "oversize_time_to_sleep": { - Type: schema.TypeInt, - Computed: true, - }, - "purge_attempts_threshold": { - Type: schema.TypeInt, - Computed: true, - }, - "purgatory_id": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - } -} - -func dataSourceSepConfigDes() *schema.Resource { - return &schema.Resource{ - SchemaVersion: 1, - - Read: dataSourceSepConfigDesRead, - - Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, - }, - - Schema: dataSourceSepConfigDesSchemaMake(), - } -} diff --git a/decort/data_source_sep_des_pool.go b/decort/data_source_sep_des_pool.go deleted file mode 100644 index 13afeca..0000000 --- a/decort/data_source_sep_des_pool.go +++ /dev/null @@ -1,129 +0,0 @@ -/* -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 dataSourceSepDesPoolRead(d *schema.ResourceData, m interface{}) error { - desSepPool, err := utilitySepDesPoolCheckPresence(d, m) - if err != nil { - return err - } - id := uuid.New() - d.SetId(id.String()) - - d.Set("pool", flattenSepDesPool(desSepPool)) - - return nil -} - -func flattenSepDesPool(pool *DesConfigPool) []map[string]interface{} { - temp := make([]map[string]interface{}, 0) - t := map[string]interface{}{ - "types": pool.Types, - "reference_id": pool.ReferenceId, - "name": pool.Name, - "pagecache_ratio": pool.PagecacheRatio, - "uris": flattenDesSepPoolUris(pool.URIS), - } - temp = append(temp, t) - return temp -} - -func dataSourceSepDesPoolSchemaMake() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "sep_id": { - Type: schema.TypeInt, - Required: true, - Description: "storage endpoint provider ID", - }, - "pool_name": { - Type: schema.TypeString, - Required: true, - Description: "pool name", - }, - "pool": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "types": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "reference_id": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "pagecache_ratio": { - Type: schema.TypeInt, - Computed: true, - }, - "uris": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "ip": { - Type: schema.TypeString, - Computed: true, - }, - "port": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - }, - }, - }, - } -} - -func dataSourceSepDesPool() *schema.Resource { - return &schema.Resource{ - SchemaVersion: 1, - - Read: dataSourceSepDesPoolRead, - - Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, - }, - - Schema: dataSourceSepDesPoolSchemaMake(), - } -} diff --git a/decort/data_source_sep_dorado.go b/decort/data_source_sep_dorado.go deleted file mode 100644 index 7f0e7ba..0000000 --- a/decort/data_source_sep_dorado.go +++ /dev/null @@ -1,348 +0,0 @@ -/* -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" - - "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -func dataSourceSepDoradoRead(d *schema.ResourceData, m interface{}) error { - doradoSep, err := utilitySepDoradoCheckPresence(d, m) - if err != nil { - return err - } - id := uuid.New() - d.SetId(id.String()) - - d.Set("ckey", doradoSep.Ckey) - d.Set("meta", flattenMeta(doradoSep.Meta)) - d.Set("consumed_by", doradoSep.ConsumedBy) - d.Set("desc", doradoSep.Desc) - d.Set("gid", doradoSep.Gid) - d.Set("guid", doradoSep.Guid) - d.Set("sep_id", doradoSep.Id) - d.Set("milestones", doradoSep.Milestones) - d.Set("name", doradoSep.Name) - d.Set("obj_status", doradoSep.ObjStatus) - d.Set("provided_by", doradoSep.ProvidedBy) - d.Set("tech_status", doradoSep.TechStatus) - d.Set("type", doradoSep.Type) - data, _ := json.Marshal(doradoSep.Config) - d.Set("config_string", string(data)) - d.Set("config", flattenSepDoradoConfig(doradoSep.Config)) - - return nil -} - -func flattenSepDoradoConfig(dc DoradoConfigSep) []interface{} { - return []interface{}{ - map[string]interface{}{ - "api_urls": dc.ApiUrls, - "disk_max_size": dc.DiskMaxSize, - "edgeuser_password": dc.EdgeuserPassword, - "edgeuser_name": dc.EdgeuserName, - "format": dc.Format, - "groups": []interface{}{ - map[string]interface{}{ - "host_group": dc.Groups.HostGroup, - "lung_group": dc.Groups.LungGroup, - "port_group": dc.Groups.PortGroup, - }, - }, - "ovs_settings": []interface{}{ - map[string]interface{}{ - "vpool_data_metadatacache": dc.OVSSettings.VPoolDataMetadataCache, - "vpool_vmstor_metadatacache": dc.OVSSettings.VPoolVMstorMetadataCache, - }, - }, - "host_group_name": dc.HostGroupName, - "housekeeping_settings": []interface{}{ - map[string]interface{}{ - "disk_del_queue": []interface{}{ - map[string]interface{}{ - "purgatory_id": dc.HousekeepingSettings.DiskDelQueue.PurgatoryId, - "chunk_max_size": dc.HousekeepingSettings.DiskDelQueue.ChunkMaxSize, - "disk_count_max": dc.HousekeepingSettings.DiskDelQueue.DiskCountMax, - "enabled": dc.HousekeepingSettings.DiskDelQueue.Enabled, - "normal_time_to_sleep": dc.HousekeepingSettings.DiskDelQueue.NormalTimeToSleep, - "one_minute_la_threshold": dc.HousekeepingSettings.DiskDelQueue.OneMinuteLaThreshold, - "oversize_time_to_sleep": dc.HousekeepingSettings.DiskDelQueue.OversizeTimeToSleep, - "purge_attempts_threshold": dc.HousekeepingSettings.DiskDelQueue.PurgeAttemptsThreshold, - }, - }, - }, - }, - "mgmt_password": dc.MGMTPassword, - "mgmt_user": dc.MGMTUser, - "model": dc.Model, - "name_prefix": dc.NamePrefix, - "pools": flattenSepDoradoPools(dc.Pools), - "ports": flattenSepDoradoPorts(dc.Ports), - "protocol": dc.Protocol, - }, - } -} - -func flattenSepDoradoPorts(dp DoradoPortList) []map[string]interface{} { - temp := make([]map[string]interface{}, 0) - for _, port := range dp { - t := map[string]interface{}{ - "name": port.Name, - "ip": port.IP, - } - temp = append(temp, t) - } - - return temp -} - -func flattenSepDoradoPools(dp PoolList) []map[string]interface{} { - temp := make([]map[string]interface{}, 0) - for _, pool := range dp { - t := map[string]interface{}{ - "name": pool.Name, - "types": pool.Types, - "usage_limit": pool.UsageLimit, - } - temp = append(temp, t) - } - - return temp -} - -func dataSourceSepDoradoSchemaMake(sh map[string]*schema.Schema) map[string]*schema.Schema { - sh["config"] = &schema.Schema{ - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "api_urls": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "disk_max_size": { - Type: schema.TypeInt, - Computed: true, - }, - "edgeuser_password": { - Type: schema.TypeString, - Computed: true, - }, - "edgeuser_name": { - Type: schema.TypeString, - Computed: true, - }, - "format": { - Type: schema.TypeString, - Computed: true, - }, - "groups": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "host_group": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "lung_group": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "port_group": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - }, - }, - }, - "host_group_name": { - Type: schema.TypeString, - Computed: true, - }, - "housekeeping_settings": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "disk_del_queue": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "purge_attempts_threshold": { - Type: schema.TypeInt, - Computed: true, - }, - "chunk_max_size": { - Type: schema.TypeInt, - Computed: true, - }, - "disk_count_max": { - Type: schema.TypeInt, - Computed: true, - }, - "enabled": { - Type: schema.TypeBool, - Computed: true, - }, - "normal_time_to_sleep": { - Type: schema.TypeInt, - Computed: true, - }, - "one_minute_la_threshold": { - Type: schema.TypeInt, - Computed: true, - }, - "oversize_time_to_sleep": { - Type: schema.TypeInt, - Computed: true, - }, - "purgatory_id": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - }, - }, - }, - "mgmt_password": { - Type: schema.TypeString, - Computed: true, - }, - "mgmt_user": { - Type: schema.TypeString, - Computed: true, - }, - "model": { - Type: schema.TypeString, - Computed: true, - }, - "name_prefix": { - Type: schema.TypeString, - Computed: true, - }, - "ovs_settings": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "vpool_data_metadatacache": { - Type: schema.TypeInt, - Computed: true, - }, - "vpool_vmstor_metadatacache": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "pools": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Computed: true, - }, - "types": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "usage_limit": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "ports": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "ip": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - "protocol": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - } - - return sh -} - -func dataSourceSepDorado() *schema.Resource { - return &schema.Resource{ - SchemaVersion: 1, - - Read: dataSourceSepDoradoRead, - - Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, - }, - - Schema: dataSourceSepDoradoSchemaMake(dataSourceSepSchemaMake()), - } -} diff --git a/decort/data_source_sep_dorado_config.go b/decort/data_source_sep_dorado_config.go deleted file mode 100644 index 17109f5..0000000 --- a/decort/data_source_sep_dorado_config.go +++ /dev/null @@ -1,268 +0,0 @@ -/* -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" - - "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -func dataSourceSepDoradoConfigRead(d *schema.ResourceData, m interface{}) error { - doradoSepConfig, err := utilitySepDoradoConfigCheckPresence(d, m) - if err != nil { - return err - } - id := uuid.New() - d.SetId(id.String()) - - data, _ := json.Marshal(doradoSepConfig) - d.Set("config_string", string(data)) - d.Set("config", flattenSepDoradoConfig(*doradoSepConfig)) - - return nil -} - -func dataSourceSepDoradoConfigSchemaMake() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "sep_id": { - Type: schema.TypeInt, - Required: true, - Description: "storage endpoint provider ID", - }, - "config_string": { - Type: schema.TypeString, - Computed: true, - }, - "config": { - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "api_urls": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "disk_max_size": { - Type: schema.TypeInt, - Computed: true, - }, - "edgeuser_password": { - Type: schema.TypeString, - Computed: true, - }, - "edgeuser_name": { - Type: schema.TypeString, - Computed: true, - }, - "format": { - Type: schema.TypeString, - Computed: true, - }, - "groups": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "host_group": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "lung_group": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "port_group": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - }, - }, - }, - "host_group_name": { - Type: schema.TypeString, - Computed: true, - }, - "housekeeping_settings": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "disk_del_queue": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "purge_attempts_threshold": { - Type: schema.TypeInt, - Computed: true, - }, - "chunk_max_size": { - Type: schema.TypeInt, - Computed: true, - }, - "disk_count_max": { - Type: schema.TypeInt, - Computed: true, - }, - "enabled": { - Type: schema.TypeBool, - Computed: true, - }, - "normal_time_to_sleep": { - Type: schema.TypeInt, - Computed: true, - }, - "one_minute_la_threshold": { - Type: schema.TypeInt, - Computed: true, - }, - "oversize_time_to_sleep": { - Type: schema.TypeInt, - Computed: true, - }, - "purgatory_id": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - }, - }, - }, - "mgmt_password": { - Type: schema.TypeString, - Computed: true, - }, - "mgmt_user": { - Type: schema.TypeString, - Computed: true, - }, - "model": { - Type: schema.TypeString, - Computed: true, - }, - "name_prefix": { - Type: schema.TypeString, - Computed: true, - }, - "ovs_settings": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "vpool_data_metadatacache": { - Type: schema.TypeInt, - Computed: true, - }, - "vpool_vmstor_metadatacache": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "pools": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Computed: true, - }, - "types": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "usage_limit": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "ports": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "ip": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - "protocol": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - } -} - -func dataSourceSepDoradoConfig() *schema.Resource { - return &schema.Resource{ - SchemaVersion: 1, - - Read: dataSourceSepDoradoConfigRead, - - Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, - }, - - Schema: dataSourceSepDoradoConfigSchemaMake(), - } -} diff --git a/decort/data_source_sep_hitachi.go b/decort/data_source_sep_hitachi.go deleted file mode 100644 index ee31f9f..0000000 --- a/decort/data_source_sep_hitachi.go +++ /dev/null @@ -1,329 +0,0 @@ -/* -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" - - "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -func dataSourceSepHitachiRead(d *schema.ResourceData, m interface{}) error { - hitachiSep, err := utilitySepHitachiCheckPresence(d, m) - if err != nil { - return err - } - id := uuid.New() - d.SetId(id.String()) - - d.Set("ckey", hitachiSep.Ckey) - d.Set("meta", flattenMeta(hitachiSep.Meta)) - d.Set("consumed_by", hitachiSep.ConsumedBy) - d.Set("desc", hitachiSep.Desc) - d.Set("gid", hitachiSep.Gid) - d.Set("guid", hitachiSep.Guid) - d.Set("sep_id", hitachiSep.Id) - d.Set("milestones", hitachiSep.Milestones) - d.Set("name", hitachiSep.Name) - d.Set("obj_status", hitachiSep.ObjStatus) - d.Set("provided_by", hitachiSep.ProvidedBy) - d.Set("tech_status", hitachiSep.TechStatus) - d.Set("type", hitachiSep.Type) - data, _ := json.Marshal(hitachiSep.Config) - d.Set("config_string", string(data)) - d.Set("config", flattenSepHitachiConfig(hitachiSep.Config)) - - return nil -} - -func flattenSepHitachiConfig(hc HitachiConfigSep) []interface{} { - return []interface{}{ - map[string]interface{}{ - "api_urls": hc.ApiUrls, - "sn": hc.SN, - "disk_max_size": hc.DiskMaxSize, - "format": hc.Format, - "host_group_num_max": hc.HostGroupNumMax, - "host_group_num_min": hc.HostGroupNumMin, - "host_group_number": hc.HostGroupNumber, - "mgmt_password": hc.MGMTPassword, - "mgmt_user": hc.MGMTUser, - "model": hc.Model, - "name_prefix": hc.NamePrefix, - "ports": hc.Ports, - "protocol": hc.Protocol, - "ssl_verify": hc.SSLVerify, - "pools": flattenSepHitachiPools(hc.Pools), - "ovs_settings": []interface{}{ - map[string]interface{}{ - "vpool_data_metadatacache": hc.OVSSettings.VPoolDataMetadataCache, - "vpool_vmstor_metadatacache": hc.OVSSettings.VPoolVMstorMetadataCache, - }, - }, - "housekeeping_settings": []interface{}{ - map[string]interface{}{ - "disk_del_queue": []interface{}{ - map[string]interface{}{ - "purgatory_id": hc.HousekeepingSettings.DiskDelQueue.PurgatoryId, - "chunk_max_size": hc.HousekeepingSettings.DiskDelQueue.ChunkMaxSize, - "disk_count_max": hc.HousekeepingSettings.DiskDelQueue.DiskCountMax, - "enabled": hc.HousekeepingSettings.DiskDelQueue.Enabled, - "normal_time_to_sleep": hc.HousekeepingSettings.DiskDelQueue.NormalTimeToSleep, - "one_minute_la_threshold": hc.HousekeepingSettings.DiskDelQueue.OneMinuteLaThreshold, - "oversize_time_to_sleep": hc.HousekeepingSettings.DiskDelQueue.OversizeTimeToSleep, - "purge_attempts_threshold": hc.HousekeepingSettings.DiskDelQueue.PurgeAttemptsThreshold, - }, - }, - }, - }, - }, - } - -} - -func flattenSepHitachiPools(hp HitachiConfigPoolList) []map[string]interface{} { - temp := make([]map[string]interface{}, 0) - for _, pool := range hp { - t := map[string]interface{}{ - "clone_technology": pool.CloneTechnology, - "id": pool.Id, - "max_l_dev_id": pool.MaxLdevId, - "min_l_dev_id": pool.MinLdevId, - "name": pool.Name, - "snapshot_pool_id": pool.SnapshotPoolId, - "snapshotable": pool.Snapshotable, - "types": pool.Types, - "usage_limit": pool.UsageLimit, - } - temp = append(temp, t) - } - return temp -} - -func dataSourceSepHitachiSchemaMake(sh map[string]*schema.Schema) map[string]*schema.Schema { - sh["config"] = &schema.Schema{ - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "api_urls": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "sn": { - Type: schema.TypeInt, - Computed: true, - }, - "disk_max_size": { - Type: schema.TypeInt, - Computed: true, - }, - "format": { - Type: schema.TypeString, - Computed: true, - }, - "host_group_num_max": { - Type: schema.TypeInt, - Computed: true, - }, - "host_group_num_min": { - Type: schema.TypeInt, - Computed: true, - }, - "host_group_number": { - Type: schema.TypeInt, - Computed: true, - }, - "housekeeping_settings": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "disk_del_queue": { - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "purge_attempts_threshold": { - Type: schema.TypeInt, - Computed: true, - }, - "chunk_max_size": { - Type: schema.TypeInt, - Computed: true, - }, - "disk_count_max": { - Type: schema.TypeInt, - Computed: true, - }, - "enabled": { - Type: schema.TypeBool, - Computed: true, - }, - "normal_time_to_sleep": { - Type: schema.TypeInt, - Computed: true, - }, - "one_minute_la_threshold": { - Type: schema.TypeInt, - Computed: true, - }, - "oversize_time_to_sleep": { - Type: schema.TypeInt, - Computed: true, - }, - "purgatory_id": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - }, - }, - }, - "ovs_settings": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "vpool_data_metadatacache": { - Type: schema.TypeInt, - Computed: true, - }, - "vpool_vmstor_metadatacache": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "mgmt_password": { - Type: schema.TypeString, - Computed: true, - }, - "mgmt_user": { - Type: schema.TypeString, - Computed: true, - }, - "model": { - Type: schema.TypeString, - Computed: true, - }, - "name_prefix": { - Type: schema.TypeString, - Computed: true, - }, - "pools": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "clone_technology": { - Type: schema.TypeString, - Computed: true, - }, - "id": { - Type: schema.TypeInt, - Computed: true, - }, - "max_l_dev_id": { - Type: schema.TypeInt, - Computed: true, - }, - "min_l_dev_id": { - Type: schema.TypeInt, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "snapshot_pool_id": { - Type: schema.TypeInt, - Computed: true, - }, - "snapshotable": { - Type: schema.TypeBool, - Computed: true, - }, - "types": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "usage_limit": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "ports": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "protocol": { - Type: schema.TypeString, - Computed: true, - }, - "ssl_verify": { - Type: schema.TypeBool, - Computed: true, - }, - }, - }, - } - - return sh -} - -func dataSourceSepHitachi() *schema.Resource { - return &schema.Resource{ - SchemaVersion: 1, - - Read: dataSourceSepHitachiRead, - - Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, - }, - - Schema: dataSourceSepHitachiSchemaMake(dataSourceSepSchemaMake()), - } -} diff --git a/decort/data_source_sep_hitachi_config.go b/decort/data_source_sep_hitachi_config.go deleted file mode 100644 index 1e45763..0000000 --- a/decort/data_source_sep_hitachi_config.go +++ /dev/null @@ -1,261 +0,0 @@ -/* -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" - - "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -func dataSourceSepHitachiConfigRead(d *schema.ResourceData, m interface{}) error { - hitachiSepConfig, err := utilitySepHitachiConfigCheckPresence(d, m) - if err != nil { - return err - } - id := uuid.New() - d.SetId(id.String()) - - data, _ := json.Marshal(hitachiSepConfig) - d.Set("config_string", string(data)) - d.Set("config", flattenSepHitachiConfig(*hitachiSepConfig)) - - return nil -} - -func dataSourceSepHitachiConfigSchemaMake() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "sep_id": { - Type: schema.TypeInt, - Required: true, - Description: "storage endpoint provider ID", - }, - "config_string": { - Type: schema.TypeString, - Computed: true, - }, - "config": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "api_urls": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "sn": { - Type: schema.TypeInt, - Computed: true, - }, - "disk_max_size": { - Type: schema.TypeInt, - Computed: true, - }, - "format": { - Type: schema.TypeString, - Computed: true, - }, - "host_group_num_max": { - Type: schema.TypeInt, - Computed: true, - }, - "host_group_num_min": { - Type: schema.TypeInt, - Computed: true, - }, - "host_group_number": { - Type: schema.TypeInt, - Computed: true, - }, - "housekeeping_settings": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "disk_del_queue": { - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "purge_attempts_threshold": { - Type: schema.TypeInt, - Computed: true, - }, - "chunk_max_size": { - Type: schema.TypeInt, - Computed: true, - }, - "disk_count_max": { - Type: schema.TypeInt, - Computed: true, - }, - "enabled": { - Type: schema.TypeBool, - Computed: true, - }, - "normal_time_to_sleep": { - Type: schema.TypeInt, - Computed: true, - }, - "one_minute_la_threshold": { - Type: schema.TypeInt, - Computed: true, - }, - "oversize_time_to_sleep": { - Type: schema.TypeInt, - Computed: true, - }, - "purgatory_id": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - }, - }, - }, - "ovs_settings": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "vpool_data_metadatacache": { - Type: schema.TypeInt, - Computed: true, - }, - "vpool_vmstor_metadatacache": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "mgmt_password": { - Type: schema.TypeString, - Computed: true, - }, - "mgmt_user": { - Type: schema.TypeString, - Computed: true, - }, - "model": { - Type: schema.TypeString, - Computed: true, - }, - "name_prefix": { - Type: schema.TypeString, - Computed: true, - }, - "pools": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "clone_technology": { - Type: schema.TypeString, - Computed: true, - }, - "id": { - Type: schema.TypeInt, - Computed: true, - }, - "max_l_dev_id": { - Type: schema.TypeInt, - Computed: true, - }, - "min_l_dev_id": { - Type: schema.TypeInt, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "snapshot_pool_id": { - Type: schema.TypeInt, - Computed: true, - }, - "snapshotable": { - Type: schema.TypeBool, - Computed: true, - }, - "types": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "usage_limit": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "ports": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "protocol": { - Type: schema.TypeString, - Computed: true, - }, - "ssl_verify": { - Type: schema.TypeBool, - Computed: true, - }, - }, - }, - }, - } -} - -func dataSourceSepHitachiConfig() *schema.Resource { - return &schema.Resource{ - SchemaVersion: 1, - - Read: dataSourceSepHitachiConfigRead, - - Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, - }, - - Schema: dataSourceSepHitachiConfigSchemaMake(), - } -} diff --git a/decort/data_source_sep_hitachi_pool.go b/decort/data_source_sep_hitachi_pool.go deleted file mode 100644 index 5c7318e..0000000 --- a/decort/data_source_sep_hitachi_pool.go +++ /dev/null @@ -1,127 +0,0 @@ -/* -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 dataSourceSepHitachiPoolRead(d *schema.ResourceData, m interface{}) error { - hitachiSepPool, err := utilitySepHitachiPoolCheckPresence(d, m) - if err != nil { - return err - } - id := uuid.New() - d.SetId(id.String()) - - d.Set("pool", flattenSepHitachiPool(hitachiSepPool)) - - return nil -} - -func flattenSepHitachiPool(pool *HitachiConfigPool) []map[string]interface{} { - temp := make([]map[string]interface{}, 0) - t := map[string]interface{}{ - "clone_technology": pool.CloneTechnology, - "id": pool.Id, - "max_l_dev_id": pool.MaxLdevId, - "min_l_dev_id": pool.MinLdevId, - "name": pool.Name, - "snapshot_pool_id": pool.SnapshotPoolId, - "snapshotable": pool.Snapshotable, - "types": pool.Types, - "usage_limit": pool.UsageLimit, - } - temp = append(temp, t) - return temp -} - -func dataSourceSepHitachiPoolSchemaMake() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "pool": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "clone_technology": { - Type: schema.TypeString, - Computed: true, - }, - "id": { - Type: schema.TypeInt, - Computed: true, - }, - "max_l_dev_id": { - Type: schema.TypeInt, - Computed: true, - }, - "min_l_dev_id": { - Type: schema.TypeInt, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "snapshot_pool_id": { - Type: schema.TypeInt, - Computed: true, - }, - "snapshotable": { - Type: schema.TypeBool, - Computed: true, - }, - "types": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "usage_limit": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - } -} - -func dataSourceSepHitachiPool() *schema.Resource { - return &schema.Resource{ - SchemaVersion: 1, - - Read: dataSourceSepHitachiPoolRead, - - Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, - }, - - Schema: dataSourceSepHitachiPoolSchemaMake(), - } -} diff --git a/decort/data_source_sep_list.go b/decort/data_source_sep_list.go index 927dba1..89f0340 100644 --- a/decort/data_source_sep_list.go +++ b/decort/data_source_sep_list.go @@ -34,23 +34,22 @@ import ( func flattenSepList(sl SepList) []map[string]interface{} { res := make([]map[string]interface{}, 0) for _, item := range sl { - d, _ := json.Marshal(item.ConfigString) - configString := string(d) + data, _ := json.Marshal(item.Config) temp := map[string]interface{}{ - "ckey": item.Ckey, - "meta": flattenMeta(item.Meta), - "consumed_by": item.ConsumedBy, - "desc": item.Desc, - "gid": item.Gid, - "guid": item.Guid, - "sep_id": item.Id, - "milestones": item.Milestones, - "name": item.Name, - "obj_status": item.ObjStatus, - "provided_by": item.ProvidedBy, - "tech_status": item.TechStatus, - "type": item.Type, - "config_string": configString, + "ckey": item.Ckey, + "meta": flattenMeta(item.Meta), + "consumed_by": item.ConsumedBy, + "desc": item.Desc, + "gid": item.Gid, + "guid": item.Guid, + "sep_id": item.Id, + "milestones": item.Milestones, + "name": item.Name, + "obj_status": item.ObjStatus, + "provided_by": item.ProvidedBy, + "tech_status": item.TechStatus, + "type": item.Type, + "config": string(data), } res = append(res, temp) @@ -158,7 +157,7 @@ func dataSourceSepShortSchemaMake() map[string]*schema.Schema { Type: schema.TypeString, Computed: true, }, - "config_string": { + "config": { Type: schema.TypeString, Computed: true, }, diff --git a/decort/data_source_sep_dorado_pool.go b/decort/data_source_sep_pool.go similarity index 56% rename from decort/data_source_sep_dorado_pool.go rename to decort/data_source_sep_pool.go index 15dd3fa..6f401ba 100644 --- a/decort/data_source_sep_dorado_pool.go +++ b/decort/data_source_sep_pool.go @@ -25,35 +25,27 @@ Visit https://github.com/rudecs/terraform-provider-decort for full source code p package decort import ( + "encoding/json" + "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func dataSourceSepDoradoPoolRead(d *schema.ResourceData, m interface{}) error { - doradoSepPool, err := utilitySepDoradoPoolCheckPresence(d, m) +func dataSourceSepPoolRead(d *schema.ResourceData, m interface{}) error { + sepPool, err := utilitySepPoolCheckPresence(d, m) if err != nil { return err } id := uuid.New() d.SetId(id.String()) - d.Set("pool", flattenSepDoradoPool(doradoSepPool)) - - return nil -} -func flattenSepDoradoPool(pool *Pool) []map[string]interface{} { - temp := make([]map[string]interface{}, 0) - t := map[string]interface{}{ - "name": pool.Name, - "types": pool.Types, - "usage_limit": pool.UsageLimit, - } - temp = append(temp, t) + data, _ := json.Marshal(sepPool) + d.Set("pool", string(data)) - return temp + return nil } -func dataSourceSepDoradoPoolSchemaMake() map[string]*schema.Schema { +func dataSourceSepPoolSchemaMake() map[string]*schema.Schema { return map[string]*schema.Schema{ "sep_id": { Type: schema.TypeInt, @@ -66,42 +58,23 @@ func dataSourceSepDoradoPoolSchemaMake() map[string]*schema.Schema { Description: "pool name", }, "pool": { - Type: schema.TypeList, + Type: schema.TypeString, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Computed: true, - }, - "types": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "usage_limit": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, }, } } -func dataSourceSepDoradoPool() *schema.Resource { +func dataSourceSepPool() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceSepDoradoPoolRead, + Read: dataSourceSepPoolRead, Timeouts: &schema.ResourceTimeout{ Read: &Timeout30s, Default: &Timeout60s, }, - Schema: dataSourceSepDoradoPoolSchemaMake(), + Schema: dataSourceSepPoolSchemaMake(), } } diff --git a/decort/data_source_sep_tatlin.go b/decort/data_source_sep_tatlin.go deleted file mode 100644 index 2e2010b..0000000 --- a/decort/data_source_sep_tatlin.go +++ /dev/null @@ -1,352 +0,0 @@ -/* -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" - - "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -func dataSourceSepTatlinRead(d *schema.ResourceData, m interface{}) error { - tatlinSep, err := utilitySepTatlinCheckPresence(d, m) - if err != nil { - return err - } - id := uuid.New() - d.SetId(id.String()) - - d.Set("ckey", tatlinSep.Ckey) - d.Set("meta", flattenMeta(tatlinSep.Meta)) - d.Set("consumed_by", tatlinSep.ConsumedBy) - d.Set("desc", tatlinSep.Desc) - d.Set("gid", tatlinSep.Gid) - d.Set("guid", tatlinSep.Guid) - d.Set("sep_id", tatlinSep.Id) - d.Set("milestones", tatlinSep.Milestones) - d.Set("name", tatlinSep.Name) - d.Set("obj_status", tatlinSep.ObjStatus) - d.Set("provided_by", tatlinSep.ProvidedBy) - d.Set("tech_status", tatlinSep.TechStatus) - d.Set("type", tatlinSep.Type) - data, _ := json.Marshal(tatlinSep.Config) - d.Set("config_string", string(data)) - d.Set("config", flattenSepTatlinConfig(tatlinSep.Config)) - - return nil -} - -func flattenSepTatlinConfig(tc TatlinConfigSep) []interface{} { - return []interface{}{ - map[string]interface{}{ - "api_urls": tc.ApiUrls, - "disk_max_size": tc.DiskMaxSize, - "edgeuser_password": tc.EdgeuserPassword, - "edgeuser_name": tc.EdgeuserName, - "format": tc.Format, - "host_group_name": tc.HostGroupName, - "housekeeping_settings": []interface{}{ - map[string]interface{}{ - "disk_del_queue": []interface{}{ - map[string]interface{}{ - "purgatory_id": tc.HousekeepingSettings.DiskDelQueue.PurgatoryId, - "chunk_max_size": tc.HousekeepingSettings.DiskDelQueue.ChunkMaxSize, - "disk_count_max": tc.HousekeepingSettings.DiskDelQueue.DiskCountMax, - "enabled": tc.HousekeepingSettings.DiskDelQueue.Enabled, - "normal_time_to_sleep": tc.HousekeepingSettings.DiskDelQueue.NormalTimeToSleep, - "one_minute_la_threshold": tc.HousekeepingSettings.DiskDelQueue.OneMinuteLaThreshold, - "oversize_time_to_sleep": tc.HousekeepingSettings.DiskDelQueue.OversizeTimeToSleep, - "purge_attempts_threshold": tc.HousekeepingSettings.DiskDelQueue.PurgeAttemptsThreshold, - }, - }, - }, - }, - "ovs_settings": []interface{}{ - map[string]interface{}{ - "vpool_data_metadatacache": tc.OVSSettings.VPoolDataMetadataCache, - "vpool_vmstor_metadatacache": tc.OVSSettings.VPoolVMstorMetadataCache, - }, - }, - "mgmt_password": tc.MGMTPassword, - "mgmt_user": tc.MGMTUser, - "model": tc.Model, - "name_prefix": tc.NamePrefix, - "pools": flattenSepTatlinPools(tc.Pools), - "ports": flattenSepTatlinPorts(tc.Ports), - "protocol": tc.Protocol, - "tech_disk": []interface{}{ - map[string]interface{}{ - "name": tc.TechDisk.Name, - "size": tc.TechDisk.Size, - "pool": tc.TechDisk.Pool, - "wwid": tc.TechDisk.WWID, - }, - }, - }, - } -} - -func flattenSepTatlinPools(tp PoolList) []map[string]interface{} { - temp := make([]map[string]interface{}, 0) - for _, pool := range tp { - t := map[string]interface{}{ - "name": pool.Name, - "types": pool.Types, - "usage_limit": pool.UsageLimit, - } - temp = append(temp, t) - } - - return temp -} - -func flattenSepTatlinPorts(tp TatlinPortList) []map[string]interface{} { - temp := make([]map[string]interface{}, 0) - for _, port := range tp { - t := map[string]interface{}{ - "ips": port.IPS, - "iqn": port.IQN, - "name": port.Name, - } - temp = append(temp, t) - } - - return temp -} - -func dataSourceSepTatlinSchemaMake(sh map[string]*schema.Schema) map[string]*schema.Schema { - sh["config"] = &schema.Schema{ - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "api_urls": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "disk_max_size": { - Type: schema.TypeInt, - Computed: true, - }, - "ovs_settings": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "vpool_data_metadatacache": { - Type: schema.TypeInt, - Computed: true, - }, - "vpool_vmstor_metadatacache": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "edgeuser_password": { - Type: schema.TypeString, - Computed: true, - }, - "edgeuser_name": { - Type: schema.TypeString, - Computed: true, - }, - "format": { - Type: schema.TypeString, - Computed: true, - }, - "host_group_name": { - Type: schema.TypeString, - Computed: true, - }, - "housekeeping_settings": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "disk_del_queue": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "purge_attempts_threshold": { - Type: schema.TypeInt, - Computed: true, - }, - "chunk_max_size": { - Type: schema.TypeInt, - Computed: true, - }, - "disk_count_max": { - Type: schema.TypeInt, - Computed: true, - }, - "enabled": { - Type: schema.TypeBool, - Computed: true, - }, - "normal_time_to_sleep": { - Type: schema.TypeInt, - Computed: true, - }, - "one_minute_la_threshold": { - Type: schema.TypeInt, - Computed: true, - }, - "oversize_time_to_sleep": { - Type: schema.TypeInt, - Computed: true, - }, - "purgatory_id": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - }, - }, - }, - "mgmt_password": { - Type: schema.TypeString, - Computed: true, - }, - "mgmt_user": { - Type: schema.TypeString, - Computed: true, - }, - "model": { - Type: schema.TypeString, - Computed: true, - }, - "name_prefix": { - Type: schema.TypeString, - Computed: true, - }, - "pools": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Computed: true, - }, - "types": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "usage_limit": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "ports": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "ips": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "iqn": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - "protocol": { - Type: schema.TypeString, - Computed: true, - }, - "tech_disk": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Computed: true, - }, - "pool": { - Type: schema.TypeString, - Computed: true, - }, - "size": { - Type: schema.TypeInt, - Computed: true, - }, - "wwid": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - }, - }, - } - - return sh -} - -func dataSourceSepTatlin() *schema.Resource { - return &schema.Resource{ - SchemaVersion: 1, - - Read: dataSourceSepTatlinRead, - - Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, - }, - - Schema: dataSourceSepTatlinSchemaMake(dataSourceSepSchemaMake()), - } -} diff --git a/decort/data_source_sep_tatlin_config.go b/decort/data_source_sep_tatlin_config.go deleted file mode 100644 index c98aed9..0000000 --- a/decort/data_source_sep_tatlin_config.go +++ /dev/null @@ -1,270 +0,0 @@ -/* -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" - - "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -func dataSourceSepTatlinConfigRead(d *schema.ResourceData, m interface{}) error { - tatlinSepConfig, err := utilitySepTatlinConfigCheckPresence(d, m) - if err != nil { - return err - } - id := uuid.New() - d.SetId(id.String()) - - data, _ := json.Marshal(tatlinSepConfig) - d.Set("config_string", string(data)) - d.Set("config", flattenSepTatlinConfig(*tatlinSepConfig)) - - return nil -} - -func dataSourceSepTatlinConfigSchemaMake() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "sep_id": { - Type: schema.TypeInt, - Required: true, - Description: "storage endpoint provider ID", - }, - "config_string": { - Type: schema.TypeString, - Computed: true, - }, - "config": { - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "api_urls": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "disk_max_size": { - Type: schema.TypeInt, - Computed: true, - }, - "ovs_settings": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "vpool_data_metadatacache": { - Type: schema.TypeInt, - Computed: true, - }, - "vpool_vmstor_metadatacache": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "edgeuser_password": { - Type: schema.TypeString, - Computed: true, - }, - "edgeuser_name": { - Type: schema.TypeString, - Computed: true, - }, - "format": { - Type: schema.TypeString, - Computed: true, - }, - "host_group_name": { - Type: schema.TypeString, - Computed: true, - }, - "housekeeping_settings": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "disk_del_queue": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "purge_attempts_threshold": { - Type: schema.TypeInt, - Computed: true, - }, - "chunk_max_size": { - Type: schema.TypeInt, - Computed: true, - }, - "disk_count_max": { - Type: schema.TypeInt, - Computed: true, - }, - "enabled": { - Type: schema.TypeBool, - Computed: true, - }, - "normal_time_to_sleep": { - Type: schema.TypeInt, - Computed: true, - }, - "one_minute_la_threshold": { - Type: schema.TypeInt, - Computed: true, - }, - "oversize_time_to_sleep": { - Type: schema.TypeInt, - Computed: true, - }, - "purgatory_id": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - }, - }, - }, - "mgmt_password": { - Type: schema.TypeString, - Computed: true, - }, - "mgmt_user": { - Type: schema.TypeString, - Computed: true, - }, - "model": { - Type: schema.TypeString, - Computed: true, - }, - "name_prefix": { - Type: schema.TypeString, - Computed: true, - }, - "pools": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Computed: true, - }, - "types": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "usage_limit": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "ports": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "ips": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "iqn": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - "protocol": { - Type: schema.TypeString, - Computed: true, - }, - "tech_disk": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Computed: true, - }, - "pool": { - Type: schema.TypeString, - Computed: true, - }, - "size": { - Type: schema.TypeInt, - Computed: true, - }, - "wwid": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - }, - }, - }, - } -} - -func dataSourceSepTatlinConfig() *schema.Resource { - return &schema.Resource{ - SchemaVersion: 1, - - Read: dataSourceSepTatlinConfigRead, - - Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, - }, - - Schema: dataSourceSepTatlinConfigSchemaMake(), - } -} diff --git a/decort/data_source_sep_tatlin_pool.go b/decort/data_source_sep_tatlin_pool.go deleted file mode 100644 index 760dc57..0000000 --- a/decort/data_source_sep_tatlin_pool.go +++ /dev/null @@ -1,98 +0,0 @@ -/* -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 dataSourceSepTatlinPoolRead(d *schema.ResourceData, m interface{}) error { - tatlinSepPool, err := utilitySepTatlinPoolCheckPresence(d, m) - if err != nil { - return err - } - id := uuid.New() - d.SetId(id.String()) - - d.Set("pool", flattenSepTatlinPool(tatlinSepPool)) - - return nil -} - -func flattenSepTatlinPool(pool *Pool) []map[string]interface{} { - temp := make([]map[string]interface{}, 0) - t := map[string]interface{}{ - "name": pool.Name, - "types": pool.Types, - "usage_limit": pool.UsageLimit, - } - temp = append(temp, t) - - return temp -} - -func dataSourceSepTatlinPoolSchemaMake() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "pools": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Computed: true, - }, - "types": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "usage_limit": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - } -} - -func dataSourceSepTatlinPool() *schema.Resource { - return &schema.Resource{ - SchemaVersion: 1, - - Read: dataSourceSepTatlinPoolRead, - - Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, - }, - - Schema: dataSourceSepTatlinPoolSchemaMake(), - } -} diff --git a/decort/models_api.go b/decort/models_api.go index c7e43d3..8657058 100644 --- a/decort/models_api.go +++ b/decort/models_api.go @@ -866,240 +866,7 @@ const sepListAPI = "/restmachine/cloudbroker/sep/list" const sepUpdateCapacityLimitAPI = "/restmachine/cloudbroker/sep/updateCapacityLimit" -///Sep Configs -///////DES config -type DesDiskDelQueue struct { - PurgatoryId int `json:"purgatory_id"` - ChunkMaxSize int `json:"chunk_max_size"` - DiskCountMax int `json:"disk_count_max"` - Enabled bool `json:"enabled"` - NormalTimeToSleep int `json:"normal_time_to_sleep"` - OneMinuteLaThreshold int `json:"one_minute_la_threshold"` - OversizeTimeToSleep int `json:"oversize_time_to_sleep"` - PurgeAttemptsThreshold int `json:"purge_attempts_threshold"` -} - -type DesHousekeepingSettings struct { - DiskDelQueue DesDiskDelQueue `json:"disk_del_queue"` -} - -type URI struct { - IP string `json:"ip"` - Port int `json:"port"` -} - -type URIList []URI - -type DesConfigPool struct { - Types []string `json:"types"` - ReferenceId string `json:"referenceId"` - Name string `json:"name"` - PagecacheRatio int `json:"pagecache_ratio"` - URIS []URI `json:"uris"` -} - -type DesConfigPoolList []DesConfigPool - -type OVSSettings struct { - VPoolDataMetadataCache int `json:"vpool_data_metadatacache"` - VPoolVMstorMetadataCache int `json:"vpool_vmstor_metadatacache"` -} - -type DesConfigSep struct { - ApiIps []string `json:"API_IPs"` - Protocol string `json:"protocol"` - Decs3oAppSecret string `json:"decs3o_app_secret"` - Decs3oAppId string `json:"decs3o_app_id"` - Format string `json:"format"` - EdgeuserName string `json:"edgeuser_name"` - EdgeuserPassword string `json:"edgeuser_password"` - HousekeepingSettings DesHousekeepingSettings `json:"housekeeping_settings"` - Pools DesConfigPoolList `json:"pools"` - Transport string `json:"transport"` - CapacityLimit int `json:"capacity_limit"` - OVSSettings OVSSettings `json:"ovs_settings"` -} - -///////Hitachi config - -type HitachiConfigPool struct { - CloneTechnology string `json:"clone_technology"` - Id int `json:"id"` - MaxLdevId int `json:"maxLdevId"` - MinLdevId int `json:"minLdevId"` - Name string `json:"name"` - SnapshotPoolId int `json:"snapshot_pool_id"` - Snapshotable bool `json:"snapshotable"` - Types []string `json:"types"` - UsageLimit int `json:"usage_limit"` -} - -type HitachiConfigPoolList []HitachiConfigPool - -type HitachiConfigSep struct { - ApiUrls []string `json:"API_URLs"` - SN int `json:"SN"` - DiskMaxSize int `json:"disk_max_size"` - Format string `json:"format"` - HostGroupNumMax int `json:"hostGroupNumMax"` - HostGroupNumMin int `json:"hostGroupNumMin"` - HostGroupNumber int `json:"hostGroupNumber"` - HousekeepingSettings HousekeepingSettings `json:"housekeeping_settings"` - MGMTPassword string `json:"mgmt_password"` - MGMTUser string `json:"mgmt_user"` - Model string `json:"model"` - NamePrefix string `json:"name_prefix"` - Pools HitachiConfigPoolList `json:"pools"` - Ports []string `json:"ports"` - Protocol string `json:"protocol"` - SSLVerify bool `json:"ssl_verify"` - OVSSettings OVSSettings `json:"ovs_settings"` -} - -///////Tatlin Config - -type TatlinPort struct { - IPS []string `json:"ips"` - IQN string `json:"iqn"` - Name string `json:"name"` -} - -type TatlinPortList []TatlinPort - -type Pool struct { - Name string `json:"name"` - Types []string `json:"types"` - UsageLimit int `json:"usage_limit"` -} - -type PoolList []Pool - -type TatlinTechDisk struct { - Name string `json:"name"` - Size int `json:"size"` - Pool string `json:"pool"` - WWID string `json:"wwid"` -} - -type DiskDelQueue struct { - PurgatoryId int `json:"purgatory_id"` - ChunkMaxSize int `json:"chunk_max_size"` - DiskCountMax int `json:"disk_count_max"` - Enabled bool `json:"enabled"` - NormalTimeToSleep int `json:"normal_time_to_sleep"` - OneMinuteLaThreshold int `json:"one_minute_la_threshold"` - OversizeTimeToSleep int `json:"oversize_time_to_sleep"` - PurgeAttemptsThreshold int `json:"purge_attempts_threshold"` -} - -type HousekeepingSettings struct { - DiskDelQueue DiskDelQueue `json:"disk_del_queue"` -} - -type TatlinConfigSep struct { - ApiUrls []string `json:"API_URLs"` - DiskMaxSize int `json:"disk_max_size"` - Format string `json:"format"` - EdgeuserName string `json:"edgeuser_name"` - EdgeuserPassword string `json:"edgeuser_password"` - MGMTPassword string `json:"mgmt_password"` - MGMTUser string `json:"mgmt_user"` - HostGroupName string `json:"hostGroupName"` - Model string `json:"model"` - NamePrefix string `json:"name_prefix"` - Ports TatlinPortList `json:"ports"` - Pools PoolList `json:"pools"` - Protocol string `json:"protocol"` - TechDisk TatlinTechDisk `json:"techDisk"` - HousekeepingSettings HousekeepingSettings `json:"housekeeping_settings"` - OVSSettings OVSSettings `json:"ovs_settings"` -} - -//////Huawei Dorado - -type DoradoPort struct { - IP string `json:"ip"` - Name string `json:"name"` -} - -type DoradoPortList []DoradoPort - -type DoradoGroup struct { - HostGroup []string `json:"hostgroup"` - LungGroup []string `json:"lungroup"` - PortGroup []string `json:"portgroup"` -} - -type DoradoConfigSep struct { - ApiUrls []string `json:"API_URLs"` - DiskMaxSize int `json:"disk_max_size"` - Format string `json:"format"` - EdgeuserName string `json:"edgeuser_name"` - EdgeuserPassword string `json:"edgeuser_password"` - MGMTPassword string `json:"mgmt_password"` - MGMTUser string `json:"mgmt_user"` - HostGroupName string `json:"hostGroupName"` - Model string `json:"model"` - NamePrefix string `json:"name_prefix"` - Pools PoolList `json:"pools"` - Protocol string `json:"protocol"` - Ports DoradoPortList `json:"ports"` - Groups DoradoGroup `json:"groups"` - HousekeepingSettings HousekeepingSettings `json:"housekeeping_settings"` - OVSSettings OVSSettings `json:"ovs_settings"` -} - -////////////SEP - -type SepCommon struct { - Ckey string `json:"_ckey"` - Meta []interface{} `json:"_meta"` - ConsumedBy []int `json:"consumedBy"` - Desc string `json:"desc"` - Gid int `json:"gid"` - Guid int `json:"guid"` - Id int `json:"id"` - Milestones int `json:"milestones"` - Name string `json:"name"` - ObjStatus string `json:"objStatus"` - ProvidedBy []int `json:"providedBy"` - TechStatus string `json:"techStatus"` - Type string `json:"type"` - ConfigString interface{} `json:"config"` -} - -type SepList []SepCommon - -type SepDes struct { - SepCommon - Config DesConfigSep `json:"config"` -} - -type SepDesList []SepDes - -type SepHitachi struct { - SepCommon - Config HitachiConfigSep `json:"config"` -} - -type SepHitachiList []SepHitachi - -type SepTatlin struct { - SepCommon - Config TatlinConfigSep `json:"config"` -} - -type SepTatlinList []SepTatlin - -type SepDorado struct { - SepCommon - Config DoradoConfigSep `json:"config"` -} - -type SepDoradoList []SepDorado - -//////Consumption - +///Sep Models type SepConsumptionInd struct { DiskCount int `json:"disk_count"` DiskUsage int `json:"disk_usage"` @@ -1121,3 +888,25 @@ type SepConsumption struct { } type SepDiskList []int + +type Sep struct { + Ckey string `json:"_ckey"` + Meta []interface{} `json:"_meta"` + ConsumedBy []int `json:"consumedBy"` + Desc string `json:"desc"` + Gid int `json:"gid"` + Guid int `json:"guid"` + Id int `json:"id"` + Milestones int `json:"milestones"` + Name string `json:"name"` + ObjStatus string `json:"objStatus"` + ProvidedBy []int `json:"providedBy"` + TechStatus string `json:"techStatus"` + Type string `json:"type"` + Config SepConfig `json:"config"` +} + +type SepConfig map[string]interface{} + +type SepList []Sep +type SepPool map[string]interface{} diff --git a/decort/provider.go b/decort/provider.go index 4a8c185..69b95ef 100644 --- a/decort/provider.go +++ b/decort/provider.go @@ -111,36 +111,28 @@ func Provider() *schema.Provider { "decort_cdrom_image": resourceCDROMImage(), "decort_delete_images": resourceDeleteImages(), "decort_snapshot": resourceSnapshot(), - "decort_sep_des": resourceSepDes(), + "decort_sep": resourceSep(), + "decort_sep_config": resourceSepConfig(), }, 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_sep_list": dataSourceSepList(), - "decort_sep_des": dataSourceSepDes(), - "decort_sep_hitachi": dataSourceSepHitachi(), - "decort_sep_tatlin": dataSourceSepTatlin(), - "decort_sep_dorado": dataSourceSepDorado(), - "decort_sep_consumption": dataSourceSepConsumption(), - "decort_sep_disk_list": dataSourceSepDiskList(), - "decort_sep_des_pool": dataSourceSepDesPool(), - "decort_sep_dorado_pool": dataSourceSepDoradoPool(), - "decort_sep_hitachi_pool": dataSourceSepHitachiPool(), - "decort_sep_tatlin_pool": dataSourceSepTatlinPool(), - "decort_sep_des_config": dataSourceSepConfigDes(), - "decort_sep_hitahci_config": dataSourceSepHitachiConfig(), - "decort_sep_dorado_config": dataSourceSepDoradoConfig(), - "decort_sep_tatlin_config": dataSourceSepTatlinConfig(), + "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_sep_list": dataSourceSepList(), + "decort_sep": dataSourceSep(), + "decort_sep_consumption": dataSourceSepConsumption(), + "decort_sep_disk_list": dataSourceSepDiskList(), + "decort_sep_config": dataSourceSepConfig(), + "decort_sep_pool": dataSourceSepPool(), // "decort_pfw": dataSourcePfw(), }, diff --git a/decort/resource_sep_des.go b/decort/resource_sep.go similarity index 60% rename from decort/resource_sep_des.go rename to decort/resource_sep.go index 33b75ab..059198d 100644 --- a/decort/resource_sep_des.go +++ b/decort/resource_sep.go @@ -36,23 +36,23 @@ import ( log "github.com/sirupsen/logrus" ) -func resourceSepDesCreate(d *schema.ResourceData, m interface{}) error { - log.Debugf("resourceSepDesCreate: called for sep %s type \"des\"", d.Get("name").(string)) +func resourceSepCreate(d *schema.ResourceData, m interface{}) error { + log.Debugf("resourceSepCreate: called for sep %s", d.Get("name").(string)) if sepId, ok := d.GetOk("sep_id"); ok { - if exists, err := resourceSepDesExists(d, m); exists { + if exists, err := resourceSepExists(d, m); exists { if err != nil { return err } d.SetId(strconv.Itoa(sepId.(int))) - err = resourceSepDesRead(d, m) + err = resourceSepRead(d, m) if err != nil { return err } return nil } - return errors.New("provided device id does not exist") + return errors.New("provided sep id does not exist") } controller := m.(*ControllerCfg) @@ -60,12 +60,12 @@ func resourceSepDesCreate(d *schema.ResourceData, m interface{}) error { urlValues.Add("name", d.Get("name").(string)) urlValues.Add("gid", strconv.Itoa(d.Get("gid").(int))) - urlValues.Add("sep_type", "des") + urlValues.Add("sep_type", d.Get("type").(string)) if desc, ok := d.GetOk("desc"); ok { urlValues.Add("description", desc.(string)) } - if configString, ok := d.GetOk("config_string"); ok { + if configString, ok := d.GetOk("config"); ok { urlValues.Add("config", configString.(string)) } if enable, ok := d.GetOk("enable"); ok { @@ -98,16 +98,16 @@ func resourceSepDesCreate(d *schema.ResourceData, m interface{}) error { temp = "[" + temp + "]" urlValues.Add("provider_nids", temp) - sepDesId, err := controller.decortAPICall("POST", sepCreateAPI, urlValues) + sepId, err := controller.decortAPICall("POST", sepCreateAPI, urlValues) if err != nil { return err } id := uuid.New() - d.SetId(sepDesId) - d.Set("sep_id", sepDesId) + d.SetId(sepId) + d.Set("sep_id", sepId) - err = resourceSepDesRead(d, m) + err = resourceSepRead(d, m) if err != nil { return err } @@ -117,39 +117,38 @@ func resourceSepDesCreate(d *schema.ResourceData, m interface{}) error { return nil } -func resourceSepDesRead(d *schema.ResourceData, m interface{}) error { - log.Debugf("resourceSepDesRead: called for %s id: %d", d.Get("name").(string), d.Get("sep_id").(int)) +func resourceSepRead(d *schema.ResourceData, m interface{}) error { + log.Debugf("resourceSepRead: called for %s id: %d", d.Get("name").(string), d.Get("sep_id").(int)) - sepDes, err := utilitySepDesCheckPresence(d, m) - if sepDes == nil { + sep, err := utilitySepCheckPresence(d, m) + if sep == nil { d.SetId("") return err } - d.Set("ckey", sepDes.Ckey) - d.Set("meta", flattenMeta(sepDes.Meta)) - d.Set("consumed_by", sepDes.ConsumedBy) - d.Set("desc", sepDes.Desc) - d.Set("gid", sepDes.Gid) - d.Set("guid", sepDes.Guid) - d.Set("sep_id", sepDes.Id) - d.Set("milestones", sepDes.Milestones) - d.Set("name", sepDes.Name) - d.Set("obj_status", sepDes.ObjStatus) - d.Set("provided_by", sepDes.ProvidedBy) - d.Set("tech_status", sepDes.TechStatus) - d.Set("type", sepDes.Type) - data, _ := json.Marshal(sepDes.Config) - d.Set("config_string", string(data)) - d.Set("config", flattenSepDesConfig(sepDes.Config)) + d.Set("ckey", sep.Ckey) + d.Set("meta", flattenMeta(sep.Meta)) + d.Set("consumed_by", sep.ConsumedBy) + d.Set("desc", sep.Desc) + d.Set("gid", sep.Gid) + d.Set("guid", sep.Guid) + d.Set("sep_id", sep.Id) + d.Set("milestones", sep.Milestones) + d.Set("name", sep.Name) + d.Set("obj_status", sep.ObjStatus) + d.Set("provided_by", sep.ProvidedBy) + d.Set("tech_status", sep.TechStatus) + d.Set("type", sep.Type) + data, _ := json.Marshal(sep.Config) + d.Set("config", string(data)) return nil } -func resourceSepDesDelete(d *schema.ResourceData, m interface{}) error { - log.Debugf("resourceSepDesDelete: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int)) +func resourceSepDelete(d *schema.ResourceData, m interface{}) error { + log.Debugf("resourceSepDelete: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int)) - sepDes, err := utilitySepDesCheckPresence(d, m) + sepDes, err := utilitySepCheckPresence(d, m) if sepDes == nil { if err != nil { return err @@ -170,10 +169,10 @@ func resourceSepDesDelete(d *schema.ResourceData, m interface{}) error { return nil } -func resourceSepDesExists(d *schema.ResourceData, m interface{}) (bool, error) { - log.Debugf("resourceSepDesExists: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int)) +func resourceSepExists(d *schema.ResourceData, m interface{}) (bool, error) { + log.Debugf("resourceSepExists: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int)) - sepDes, err := utilitySepDesCheckPresence(d, m) + sepDes, err := utilitySepCheckPresence(d, m) if sepDes == nil { if err != nil { return false, err @@ -184,14 +183,14 @@ func resourceSepDesExists(d *schema.ResourceData, m interface{}) (bool, error) { return true, nil } -func resourceSepDesEdit(d *schema.ResourceData, m interface{}) error { - log.Debugf("resourceSepDesEdit: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int)) +func resourceSepEdit(d *schema.ResourceData, m interface{}) error { + log.Debugf("resourceSepEdit: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int)) c := m.(*ControllerCfg) - urlValues := &url.Values{} - if d.HasChange("decommision") { - decommision := d.Get("decommision").(bool) - if decommision { + urlValues := &url.Values{} + if d.HasChange("decommission") { + decommission := d.Get("decommission").(bool) + if decommission { urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) urlValues.Add("clear_physically", strconv.FormatBool(d.Get("clear_physically").(bool))) _, err := c.decortAPICall("POST", sepDecommissionAPI, urlValues) @@ -200,6 +199,7 @@ func resourceSepDesEdit(d *schema.ResourceData, m interface{}) error { } } } + urlValues = &url.Values{} if d.HasChange("upd_capacity_limit") { updCapacityLimit := d.Get("upd_capacity_limit").(bool) @@ -213,8 +213,37 @@ func resourceSepDesEdit(d *schema.ResourceData, m interface{}) error { } urlValues = &url.Values{} + if d.HasChange("config") { + urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) + urlValues.Add("config", d.Get("config").(string)) + _, err := c.decortAPICall("POST", sepConfigValidateAPI, urlValues) + if err != nil { + return err + } + _, err = c.decortAPICall("POST", sepConfigInsertAPI, urlValues) + if err != nil { + return err + } - err := resourceSepDesRead(d, m) + } + + urlValues = &url.Values{} + if d.HasChange("field_edit") { + fieldConfig := d.Get("field_edit").([]interface{}) + field := fieldConfig[0].(map[string]interface{}) + urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) + urlValues.Add("field_name", field["field_name"].(string)) + urlValues.Add("field_value", field["field_value"].(string)) + urlValues.Add("field_type", field["field_type"].(string)) + + _, err := c.decortAPICall("POST", sepConfigFieldEditAPI, urlValues) + if err != nil { + return err + } + } + + urlValues = &url.Values{} + err := resourceSepRead(d, m) if err != nil { return err } @@ -340,7 +369,7 @@ func resourceSepSchemaMake() map[string]*schema.Schema { Default: false, Description: "Update SEP capacity limit", }, - "decommision": { + "decommission": { Type: schema.TypeBool, Optional: true, Default: false, @@ -352,7 +381,7 @@ func resourceSepSchemaMake() map[string]*schema.Schema { Default: true, Description: "clear disks and images physically", }, - "config_string": { + "config": { Type: schema.TypeString, Optional: true, Computed: true, @@ -421,7 +450,7 @@ func resourceSepSchemaMake() map[string]*schema.Schema { }, "type": { Type: schema.TypeString, - Computed: true, + Required: true, Description: "type of storage", }, "enable": { @@ -430,164 +459,40 @@ func resourceSepSchemaMake() map[string]*schema.Schema { Default: false, Description: "enable SEP after creation", }, - } -} - -func resourceSepDesSchemaMake(sh map[string]*schema.Schema) map[string]*schema.Schema { - sh["config"] = &schema.Schema{ - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "api_ips": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + "field_edit": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "field_name": { + Type: schema.TypeString, + Required: true, }, - }, - "capacity_limit": { - Type: schema.TypeInt, - Computed: true, - }, - "protocol": { - Type: schema.TypeString, - Computed: true, - }, - "decs3o_app_secret": { - Type: schema.TypeString, - Computed: true, - }, - "format": { - Type: schema.TypeString, - Computed: true, - }, - "edgeuser_password": { - Type: schema.TypeString, - Computed: true, - }, - "edgeuser_name": { - Type: schema.TypeString, - Computed: true, - }, - "decs3o_app_id": { - Type: schema.TypeString, - Computed: true, - }, - "transport": { - Type: schema.TypeString, - Computed: true, - }, - "pools": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "types": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "reference_id": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "pagecache_ratio": { - Type: schema.TypeInt, - Computed: true, - }, - "uris": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "ip": { - Type: schema.TypeString, - Computed: true, - }, - "port": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - }, + "field_value": { + Type: schema.TypeString, + Required: true, }, - }, - "housekeeping_settings": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "disk_del_queue": { - Type: schema.TypeList, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "chunk_max_size": { - Type: schema.TypeInt, - Computed: true, - }, - "disk_count_max": { - Type: schema.TypeInt, - Computed: true, - }, - "enabled": { - Type: schema.TypeBool, - Computed: true, - }, - "normal_time_to_sleep": { - Type: schema.TypeInt, - Computed: true, - }, - "one_minute_la_threshold": { - Type: schema.TypeInt, - Computed: true, - }, - "oversize_time_to_sleep": { - Type: schema.TypeInt, - Computed: true, - }, - "purge_attempts_threshold": { - Type: schema.TypeInt, - Computed: true, - }, - "purgatory_id": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - }, + "field_type": { + Type: schema.TypeString, + Required: true, }, }, }, }, } - - return sh } -func resourceSepDes() *schema.Resource { +func resourceSep() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Create: resourceSepDesCreate, - Read: resourceSepDesRead, - Update: resourceSepDesEdit, - Delete: resourceSepDesDelete, - Exists: resourceSepDesExists, + Create: resourceSepCreate, + Read: resourceSepRead, + Update: resourceSepEdit, + Delete: resourceSepDelete, + Exists: resourceSepExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, @@ -601,7 +506,7 @@ func resourceSepDes() *schema.Resource { Default: &Timeout60s, }, - Schema: resourceSepDesSchemaMake(resourceSepSchemaMake()), + Schema: resourceSepSchemaMake(), CustomizeDiff: customdiff.All( customdiff.IfValueChange("enable", func(old, new, meta interface{}) bool { diff --git a/decort/resource_sep_config.go b/decort/resource_sep_config.go new file mode 100644 index 0000000..9663291 --- /dev/null +++ b/decort/resource_sep_config.go @@ -0,0 +1,197 @@ +/* +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" + "errors" + "net/url" + "strconv" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + log "github.com/sirupsen/logrus" +) + +func resourceSepConfigCreate(d *schema.ResourceData, m interface{}) error { + log.Debugf("resourceSepConfigCreate: called for sep id %d", d.Get("sep_id").(int)) + + if _, ok := d.GetOk("sep_id"); ok { + if exists, err := resourceSepConfigExists(d, m); exists { + if err != nil { + return err + } + id := uuid.New() + d.SetId(id.String()) + err = resourceSepConfigRead(d, m) + if err != nil { + return err + } + + return nil + } + return errors.New("provided sep id config does not exist") + } + + resourceSepConfigRead(d, m) + + return nil +} + +func resourceSepConfigRead(d *schema.ResourceData, m interface{}) error { + log.Debugf("resourceSepConfigRead: called for sep id: %d", d.Get("sep_id").(int)) + + sepConfig, err := utilitySepConfigCheckPresence(d, m) + if sepConfig == nil { + d.SetId("") + return err + } + data, _ := json.Marshal(sepConfig) + d.Set("config", string(data)) + return nil +} + +func resourceSepConfigDelete(d *schema.ResourceData, m interface{}) error { + d.SetId("") + return nil +} + +func resourceSepConfigExists(d *schema.ResourceData, m interface{}) (bool, error) { + log.Debugf("resourceSepConfigExists: called for sep id: %d", d.Get("sep_id").(int)) + + sepDesConfig, err := utilitySepConfigCheckPresence(d, m) + if sepDesConfig == nil { + if err != nil { + return false, err + } + return false, nil + } + + return true, nil +} + +func resourceSepConfigEdit(d *schema.ResourceData, m interface{}) error { + log.Debugf("resourceSepConfigEdit: called for sep id: %d", d.Get("sep_id").(int)) + c := m.(*ControllerCfg) + + urlValues := &url.Values{} + if d.HasChange("config") { + urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) + urlValues.Add("config", d.Get("config").(string)) + _, err := c.decortAPICall("POST", sepConfigValidateAPI, urlValues) + if err != nil { + return err + } + _, err = c.decortAPICall("POST", sepConfigInsertAPI, urlValues) + if err != nil { + return err + } + + } + + urlValues = &url.Values{} + if d.HasChange("field_edit") { + fieldConfig := d.Get("field_edit").([]interface{}) + field := fieldConfig[0].(map[string]interface{}) + urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) + urlValues.Add("field_name", field["field_name"].(string)) + urlValues.Add("field_value", field["field_value"].(string)) + urlValues.Add("field_type", field["field_type"].(string)) + + _, err := c.decortAPICall("POST", sepConfigFieldEditAPI, urlValues) + if err != nil { + return err + } + } + + err := resourceSepConfigRead(d, m) + if err != nil { + return err + } + + return nil +} + +func resourceSepConfigSchemaMake() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "sep_id": { + Type: schema.TypeInt, + Required: true, + }, + "config": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "field_edit": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "field_name": { + Type: schema.TypeString, + Required: true, + }, + "field_value": { + Type: schema.TypeString, + Required: true, + }, + "field_type": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, + } +} + +func resourceSepConfig() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + Create: resourceSepConfigCreate, + Read: resourceSepConfigRead, + Update: resourceSepConfigEdit, + Delete: resourceSepConfigDelete, + Exists: resourceSepConfigExists, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: &Timeout60s, + Read: &Timeout30s, + Update: &Timeout60s, + Delete: &Timeout60s, + Default: &Timeout60s, + }, + + Schema: resourceSepConfigSchemaMake(), + } +} diff --git a/decort/utility_sep_des.go b/decort/utility_sep.go similarity index 73% rename from decort/utility_sep_des.go rename to decort/utility_sep.go index 1135f6e..20dbf3d 100644 --- a/decort/utility_sep_des.go +++ b/decort/utility_sep.go @@ -26,21 +26,19 @@ package decort import ( "encoding/json" - "errors" "net/url" "strconv" - "strings" log "github.com/sirupsen/logrus" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func utilitySepDesCheckPresence(d *schema.ResourceData, m interface{}) (*SepDes, error) { +func utilitySepCheckPresence(d *schema.ResourceData, m interface{}) (*Sep, error) { controller := m.(*ControllerCfg) urlValues := &url.Values{} - sepDes := &SepDes{} + sep := &Sep{} if d.Get("sep_id").(int) == 0 { urlValues.Add("sep_id", d.Id()) @@ -48,19 +46,16 @@ func utilitySepDesCheckPresence(d *schema.ResourceData, m interface{}) (*SepDes, urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) } - log.Debugf("utilitySepDesCheckPresence: load sep") - sepDesRaw, err := controller.decortAPICall("POST", sepGetAPI, urlValues) + log.Debugf("utilitySepCheckPresence: load sep") + sepRaw, err := controller.decortAPICall("POST", sepGetAPI, urlValues) if err != nil { return nil, err } - err = json.Unmarshal([]byte(sepDesRaw), sepDes) + err = json.Unmarshal([]byte(sepRaw), sep) if err != nil { return nil, err } - if strings.ToLower(sepDes.Type) != "des" { - return nil, errors.New("Invalid sep type") - } - return sepDes, nil + return sep, nil } diff --git a/decort/utility_sep_des_config.go b/decort/utility_sep_config.go similarity index 75% rename from decort/utility_sep_des_config.go rename to decort/utility_sep_config.go index 3a4120c..ac98899 100644 --- a/decort/utility_sep_des_config.go +++ b/decort/utility_sep_config.go @@ -34,24 +34,24 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func utilitySepConfigDesCheckPresence(d *schema.ResourceData, m interface{}) (*DesConfigSep, error) { +func utilitySepConfigCheckPresence(d *schema.ResourceData, m interface{}) (SepConfig, error) { controller := m.(*ControllerCfg) urlValues := &url.Values{} - sepConfigDes := &DesConfigSep{} + sepConfig := SepConfig{} urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) - log.Debugf("utilitySepConfigDesCheckPresence: load sep") - sepConfigDesRaw, err := controller.decortAPICall("POST", sepGetConfigAPI, urlValues) + log.Debugf("utilitySepConfigCheckPresence: load sep config") + sepConfigRaw, err := controller.decortAPICall("POST", sepGetConfigAPI, urlValues) if err != nil { return nil, err } - err = json.Unmarshal([]byte(sepConfigDesRaw), sepConfigDes) + err = json.Unmarshal([]byte(sepConfigRaw), &sepConfig) if err != nil { return nil, err } - return sepConfigDes, nil + return sepConfig, nil } diff --git a/decort/utility_sep_dorado.go b/decort/utility_sep_dorado.go deleted file mode 100644 index c022a75..0000000 --- a/decort/utility_sep_dorado.go +++ /dev/null @@ -1,67 +0,0 @@ -/* -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" - "errors" - "net/url" - "strconv" - "strings" - - log "github.com/sirupsen/logrus" - - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -func utilitySepDoradoCheckPresence(d *schema.ResourceData, m interface{}) (*SepDorado, error) { - controller := m.(*ControllerCfg) - urlValues := &url.Values{} - - sepDorado := &SepDorado{} - - if d.Get("sep_id").(int) == 0 { - urlValues.Add("sep_id", d.Id()) - } else { - urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) - } - - log.Debugf("utilitySepDoradoCheckPresence: load sep") - sepDoradoRaw, err := controller.decortAPICall("POST", sepGetAPI, urlValues) - if err != nil { - return nil, err - } - - err = json.Unmarshal([]byte(sepDoradoRaw), sepDorado) - if err != nil { - return nil, err - } - - if strings.ToLower(sepDorado.Type) != "dorado" { - return nil, errors.New("Invalid sep type") - } - - return sepDorado, nil -} diff --git a/decort/utility_sep_dorado_config.go b/decort/utility_sep_dorado_config.go deleted file mode 100644 index f399cec..0000000 --- a/decort/utility_sep_dorado_config.go +++ /dev/null @@ -1,57 +0,0 @@ -/* -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 utilitySepDoradoConfigCheckPresence(d *schema.ResourceData, m interface{}) (*DoradoConfigSep, error) { - controller := m.(*ControllerCfg) - urlValues := &url.Values{} - - sepDoradoConfig := &DoradoConfigSep{} - - urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) - - log.Debugf("utilitySepDoradoConfigCheckPresence: load sep") - sepDoradoConfigRaw, err := controller.decortAPICall("POST", sepGetConfigAPI, urlValues) - if err != nil { - return nil, err - } - - err = json.Unmarshal([]byte(sepDoradoConfigRaw), sepDoradoConfig) - if err != nil { - return nil, err - } - - return sepDoradoConfig, nil -} diff --git a/decort/utility_sep_dorado_pool.go b/decort/utility_sep_dorado_pool.go deleted file mode 100644 index fdb96bf..0000000 --- a/decort/utility_sep_dorado_pool.go +++ /dev/null @@ -1,58 +0,0 @@ -/* -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 utilitySepDoradoPoolCheckPresence(d *schema.ResourceData, m interface{}) (*Pool, error) { - controller := m.(*ControllerCfg) - urlValues := &url.Values{} - - sepDoradoPool := &Pool{} - - urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) - urlValues.Add("pool_name", d.Get("pool_name").(string)) - - log.Debugf("utilitySepDoradoPoolCheckPresence: load sep") - sepDoradoPoolRaw, err := controller.decortAPICall("POST", sepGetPoolAPI, urlValues) - if err != nil { - return nil, err - } - - err = json.Unmarshal([]byte(sepDoradoPoolRaw), sepDoradoPool) - if err != nil { - return nil, err - } - - return sepDoradoPool, nil -} diff --git a/decort/utility_sep_hitachi.go b/decort/utility_sep_hitachi.go deleted file mode 100644 index 6e55625..0000000 --- a/decort/utility_sep_hitachi.go +++ /dev/null @@ -1,67 +0,0 @@ -/* -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" - "errors" - "net/url" - "strconv" - "strings" - - log "github.com/sirupsen/logrus" - - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -func utilitySepHitachiCheckPresence(d *schema.ResourceData, m interface{}) (*SepHitachi, error) { - controller := m.(*ControllerCfg) - urlValues := &url.Values{} - - sepHitachi := &SepHitachi{} - - if d.Get("sep_id").(int) == 0 { - urlValues.Add("sep_id", d.Id()) - } else { - urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) - } - - log.Debugf("utilitySepHitachiCheckPresence: load sep") - sepHitachiRaw, err := controller.decortAPICall("POST", sepGetAPI, urlValues) - if err != nil { - return nil, err - } - - err = json.Unmarshal([]byte(sepHitachiRaw), sepHitachi) - if err != nil { - return nil, err - } - - if strings.ToLower(sepHitachi.Type) != "hitachi" { - return nil, errors.New("Invalid sep type") - } - - return sepHitachi, nil -} diff --git a/decort/utility_sep_hitachi_config.go b/decort/utility_sep_hitachi_config.go deleted file mode 100644 index 3d38359..0000000 --- a/decort/utility_sep_hitachi_config.go +++ /dev/null @@ -1,57 +0,0 @@ -/* -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 utilitySepHitachiConfigCheckPresence(d *schema.ResourceData, m interface{}) (*HitachiConfigSep, error) { - controller := m.(*ControllerCfg) - urlValues := &url.Values{} - - sepHitachiConfig := &HitachiConfigSep{} - - urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) - - log.Debugf("utilitySepHitachiConfigCheckPresence: load sep") - sepHitachiConfigRaw, err := controller.decortAPICall("POST", sepGetConfigAPI, urlValues) - if err != nil { - return nil, err - } - - err = json.Unmarshal([]byte(sepHitachiConfigRaw), sepHitachiConfig) - if err != nil { - return nil, err - } - - return sepHitachiConfig, nil -} diff --git a/decort/utility_sep_hitachi_pool.go b/decort/utility_sep_hitachi_pool.go deleted file mode 100644 index c042009..0000000 --- a/decort/utility_sep_hitachi_pool.go +++ /dev/null @@ -1,58 +0,0 @@ -/* -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 utilitySepHitachiPoolCheckPresence(d *schema.ResourceData, m interface{}) (*HitachiConfigPool, error) { - controller := m.(*ControllerCfg) - urlValues := &url.Values{} - - sepHitachiPool := &HitachiConfigPool{} - - urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) - urlValues.Add("pool_name", d.Get("pool_name").(string)) - - log.Debugf("utilitySepDoradoPoolCheckPresence: load sep") - sepHitachiPoolRaw, err := controller.decortAPICall("POST", sepGetPoolAPI, urlValues) - if err != nil { - return nil, err - } - - err = json.Unmarshal([]byte(sepHitachiPoolRaw), sepHitachiPool) - if err != nil { - return nil, err - } - - return sepHitachiPool, nil -} diff --git a/decort/utility_sep_des_pool.go b/decort/utility_sep_pool.go similarity index 79% rename from decort/utility_sep_des_pool.go rename to decort/utility_sep_pool.go index 9c4cb8a..048bc4b 100644 --- a/decort/utility_sep_des_pool.go +++ b/decort/utility_sep_pool.go @@ -34,25 +34,25 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func utilitySepDesPoolCheckPresence(d *schema.ResourceData, m interface{}) (*DesConfigPool, error) { +func utilitySepPoolCheckPresence(d *schema.ResourceData, m interface{}) (SepPool, error) { controller := m.(*ControllerCfg) urlValues := &url.Values{} - sepDesPool := &DesConfigPool{} + sepPool := SepPool{} urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) urlValues.Add("pool_name", d.Get("pool_name").(string)) log.Debugf("utilitySepDesPoolCheckPresence: load sep") - sepDesPoolRaw, err := controller.decortAPICall("POST", sepGetPoolAPI, urlValues) + sepPoolRaw, err := controller.decortAPICall("POST", sepGetPoolAPI, urlValues) if err != nil { return nil, err } - err = json.Unmarshal([]byte(sepDesPoolRaw), sepDesPool) + err = json.Unmarshal([]byte(sepPoolRaw), &sepPool) if err != nil { return nil, err } - return sepDesPool, nil + return sepPool, nil } diff --git a/decort/utility_sep_tatlin_config.go b/decort/utility_sep_tatlin_config.go deleted file mode 100644 index 076047c..0000000 --- a/decort/utility_sep_tatlin_config.go +++ /dev/null @@ -1,57 +0,0 @@ -/* -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 utilitySepTatlinConfigCheckPresence(d *schema.ResourceData, m interface{}) (*TatlinConfigSep, error) { - controller := m.(*ControllerCfg) - urlValues := &url.Values{} - - sepTatlinConfig := &TatlinConfigSep{} - - urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) - - log.Debugf("utilitySepTatlinConfigCheckPresence: load sep") - sepTatlinConfigRaw, err := controller.decortAPICall("POST", sepGetConfigAPI, urlValues) - if err != nil { - return nil, err - } - - err = json.Unmarshal([]byte(sepTatlinConfigRaw), sepTatlinConfig) - if err != nil { - return nil, err - } - - return sepTatlinConfig, nil -} diff --git a/decort/utility_sep_tatlin_pool.go b/decort/utility_sep_tatlin_pool.go deleted file mode 100644 index 67bb16f..0000000 --- a/decort/utility_sep_tatlin_pool.go +++ /dev/null @@ -1,58 +0,0 @@ -/* -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 utilitySepTatlinPoolCheckPresence(d *schema.ResourceData, m interface{}) (*Pool, error) { - controller := m.(*ControllerCfg) - urlValues := &url.Values{} - - sepTatlinPool := &Pool{} - - urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) - urlValues.Add("pool_name", d.Get("pool_name").(string)) - - log.Debugf("utilitySepDoradoPoolCheckPresence: load sep") - sepTatlinPoolRaw, err := controller.decortAPICall("POST", sepGetPoolAPI, urlValues) - if err != nil { - return nil, err - } - - err = json.Unmarshal([]byte(sepTatlinPoolRaw), sepTatlinPool) - if err != nil { - return nil, err - } - - return sepTatlinPool, nil -} diff --git a/samples/README.md b/samples/README.md index d2b060f..b27fa02 100644 --- a/samples/README.md +++ b/samples/README.md @@ -9,6 +9,12 @@ - image_list - image_list_stacks - snapshot_list + - sep + - sep_list + - sep_disk_list + - sep_config + - sep_pool + - sep_consumption - resources: - image - virtual_image @@ -17,6 +23,8 @@ - k8s - k8s_wg - snapshot + - sep + - sep_config ## Как пользоваться примерами 1. Установить terraform diff --git a/samples/data_sep_des/main.tf b/samples/data_sep/main.tf similarity index 50% rename from samples/data_sep_des/main.tf rename to samples/data_sep/main.tf index 79833b3..2e7983d 100644 --- a/samples/data_sep_des/main.tf +++ b/samples/data_sep/main.tf @@ -1,16 +1,11 @@ /* Пример использования -Ресурса cdrom image -Ресурс позволяет: -1. Создавать образ -2. Редактировать образ -3. Удалять образ - +Получение данных sep */ -#Расскомментируйте этот код, +#Расскомментируйте код ниже, #и внесите необходимые правки в версию и путь, #чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером - +/* terraform { required_providers { decort = { @@ -19,23 +14,29 @@ terraform { } } } +*/ provider "decort" { authenticator = "oauth2" #controller_url = - #controller_url = "https://ds1.digitalenergy.online" - controller_url = "https://alfa.dev.decs.online" + controller_url = "https://ds1.digitalenergy.online" #oauth2_url = - #oauth2_url = "https://sso.digitalenergy.online" - oauth2_url = "https://iyo-alfa.dev.decs.online:8443" + oauth2_url = "https://sso.digitalenergy.online" allow_unverified_ssl = true } -data "decort_sep_des" "sl" { - sep_id = 1206 +data "decort_sep" "sd" { + #id sep + #обязательный параметр + #тип - число + sep_id = 1111 + } output "test" { - //value = tolist(data.decort_sep_des.sl.config)[0].api_ips - value = data.decort_sep_des.sl + value = data.decort_sep.sd +} + +output "config" { + value = jsondecode(data.decort_sep.sd.config) } diff --git a/samples/data_sep_tatlin/main.tf b/samples/data_sep_config/main.tf similarity index 50% rename from samples/data_sep_tatlin/main.tf rename to samples/data_sep_config/main.tf index 79833b3..50e54ad 100644 --- a/samples/data_sep_tatlin/main.tf +++ b/samples/data_sep_config/main.tf @@ -1,16 +1,11 @@ /* Пример использования -Ресурса cdrom image -Ресурс позволяет: -1. Создавать образ -2. Редактировать образ -3. Удалять образ - +Получение данных конфигурации sep */ -#Расскомментируйте этот код, +#Расскомментируйте код ниже, #и внесите необходимые правки в версию и путь, #чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером - +/* terraform { required_providers { decort = { @@ -19,23 +14,28 @@ terraform { } } } +*/ provider "decort" { authenticator = "oauth2" #controller_url = - #controller_url = "https://ds1.digitalenergy.online" - controller_url = "https://alfa.dev.decs.online" + controller_url = "https://ds1.digitalenergy.online" #oauth2_url = - #oauth2_url = "https://sso.digitalenergy.online" - oauth2_url = "https://iyo-alfa.dev.decs.online:8443" + oauth2_url = "https://sso.digitalenergy.online" allow_unverified_ssl = true } -data "decort_sep_des" "sl" { - sep_id = 1206 +data "decort_sep_config" "sc" { + #id sep + #обязательный параметр + #тип - число + sep_id = 1111 } output "test" { - //value = tolist(data.decort_sep_des.sl.config)[0].api_ips - value = data.decort_sep_des.sl + value = data.decort_sep_config.sc +} + +output "config" { + value = jsondecode(data.decort_config.sc.config) } diff --git a/samples/data_sep_consumption/main.tf b/samples/data_sep_consumption/main.tf index 2c14e9d..e0c7e06 100644 --- a/samples/data_sep_consumption/main.tf +++ b/samples/data_sep_consumption/main.tf @@ -1,16 +1,11 @@ /* Пример использования -Ресурса cdrom image -Ресурс позволяет: -1. Создавать образ -2. Редактировать образ -3. Удалять образ - +Получение общих данных об использовании sep */ -#Расскомментируйте этот код, +#Расскомментируйте код ниже, #и внесите необходимые правки в версию и путь, #чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером - +/* terraform { required_providers { decort = { @@ -19,26 +14,24 @@ terraform { } } } +*/ provider "decort" { authenticator = "oauth2" #controller_url = - #controller_url = "https://ds1.digitalenergy.online" - #controller_url = "https://gamma.dev.decs.online" - controller_url = "https://alfa.dev.decs.online" + controller_url = "https://ds1.digitalenergy.online" #oauth2_url = - #oauth2_url = "https://sso.digitalenergy.online" - #oauth2_url = "https://sso-gamma.dev.decs.online:8443" - oauth2_url = "https://iyo-alfa.dev.decs.online:8443" + oauth2_url = "https://sso.digitalenergy.online" allow_unverified_ssl = true } -data "decort_sep_consumption" "sd" { - sep_id = 1206 - +data "decort_sep_consumption" "scons" { + #id sep + #обязательный параметр + #тип - число + sep_id = 1111 } output "test" { - //value = tolist(data.decort_sep_des.sl.config)[0].api_ips - value = data.decort_sep_consumption.sd + value = data.decort_sep_consumption.scons } diff --git a/samples/data_sep_des_config/main.tf b/samples/data_sep_des_config/main.tf deleted file mode 100644 index f2917e4..0000000 --- a/samples/data_sep_des_config/main.tf +++ /dev/null @@ -1,42 +0,0 @@ -/* -Пример использования -Ресурса 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" - controller_url = "https://alfa.dev.decs.online" - #oauth2_url = - #oauth2_url = "https://sso.digitalenergy.online" - oauth2_url = "https://iyo-alfa.dev.decs.online:8443" - allow_unverified_ssl = true -} - -data "decort_sep_des_config" "sd" { - sep_id = 1206 - -} - -output "test" { - //value = tolist(data.decort_sep_des.sl.config)[0].api_ips - value = data.decort_sep_des_config.sd -} diff --git a/samples/data_sep_des_pool/main.tf b/samples/data_sep_des_pool/main.tf deleted file mode 100644 index 37a67a8..0000000 --- a/samples/data_sep_des_pool/main.tf +++ /dev/null @@ -1,43 +0,0 @@ -/* -Пример использования -Ресурса 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" - controller_url = "https://gamma.dev.decs.online" - #oauth2_url = - #oauth2_url = "https://sso.digitalenergy.online" - oauth2_url = "https://sso-gamma.dev.decs.online:8443" - allow_unverified_ssl = true -} - -data "decort_sep_des_pool" "sd" { - sep_id = 1 - pool_name = "data01" - -} - -output "test" { - //value = tolist(data.decort_sep_des.sl.config)[0].api_ips - value = data.decort_sep_des_pool.sd -} diff --git a/samples/data_sep_disk_list/main.tf b/samples/data_sep_disk_list/main.tf index 9688814..3f10d49 100644 --- a/samples/data_sep_disk_list/main.tf +++ b/samples/data_sep_disk_list/main.tf @@ -1,16 +1,12 @@ /* Пример использования -Ресурса cdrom image -Ресурс позволяет: -1. Создавать образ -2. Редактировать образ -3. Удалять образ - +Получение данных об используемых sep дисках */ -#Расскомментируйте этот код, + +#Расскомментируйте код ниже, #и внесите необходимые правки в версию и путь, #чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером - +/* terraform { required_providers { decort = { @@ -19,26 +15,28 @@ terraform { } } } +*/ provider "decort" { authenticator = "oauth2" #controller_url = - #controller_url = "https://ds1.digitalenergy.online" - #controller_url = "https://gamma.dev.decs.online" - controller_url = "https://alfa.dev.decs.online" + controller_url = "https://ds1.digitalenergy.online" #oauth2_url = - #oauth2_url = "https://sso.digitalenergy.online" - #oauth2_url = "https://sso-gamma.dev.decs.online:8443" - oauth2_url = "https://iyo-alfa.dev.decs.online:8443" + oauth2_url = "https://sso.digitalenergy.online" allow_unverified_ssl = true } -data "decort_sep_disk_list" "sd" { - sep_id = 1206 - +data "decort_sep_disk_list" "sdl" { + #id sep + #обязательный параметр + #тип - число + sep_id = 1111 + #sep pool name + #необязательный параметр + #тип - строка + #pool_name = "sep_pool" } output "test" { - //value = tolist(data.decort_sep_des.sl.config)[0].api_ips - value = data.decort_sep_disk_list.sd + value = data.decort_sep_disk_list.sdl } diff --git a/samples/data_sep_dorado_pool/main.tf b/samples/data_sep_dorado_pool/main.tf deleted file mode 100644 index 18bd388..0000000 --- a/samples/data_sep_dorado_pool/main.tf +++ /dev/null @@ -1,43 +0,0 @@ -/* -Пример использования -Ресурса 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" - controller_url = "https://gamma.dev.decs.online" - #oauth2_url = - #oauth2_url = "https://sso.digitalenergy.online" - oauth2_url = "https://sso-gamma.dev.decs.online:8443" - allow_unverified_ssl = true -} - -data "decort_sep_dorado_pool" "sd" { - sep_id = 7 - pool_name = "SP1" - -} - -output "test" { - //value = tolist(data.decort_sep_des.sl.config)[0].api_ips - value = data.decort_sep_dorado_pool.sd -} diff --git a/samples/data_sep_hitachi/main.tf b/samples/data_sep_hitachi/main.tf deleted file mode 100644 index 79833b3..0000000 --- a/samples/data_sep_hitachi/main.tf +++ /dev/null @@ -1,41 +0,0 @@ -/* -Пример использования -Ресурса 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" - controller_url = "https://alfa.dev.decs.online" - #oauth2_url = - #oauth2_url = "https://sso.digitalenergy.online" - oauth2_url = "https://iyo-alfa.dev.decs.online:8443" - allow_unverified_ssl = true -} - -data "decort_sep_des" "sl" { - sep_id = 1206 -} - -output "test" { - //value = tolist(data.decort_sep_des.sl.config)[0].api_ips - value = data.decort_sep_des.sl -} diff --git a/samples/data_sep_hitachi_pool/main.tf b/samples/data_sep_hitachi_pool/main.tf deleted file mode 100644 index ab7b63b..0000000 --- a/samples/data_sep_hitachi_pool/main.tf +++ /dev/null @@ -1,43 +0,0 @@ -/* -Пример использования -Ресурса 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" - controller_url = "https://gamma.dev.decs.online" - #oauth2_url = - #oauth2_url = "https://sso.digitalenergy.online" - oauth2_url = "https://sso-gamma.dev.decs.online:8443" - allow_unverified_ssl = true -} - -data "decort_sep_hitachi_pool" "sd" { - sep_id = 7 - pool_name = "SP1" - -} - -output "test" { - //value = tolist(data.decort_sep_des.sl.config)[0].api_ips - value = data.decort_sep_hitachi_pool.sd -} diff --git a/samples/data_sep_list/main.tf b/samples/data_sep_list/main.tf index 5f49a28..b64f77d 100644 --- a/samples/data_sep_list/main.tf +++ b/samples/data_sep_list/main.tf @@ -1,16 +1,11 @@ /* Пример использования -Ресурса cdrom image -Ресурс позволяет: -1. Создавать образ -2. Редактировать образ -3. Удалять образ - +Получение списка sep */ -#Расскомментируйте этот код, +#Расскомментируйте код ниже, #и внесите необходимые правки в версию и путь, #чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером - +/* terraform { required_providers { decort = { @@ -19,19 +14,25 @@ terraform { } } } - +*/ provider "decort" { authenticator = "oauth2" #controller_url = - #controller_url = "https://ds1.digitalenergy.online" - controller_url = "https://alfa.dev.decs.online" + controller_url = "https://ds1.digitalenergy.online" #oauth2_url = - #oauth2_url = "https://sso.digitalenergy.online" - oauth2_url = "https://iyo-alfa.dev.decs.online:8443" + oauth2_url = "https://sso.digitalenergy.online" allow_unverified_ssl = true } data "decort_sep_list" "sl" { + #страница + #необязательный параметр + #тип - число + #page = 3 + #размер страницы + #необязательный параметр + #тип - число + #size = 2 } output "test" { diff --git a/samples/data_sep_dorado/main.tf b/samples/data_sep_pool/main.tf similarity index 50% rename from samples/data_sep_dorado/main.tf rename to samples/data_sep_pool/main.tf index 79833b3..1bed890 100644 --- a/samples/data_sep_dorado/main.tf +++ b/samples/data_sep_pool/main.tf @@ -1,16 +1,12 @@ /* Пример использования -Ресурса cdrom image -Ресурс позволяет: -1. Создавать образ -2. Редактировать образ -3. Удалять образ +Получение данных sep pool */ -#Расскомментируйте этот код, +#Расскомментируйте код ниже, #и внесите необходимые правки в версию и путь, #чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером - +/* terraform { required_providers { decort = { @@ -19,23 +15,32 @@ terraform { } } } +*/ provider "decort" { authenticator = "oauth2" #controller_url = - #controller_url = "https://ds1.digitalenergy.online" - controller_url = "https://alfa.dev.decs.online" + controller_url = "https://ds1.digitalenergy.online" #oauth2_url = - #oauth2_url = "https://sso.digitalenergy.online" - oauth2_url = "https://iyo-alfa.dev.decs.online:8443" + oauth2_url = "https://sso.digitalenergy.online" allow_unverified_ssl = true } -data "decort_sep_des" "sl" { - sep_id = 1206 +data "decort_sep_pool" "sp" { + #id sep + #обязательный параметр + #тип - число + sep_id = 1111 + #sep pool name + #обязательный параметр + #тип - строка + pool_name = "sep_pool" } output "test" { - //value = tolist(data.decort_sep_des.sl.config)[0].api_ips - value = data.decort_sep_des.sl + value = data.decort_sep_pool.sp +} + +output "pool" { + value = jsondecode(data.decort_sep_pool.sp.pool) } diff --git a/samples/data_sep_tatlin_pool/main.tf b/samples/data_sep_tatlin_pool/main.tf deleted file mode 100644 index 95da0d5..0000000 --- a/samples/data_sep_tatlin_pool/main.tf +++ /dev/null @@ -1,43 +0,0 @@ -/* -Пример использования -Ресурса 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" - controller_url = "https://gamma.dev.decs.online" - #oauth2_url = - #oauth2_url = "https://sso.digitalenergy.online" - oauth2_url = "https://sso-gamma.dev.decs.online:8443" - allow_unverified_ssl = true -} - -data "decort_sep_tatlin_pool" "sd" { - sep_id = 7 - pool_name = "SP1" - -} - -output "test" { - //value = tolist(data.decort_sep_des.sl.config)[0].api_ips - value = data.decort_sep_tatlin_pool.sd -} diff --git a/samples/resource_sep/main.tf b/samples/resource_sep/main.tf new file mode 100644 index 0000000..c7e016c --- /dev/null +++ b/samples/resource_sep/main.tf @@ -0,0 +1,124 @@ +/* +Пример использования +Ресурса sep +Ресурс позволяет: +1. Создавать sep. +2. Редактировать sep. +3. Удалять sep. +4. Конфигурировать sep. + +*/ +#Расскомментируйте код ниже, +#и внесите необходимые правки в версию и путь, +#чтобы работать с установленным вручную (не через 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_sep" "s" { + #grid id + #обязательный параметр + #тип - число + gid = 212 + + #sep name + #обязательный параметр + #тип - строка + name = "test sep" + + #тип sep + #обязательный параметр + #тип - строка + #возможные значения - des, dorado, tatlin, hitachi + type = "des" + + #описание sep + #необязательный параметр, используется при создании ресурса + #тип - строка + desc = "rrrrr" + + #конфигурация sep + #необязательный параметр, мб применен при создании или редактировании sep + #представляет собой json-строку + #тип - строка + #config = file("./config.json") + + #изменение поля в конфигурации + #необязательный параметр, мб применен на уже созданном sep + #тип - объект + #внимание, во избежание конфликтов не использовать с полем config + /* + field_edit { + #имя поля + #обязательный параметр + #тип - строка + field_name = "edgeuser_password" + + #значение поля + #обязательный параметр + #тип - json строка + field_value = "mosk" + + #тип значения + #обязательный параметр + #тип - строка, возможные значения: list,dict,int,bool,str + field_type = "str" + } + */ + + #доступность sep + #необязательный параметр, мб применен на уже созданном ресурсе + #тип - булево значение + #enable = false + + #использование нодами + #необязательный параметр, используется при редактировании ресурса + #тип - массив чисел + #consumed_by = [] + + #обновление лимита объема + #необязательный параметр, применяется на уж созданнном ресурсе + #тип - булев тип + #upd_capacity_limit = true + + #id provided nodes + #необязательный параметр, применяется на уже созданном ресурсе + #тип - массив чисел + #provided_by = [16, 14, 15] + + #отключение nodes + #необязательный параметр, применяется на уже созданном ресурсе + #тип - булев тип + #используется в связке с clear_physically + #decommission = true + + #физическое очищение nodes + #необязательный параметр, используется при удалении ресурса + #тип - булев тип + #clear_physically = false + +} + +output "test" { + value = decort_sep.s +} + +output "config" { + value = jsondecode(decort_sep.s.config) + +} diff --git a/samples/resource_sep_config/main.tf b/samples/resource_sep_config/main.tf new file mode 100644 index 0000000..83341b6 --- /dev/null +++ b/samples/resource_sep_config/main.tf @@ -0,0 +1,73 @@ +/* +Пример использования +Ресурс конфигурации sep +Ресурс позволяет: +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_sep_config" "sc" { + #id sep + #обязательный параметр + #тип - число + sep_id = 1111 + + #конфигурация + #необязательное поле, используется для изменения конфигурации + #тип - json-строка + #config = file("./config.json") + + #редактироваие поля + #неоябазательный параметр, используется при редактировании ресурса + #тип - объект + /* + field_edit { + #имя поля + #обязательный параметр + #тип - строка + field_name = "edgeuser_password" + + #значение поля + #обязательный параметр + #тип - строка + field_value = "shshs" + + #тип поля + #обязательный параметр + #тип - строка + #возможные значения - int,bool, str, dict, list + field_type = "str" + } + */ +} + +output "sep_config" { + value = decort_sep_config.sc +} + +output "sep_config_json" { + value = jsondecode(decort_sep_config.sc.config) +} diff --git a/samples/resource_sep_des/main.tf b/samples/resource_sep_des/main.tf deleted file mode 100644 index 4c1accd..0000000 --- a/samples/resource_sep_des/main.tf +++ /dev/null @@ -1,51 +0,0 @@ -/* -Пример использования -Ресурса 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" - controller_url = "https://gamma.dev.decs.online" - #oauth2_url = - #oauth2_url = "https://sso.digitalenergy.online" - oauth2_url = "https://sso-gamma.dev.decs.online:8443" - allow_unverified_ssl = true -} - -resource "decort_sep_des" "sd" { - sep_id = 11 - gid = 214 - name = "test sep" - desc = "rrrrr" - enable = false - consumed_by = [] - upd_capacity_limit = true - #provided_by = [16, 14, 15] - #decommision = true - #clear_physically = false - -} - -output "test" { - //value = tolist(data.decort_sep_des.sl.config)[0].api_ips - value = decort_sep_des.sd -}