|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
/*
|
|
|
|
|
Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
|
|
|
|
Author: Sergey Shubin, <sergey.shubin@digitalenergy.online>, <svs1370@gmail.com>
|
|
|
|
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
|
|
|
|
Author: Stanislav Solovev, <spsolovev@digitalenergy.online>
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
@ -25,45 +25,298 @@ Visit https://github.com/rudecs/terraform-provider-decort for full source code p
|
|
|
|
|
package decort
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
// "net/url"
|
|
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func flattenAccount(d *schema.ResourceData, acc_facts string) error {
|
|
|
|
|
// NOTE: this function modifies ResourceData argument - as such it should never be called
|
|
|
|
|
// from resourceAccountExists(...) method
|
|
|
|
|
|
|
|
|
|
// log.Debugf("flattenAccount: ready to decode response body from %q", CloudspacesGetAPI)
|
|
|
|
|
details := AccountRecord{}
|
|
|
|
|
err := json.Unmarshal([]byte(acc_facts), &details)
|
|
|
|
|
func dataSourceAccountRead(d *schema.ResourceData, m interface{}) error {
|
|
|
|
|
acc, err := utilityAccountCheckPresence(d, m)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Debugf("flattenAccount: decoded Account name %q / ID %d, status %q", details.Name, details.ID, details.Status)
|
|
|
|
|
|
|
|
|
|
d.SetId(fmt.Sprintf("%d", details.ID))
|
|
|
|
|
d.Set("name", details.Name)
|
|
|
|
|
d.Set("status", details.Status)
|
|
|
|
|
|
|
|
|
|
id := uuid.New()
|
|
|
|
|
d.SetId(id.String())
|
|
|
|
|
d.Set("dc_location", acc.DCLocation)
|
|
|
|
|
d.Set("resources", flattenAccResources(acc.Resources))
|
|
|
|
|
d.Set("ckey", acc.CKey)
|
|
|
|
|
d.Set("meta", flattenMeta(acc.Meta))
|
|
|
|
|
d.Set("acl", flattenRgAcl(acc.Acl))
|
|
|
|
|
d.Set("company", acc.Company)
|
|
|
|
|
d.Set("companyurl", acc.CompanyUrl)
|
|
|
|
|
d.Set("created_by", acc.CreatedBy)
|
|
|
|
|
d.Set("created_time", acc.CreatedTime)
|
|
|
|
|
d.Set("deactivation_time", acc.DeactiovationTime)
|
|
|
|
|
d.Set("deleted_by", acc.DeletedBy)
|
|
|
|
|
d.Set("deleted_time", acc.DeletedTime)
|
|
|
|
|
d.Set("displayname", acc.DisplayName)
|
|
|
|
|
d.Set("guid", acc.GUID)
|
|
|
|
|
d.Set("account_id", acc.ID)
|
|
|
|
|
d.Set("account_name", acc.Name)
|
|
|
|
|
d.Set("resource_limits", flattenRgResourceLimits(acc.ResourceLimits))
|
|
|
|
|
d.Set("send_access_emails", acc.SendAccessEmails)
|
|
|
|
|
d.Set("service_account", acc.ServiceAccount)
|
|
|
|
|
d.Set("status", acc.Status)
|
|
|
|
|
d.Set("updated_time", acc.UpdatedTime)
|
|
|
|
|
d.Set("version", acc.Version)
|
|
|
|
|
d.Set("vins", acc.Vins)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func dataSourceAccountRead(d *schema.ResourceData, m interface{}) error {
|
|
|
|
|
acc_facts, err := utilityAccountCheckPresence(d, m)
|
|
|
|
|
if acc_facts == "" {
|
|
|
|
|
// if empty string is returned from utilityAccountCheckPresence then there is no
|
|
|
|
|
// such account and err tells so - just return it to the calling party
|
|
|
|
|
d.SetId("") // ensure ID is empty in this case
|
|
|
|
|
return err
|
|
|
|
|
func flattenAccResources(r Resources) []map[string]interface{} {
|
|
|
|
|
res := make([]map[string]interface{}, 0)
|
|
|
|
|
temp := map[string]interface{}{
|
|
|
|
|
"current": flattenAccResource(r.Current),
|
|
|
|
|
"reserved": flattenAccResource(r.Reserved),
|
|
|
|
|
}
|
|
|
|
|
res = append(res, temp)
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func flattenAccResource(r Resource) []map[string]interface{} {
|
|
|
|
|
res := make([]map[string]interface{}, 0)
|
|
|
|
|
temp := map[string]interface{}{
|
|
|
|
|
"cpu": r.CPU,
|
|
|
|
|
"disksize": r.Disksize,
|
|
|
|
|
"extips": r.Extips,
|
|
|
|
|
"exttraffic": r.Exttraffic,
|
|
|
|
|
"gpu": r.GPU,
|
|
|
|
|
"ram": r.RAM,
|
|
|
|
|
}
|
|
|
|
|
res = append(res, temp)
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return flattenAccount(d, acc_facts)
|
|
|
|
|
func dataSourceAccountSchemaMake() map[string]*schema.Schema {
|
|
|
|
|
res := map[string]*schema.Schema{
|
|
|
|
|
"account_id": {
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
Required: true,
|
|
|
|
|
},
|
|
|
|
|
"dc_location": {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"resources": {
|
|
|
|
|
Type: schema.TypeList,
|
|
|
|
|
Computed: true,
|
|
|
|
|
MaxItems: 1,
|
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
|
"current": {
|
|
|
|
|
Type: schema.TypeList,
|
|
|
|
|
Computed: true,
|
|
|
|
|
MaxItems: 1,
|
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
|
"cpu": {
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"disksize": {
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"extips": {
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"exttraffic": {
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"gpu": {
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"ram": {
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"reserved": {
|
|
|
|
|
Type: schema.TypeList,
|
|
|
|
|
Computed: true,
|
|
|
|
|
MaxItems: 1,
|
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
|
"cpu": {
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"disksize": {
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"extips": {
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"exttraffic": {
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"gpu": {
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"ram": {
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"ckey": {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"meta": {
|
|
|
|
|
Type: schema.TypeList,
|
|
|
|
|
Computed: true,
|
|
|
|
|
Elem: &schema.Schema{
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"acl": {
|
|
|
|
|
Type: schema.TypeList,
|
|
|
|
|
Computed: true,
|
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
|
"explicit": {
|
|
|
|
|
Type: schema.TypeBool,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"guid": {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"right": {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"status": {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"type": {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"user_group_id": {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"company": {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"companyurl": {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"created_by": {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"created_time": {
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"deactivation_time": {
|
|
|
|
|
Type: schema.TypeFloat,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"deleted_by": {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"deleted_time": {
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"displayname": {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"guid": {
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"account_name": {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"resource_limits": {
|
|
|
|
|
Type: schema.TypeList,
|
|
|
|
|
Computed: true,
|
|
|
|
|
MaxItems: 1,
|
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
|
"cu_c": {
|
|
|
|
|
Type: schema.TypeFloat,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"cu_d": {
|
|
|
|
|
Type: schema.TypeFloat,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"cu_i": {
|
|
|
|
|
Type: schema.TypeFloat,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"cu_m": {
|
|
|
|
|
Type: schema.TypeFloat,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"cu_np": {
|
|
|
|
|
Type: schema.TypeFloat,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"gpu_units": {
|
|
|
|
|
Type: schema.TypeFloat,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"send_access_emails": {
|
|
|
|
|
Type: schema.TypeBool,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"service_account": {
|
|
|
|
|
Type: schema.TypeBool,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"status": {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"updated_time": {
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"version": {
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
Computed: true,
|
|
|
|
|
},
|
|
|
|
|
"vins": {
|
|
|
|
|
Type: schema.TypeList,
|
|
|
|
|
Computed: true,
|
|
|
|
|
Elem: &schema.Schema{
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func dataSourceAccount() *schema.Resource {
|
|
|
|
@ -77,56 +330,6 @@ func dataSourceAccount() *schema.Resource {
|
|
|
|
|
Default: &Timeout60s,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
|
"name": {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Optional: true,
|
|
|
|
|
Description: "Name of the account. Names are case sensitive and unique.",
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"account_id": {
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
Optional: true,
|
|
|
|
|
Description: "Unique ID of the account. If account ID is specified, then account name is ignored.",
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"status": {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Computed: true,
|
|
|
|
|
Description: "Current status of the account.",
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/* We keep the following attributes commented out, as we are not implementing account
|
|
|
|
|
management with Terraform plugin, so we do not need this extra info.
|
|
|
|
|
|
|
|
|
|
"quota": {
|
|
|
|
|
Type: schema.TypeList,
|
|
|
|
|
Optional: true,
|
|
|
|
|
MaxItems: 1,
|
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
|
Schema: quotaRgSubresourceSchema(), // this is a dictionary
|
|
|
|
|
},
|
|
|
|
|
Description: "Quotas on the resources for this account and all its resource groups.",
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"resource_groups": {
|
|
|
|
|
Type: schema.TypeList,
|
|
|
|
|
Computed: true,
|
|
|
|
|
Elem: &schema.Schema {
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
},
|
|
|
|
|
Description: "IDs of resource groups in this account."
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"vins": {
|
|
|
|
|
Type: schema.TypeList,
|
|
|
|
|
Computed: true,
|
|
|
|
|
Elem: &schema.Schema {
|
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
|
},
|
|
|
|
|
Description: "IDs of VINSes created at the account level."
|
|
|
|
|
},
|
|
|
|
|
*/
|
|
|
|
|
},
|
|
|
|
|
Schema: dataSourceAccountSchemaMake(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|