This commit is contained in:
2023-07-26 13:32:39 +03:00
parent f731cf246f
commit 272e385318
167 changed files with 5194 additions and 890 deletions

View File

@@ -43,9 +43,9 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
)
func flattenLocationsList(ll locations.ListLocations) []map[string]interface{} {
func flattenLocationsList(ll *locations.ListLocations) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, l := range ll {
for _, l := range ll.Data {
temp := map[string]interface{}{
"ckey": l.CKey,
"meta": flattens.FlattenMeta(l.Meta),
@@ -72,12 +72,33 @@ func dataSourceLocationsListRead(ctx context.Context, d *schema.ResourceData, m
d.SetId(id.String())
d.Set("items", flattenLocationsList(locations))
d.Set("entry_count", locations.EntryCount)
return nil
}
func dataSourceLocationsListSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"flag": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by flag",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by name",
},
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ID",
},
"location_code": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by location code",
},
"page": {
Type: schema.TypeInt,
Optional: true,
@@ -137,6 +158,10 @@ func dataSourceLocationsListSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
}

View File

@@ -42,17 +42,34 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityLocationsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (locations.ListLocations, error) {
func utilityLocationsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*locations.ListLocations, error) {
c := m.(*controller.ControllerCfg)
req := locations.ListRequest{}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if flag, ok := d.GetOk("flag"); ok {
req.Flag = flag.(string)
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if location_code, ok := d.GetOk("location_code"); ok {
req.LocationCode = location_code.(string)
}
log.Debugf("utilityLocationsListCheckPresence: load locations list")
locationsList, err := c.CloudAPI().Locations().List(ctx, req)
if err != nil {