parent
f2f31b939e
commit
b112c5ee22
@ -1,5 +1,10 @@
|
||||
### Version 3.5.1
|
||||
## Version 3.5.2
|
||||
|
||||
## Bug Fix
|
||||
### Features
|
||||
- Add new datasource decort_kvmvm_snapshot_usage
|
||||
- Add the ability to change the size in the 'disks' block in the decort_kvmvm resource. Now when you change 'size' field in the block, the disk size on the platform will also be changed
|
||||
|
||||
- Authentication via jwt token does not work
|
||||
## Bug Fix
|
||||
- rule "release" in Makefile don't create the necessary archives
|
||||
- field "register_computes" in resource decort_resgroup is not used when creating the resource
|
||||
- removed unused optional fields in datasources
|
||||
|
@ -0,0 +1,73 @@
|
||||
package kvmvm
|
||||
|
||||
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 dataSourceComputeSnapshotUsageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
computeSnapshotUsage, err := utilityComputeSnapshotUasgeCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenSnapshotUsage(computeSnapshotUsage))
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceComputeSnapshotUsagSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"label": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"stored": {
|
||||
Type: schema.TypeFloat,
|
||||
Computed: true,
|
||||
},
|
||||
"label": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"timestamp": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DataSourceComputeSnapshotUsage() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceComputeSnapshotUsageRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceComputeSnapshotUsagSchemaMake(),
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityComputeSnapshotUasgeCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ListUsageSnapshots, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
urlValues := &url.Values{}
|
||||
UsageSnapshotList := &ListUsageSnapshots{}
|
||||
|
||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||
if label, ok := d.GetOk("label"); ok {
|
||||
urlValues.Add("label", label.(string))
|
||||
}
|
||||
computeSnapshotUsage, err := c.DecortAPICall(ctx, "POST", ComputeSnapshotUsageAPI, urlValues)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(computeSnapshotUsage), &UsageSnapshotList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return *UsageSnapshotList, err
|
||||
|
||||
}
|
Loading…
Reference in new issue