Merge branch '2.2/feature/sep' into '2.1'
2.2/feature/sep See merge request rudecs/terraform-provider-decort!6
This commit is contained in:
@@ -15,7 +15,8 @@ Terraform provider для платформы Digital Energy Cloud Orchestration
|
|||||||
- Работа с VINS,
|
- Работа с VINS,
|
||||||
- Работа с pfw,
|
- Работа с pfw,
|
||||||
- Работа с accounts,
|
- Работа с accounts,
|
||||||
- Работа с snapshots.
|
- Работа с snapshots,
|
||||||
|
- Работа с sep.
|
||||||
|
|
||||||
Вики проекта: https://github.com/rudecs/terraform-provider-decort/wiki
|
Вики проекта: https://github.com/rudecs/terraform-provider-decort/wiki
|
||||||
|
|
||||||
|
|||||||
@@ -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 VINS,
|
||||||
- Work with pfw,
|
- Work with pfw,
|
||||||
- Work with accounts,
|
- Work with accounts,
|
||||||
- Work with snapshots.
|
- Work with snapshots,
|
||||||
|
- Work with sep.
|
||||||
|
|
||||||
This provider supports Import operations on pre-existing resources.
|
This provider supports Import operations on pre-existing resources.
|
||||||
|
|
||||||
|
|||||||
145
decort/data_source_sep.go
Normal file
145
decort/data_source_sep.go
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
|
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||||
|
Technology platfom.
|
||||||
|
|
||||||
|
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package decort
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
77
decort/data_source_sep_config.go
Normal file
77
decort/data_source_sep_config.go
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
|
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||||
|
Technology platfom.
|
||||||
|
|
||||||
|
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package decort
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func dataSourceSepConfigRead(d *schema.ResourceData, m interface{}) error {
|
||||||
|
sepConfig, err := utilitySepConfigCheckPresence(d, m)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
id := uuid.New()
|
||||||
|
d.SetId(id.String())
|
||||||
|
|
||||||
|
data, _ := json.Marshal(sepConfig)
|
||||||
|
d.Set("config", string(data))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func dataSourceSepConfig() *schema.Resource {
|
||||||
|
return &schema.Resource{
|
||||||
|
SchemaVersion: 1,
|
||||||
|
|
||||||
|
Read: dataSourceSepConfigRead,
|
||||||
|
|
||||||
|
Timeouts: &schema.ResourceTimeout{
|
||||||
|
Read: &Timeout30s,
|
||||||
|
Default: &Timeout60s,
|
||||||
|
},
|
||||||
|
|
||||||
|
Schema: dataSourceSepConfigSchemaMake(),
|
||||||
|
}
|
||||||
|
}
|
||||||
195
decort/data_source_sep_consumption.go
Normal file
195
decort/data_source_sep_consumption.go
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
|
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||||
|
Technology platfom.
|
||||||
|
|
||||||
|
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package decort
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func dataSourceSepConsumptionRead(d *schema.ResourceData, m interface{}) error {
|
||||||
|
sepCons, err := utilitySepConsumptionCheckPresence(d, m)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
id := uuid.New()
|
||||||
|
d.SetId(id.String())
|
||||||
|
|
||||||
|
d.Set("type", sepCons.Type)
|
||||||
|
d.Set("total", flattenSepConsumption(sepCons.Total))
|
||||||
|
d.Set("by_pool", flattenSepConsumptionPools(sepCons.ByPool))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func flattenSepConsumptionPools(mp map[string]SepConsumptionInd) []map[string]interface{} {
|
||||||
|
sh := make([]map[string]interface{}, 0)
|
||||||
|
for k, v := range mp {
|
||||||
|
temp := map[string]interface{}{
|
||||||
|
"name": k,
|
||||||
|
"disk_count": v.DiskCount,
|
||||||
|
"disk_usage": v.DiskUsage,
|
||||||
|
"snapshot_count": v.SnapshotCount,
|
||||||
|
"snapshot_usage": v.SnapshotUsage,
|
||||||
|
"usage": v.Usage,
|
||||||
|
"usage_limit": v.UsageLimit,
|
||||||
|
}
|
||||||
|
sh = append(sh, temp)
|
||||||
|
}
|
||||||
|
return sh
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
return map[string]*schema.Schema{
|
||||||
|
"sep_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Required: true,
|
||||||
|
Description: "sep id",
|
||||||
|
},
|
||||||
|
"by_pool": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Resource{
|
||||||
|
Schema: map[string]*schema.Schema{
|
||||||
|
"name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "pool name",
|
||||||
|
},
|
||||||
|
"disk_count": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "number of disks",
|
||||||
|
},
|
||||||
|
"disk_usage": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "disk usage",
|
||||||
|
},
|
||||||
|
"snapshot_count": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "number of snapshots",
|
||||||
|
},
|
||||||
|
"snapshot_usage": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "snapshot usage",
|
||||||
|
},
|
||||||
|
"usage": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "usage",
|
||||||
|
},
|
||||||
|
"usage_limit": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "usage limit",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Description: "consumption divided by pool",
|
||||||
|
},
|
||||||
|
"total": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
MaxItems: 1,
|
||||||
|
Elem: &schema.Resource{
|
||||||
|
Schema: map[string]*schema.Schema{
|
||||||
|
"capacity_limit": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"disk_count": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "number of disks",
|
||||||
|
},
|
||||||
|
"disk_usage": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "disk usage",
|
||||||
|
},
|
||||||
|
"snapshot_count": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "number of snapshots",
|
||||||
|
},
|
||||||
|
"snapshot_usage": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "snapshot usage",
|
||||||
|
},
|
||||||
|
"usage": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "usage",
|
||||||
|
},
|
||||||
|
"usage_limit": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "usage limit",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Description: "total consumption",
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "sep type",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func dataSourceSepConsumption() *schema.Resource {
|
||||||
|
return &schema.Resource{
|
||||||
|
SchemaVersion: 1,
|
||||||
|
|
||||||
|
Read: dataSourceSepConsumptionRead,
|
||||||
|
|
||||||
|
Timeouts: &schema.ResourceTimeout{
|
||||||
|
Read: &Timeout30s,
|
||||||
|
Default: &Timeout60s,
|
||||||
|
},
|
||||||
|
|
||||||
|
Schema: dataSourceSepConsumptionSchemaMake(),
|
||||||
|
}
|
||||||
|
}
|
||||||
82
decort/data_source_sep_disk_list.go
Normal file
82
decort/data_source_sep_disk_list.go
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
|
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||||
|
Technology platfom.
|
||||||
|
|
||||||
|
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package decort
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func dataSourceSepDiskListRead(d *schema.ResourceData, m interface{}) error {
|
||||||
|
sepDiskList, err := utilitySepDiskListCheckPresence(d, m)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
id := uuid.New()
|
||||||
|
d.SetId(id.String())
|
||||||
|
d.Set("items", sepDiskList)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func dataSourceSepDiskListSchemaMake() map[string]*schema.Schema {
|
||||||
|
rets := map[string]*schema.Schema{
|
||||||
|
"sep_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Required: true,
|
||||||
|
Description: "storage endpoint provider ID",
|
||||||
|
},
|
||||||
|
"pool_name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
Description: "pool name",
|
||||||
|
},
|
||||||
|
"items": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Description: "sep disk list",
|
||||||
|
Elem: &schema.Schema{
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return rets
|
||||||
|
}
|
||||||
|
|
||||||
|
func dataSourceSepDiskList() *schema.Resource {
|
||||||
|
return &schema.Resource{
|
||||||
|
SchemaVersion: 1,
|
||||||
|
|
||||||
|
Read: dataSourceSepDiskListRead,
|
||||||
|
|
||||||
|
Timeouts: &schema.ResourceTimeout{
|
||||||
|
Read: &Timeout30s,
|
||||||
|
Default: &Timeout60s,
|
||||||
|
},
|
||||||
|
|
||||||
|
Schema: dataSourceSepDiskListSchemaMake(),
|
||||||
|
}
|
||||||
|
}
|
||||||
180
decort/data_source_sep_list.go
Normal file
180
decort/data_source_sep_list.go
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
|
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||||
|
Technology platfom.
|
||||||
|
|
||||||
|
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package decort
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func flattenSepList(sl SepList) []map[string]interface{} {
|
||||||
|
res := make([]map[string]interface{}, 0)
|
||||||
|
for _, item := range sl {
|
||||||
|
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(data),
|
||||||
|
}
|
||||||
|
|
||||||
|
res = append(res, temp)
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func dataSourceSepListRead(d *schema.ResourceData, m interface{}) error {
|
||||||
|
sepList, err := utilitySepListCheckPresence(d, m)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
id := uuid.New()
|
||||||
|
d.SetId(id.String())
|
||||||
|
d.Set("items", flattenSepList(sepList))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func dataSourceSepListSchemaMake() map[string]*schema.Schema {
|
||||||
|
rets := map[string]*schema.Schema{
|
||||||
|
"page": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Optional: true,
|
||||||
|
Description: "page number",
|
||||||
|
},
|
||||||
|
"size": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Optional: true,
|
||||||
|
Description: "page size",
|
||||||
|
},
|
||||||
|
"items": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Description: "sep list",
|
||||||
|
Elem: &schema.Resource{
|
||||||
|
Schema: dataSourceSepShortSchemaMake(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return rets
|
||||||
|
}
|
||||||
|
|
||||||
|
func dataSourceSepShortSchemaMake() map[string]*schema.Schema {
|
||||||
|
return map[string]*schema.Schema{
|
||||||
|
"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,
|
||||||
|
},
|
||||||
|
"sep_id": {
|
||||||
|
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 dataSourceSepList() *schema.Resource {
|
||||||
|
return &schema.Resource{
|
||||||
|
SchemaVersion: 1,
|
||||||
|
|
||||||
|
Read: dataSourceSepListRead,
|
||||||
|
|
||||||
|
Timeouts: &schema.ResourceTimeout{
|
||||||
|
Read: &Timeout30s,
|
||||||
|
Default: &Timeout60s,
|
||||||
|
},
|
||||||
|
|
||||||
|
Schema: dataSourceSepListSchemaMake(),
|
||||||
|
}
|
||||||
|
}
|
||||||
80
decort/data_source_sep_pool.go
Normal file
80
decort/data_source_sep_pool.go
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
|
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||||
|
Technology platfom.
|
||||||
|
|
||||||
|
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package decort
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
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())
|
||||||
|
|
||||||
|
data, _ := json.Marshal(sepPool)
|
||||||
|
d.Set("pool", string(data))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func dataSourceSepPoolSchemaMake() 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.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func dataSourceSepPool() *schema.Resource {
|
||||||
|
return &schema.Resource{
|
||||||
|
SchemaVersion: 1,
|
||||||
|
|
||||||
|
Read: dataSourceSepPoolRead,
|
||||||
|
|
||||||
|
Timeouts: &schema.ResourceTimeout{
|
||||||
|
Read: &Timeout30s,
|
||||||
|
Default: &Timeout60s,
|
||||||
|
},
|
||||||
|
|
||||||
|
Schema: dataSourceSepPoolSchemaMake(),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -835,3 +835,78 @@ type Snapshot struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SnapshotList []Snapshot
|
type SnapshotList []Snapshot
|
||||||
|
|
||||||
|
///////////////////
|
||||||
|
///// SEP API /////
|
||||||
|
///////////////////
|
||||||
|
const sepAddConsumerNodesAPI = "/restmachine/cloudbroker/sep/addConsumerNodes"
|
||||||
|
const sepDelConsumerNodesAPI = "/restmachine/cloudbroker/sep/delConsumerNodes"
|
||||||
|
const sepAddProviderNodesAPI = "/restmachine/cloudbroker/sep/addProviderNodes"
|
||||||
|
|
||||||
|
const sepConfigFieldEditAPI = "/restmachine/cloudbroker/sep/configFieldEdit"
|
||||||
|
const sepConfigInsertAPI = "/restmachine/cloudbroker/sep/configInsert"
|
||||||
|
const sepConfigValidateAPI = "/restmachine/cloudbroker/sep/configValidate"
|
||||||
|
|
||||||
|
const sepConsumptionAPI = "/restmachine/cloudbroker/sep/consumption"
|
||||||
|
|
||||||
|
const sepDecommissionAPI = "/restmachine/cloudbroker/sep/decommission"
|
||||||
|
|
||||||
|
const sepEnableAPI = "/restmachine/cloudbroker/sep/enable"
|
||||||
|
const sepDisableAPI = "/restmachine/cloudbroker/sep/disable"
|
||||||
|
|
||||||
|
const sepDiskListAPI = "/restmachine/cloudbroker/sep/diskList"
|
||||||
|
|
||||||
|
const sepGetAPI = "/restmachine/cloudbroker/sep/get"
|
||||||
|
const sepGetConfigAPI = "/restmachine/cloudbroker/sep/getConfig"
|
||||||
|
const sepGetPoolAPI = "/restmachine/cloudbroker/sep/getPool"
|
||||||
|
|
||||||
|
const sepCreateAPI = "/restmachine/cloudbroker/sep/create"
|
||||||
|
const sepDeleteAPI = "/restmachine/cloudbroker/sep/delete"
|
||||||
|
const sepListAPI = "/restmachine/cloudbroker/sep/list"
|
||||||
|
|
||||||
|
const sepUpdateCapacityLimitAPI = "/restmachine/cloudbroker/sep/updateCapacityLimit"
|
||||||
|
|
||||||
|
///Sep Models
|
||||||
|
type SepConsumptionInd struct {
|
||||||
|
DiskCount int `json:"disk_count"`
|
||||||
|
DiskUsage int `json:"disk_usage"`
|
||||||
|
SnapshotCount int `json:"snapshot_count"`
|
||||||
|
SnapshotUsage int `json:"snapshot_usage"`
|
||||||
|
Usage int `json:"usage"`
|
||||||
|
UsageLimit int `json:"usage_limit"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SepConsumptionTotal struct {
|
||||||
|
CapacityLimit int `json:"capacity_limit"`
|
||||||
|
SepConsumptionInd
|
||||||
|
}
|
||||||
|
|
||||||
|
type SepConsumption struct {
|
||||||
|
Total SepConsumptionTotal `json:"total"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
ByPool map[string]SepConsumptionInd `json:"byPool"`
|
||||||
|
}
|
||||||
|
|
||||||
|
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{}
|
||||||
|
|||||||
@@ -111,6 +111,8 @@ func Provider() *schema.Provider {
|
|||||||
"decort_cdrom_image": resourceCDROMImage(),
|
"decort_cdrom_image": resourceCDROMImage(),
|
||||||
"decort_delete_images": resourceDeleteImages(),
|
"decort_delete_images": resourceDeleteImages(),
|
||||||
"decort_snapshot": resourceSnapshot(),
|
"decort_snapshot": resourceSnapshot(),
|
||||||
|
"decort_sep": resourceSep(),
|
||||||
|
"decort_sep_config": resourceSepConfig(),
|
||||||
},
|
},
|
||||||
|
|
||||||
DataSourcesMap: map[string]*schema.Resource{
|
DataSourcesMap: map[string]*schema.Resource{
|
||||||
@@ -125,6 +127,12 @@ func Provider() *schema.Provider {
|
|||||||
"decort_image_list": dataSourceImageList(),
|
"decort_image_list": dataSourceImageList(),
|
||||||
"decort_image_list_stacks": dataSourceImageListStacks(),
|
"decort_image_list_stacks": dataSourceImageListStacks(),
|
||||||
"decort_snapshot_list": dataSourceSnapshotList(),
|
"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(),
|
// "decort_pfw": dataSourcePfw(),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
560
decort/resource_sep.go
Normal file
560
decort/resource_sep.go
Normal file
@@ -0,0 +1,560 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
|
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||||
|
Technology platfom.
|
||||||
|
|
||||||
|
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package decort
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/helper/customdiff"
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
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 := resourceSepExists(d, m); exists {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
d.SetId(strconv.Itoa(sepId.(int)))
|
||||||
|
err = resourceSepRead(d, m)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return errors.New("provided sep id does not exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
controller := m.(*ControllerCfg)
|
||||||
|
urlValues := &url.Values{}
|
||||||
|
|
||||||
|
urlValues.Add("name", d.Get("name").(string))
|
||||||
|
urlValues.Add("gid", strconv.Itoa(d.Get("gid").(int)))
|
||||||
|
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"); ok {
|
||||||
|
urlValues.Add("config", configString.(string))
|
||||||
|
}
|
||||||
|
if enable, ok := d.GetOk("enable"); ok {
|
||||||
|
urlValues.Add("enable", strconv.FormatBool(enable.(bool)))
|
||||||
|
}
|
||||||
|
|
||||||
|
tstr := d.Get("consumed_by").([]interface{})
|
||||||
|
temp := ""
|
||||||
|
l := len(tstr)
|
||||||
|
for i, str := range tstr {
|
||||||
|
s := "\"" + str.(string) + "\""
|
||||||
|
if i != (l - 1) {
|
||||||
|
s += ","
|
||||||
|
}
|
||||||
|
temp = temp + s
|
||||||
|
}
|
||||||
|
temp = "[" + temp + "]"
|
||||||
|
urlValues.Add("consumer_nids", temp)
|
||||||
|
|
||||||
|
tstr = d.Get("provided_by").([]interface{})
|
||||||
|
temp = ""
|
||||||
|
l = len(tstr)
|
||||||
|
for i, str := range tstr {
|
||||||
|
s := "\"" + str.(string) + "\""
|
||||||
|
if i != (l - 1) {
|
||||||
|
s += ","
|
||||||
|
}
|
||||||
|
temp = temp + s
|
||||||
|
}
|
||||||
|
temp = "[" + temp + "]"
|
||||||
|
urlValues.Add("provider_nids", temp)
|
||||||
|
|
||||||
|
sepId, err := controller.decortAPICall("POST", sepCreateAPI, urlValues)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
id := uuid.New()
|
||||||
|
d.SetId(sepId)
|
||||||
|
d.Set("sep_id", sepId)
|
||||||
|
|
||||||
|
err = resourceSepRead(d, m)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
d.SetId(id.String())
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
|
||||||
|
sep, err := utilitySepCheckPresence(d, m)
|
||||||
|
if sep == nil {
|
||||||
|
d.SetId("")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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 := utilitySepCheckPresence(d, m)
|
||||||
|
if sepDes == nil {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
controller := m.(*ControllerCfg)
|
||||||
|
urlValues := &url.Values{}
|
||||||
|
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||||
|
|
||||||
|
_, err = controller.decortAPICall("POST", sepDeleteAPI, urlValues)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
d.SetId("")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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 := utilitySepCheckPresence(d, m)
|
||||||
|
if sepDes == nil {
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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("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)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
urlValues = &url.Values{}
|
||||||
|
if d.HasChange("upd_capacity_limit") {
|
||||||
|
updCapacityLimit := d.Get("upd_capacity_limit").(bool)
|
||||||
|
if updCapacityLimit {
|
||||||
|
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||||
|
_, err := c.decortAPICall("POST", sepUpdateCapacityLimitAPI, urlValues)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
urlValues = &url.Values{}
|
||||||
|
err := resourceSepRead(d, m)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func resourceSepChangeEnabled(d *schema.ResourceDiff, m interface{}) error {
|
||||||
|
var api string
|
||||||
|
|
||||||
|
c := m.(*ControllerCfg)
|
||||||
|
urlValues := &url.Values{}
|
||||||
|
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||||
|
if d.Get("enable").(bool) {
|
||||||
|
api = sepEnableAPI
|
||||||
|
} else {
|
||||||
|
api = sepDisableAPI
|
||||||
|
}
|
||||||
|
resp, err := c.decortAPICall("POST", api, urlValues)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
res, err := strconv.ParseBool(resp)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !res {
|
||||||
|
return errors.New("Cannot enable/disable")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func resourceSepUpdateNodes(d *schema.ResourceDiff, m interface{}) error {
|
||||||
|
log.Debugf("resourceSepUpdateNodes: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int))
|
||||||
|
c := m.(*ControllerCfg)
|
||||||
|
urlValues := &url.Values{}
|
||||||
|
|
||||||
|
t1, t2 := d.GetChange("consumed_by")
|
||||||
|
d1 := t1.([]interface{})
|
||||||
|
d2 := t2.([]interface{})
|
||||||
|
|
||||||
|
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||||
|
|
||||||
|
consumedIds := make([]interface{}, 0)
|
||||||
|
temp := ""
|
||||||
|
api := ""
|
||||||
|
|
||||||
|
if len(d1) > len(d2) {
|
||||||
|
for _, n := range d2 {
|
||||||
|
if !findElInt(d1, n) {
|
||||||
|
consumedIds = append(consumedIds, n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
api = sepDelConsumerNodesAPI
|
||||||
|
} else {
|
||||||
|
consumedIds = d.Get("consumed_by").([]interface{})
|
||||||
|
api = sepAddConsumerNodesAPI
|
||||||
|
}
|
||||||
|
|
||||||
|
l := len(consumedIds)
|
||||||
|
for i, consumedId := range consumedIds {
|
||||||
|
s := strconv.Itoa(consumedId.(int))
|
||||||
|
if i != (l - 1) {
|
||||||
|
s += ","
|
||||||
|
}
|
||||||
|
temp = temp + s
|
||||||
|
}
|
||||||
|
temp = "[" + temp + "]"
|
||||||
|
urlValues.Add("consumer_nids", temp)
|
||||||
|
_, err := c.decortAPICall("POST", api, urlValues)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func findElInt(sl []interface{}, el interface{}) bool {
|
||||||
|
for _, e := range sl {
|
||||||
|
if e.(int) == el.(int) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func resourceSepUpdateProviders(d *schema.ResourceDiff, m interface{}) error {
|
||||||
|
log.Debugf("resourceSepUpdateProviders: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int))
|
||||||
|
c := m.(*ControllerCfg)
|
||||||
|
urlValues := &url.Values{}
|
||||||
|
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||||
|
providerIds := d.Get("provided_by").([]interface{})
|
||||||
|
temp := ""
|
||||||
|
l := len(providerIds)
|
||||||
|
for i, providerId := range providerIds {
|
||||||
|
s := strconv.Itoa(providerId.(int))
|
||||||
|
if i != (l - 1) {
|
||||||
|
s += ","
|
||||||
|
}
|
||||||
|
temp = temp + s
|
||||||
|
}
|
||||||
|
temp = "[" + temp + "]"
|
||||||
|
urlValues.Add("provider_nids", temp)
|
||||||
|
_, err := c.decortAPICall("POST", sepAddProviderNodesAPI, urlValues)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func resourceSepSchemaMake() map[string]*schema.Schema {
|
||||||
|
return map[string]*schema.Schema{
|
||||||
|
"sep_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
Description: "sep type des id",
|
||||||
|
},
|
||||||
|
"upd_capacity_limit": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
Default: false,
|
||||||
|
Description: "Update SEP capacity limit",
|
||||||
|
},
|
||||||
|
"decommission": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
Default: false,
|
||||||
|
Description: "unlink everything that exists from SEP",
|
||||||
|
},
|
||||||
|
"clear_physically": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
Default: true,
|
||||||
|
Description: "clear disks and images physically",
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
Description: "sep config string",
|
||||||
|
},
|
||||||
|
"ckey": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"meta": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"consumed_by": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Schema{
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
},
|
||||||
|
Description: "list of consumer nodes IDs",
|
||||||
|
},
|
||||||
|
"desc": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Optional: true,
|
||||||
|
Description: "sep description",
|
||||||
|
},
|
||||||
|
"gid": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Required: true,
|
||||||
|
Description: "grid (platform) ID",
|
||||||
|
},
|
||||||
|
"guid": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"milestones": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Required: true,
|
||||||
|
Description: "SEP name",
|
||||||
|
},
|
||||||
|
"obj_status": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"provided_by": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Schema{
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
},
|
||||||
|
Description: "list of provider nodes IDs",
|
||||||
|
},
|
||||||
|
"tech_status": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Required: true,
|
||||||
|
Description: "type of storage",
|
||||||
|
},
|
||||||
|
"enable": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
Default: false,
|
||||||
|
Description: "enable SEP after creation",
|
||||||
|
},
|
||||||
|
"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 resourceSep() *schema.Resource {
|
||||||
|
return &schema.Resource{
|
||||||
|
SchemaVersion: 1,
|
||||||
|
|
||||||
|
Create: resourceSepCreate,
|
||||||
|
Read: resourceSepRead,
|
||||||
|
Update: resourceSepEdit,
|
||||||
|
Delete: resourceSepDelete,
|
||||||
|
Exists: resourceSepExists,
|
||||||
|
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
|
Timeouts: &schema.ResourceTimeout{
|
||||||
|
Create: &Timeout60s,
|
||||||
|
Read: &Timeout30s,
|
||||||
|
Update: &Timeout60s,
|
||||||
|
Delete: &Timeout60s,
|
||||||
|
Default: &Timeout60s,
|
||||||
|
},
|
||||||
|
|
||||||
|
Schema: resourceSepSchemaMake(),
|
||||||
|
|
||||||
|
CustomizeDiff: customdiff.All(
|
||||||
|
customdiff.IfValueChange("enable", func(old, new, meta interface{}) bool {
|
||||||
|
if old.(bool) != new.(bool) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}, resourceSepChangeEnabled),
|
||||||
|
customdiff.IfValueChange("consumed_by", func(old, new, meta interface{}) bool {
|
||||||
|
o := old.([]interface{})
|
||||||
|
n := new.([]interface{})
|
||||||
|
|
||||||
|
if len(o) != len(n) {
|
||||||
|
return true
|
||||||
|
} else if len(o) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
count := 0
|
||||||
|
for i, v := range n {
|
||||||
|
if v.(int) == o[i].(int) {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if count == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}, resourceSepUpdateNodes),
|
||||||
|
customdiff.IfValueChange("provided_by", func(old, new, meta interface{}) bool {
|
||||||
|
o := old.([]interface{})
|
||||||
|
n := new.([]interface{})
|
||||||
|
|
||||||
|
if len(o) != len(n) {
|
||||||
|
return true
|
||||||
|
} else if len(o) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
count := 0
|
||||||
|
for i, v := range n {
|
||||||
|
if v.(int) == o[i].(int) {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if count == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}, resourceSepUpdateProviders),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
197
decort/resource_sep_config.go
Normal file
197
decort/resource_sep_config.go
Normal file
@@ -0,0 +1,197 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
|
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||||
|
Technology platfom.
|
||||||
|
|
||||||
|
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package decort
|
||||||
|
|
||||||
|
import (
|
||||||
|
"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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
61
decort/utility_sep.go
Normal file
61
decort/utility_sep.go
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
|
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||||
|
Technology platfom.
|
||||||
|
|
||||||
|
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package decort
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func utilitySepCheckPresence(d *schema.ResourceData, m interface{}) (*Sep, error) {
|
||||||
|
controller := m.(*ControllerCfg)
|
||||||
|
urlValues := &url.Values{}
|
||||||
|
|
||||||
|
sep := &Sep{}
|
||||||
|
|
||||||
|
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("utilitySepCheckPresence: load sep")
|
||||||
|
sepRaw, err := controller.decortAPICall("POST", sepGetAPI, urlValues)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(sepRaw), sep)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return sep, nil
|
||||||
|
}
|
||||||
57
decort/utility_sep_config.go
Normal file
57
decort/utility_sep_config.go
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
|
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||||
|
Technology platfom.
|
||||||
|
|
||||||
|
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package decort
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func utilitySepConfigCheckPresence(d *schema.ResourceData, m interface{}) (SepConfig, error) {
|
||||||
|
controller := m.(*ControllerCfg)
|
||||||
|
urlValues := &url.Values{}
|
||||||
|
|
||||||
|
sepConfig := SepConfig{}
|
||||||
|
|
||||||
|
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||||
|
|
||||||
|
log.Debugf("utilitySepConfigCheckPresence: load sep config")
|
||||||
|
sepConfigRaw, err := controller.decortAPICall("POST", sepGetConfigAPI, urlValues)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(sepConfigRaw), &sepConfig)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return sepConfig, nil
|
||||||
|
}
|
||||||
54
decort/utility_sep_consumption.go
Normal file
54
decort/utility_sep_consumption.go
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
|
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||||
|
Technology platfom.
|
||||||
|
|
||||||
|
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package decort
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func utilitySepConsumptionCheckPresence(d *schema.ResourceData, m interface{}) (*SepConsumption, error) {
|
||||||
|
controller := m.(*ControllerCfg)
|
||||||
|
urlValues := &url.Values{}
|
||||||
|
|
||||||
|
sepCons := &SepConsumption{}
|
||||||
|
|
||||||
|
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||||
|
|
||||||
|
sepConsRaw, err := controller.decortAPICall("POST", sepConsumptionAPI, urlValues)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(sepConsRaw), sepCons)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return sepCons, nil
|
||||||
|
}
|
||||||
61
decort/utility_sep_disk_list.go
Normal file
61
decort/utility_sep_disk_list.go
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
|
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||||
|
Technology platfom.
|
||||||
|
|
||||||
|
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package decort
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func utilitySepDiskListCheckPresence(d *schema.ResourceData, m interface{}) ([]int, error) {
|
||||||
|
controller := m.(*ControllerCfg)
|
||||||
|
urlValues := &url.Values{}
|
||||||
|
|
||||||
|
sepDiskList := SepDiskList{}
|
||||||
|
|
||||||
|
urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int)))
|
||||||
|
|
||||||
|
if poolName, ok := d.GetOk("pool_name"); ok {
|
||||||
|
urlValues.Add("pool_name", poolName.(string))
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("utilitySepDiskListCheckPresence: load sep")
|
||||||
|
sepDiskListRaw, err := controller.decortAPICall("POST", sepDiskListAPI, urlValues)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(sepDiskListRaw), &sepDiskList)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return sepDiskList, nil
|
||||||
|
}
|
||||||
61
decort/utility_sep_list.go
Normal file
61
decort/utility_sep_list.go
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
|
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||||
|
Technology platfom.
|
||||||
|
|
||||||
|
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package decort
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func utilitySepListCheckPresence(d *schema.ResourceData, m interface{}) (SepList, error) {
|
||||||
|
sepList := SepList{}
|
||||||
|
controller := m.(*ControllerCfg)
|
||||||
|
urlValues := &url.Values{}
|
||||||
|
|
||||||
|
if page, ok := d.GetOk("page"); ok {
|
||||||
|
urlValues.Add("page", strconv.Itoa(page.(int)))
|
||||||
|
}
|
||||||
|
if size, ok := d.GetOk("size"); ok {
|
||||||
|
urlValues.Add("size", strconv.Itoa(size.(int)))
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("utilitySepListCheckPresence: load image list")
|
||||||
|
sepListRaw, err := controller.decortAPICall("POST", sepListAPI, urlValues)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(sepListRaw), &sepList)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return sepList, nil
|
||||||
|
}
|
||||||
58
decort/utility_sep_pool.go
Normal file
58
decort/utility_sep_pool.go
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
|
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>, <svs1370@gmail.com>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration
|
||||||
|
Technology platfom.
|
||||||
|
|
||||||
|
Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package decort
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func utilitySepPoolCheckPresence(d *schema.ResourceData, m interface{}) (SepPool, error) {
|
||||||
|
controller := m.(*ControllerCfg)
|
||||||
|
urlValues := &url.Values{}
|
||||||
|
|
||||||
|
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")
|
||||||
|
sepPoolRaw, err := controller.decortAPICall("POST", sepGetPoolAPI, urlValues)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(sepPoolRaw), &sepPool)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return sepPool, nil
|
||||||
|
}
|
||||||
@@ -9,6 +9,12 @@
|
|||||||
- image_list
|
- image_list
|
||||||
- image_list_stacks
|
- image_list_stacks
|
||||||
- snapshot_list
|
- snapshot_list
|
||||||
|
- sep
|
||||||
|
- sep_list
|
||||||
|
- sep_disk_list
|
||||||
|
- sep_config
|
||||||
|
- sep_pool
|
||||||
|
- sep_consumption
|
||||||
- resources:
|
- resources:
|
||||||
- image
|
- image
|
||||||
- virtual_image
|
- virtual_image
|
||||||
@@ -17,6 +23,8 @@
|
|||||||
- k8s
|
- k8s
|
||||||
- k8s_wg
|
- k8s_wg
|
||||||
- snapshot
|
- snapshot
|
||||||
|
- sep
|
||||||
|
- sep_config
|
||||||
|
|
||||||
## Как пользоваться примерами
|
## Как пользоваться примерами
|
||||||
1. Установить terraform
|
1. Установить terraform
|
||||||
|
|||||||
42
samples/data_sep/main.tf
Normal file
42
samples/data_sep/main.tf
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
Пример использования
|
||||||
|
Получение данных sep
|
||||||
|
*/
|
||||||
|
#Расскомментируйте код ниже,
|
||||||
|
#и внесите необходимые правки в версию и путь,
|
||||||
|
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
|
||||||
|
/*
|
||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
decort = {
|
||||||
|
version = "1.1"
|
||||||
|
source = "digitalenergy.online/decort/decort"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
provider "decort" {
|
||||||
|
authenticator = "oauth2"
|
||||||
|
#controller_url = <DECORT_CONTROLLER_URL>
|
||||||
|
controller_url = "https://ds1.digitalenergy.online"
|
||||||
|
#oauth2_url = <DECORT_SSO_URL>
|
||||||
|
oauth2_url = "https://sso.digitalenergy.online"
|
||||||
|
allow_unverified_ssl = true
|
||||||
|
}
|
||||||
|
|
||||||
|
data "decort_sep" "sd" {
|
||||||
|
#id sep
|
||||||
|
#обязательный параметр
|
||||||
|
#тип - число
|
||||||
|
sep_id = 1111
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
output "test" {
|
||||||
|
value = data.decort_sep.sd
|
||||||
|
}
|
||||||
|
|
||||||
|
output "config" {
|
||||||
|
value = jsondecode(data.decort_sep.sd.config)
|
||||||
|
}
|
||||||
41
samples/data_sep_config/main.tf
Normal file
41
samples/data_sep_config/main.tf
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
Пример использования
|
||||||
|
Получение данных конфигурации sep
|
||||||
|
*/
|
||||||
|
#Расскомментируйте код ниже,
|
||||||
|
#и внесите необходимые правки в версию и путь,
|
||||||
|
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
|
||||||
|
/*
|
||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
decort = {
|
||||||
|
version = "1.1"
|
||||||
|
source = "digitalenergy.online/decort/decort"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
provider "decort" {
|
||||||
|
authenticator = "oauth2"
|
||||||
|
#controller_url = <DECORT_CONTROLLER_URL>
|
||||||
|
controller_url = "https://ds1.digitalenergy.online"
|
||||||
|
#oauth2_url = <DECORT_SSO_URL>
|
||||||
|
oauth2_url = "https://sso.digitalenergy.online"
|
||||||
|
allow_unverified_ssl = true
|
||||||
|
}
|
||||||
|
|
||||||
|
data "decort_sep_config" "sc" {
|
||||||
|
#id sep
|
||||||
|
#обязательный параметр
|
||||||
|
#тип - число
|
||||||
|
sep_id = 1111
|
||||||
|
}
|
||||||
|
|
||||||
|
output "test" {
|
||||||
|
value = data.decort_sep_config.sc
|
||||||
|
}
|
||||||
|
|
||||||
|
output "config" {
|
||||||
|
value = jsondecode(data.decort_config.sc.config)
|
||||||
|
}
|
||||||
37
samples/data_sep_consumption/main.tf
Normal file
37
samples/data_sep_consumption/main.tf
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
Пример использования
|
||||||
|
Получение общих данных об использовании sep
|
||||||
|
*/
|
||||||
|
#Расскомментируйте код ниже,
|
||||||
|
#и внесите необходимые правки в версию и путь,
|
||||||
|
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
|
||||||
|
/*
|
||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
decort = {
|
||||||
|
version = "1.1"
|
||||||
|
source = "digitalenergy.online/decort/decort"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
provider "decort" {
|
||||||
|
authenticator = "oauth2"
|
||||||
|
#controller_url = <DECORT_CONTROLLER_URL>
|
||||||
|
controller_url = "https://ds1.digitalenergy.online"
|
||||||
|
#oauth2_url = <DECORT_SSO_URL>
|
||||||
|
oauth2_url = "https://sso.digitalenergy.online"
|
||||||
|
allow_unverified_ssl = true
|
||||||
|
}
|
||||||
|
|
||||||
|
data "decort_sep_consumption" "scons" {
|
||||||
|
#id sep
|
||||||
|
#обязательный параметр
|
||||||
|
#тип - число
|
||||||
|
sep_id = 1111
|
||||||
|
}
|
||||||
|
|
||||||
|
output "test" {
|
||||||
|
value = data.decort_sep_consumption.scons
|
||||||
|
}
|
||||||
42
samples/data_sep_disk_list/main.tf
Normal file
42
samples/data_sep_disk_list/main.tf
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
Пример использования
|
||||||
|
Получение данных об используемых sep дисках
|
||||||
|
*/
|
||||||
|
|
||||||
|
#Расскомментируйте код ниже,
|
||||||
|
#и внесите необходимые правки в версию и путь,
|
||||||
|
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
|
||||||
|
/*
|
||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
decort = {
|
||||||
|
version = "1.1"
|
||||||
|
source = "digitalenergy.online/decort/decort"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
provider "decort" {
|
||||||
|
authenticator = "oauth2"
|
||||||
|
#controller_url = <DECORT_CONTROLLER_URL>
|
||||||
|
controller_url = "https://ds1.digitalenergy.online"
|
||||||
|
#oauth2_url = <DECORT_SSO_URL>
|
||||||
|
oauth2_url = "https://sso.digitalenergy.online"
|
||||||
|
allow_unverified_ssl = true
|
||||||
|
}
|
||||||
|
|
||||||
|
data "decort_sep_disk_list" "sdl" {
|
||||||
|
#id sep
|
||||||
|
#обязательный параметр
|
||||||
|
#тип - число
|
||||||
|
sep_id = 1111
|
||||||
|
#sep pool name
|
||||||
|
#необязательный параметр
|
||||||
|
#тип - строка
|
||||||
|
#pool_name = "sep_pool"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "test" {
|
||||||
|
value = data.decort_sep_disk_list.sdl
|
||||||
|
}
|
||||||
40
samples/data_sep_list/main.tf
Normal file
40
samples/data_sep_list/main.tf
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
Пример использования
|
||||||
|
Получение списка sep
|
||||||
|
*/
|
||||||
|
#Расскомментируйте код ниже,
|
||||||
|
#и внесите необходимые правки в версию и путь,
|
||||||
|
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
|
||||||
|
/*
|
||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
decort = {
|
||||||
|
version = "1.1"
|
||||||
|
source = "digitalenergy.online/decort/decort"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
provider "decort" {
|
||||||
|
authenticator = "oauth2"
|
||||||
|
#controller_url = <DECORT_CONTROLLER_URL>
|
||||||
|
controller_url = "https://ds1.digitalenergy.online"
|
||||||
|
#oauth2_url = <DECORT_SSO_URL>
|
||||||
|
oauth2_url = "https://sso.digitalenergy.online"
|
||||||
|
allow_unverified_ssl = true
|
||||||
|
}
|
||||||
|
|
||||||
|
data "decort_sep_list" "sl" {
|
||||||
|
#страница
|
||||||
|
#необязательный параметр
|
||||||
|
#тип - число
|
||||||
|
#page = 3
|
||||||
|
#размер страницы
|
||||||
|
#необязательный параметр
|
||||||
|
#тип - число
|
||||||
|
#size = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
output "test" {
|
||||||
|
value = data.decort_sep_list.sl
|
||||||
|
}
|
||||||
46
samples/data_sep_pool/main.tf
Normal file
46
samples/data_sep_pool/main.tf
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
Пример использования
|
||||||
|
Получение данных sep pool
|
||||||
|
|
||||||
|
*/
|
||||||
|
#Расскомментируйте код ниже,
|
||||||
|
#и внесите необходимые правки в версию и путь,
|
||||||
|
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
|
||||||
|
/*
|
||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
decort = {
|
||||||
|
version = "1.1"
|
||||||
|
source = "digitalenergy.online/decort/decort"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
provider "decort" {
|
||||||
|
authenticator = "oauth2"
|
||||||
|
#controller_url = <DECORT_CONTROLLER_URL>
|
||||||
|
controller_url = "https://ds1.digitalenergy.online"
|
||||||
|
#oauth2_url = <DECORT_SSO_URL>
|
||||||
|
oauth2_url = "https://sso.digitalenergy.online"
|
||||||
|
allow_unverified_ssl = true
|
||||||
|
}
|
||||||
|
|
||||||
|
data "decort_sep_pool" "sp" {
|
||||||
|
#id sep
|
||||||
|
#обязательный параметр
|
||||||
|
#тип - число
|
||||||
|
sep_id = 1111
|
||||||
|
#sep pool name
|
||||||
|
#обязательный параметр
|
||||||
|
#тип - строка
|
||||||
|
pool_name = "sep_pool"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "test" {
|
||||||
|
value = data.decort_sep_pool.sp
|
||||||
|
}
|
||||||
|
|
||||||
|
output "pool" {
|
||||||
|
value = jsondecode(data.decort_sep_pool.sp.pool)
|
||||||
|
}
|
||||||
124
samples/resource_sep/main.tf
Normal file
124
samples/resource_sep/main.tf
Normal file
@@ -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 = <DECORT_CONTROLLER_URL>
|
||||||
|
controller_url = "https://ds1.digitalenergy.online"
|
||||||
|
#oauth2_url = <DECORT_SSO_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)
|
||||||
|
|
||||||
|
}
|
||||||
73
samples/resource_sep_config/main.tf
Normal file
73
samples/resource_sep_config/main.tf
Normal file
@@ -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 = <DECORT_CONTROLLER_URL>
|
||||||
|
controller_url = "https://ds1.digitalenergy.online"
|
||||||
|
#oauth2_url = <DECORT_SSO_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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user