4.5.0-alpha
This commit is contained in:
119
internal/service/cloudbroker/stack/data_source_stack_list.go
Normal file
119
internal/service/cloudbroker/stack/data_source_stack_list.go
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Sergey Kisil, <svkisil@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.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package stack
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceStackListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
stackList, err := utilityStackListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenStacksList(stackList))
|
||||
d.Set("entry_count", stackList.EntryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceStaksListSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"by_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "by_id",
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "name",
|
||||
},
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "type",
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "type",
|
||||
},
|
||||
"page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "page number",
|
||||
},
|
||||
"size": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "page size",
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: dataSourceStackSchemaMake(),
|
||||
},
|
||||
Description: "items of stacks list",
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "entry_count",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DataSourceStacksList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceStackListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceStaksListSchemaMake(),
|
||||
}
|
||||
}
|
||||
319
internal/service/cloudbroker/stack/data_sourse_stack.go
Normal file
319
internal/service/cloudbroker/stack/data_sourse_stack.go
Normal file
@@ -0,0 +1,319 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
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.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package stack
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceStackRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
stack, err := utilityStackCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenStack(d, stack)
|
||||
d.SetId(strconv.Itoa(d.Get("stack_id").(int)))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceStackSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"stack_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "stack_id",
|
||||
},
|
||||
"ckey": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ckey",
|
||||
},
|
||||
"meta": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Description: "meta",
|
||||
},
|
||||
"api_url": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "api_url",
|
||||
},
|
||||
"api_key": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "api_key",
|
||||
},
|
||||
"app_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "api_id",
|
||||
},
|
||||
"cpu_allocation_ratio": {
|
||||
Type: schema.TypeFloat,
|
||||
Computed: true,
|
||||
Description: "cpu_allocation_ratio",
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "description",
|
||||
},
|
||||
"descr": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "descr",
|
||||
},
|
||||
"drivers": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Description: "drivers",
|
||||
},
|
||||
"eco": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "eco",
|
||||
},
|
||||
"error": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "error",
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "gid",
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "guid",
|
||||
},
|
||||
"images": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "images",
|
||||
},
|
||||
"login": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "login",
|
||||
},
|
||||
"mem_allocation_ratio": {
|
||||
Type: schema.TypeFloat,
|
||||
Computed: true,
|
||||
Description: "mem_allocation_ratio",
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "name",
|
||||
},
|
||||
"packages": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: packagesSchemaMake(),
|
||||
},
|
||||
},
|
||||
"passwd": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "password",
|
||||
},
|
||||
"reference_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "reference_id",
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "status",
|
||||
},
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "type",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func packagesSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"libvirt_bin": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "libvirt_bin",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"installed_size": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "installed_size",
|
||||
},
|
||||
"ver": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ver",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"lvm2_lockd": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "lvm2_lockd",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"installed_size": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "installed_size",
|
||||
},
|
||||
"ver": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ver",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"openvswitch_common": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "openvswitch_common",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"installed_size": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "installed_size",
|
||||
},
|
||||
"ver": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ver",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"openvswitch_switch": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "openvswitch_switch",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"installed_size": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "installed_size",
|
||||
},
|
||||
"ver": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ver",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"qemu_system_x86": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "qemu_system_x86",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"installed_size": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "installed_size",
|
||||
},
|
||||
"ver": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ver",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"sanlock": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "sanlock",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"installed_size": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "installed_size",
|
||||
},
|
||||
"ver": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ver",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func DataSourceStack() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceStackRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceStackSchemaMake(),
|
||||
}
|
||||
}
|
||||
190
internal/service/cloudbroker/stack/flattens.go
Normal file
190
internal/service/cloudbroker/stack/flattens.go
Normal file
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Sergey Kisil, <svkisil@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.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package stack
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/stack"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
|
||||
)
|
||||
|
||||
func flattenStack(d *schema.ResourceData, st *stack.InfoStack) {
|
||||
d.Set("ckey", st.Ckey)
|
||||
d.Set("meta", flattens.FlattenMeta(st.Meta))
|
||||
d.Set("api_url", st.APIURL)
|
||||
d.Set("api_key", st.Apikey)
|
||||
d.Set("app_id", st.AppID)
|
||||
d.Set("cpu_allocation_ratio", st.CPUAllocationRatio)
|
||||
d.Set("description", st.Description)
|
||||
d.Set("descr", st.Descr)
|
||||
d.Set("drivers", st.Drivers)
|
||||
d.Set("eco", flattenEco(st.Eco))
|
||||
d.Set("error", st.Error)
|
||||
d.Set("gid", st.GID)
|
||||
d.Set("guid", st.GUID)
|
||||
d.Set("stack_id", st.ID)
|
||||
d.Set("images", st.Images)
|
||||
d.Set("login", st.Login)
|
||||
d.Set("mem_allocation_ratio", st.MemAllocationRatio)
|
||||
d.Set("name", st.Name)
|
||||
d.Set("packages", flattenPackages(st.Packages))
|
||||
d.Set("passwd", st.Password)
|
||||
d.Set("reference_id", st.ReferenceID)
|
||||
d.Set("status", st.Status)
|
||||
d.Set("type", st.Type)
|
||||
}
|
||||
|
||||
func flattenPackages(pg stack.Packages) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"libvirt_bin": flattenLibvirtBin (pg),
|
||||
"lvm2_lockd": flattenLvm2Lockd (pg),
|
||||
"openvswitch_common": flattenOpenvswitchCommon (pg),
|
||||
"openvswitch_switch": flattenOpenvswitchSwitch (pg),
|
||||
"qemu_system_x86": flattenQemuSystemX86 (pg),
|
||||
"sanlock": flattenSanlock (pg),
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenLibvirtBin(lb stack.Packages) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"installed_size": lb.LibvirtBin.InstalledSize,
|
||||
"ver": lb.LibvirtBin.Ver,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenLvm2Lockd(ll stack.Packages) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"installed_size": ll.Lvm2Lockd.InstalledSize,
|
||||
"ver": ll.Lvm2Lockd.Ver,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenOpenvswitchCommon(oc stack.Packages) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"installed_size": oc.OpenvswitchCommon.InstalledSize,
|
||||
"ver": oc.OpenvswitchCommon.Ver,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenOpenvswitchSwitch(os stack.Packages) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"installed_size": os.OpenvswitchSwitch.InstalledSize,
|
||||
"ver": os.OpenvswitchSwitch.Ver,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenQemuSystemX86(qs stack.Packages) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"installed_size": qs.QemuSystemX86.InstalledSize,
|
||||
"ver": qs.QemuSystemX86.Ver,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenSanlock(sl stack.Packages) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"installed_size": sl.Sanlock.InstalledSize,
|
||||
"ver": sl.Sanlock.Ver,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
func flattenEco(m interface{}) string {
|
||||
switch d := m.(type) {
|
||||
case string:
|
||||
return d
|
||||
case int:
|
||||
return strconv.Itoa(d)
|
||||
case int64:
|
||||
return strconv.FormatInt(d, 10)
|
||||
case float64:
|
||||
return strconv.FormatInt(int64(d), 10)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func flattenStacksList(sl *stack.ListStacks) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(sl.Data))
|
||||
for _, item := range sl.Data {
|
||||
temp := map[string]interface{}{
|
||||
"ckey": item.Ckey,
|
||||
"meta": flattens.FlattenMeta(item.Meta),
|
||||
"api_url": item.APIURL,
|
||||
"api_key": item.Apikey,
|
||||
"app_id": item.AppID,
|
||||
"cpu_allocation_ratio": item.CPUAllocationRatio,
|
||||
"description": item.Description,
|
||||
"descr": item.Descr,
|
||||
"drivers": item.Drivers,
|
||||
"eco": flattenEco(item.Eco),
|
||||
"error": item.Error,
|
||||
"gid": item.GID,
|
||||
"guid": item.GUID,
|
||||
"stack_id": item.ID,
|
||||
"images": item.Images,
|
||||
"login": item.Login,
|
||||
"mem_allocation_ratio": item.MemAllocationRatio,
|
||||
"name": item.Name,
|
||||
"packages": flattenPackages(item.Packages),
|
||||
"passwd": item.Password,
|
||||
"reference_id": item.ReferenceID,
|
||||
"status": item.Status,
|
||||
"type": item.Type,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
64
internal/service/cloudbroker/stack/utility_stack.go
Normal file
64
internal/service/cloudbroker/stack/utility_stack.go
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Sergey Kisil, <svkisil@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.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package stack
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/stack"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityStackCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*stack.InfoStack, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := stack.GetRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.StackId = id
|
||||
} else {
|
||||
req.StackId = uint64(d.Get("stack_id").(int))
|
||||
}
|
||||
|
||||
log.Debugf("utilityStackListCheckPresence: load stack list")
|
||||
stackInfo, err := c.CloudBroker().Stack().Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return stackInfo, nil
|
||||
}
|
||||
75
internal/service/cloudbroker/stack/utility_stack_list.go
Normal file
75
internal/service/cloudbroker/stack/utility_stack_list.go
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Sergey Kisil, <svkisil@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.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package stack
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/stack"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityStackListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*stack.ListStacks, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := stack.ListRequest{}
|
||||
|
||||
if ByID, ok := d.GetOk("by_id"); ok {
|
||||
req.ByID = uint64(ByID.(int))
|
||||
}
|
||||
if Name, ok := d.GetOk("name"); ok {
|
||||
req.Name = string(Name.(string))
|
||||
}
|
||||
if Type, ok := d.GetOk("type"); ok {
|
||||
req.Type = string(Type.(string))
|
||||
}
|
||||
if Status, ok := d.GetOk("status"); ok {
|
||||
req.Status = string(Status.(string))
|
||||
}
|
||||
if Page, ok := d.GetOk("page"); ok {
|
||||
req.Page = uint64(Page.(int))
|
||||
}
|
||||
if Size, ok := d.GetOk("size"); ok {
|
||||
req.Size = uint64(Size.(int))
|
||||
}
|
||||
|
||||
log.Debugf("utilityStackListCheckPresence: load stack list")
|
||||
stackList, err := c.CloudBroker().Stack().List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return stackList, nil
|
||||
}
|
||||
Reference in New Issue
Block a user