You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
terraform-provider-decort/internal/service/cloudapi/image/flattens.go

88 lines
2.5 KiB

package image
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/image"
)
func flattenHistory(history []image.History) []map[string]interface{} {
temp := make([]map[string]interface{}, 0)
for _, item := range history {
t := map[string]interface{}{
"id": item.ID,
"guid": item.GUID,
"timestamp": item.Timestamp,
}
temp = append(temp, t)
}
return temp
}
func flattenImage(d *schema.ResourceData, img *image.RecordImage) {
d.Set("unc_path", img.UNCPath)
d.Set("ckey", img.CKey)
d.Set("account_id", img.AccountID)
d.Set("acl", img.ACL)
d.Set("architecture", img.Architecture)
d.Set("boot_type", img.BootType)
d.Set("bootable", img.Bootable)
d.Set("compute_ci_id", img.ComputeCIID)
d.Set("deleted_time", img.DeletedTime)
d.Set("desc", img.Description)
d.Set("drivers", img.Drivers)
d.Set("enabled", img.Enabled)
d.Set("gid", img.GID)
d.Set("guid", img.GUID)
d.Set("history", flattenHistory(img.History))
d.Set("hot_resize", img.HotResize)
d.Set("image_id", img.ID)
d.Set("last_modified", img.LastModified)
d.Set("link_to", img.LinkTo)
d.Set("milestones", img.Milestones)
d.Set("image_name", img.Name)
d.Set("password", img.Password)
d.Set("pool_name", img.Pool)
d.Set("provider_name", img.ProviderName)
d.Set("purge_attempts", img.PurgeAttempts)
d.Set("present_to", img.PresentTo)
d.Set("res_id", img.ResID)
d.Set("rescuecd", img.RescueCD)
d.Set("sep_id", img.SepID)
d.Set("shared_with", img.SharedWith)
d.Set("size", img.Size)
d.Set("status", img.Status)
d.Set("tech_status", img.TechStatus)
d.Set("type", img.Type)
d.Set("username", img.Username)
d.Set("version", img.Version)
}
func flattenImageList(il image.ListImages) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, img := range il {
temp := map[string]interface{}{
"account_id": img.AccountID,
"architecture": img.Architecture,
"boot_type": img.BootType,
"bootable": img.Bootable,
"cdrom": img.CDROM,
"desc": img.Description,
"drivers": img.Drivers,
"hot_resize": img.HotResize,
"image_id": img.ID,
"link_to": img.LinkTo,
"image_name": img.Name,
"pool_name": img.Pool,
"sep_id": img.SepID,
"size": img.Size,
"status": img.Status,
"type": img.Type,
"username": img.Username,
"virtual": img.Virtual,
}
res = append(res, temp)
}
return res
}