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/cloudbroker/image/flattens.go

158 lines
4.6 KiB

package image
import (
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/image"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
)
func flattenImage(d *schema.ResourceData, img *image.RecordImage) {
d.Set("name", img.Name)
d.Set("drivers", img.Drivers)
d.Set("url", img.URL)
d.Set("gid", img.GID)
d.Set("image_id", img.ID)
d.Set("boot_type", img.BootType)
d.Set("image_type", img.Type)
d.Set("bootable", img.Bootable)
d.Set("sep_id", img.SEPID)
d.Set("unc_path", img.UNCPath)
d.Set("link_to", img.LinkTo)
d.Set("status", img.Status)
d.Set("tech_status", img.TechStatus)
d.Set("version", img.Version)
d.Set("size", img.Size)
d.Set("enabled", img.Enabled)
d.Set("computeci_id", img.ComputeCIID)
d.Set("pool_name", img.Pool)
d.Set("username", img.Username)
// d.Set("username_dl", img.UsernameDL)
d.Set("password", img.Password)
// d.Set("password_dl", img.PasswordDL)
d.Set("account_id", img.AccountID)
d.Set("guid", img.GUID)
d.Set("milestones", img.Milestones)
d.Set("provider_name", img.ProviderName)
d.Set("purge_attempts", img.PurgeAttempts)
d.Set("reference_id", img.ReferenceID)
d.Set("res_id", img.ResID)
d.Set("res_name", img.ResName)
d.Set("rescuecd", img.RescueCD)
d.Set("architecture", img.Architecture)
d.Set("hot_resize", img.HotResize)
d.Set("history", flattenHistory(img.History))
d.Set("last_modified", img.LastModified)
d.Set("meta", flattens.FlattenMeta(img.Meta))
d.Set("desc", img.Description)
d.Set("shared_with", img.SharedWith)
}
func flattenMeta(m []interface{}) []string {
output := []string{}
for _, item := range m {
switch d := item.(type) {
case string:
output = append(output, d)
case int:
output = append(output, strconv.Itoa(d))
case int64:
output = append(output, strconv.FormatInt(d, 10))
case float64:
output = append(output, strconv.FormatInt(int64(d), 10))
default:
output = append(output, "")
}
}
return output
}
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 flattenImageList(il *image.ListImages) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, item := range il.Data {
temp := map[string]interface{}{
"name": item.Name,
"url": item.URL,
"gid": item.GID,
"guid": item.GUID,
"drivers": item.Drivers,
"image_id": item.ID,
"boot_type": item.BootType,
"bootable": item.Bootable,
"image_type": item.Type,
"status": item.Status,
"tech_status": item.TechStatus,
"version": item.Version,
"username": item.Username,
// "username_dl": item.UsernameDL,
"password": item.Password,
// "password_dl": item.PasswordDL,
"purge_attempts": item.PurgeAttempts,
"architecture": item.Architecture,
"account_id": item.AccountID,
"computeci_id": item.ComputeCIID,
"enabled": item.Enabled,
"reference_id": item.ReferenceID,
"res_id": item.ResID,
"res_name": item.ResName,
"rescuecd": item.RescueCD,
"provider_name": item.ProviderName,
"milestones": item.Milestones,
"size": item.Size,
"sep_id": item.SEPID,
"link_to": item.LinkTo,
"unc_path": item.UNCPath,
"pool_name": item.Pool,
"hot_resize": item.HotResize,
"history": flattenHistory(item.History),
"last_modified": item.LastModified,
"meta": flattenMeta(item.Meta),
"desc": item.Description,
"shared_with": item.SharedWith,
}
res = append(res, temp)
}
return res
}
func flattenImageListStacks(_ *schema.ResourceData, stack *image.ListStacks) []map[string]interface{} {
temp := make([]map[string]interface{}, 0)
for _, item := range stack.Data {
t := map[string]interface{}{
"api_url": item.APIURL,
"api_key": item.APIKey,
"app_id": item.AppID,
"desc": item.Description,
"drivers": item.Drivers,
"error": item.Error,
"guid": item.GUID,
"id": item.ID,
"images": item.Images,
"login": item.Login,
"name": item.Name,
"passwd": item.Password,
"reference_id": item.ReferenceID,
"status": item.Status,
"type": item.Type,
}
temp = append(temp, t)
}
return temp
}