This commit is contained in:
2023-06-08 12:26:21 +03:00
parent 371bb0d90f
commit 0e64974821
11 changed files with 910 additions and 24 deletions

View File

@@ -47,9 +47,16 @@ func dataSourceComputeListRead(ctx context.Context, d *schema.ResourceData, m in
return diag.FromErr(err)
}
result := computeList
if d.Get("ignore_k8s").(bool) {
// matches automatically generated names like "s234-g2134-c1" etc
result = matchComputes(computeList)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenComputeList(computeList))
d.Set("items", flattenComputeList(result))
return nil
}
@@ -325,7 +332,7 @@ func itemComputeSchemaMake() map[string]*schema.Schema {
}
}
func dataSourceCompputeListSchemaMake() map[string]*schema.Schema {
func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"includedeleted": {
Type: schema.TypeBool,
@@ -339,7 +346,12 @@ func dataSourceCompputeListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Optional: true,
},
"ignore_k8s": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "If set to true, ignores any VMs associated with any k8s cluster",
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -362,6 +374,6 @@ func DataSourceComputeList() *schema.Resource {
Default: &constants.Timeout60s,
},
Schema: dataSourceCompputeListSchemaMake(),
Schema: dataSourceComputeListSchemaMake(),
}
}

View File

@@ -34,6 +34,7 @@ package kvmvm
import (
"context"
"regexp"
"strconv"
log "github.com/sirupsen/logrus"
@@ -43,6 +44,16 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func matchComputes(computeList compute.ListComputes) compute.ListComputes {
matched, _ := regexp.Compile("[a-zA-Z]+\\d+-[a-zA-Z]+\\d+-[a-zA-Z]+\\d+")
result := computeList.FilterFunc(func(ic compute.ItemCompute) bool {
res := matched.Match([]byte(ic.Name))
return !res
})
return result
}
func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceData, m interface{}, do_delta bool) error {
c := m.(*controller.ControllerCfg)