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

@@ -50,10 +50,24 @@ func dataSourceBasicServiceDeletedListRead(ctx context.Context, d *schema.Resour
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenBasicServiceList(basicServiceDeletedList))
d.Set("entry_count", basicServiceDeletedList.EntryCount)
return nil
}
func dataSourceBasicServiceDeletedListSchemaMake() map[string]*schema.Schema {
temp := dataSourceBasicServiceListSchemaMake()
delete(temp, "by_id")
delete(temp, "name")
delete(temp, "rg_name")
delete(temp, "status")
delete(temp, "tech_status")
delete(temp, "account_name")
return temp
}
func DataSourceBasicServiceDeletedList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
@@ -65,6 +79,6 @@ func DataSourceBasicServiceDeletedList() *schema.Resource {
Default: &constants.Timeout60s,
},
Schema: dataSourceBasicServiceListSchemaMake(),
Schema: dataSourceBasicServiceDeletedListSchemaMake(),
}
}

View File

@@ -42,9 +42,9 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func flattenBasicServiceList(bsl bservice.ListBasicServices) []map[string]interface{} {
func flattenBasicServiceList(bsl *bservice.ListBasicServices) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, bs := range bsl {
for _, bs := range bsl.Data {
temp := map[string]interface{}{
"account_id": bs.AccountID,
"account_name": bs.AccountName,
@@ -83,12 +83,43 @@ func dataSourceBasicServiceListRead(ctx context.Context, d *schema.ResourceData,
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenBasicServiceList(basicServiceList))
d.Set("entry_count", basicServiceList.EntryCount)
return nil
}
func dataSourceBasicServiceListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"by_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Filter by ID",
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by bservice name",
},
"rg_name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by resource group name",
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by status",
},
"tech_status": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by tech status",
},
"account_name": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by account name",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
@@ -208,6 +239,10 @@ func dataSourceBasicServiceListSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}

View File

@@ -20,5 +20,5 @@ func existRGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool
rgId := uint64(d.Get("rg_id").(int))
return len(rgList.FilterByID(rgId)) != 0, nil
return len(rgList.FilterByID(rgId).Data) != 0, nil
}

View File

@@ -42,9 +42,9 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityBasicServiceDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (bservice.ListBasicServices, error) {
func utilityBasicServiceDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*bservice.ListBasicServices, error) {
c := m.(*controller.ControllerCfg)
req := bservice.ListRequest{}
req := bservice.ListDeletedRequest{}
if accountId, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountId.(int))

View File

@@ -42,7 +42,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityBasicServiceListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (bservice.ListBasicServices, error) {
func utilityBasicServiceListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*bservice.ListBasicServices, error) {
c := m.(*controller.ControllerCfg)
req := bservice.ListRequest{}
@@ -59,6 +59,30 @@ func utilityBasicServiceListCheckPresence(ctx context.Context, d *schema.Resourc
req.Size = uint64(size.(int))
}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if rg_name, ok := d.GetOk("rg_name"); ok {
req.RGName = rg_name.(string)
}
if tech_status, ok := d.GetOk("tech_status"); ok {
req.TechStatus = tech_status.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if acc_name, ok := d.GetOk("account_name"); ok {
req.AccountName = acc_name.(string)
}
log.Debugf("utilityBasicServiceListCheckPresence")
basicServiceList, err := c.CloudAPI().BService().List(ctx, req)
if err != nil {