This commit is contained in:
2025-11-18 16:20:26 +03:00
parent 4b3f21d9be
commit e42fbcef39
397 changed files with 17560 additions and 1501 deletions

View File

@@ -3,16 +3,13 @@ package account
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
)
func flattenResourceAccount(d *schema.ResourceData, acc *account.RecordAccount) {
d.Set("dc_location", acc.DCLocation)
d.Set("ckey", acc.CKey)
d.Set("acl", flattenAccAcl(acc.ACL))
d.Set("company", acc.Company)
d.Set("companyurl", acc.CompanyURL)
d.Set("compute_features", acc.ComputeFeatures)
d.Set("cpu_allocation_parameter", acc.CPUAllocationParameter)
d.Set("cpu_allocation_ratio", acc.CPUAllocationRatio)
d.Set("created_by", acc.CreatedBy)
@@ -27,6 +24,7 @@ func flattenResourceAccount(d *schema.ResourceData, acc *account.RecordAccount)
d.Set("account_id", acc.ID)
d.Set("account_name", acc.Name)
d.Set("resource_limits", flattenRgResourceLimits(acc.ResourceLimits))
d.Set("storage_policy", flattenSTPolicy(acc.ResourceLimits.StoragePolicies))
d.Set("resource_types", acc.ResTypes)
d.Set("send_access_emails", acc.SendAccessEmails)
d.Set("status", acc.Status)
@@ -34,12 +32,11 @@ func flattenResourceAccount(d *schema.ResourceData, acc *account.RecordAccount)
d.Set("updated_time", acc.UpdatedTime)
d.Set("version", acc.Version)
d.Set("vins", acc.VINS)
d.Set("zone_ids", acc.ZoneIDs)
d.Set("zone_ids", flattenZonesInResource(acc.ZoneIDs))
}
func flattenDataAccount(d *schema.ResourceData, acc *account.RecordAccount) {
d.Set("dc_location", acc.DCLocation)
d.Set("ckey", acc.CKey)
d.Set("acl", flattenAccAcl(acc.ACL))
d.Set("company", acc.Company)
d.Set("companyurl", acc.CompanyURL)
@@ -142,11 +139,26 @@ func flattenAccResource(r account.Resource) []map[string]interface{} {
"gpu": r.GPU,
"ram": r.RAM,
"seps": flattenAccountSeps(r.SEPs),
"policies": flattenAccountPolicies(r.Policies),
}
res = append(res, temp)
return res
}
func flattenAccountPolicies(policies map[string]account.Policy) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for k, dataVal := range policies {
temp := map[string]interface{}{
"id": k,
"disk_size": dataVal.DiskSize,
"disk_size_max": dataVal.DiskSizeMax,
"seps": flattenAccountSeps(dataVal.SEPs),
}
res = append(res, temp)
}
return res
}
func flattenAccAcl(acls []account.ACLWithEmails) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(acls))
for _, acls := range acls {
@@ -172,19 +184,32 @@ func flattenAccAcl(acls []account.ACLWithEmails) []map[string]interface{} {
func flattenRgResourceLimits(rl account.ResourceLimits) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"cu_c": rl.CuC,
"cu_d": rl.CuD,
"cu_dm": rl.CuDM,
"cu_i": rl.CuI,
"cu_m": rl.CuM,
"cu_np": rl.CuNP,
"gpu_units": rl.GPUUnits,
"cu_c": rl.CuC,
"cu_d": rl.CuD,
"cu_dm": rl.CuDM,
"cu_i": rl.CuI,
"cu_m": rl.CuM,
"cu_np": rl.CuNP,
"gpu_units": rl.GPUUnits,
"storage_policy": flattenSTPolicy(rl.StoragePolicies),
}
res = append(res, temp)
return res
}
func flattenSTPolicy(ast []account.StoragePolicy) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(ast))
for _, item := range ast {
temp := map[string]interface{}{
"id": item.ID,
"limit": item.Limit,
}
res = append(res, temp)
}
return res
}
func flattenRgAcl(rgAcls []account.ACL) []map[string]interface{} {
res := make([]map[string]interface{}, len(rgAcls))
for _, rgAcl := range rgAcls {
@@ -206,8 +231,6 @@ func flattenListDeleted(al *account.ListAccounts) []map[string]interface{} {
for _, acc := range al.Data {
temp := map[string]interface{}{
"dc_location": acc.DCLocation,
"ckey": acc.CKey,
"meta": flattens.FlattenMeta(acc.Meta),
"acl": flattenRgAcl(acc.ACL),
"company": acc.Company,
"companyurl": acc.CompanyURL,
@@ -228,6 +251,7 @@ func flattenListDeleted(al *account.ListAccounts) []map[string]interface{} {
"resource_types": acc.ResTypes,
"send_access_emails": acc.SendAccessEmails,
"status": acc.Status,
"storage_policy_ids": acc.StoragePolicyIDs,
"uniq_pools": acc.UniqPools,
"default_zone_id": acc.DefaultZoneID,
"zone_ids": acc.ZoneIDs,
@@ -245,8 +269,6 @@ func flattenAccountList(al *account.ListAccounts) []map[string]interface{} {
for _, acc := range al.Data {
temp := map[string]interface{}{
"dc_location": acc.DCLocation,
"ckey": acc.CKey,
"meta": flattens.FlattenMeta(acc.Meta),
"acl": flattenRgAcl(acc.ACL),
"company": acc.Company,
"companyurl": acc.CompanyURL,
@@ -267,6 +289,7 @@ func flattenAccountList(al *account.ListAccounts) []map[string]interface{} {
"resource_types": acc.ResTypes,
"send_access_emails": acc.SendAccessEmails,
"status": acc.Status,
"storage_policy_ids": acc.StoragePolicyIDs,
"uniq_pools": acc.UniqPools,
"default_zone_id": acc.DefaultZoneID,
"zone_ids": acc.ZoneIDs,
@@ -452,3 +475,11 @@ func flattenZones(zones []account.ZoneID) []map[string]interface{} {
}
return res
}
func flattenZonesInResource(zones []account.ZoneID) []int64 {
res := make([]int64, 0)
for _, zone := range zones {
res = append(res, zone.ID)
}
return res
}

View File

@@ -144,6 +144,23 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if stPolicy, ok := d.GetOk("storage_policy"); ok {
sp := stPolicy.(*schema.Set).List()
storagePolicies := make([]account.StoragePolicy, 0)
for _, elem := range sp {
stPolicyVal := elem.(map[string]interface{})
reqStPolicy := account.StoragePolicy{
ID: uint64(stPolicyVal["id"].(int)),
Limit: stPolicyVal["limit"].(int),
}
storagePolicies = append(storagePolicies, reqStPolicy)
}
req.StoragePolicies = storagePolicies
}
if compFeaturesInterface, ok := d.GetOk("compute_features"); ok {
compFeaturesInterfaces := compFeaturesInterface.(*schema.Set).List()
@@ -372,7 +389,16 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if d.HasChanges("account_name", "send_access_emails", "uniq_pools", "resource_limits", "desc", "default_zone_id") {
needUpdateSP := false
if d.HasChange("storage_policy") {
needUpdate, err := utilityAccountUpdateStPolicy(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
needUpdateSP = needUpdate
}
if d.HasChanges("account_name", "send_access_emails", "uniq_pools", "resource_limits", "desc", "default_zone_id") || needUpdateSP {
if err := utilityAccountUpdate(ctx, d, m); err != nil {
return diag.FromErr(err)
}
@@ -411,14 +437,18 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
if d.HasChange("zone_ids") {
old, new := d.GetChange("zone_ids")
//toAddSet := old.(*schema.Set).Difference(new.(*schema.Set))
toRemoveSet := new.(*schema.Set).Difference(old.(*schema.Set))
toRemoveSet := old.(*schema.Set).Difference(new.(*schema.Set))
toAddSet := new.(*schema.Set).Difference(old.(*schema.Set))
/*if err := utilityZoneIDsUpdate(ctx, d, m, toAddSet); err != nil {
return diag.FromErr(err)
}*/
if err := utilityZoneIDsRemove(ctx, d, m, toRemoveSet); err != nil {
return diag.FromErr(err)
if len(toAddSet.List()) > 0 {
if err := utilityZoneIDsAdd(ctx, d, m, toAddSet); err != nil {
return diag.FromErr(err)
}
}
if len(toRemoveSet.List()) > 0 {
if err := utilityZoneIDsRemove(ctx, d, m, toRemoveSet); err != nil {
return diag.FromErr(err)
}
}
}

View File

@@ -39,7 +39,7 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
Description: "if true send emails when a user is granted access to resources",
},
"zone_ids": {
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{
@@ -148,6 +148,39 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
Optional: true,
Computed: true,
},
"storage_policy": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
"limit": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
},
},
},
"storage_policy": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Required: true,
},
"limit": {
Type: schema.TypeInt,
Required: true,
},
},
},
},
@@ -168,17 +201,6 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
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,
@@ -523,17 +545,6 @@ func dataSourceAccountListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
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,
@@ -662,6 +673,22 @@ func dataSourceAccountListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeFloat,
Computed: true,
},
"storage_policy": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
"limit": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
},
},
},
@@ -680,6 +707,13 @@ func dataSourceAccountListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"storage_policy_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"default_zone_id": {
Type: schema.TypeInt,
Computed: true,
@@ -998,6 +1032,50 @@ func dataSourceAccountResourceConsumptionGetSchemaMake() map[string]*schema.Sche
Type: schema.TypeInt,
Computed: true,
},
"policies": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeFloat,
Computed: true,
},
"seps": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeString,
Computed: true,
},
"data_name": {
Type: schema.TypeString,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
},
},
},
"ram": {
Type: schema.TypeInt,
Computed: true,
@@ -1058,6 +1136,50 @@ func dataSourceAccountResourceConsumptionGetSchemaMake() map[string]*schema.Sche
Type: schema.TypeInt,
Computed: true,
},
"policies": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeFloat,
Computed: true,
},
"seps": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeString,
Computed: true,
},
"data_name": {
Type: schema.TypeString,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
},
},
},
"ram": {
Type: schema.TypeInt,
Computed: true,
@@ -1167,6 +1289,11 @@ func dataSourceAccountListSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Page size",
},
"zone_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Zone ID",
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -1176,17 +1303,6 @@ func dataSourceAccountListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
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,
@@ -1319,6 +1435,22 @@ func dataSourceAccountListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeFloat,
Computed: true,
},
"storage_policy": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
"limit": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
},
},
},
@@ -1337,6 +1469,13 @@ func dataSourceAccountListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"storage_policy_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"uniq_pools": {
Type: schema.TypeList,
Computed: true,
@@ -1417,6 +1556,50 @@ func dataSourceAccountResourceConsumptionListSchemaMake() map[string]*schema.Sch
Type: schema.TypeInt,
Computed: true,
},
"policies": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeFloat,
Computed: true,
},
"seps": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeString,
Computed: true,
},
"data_name": {
Type: schema.TypeString,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
},
},
},
"ram": {
Type: schema.TypeInt,
Computed: true,
@@ -1477,6 +1660,50 @@ func dataSourceAccountResourceConsumptionListSchemaMake() map[string]*schema.Sch
Type: schema.TypeInt,
Computed: true,
},
"policies": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeFloat,
Computed: true,
},
"seps": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeString,
Computed: true,
},
"data_name": {
Type: schema.TypeString,
Computed: true,
},
"disk_size": {
Type: schema.TypeFloat,
Computed: true,
},
"disk_size_max": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
},
},
},
"ram": {
Type: schema.TypeInt,
Computed: true,
@@ -1961,16 +2188,12 @@ func dataSourceAccountSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"ckey": {
Type: schema.TypeString,
Computed: true,
},
"default_zone_id": {
Type: schema.TypeInt,
Computed: true,
},
"zone_ids": {
Type: schema.TypeList,
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
@@ -2116,6 +2339,22 @@ func dataSourceAccountSchemaMake() map[string]*schema.Schema {
Type: schema.TypeFloat,
Computed: true,
},
"storage_policy": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
"limit": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
},
},
},
@@ -2156,6 +2395,13 @@ func dataSourceAccountSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"storage_policy_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
}
}

View File

@@ -211,7 +211,8 @@ func utilityAccountUpdate(ctx context.Context, d *schema.ResourceData, m interfa
accountId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := account.UpdateRequest{
AccountID: accountId,
AccountID: accountId,
SendAccessEmails: d.Get("send_access_emails").(bool),
}
if d.HasChange("account_name") {
@@ -222,18 +223,14 @@ func utilityAccountUpdate(ctx context.Context, d *schema.ResourceData, m interfa
req.Description = d.Get("desc").(string)
}
if d.HasChange("send_access_emails") {
req.SendAccessEmails = d.Get("send_access_emails").(bool)
}
if d.HasChange("default_zone_id") {
req.DefaultZoneID = uint64(d.Get("default_zone_id").(int))
}
if d.HasChange("uniq_pools") {
uniq_pools := d.Get("uniq_pools").([]interface{})
uniqPools := d.Get("uniq_pools").([]interface{})
for _, pool := range uniq_pools {
for _, pool := range uniqPools {
req.UniqPools = append(req.UniqPools, pool.(string))
}
}
@@ -292,6 +289,20 @@ func utilityAccountUpdate(ctx context.Context, d *schema.ResourceData, m interfa
}
}
_, _, updateStPolicy := utilityGetStoragePolicyUpdate(ctx, d, m)
if len(updateStPolicy) != 0 {
storagePolicies := make([]account.StoragePolicy, 0, len(updateStPolicy))
for _, stPolicyVal := range updateStPolicy {
reqStPolicy := account.StoragePolicy{
ID: uint64(stPolicyVal["id"].(int)),
Limit: stPolicyVal["limit"].(int),
}
storagePolicies = append(storagePolicies, reqStPolicy)
}
req.StoragePolicies = storagePolicies
}
_, err := c.CloudBroker().Account().Update(ctx, req)
if err != nil {
return err
@@ -300,6 +311,95 @@ func utilityAccountUpdate(ctx context.Context, d *schema.ResourceData, m interfa
return nil
}
func utilityAccountUpdateStPolicy(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
c := m.(*controller.ControllerCfg)
accountId, _ := strconv.ParseUint(d.Id(), 10, 64)
addSP, delSP, updateSP := utilityGetStoragePolicyUpdate(ctx, d, m)
needUpdate := len(updateSP) > 0
if len(addSP) > 0 {
for _, spMap := range addSP {
req := account.AddStoragePolicyRequest{
AccountID: accountId,
StoragePolicyID: uint64(spMap["id"].(int)),
Limit: spMap["limit"].(int),
}
log.Debugf("utilityAccountUpdateStPolicy: starting to add storage policy ID:%d for account %d", req.StoragePolicyID, req.AccountID)
_, err := c.CloudBroker().Account().AddStoragePolicy(ctx, req)
if err != nil {
return needUpdate, err
}
}
}
if len(delSP) > 0 {
for _, spMap := range delSP {
req := account.DelStoragePolicyRequest{
AccountID: accountId,
StoragePolicyID: uint64(spMap["id"].(int)),
}
log.Debugf("utilityAccountUpdateStPolicy: starting to delete storage policy ID:%d from account %d", req.StoragePolicyID, req.AccountID)
_, err := c.CloudBroker().Account().DelStoragePolicy(ctx, req)
if err != nil {
return needUpdate, err
}
}
}
return needUpdate, nil
}
func utilityGetStoragePolicyUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) (added, deleted, updated []map[string]interface{}) {
added = make([]map[string]interface{}, 0)
deleted = make([]map[string]interface{}, 0)
updated = make([]map[string]interface{}, 0)
oldSet, newSet := d.GetChange("storage_policy")
oldList := oldSet.(*schema.Set).List()
newList := newSet.(*schema.Set).List()
for _, oldSP := range oldList {
oldMap := oldSP.(map[string]interface{})
found := false
for _, newSP := range newList {
newMap := newSP.(map[string]interface{})
if oldMap["id"] == newMap["id"] {
found = true
if oldMap["limit"] != newMap["limit"] {
updated = append(added, newMap)
}
break
}
if found {
break
}
}
if found {
continue
}
deleted = append(deleted, oldMap)
}
for _, newSP := range newList {
newMap := newSP.(map[string]interface{})
found := false
for _, oldSP := range oldList {
oldMap := oldSP.(map[string]interface{})
if oldMap["id"] == newMap["id"] {
found = true
break
}
}
if found {
continue
}
added = append(added, newMap)
}
return
}
func utilityAccountAvailiableTemplatesUpdate(ctx context.Context, d *schema.ResourceData, m interface{}, afterCreate bool) error {
c := m.(*controller.ControllerCfg)

View File

@@ -72,6 +72,10 @@ func utilityAccountListCheckPresence(ctx context.Context, d *schema.ResourceData
req.Status = status.(string)
}
if zoneID, ok := d.GetOk("zone_id"); ok {
req.ZoneID = uint64(zoneID.(int))
}
log.Debugf("utilityAccountListCheckPresence: load account list")
accountList, err := c.CloudBroker().Account().List(ctx, req)
if err != nil {

View File

@@ -43,6 +43,7 @@ func flattenAudit(d *schema.ResourceData, au *audit.RecordAudit) {
d.Set("args", au.Arguments)
d.Set("call", au.Call)
d.Set("correlation_id", au.CorrelationID)
d.Set("guid", au.GUID)
d.Set("kwargs", au.Kwargs)
d.Set("remote_addr", au.RemoteAddr)
@@ -60,19 +61,19 @@ func flattenAuditList(au *audit.ListAudits) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(au.Data))
for _, item := range au.Data {
temp := map[string]interface{}{
"args": item.Args,
"call": item.Call,
"guid": item.GUID,
"kwargs": item.Kwargs,
"remote_addr": item.RemoteAddr,
"result": item.Result,
"responsetime": item.ResponseTime,
"status_code": item.StatusCode,
"tags": item.Tags,
"timestamp": item.Timestamp,
"timestamp_end": item.TimestampEnd,
"ttl": item.TTL,
"user": item.User,
"args": item.Args,
"call": item.Call,
"correlation_id": item.CorrelationID,
"guid": item.GUID,
"kwargs": item.Kwargs,
"remote_addr": item.RemoteAddr,
"result": item.Result,
"responsetime": item.ResponseTime,
"status_code": item.StatusCode,
"timestamp": item.Timestamp,
"timestamp_end": item.TimestampEnd,
"ttl": item.TTL,
"user": item.User,
}
res = append(res, temp)
}

View File

@@ -18,6 +18,10 @@ func dataSourceAuditSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"correlation_id": {
Type: schema.TypeString,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
@@ -42,10 +46,11 @@ func dataSourceAuditSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"tags": {
Type: schema.TypeString,
Computed: true,
},
//TODO
//"tags": {
// Type: schema.TypeString,
// Computed: true,
//},
"timestamp": {
Type: schema.TypeFloat,
Computed: true,
@@ -117,6 +122,50 @@ func dataSourceAuditListSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "page size",
},
"resgroup_id": {
Type: schema.TypeInt,
Optional: true,
},
"compute_id": {
Type: schema.TypeInt,
Optional: true,
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
},
"vins_id": {
Type: schema.TypeInt,
Optional: true,
},
"service_id": {
Type: schema.TypeInt,
Optional: true,
},
"k8s_id": {
Type: schema.TypeInt,
Optional: true,
},
"flipgroup_id": {
Type: schema.TypeInt,
Optional: true,
},
"lb_id": {
Type: schema.TypeInt,
Optional: true,
},
"sep_id": {
Type: schema.TypeInt,
Optional: true,
},
"node_id": {
Type: schema.TypeInt,
Optional: true,
},
"exclude_audit_lines": {
Type: schema.TypeBool,
Optional: true,
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -126,6 +175,10 @@ func dataSourceAuditListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"correlation_id": {
Type: schema.TypeString,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
@@ -170,10 +223,6 @@ func dataSourceAuditListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"tags": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

View File

@@ -76,6 +76,39 @@ func utilityAuditListCheckPresence(ctx context.Context, d *schema.ResourceData,
if Size, ok := d.GetOk("size"); ok {
req.Size = uint64(Size.(int))
}
if resgroupID, ok := d.GetOk("resgroup_id"); ok {
req.RGID = uint64(resgroupID.(int))
}
if computeID, ok := d.GetOk("compute_id"); ok {
req.ComputeID = uint64(computeID.(int))
}
if accountID, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountID.(int))
}
if vinsID, ok := d.GetOk("vins_id"); ok {
req.VINSID = uint64(vinsID.(int))
}
if serviceID, ok := d.GetOk("service_id"); ok {
req.ServiceID = uint64(serviceID.(int))
}
if k8sID, ok := d.GetOk("k8s_id"); ok {
req.K8SID = uint64(k8sID.(int))
}
if flipgroupID, ok := d.GetOk("flipgroup_id"); ok {
req.FLIPGroupID = uint64(flipgroupID.(int))
}
if lbID, ok := d.GetOk("lb_id"); ok {
req.LBID = uint64(lbID.(int))
}
if sepID, ok := d.GetOk("sep_id"); ok {
req.SEPID = uint64(sepID.(int))
}
if nodeID, ok := d.GetOk("node_id"); ok {
req.NodeID = uint64(nodeID.(int))
}
if excludeAuditLines, ok := d.GetOk("exclude_audit_lines"); ok {
req.ExcludeAuditLines = excludeAuditLines.(bool)
}
log.Debugf("utilityAuditListCheckPresence: load audit list")
auditList, err := c.CloudBroker().Audit().List(ctx, req)

View File

@@ -58,11 +58,13 @@ func flattenDisk(d *schema.ResourceData, disk *disks.RecordDisk) {
d.Set("size_used", disk.SizeUsed)
d.Set("snapshots", flattendDiskSnapshotList(disk.Snapshots))
d.Set("status", disk.Status)
d.Set("storage_policy_id", disk.StoragePolicyID)
d.Set("tech_status", disk.TechStatus)
d.Set("type", disk.Type)
d.Set("vmid", disk.VMID)
d.Set("updated_by", disk.UpdatedBy)
d.Set("updated_time", disk.UpdatedTime)
d.Set("to_clean", disk.ToClean)
}
func flattenDiskReplica(d *schema.ResourceData, disk *disks.RecordDisk, statusReplication string) {
@@ -224,11 +226,13 @@ func flattenDiskList(dl *disks.ListDisks) []map[string]interface{} {
"size_used": disk.SizeUsed,
"snapshots": flattendDiskSnapshotList(disk.Snapshots),
"status": disk.Status,
"storage_policy_id": disk.StoragePolicyID,
"tech_status": disk.TechStatus,
"type": disk.Type,
"vmid": disk.VMID,
"updated_by": disk.UpdatedBy,
"updated_time": disk.UpdatedTime,
"to_clean": disk.ToClean,
}
res = append(res, temp)
}

View File

@@ -57,19 +57,16 @@ func resourceDiskCreate(ctx context.Context, d *schema.ResourceData, m interface
}
req := disks.CreateRequest{
AccountID: uint64(d.Get("account_id").(int)),
Name: d.Get("disk_name").(string),
Size: uint64(d.Get("size_max").(int)),
AccountID: uint64(d.Get("account_id").(int)),
StoragePolicyID: uint64(d.Get("storage_policy_id").(int)),
Name: d.Get("disk_name").(string),
Size: uint64(d.Get("size_max").(int)),
}
if desc, ok := d.GetOk("desc"); ok {
req.Description = desc.(string)
}
if iops, ok := d.GetOk("iops"); ok {
req.IOPS = uint64(iops.(int))
}
if sepID, ok := d.GetOk("sep_id"); ok {
req.SEPID = uint64(sepID.(int))
}
@@ -202,6 +199,12 @@ func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface
}
}
if d.HasChange("storage_policy_id") {
if err := resourceDiskChangeStoragePolicyID(ctx, d, m); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("size_max") {
oldSize, newSize := d.GetChange("size_max")
if oldSize.(int) > newSize.(int) {
@@ -297,8 +300,6 @@ func resourceDiskChangeIotune(ctx context.Context, d *schema.ResourceData, m int
if _, ok := iotune["total_iops_sec"]; ok {
req.IOPS = uint64(iotune["total_iops_sec"].(int))
} else if _, ok := d.GetOk("iops"); ok {
req.IOPS = uint64(d.Get("iops").(int))
}
_, err := c.CloudBroker().Disks().LimitIO(ctx, req)
@@ -351,6 +352,16 @@ func resourceDiskChangeSize(ctx context.Context, d *schema.ResourceData, m inter
return err
}
func resourceDiskChangeStoragePolicyID(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
_, err := c.CloudBroker().Disks().ChangeDiskStoragePolicy(ctx, disks.ChangeDiskStoragePolicyRequest{
DiskID: uint64(d.Get("disk_id").(int)),
StoragePolicyID: uint64(d.Get("storage_policy_id").(int)),
})
return err
}
func resourceDiskChangeNodes(ctx context.Context, d *schema.ResourceData, m interface{}, afterCreate bool) error {
c := m.(*controller.ControllerCfg)
diskID := uint64(d.Get("disk_id").(int))

View File

@@ -333,6 +333,11 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"storage_policy_id": {
Type: schema.TypeFloat,
Computed: true,
Description: "Storage policy ID",
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
@@ -353,6 +358,10 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
}
return rets
@@ -425,6 +434,11 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Page size",
},
"storage_policy_id": {
Type: schema.TypeInt,
Optional: true,
Description: "storage policy ID ",
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -757,6 +771,11 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"storage_policy_id": {
Type: schema.TypeFloat,
Computed: true,
Description: "Storage policy ID",
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
@@ -777,6 +796,10 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
@@ -1172,6 +1195,11 @@ func dataSourceDiskListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"storage_policy_id": {
Type: schema.TypeFloat,
Computed: true,
Description: "Storage policy ID",
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
@@ -1192,6 +1220,10 @@ func dataSourceDiskListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
@@ -1358,6 +1390,11 @@ func dataSourceDiskListUnattachedSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Page size",
},
"storage_policy_id": {
Type: schema.TypeInt,
Optional: true,
Description: "storage policy ID ",
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -1863,6 +1900,10 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
Required: true,
//ForceNew: true,
},
"storage_policy_id": {
Type: schema.TypeInt,
Required: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
@@ -1889,11 +1930,6 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'",
},
"iops": {
Type: schema.TypeInt,
Optional: true,
Description: "max IOPS disk can perform",
},
"sep_id": {
Type: schema.TypeInt,
Optional: true,
@@ -2252,6 +2288,10 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
}
return rets

View File

@@ -85,6 +85,9 @@ func utilityDiskListCheckPresence(ctx context.Context, d *schema.ResourceData, m
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if storagePolicyID, ok := d.GetOk("storage_policy_id"); ok {
req.StoragePolicyID = uint64(storagePolicyID.(int))
}
log.Debugf("utilityDiskListCheckPresence: load disk list")
diskList, err := c.CloudBroker().Disks().List(ctx, req)

View File

@@ -46,6 +46,9 @@ func utilityDiskListUnattachedCheckPresence(ctx context.Context, d *schema.Resou
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if storagePolicyID, ok := d.GetOk("storage_policy_id"); ok {
req.StoragePolicyID = uint64(storagePolicyID.(int))
}
log.Debugf("utilityDiskListUnattachedCheckPresence: load disk Unattached list")
unattachedList, err := c.CloudBroker().Disks().ListUnattached(ctx, req)

View File

@@ -19,24 +19,26 @@ func flattenDPDKNet(d *schema.ResourceData, dpdk *dpdk.RecordDPDKNet) {
d.Set("vlan_id", dpdk.VlanID)
d.Set("compute_ids", dpdk.ComputeIDs)
d.Set("updated_time", dpdk.UpdatedTime)
d.Set("enable_secgroups", dpdk.EnableSecGroups)
}
func flattenDPDKNetList(list *dpdk.ListDPDKNet) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(list.Data))
for _, dpdk := range list.Data {
temp := map[string]interface{}{
"dpdk_id": dpdk.ID,
"account_access": dpdk.AccountAccess,
"desc": dpdk.Description,
"gid": dpdk.GID,
"guid": dpdk.GUID,
"name": dpdk.Name,
"rg_access": dpdk.RGAccess,
"status": dpdk.Status,
"ovs_bridge": dpdk.OVSBridge,
"vlan_id": dpdk.VlanID,
"compute_ids": dpdk.ComputeIDs,
"updated_time": dpdk.UpdatedTime,
"dpdk_id": dpdk.ID,
"account_access": dpdk.AccountAccess,
"desc": dpdk.Description,
"enable_secgroups": dpdk.EnableSecGroups,
"gid": dpdk.GID,
"guid": dpdk.GUID,
"name": dpdk.Name,
"rg_access": dpdk.RGAccess,
"status": dpdk.Status,
"ovs_bridge": dpdk.OVSBridge,
"vlan_id": dpdk.VlanID,
"compute_ids": dpdk.ComputeIDs,
"updated_time": dpdk.UpdatedTime,
}
res = append(res, temp)
}

View File

@@ -93,6 +93,17 @@ func resourceDPDKNetCreate(ctx context.Context, d *schema.ResourceData, m interf
warnings.Add(err)
}
if d.Get("enable_secgroups").(bool) {
req := dpdk.UpdateRequest{
DPDKID: dpdkID,
EnableSecGroups: true,
}
_, err := c.CloudBroker().DPDKNet().Update(ctx, req)
if err != nil {
warnings.Add(err)
}
}
return append(warnings.Get(), resourceDPDKNetRead(ctx, d, m)...)
}
@@ -167,7 +178,7 @@ func resourceDPDKNetUpdate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if d.HasChanges("name", "desc", "vlan_id", "ovs_bridge", "account_access", "rg_access") {
if d.HasChanges("name", "desc", "vlan_id", "ovs_bridge", "account_access", "rg_access", "enable_secgroups") {
if err := utilityDPDKNetUpdate(ctx, d, m); err != nil {
return diag.FromErr(err)
}

View File

@@ -161,6 +161,10 @@ func dataSourceDPDKNetListSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Description of DPDK network",
},
"enable_secgroups": {
Type: schema.TypeBool,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
@@ -275,6 +279,12 @@ func resourceDPDKNetSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Enabled or disabled DPDK network",
},
"enable_secgroups": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "enable security groups",
},
"guid": {
Type: schema.TypeInt,
Computed: true,

View File

@@ -148,6 +148,10 @@ func utilityDPDKNetUpdate(ctx context.Context, d *schema.ResourceData, m interfa
}
}
if d.HasChange("enable_secgroups") {
req.EnableSecGroups = d.Get("enable_secgroups").(bool)
}
if _, err := c.CloudBroker().DPDKNet().Update(ctx, req); err != nil {
return err
}

View File

@@ -51,11 +51,12 @@ func flattenListExtnet(extList *extnet.ListExtNet) []map[string]interface{} {
"free_ips": item.FreeIPs,
"gid": item.GID,
"guid": item.GUID,
"enable_secgroups": item.EnableSecGroups,
"extnet_id": item.ID,
"ipcidr": item.IPCIDR,
"milestones": item.Milestones,
"name": item.Name,
"network_ids": item.NetworkIDs,
"network_ids": flattenNetworkIDs(item.NetworkIDs),
"ovs_bridge": item.OVSBridge,
"pre_reservations_num": item.PreReservationsNum,
"pri_vnfdev_id": item.PriVNFDevID,
@@ -143,6 +144,7 @@ func flattenRecordExtnetResource(d *schema.ResourceData, recNet *extnet.RecordEx
d.Set("reservations", flattenExtnetReservations(recNet.Reservations))
d.Set("routes", flattenStaticRouteList(staticRouteList))
d.Set("zone_id", recNet.ZoneID)
d.Set("enable_secgroups", recNet.EnableSecGroups)
}
func flattenExtnetExcluded(ers extnet.ListReservations) []map[string]interface{} {

View File

@@ -133,7 +133,7 @@ func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interfa
}
if mtu, ok := d.GetOk("mtu"); ok {
req.MTU = mtu.(uint)
req.MTU = uint(mtu.(int))
}
log.Debugf("cloudbroker: Sent create request")
@@ -234,6 +234,18 @@ func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interfa
}
}
if d.Get("enable_secgroups").(bool) {
log.Debugf("resourceExtnetCreate: trying to enable secgroups for extnet with ID %d", netID)
req := extnet.UpdateRequest{
NetID: netID,
EnableSecGroups: true,
}
_, err := c.CloudBroker().ExtNet().Update(ctx, req)
if err != nil {
w.Add(err)
}
}
return resourceExtnetRead(ctx, d, m)
}

View File

@@ -65,6 +65,11 @@ func dataSourceExtnetListSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Page size",
},
"zone_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Zone ID",
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -130,6 +135,10 @@ func dataSourceExtnetListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"enable_secgroups": {
Type: schema.TypeBool,
Computed: true,
},
"extnet_id": {
Type: schema.TypeInt,
Computed: true,
@@ -700,6 +709,12 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
Optional: true,
Computed: true,
},
"enable_secgroups": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "enable security groups",
},
"dns": {
Type: schema.TypeList,
Optional: true,

View File

@@ -86,6 +86,10 @@ func utilityExtnetListCheckPresence(ctx context.Context, d *schema.ResourceData,
req.Size = uint64(size.(int))
}
if zoneID, ok := d.GetOk("zone_id"); ok {
req.ZoneID = uint64(zoneID.(int))
}
res, err := c.CloudBroker().ExtNet().List(ctx, req)
if err != nil {
return nil, err

View File

@@ -119,7 +119,11 @@ func handleBasicUpdate(ctx context.Context, d *schema.ResourceData, c *controlle
doBasicUpdate = true
}
if d.HasChange("mtu") {
basiUpdateReq.MTU = d.Get("mtu").(uint64)
basiUpdateReq.MTU = uint64(d.Get("mtu").(int))
doBasicUpdate = true
}
if d.HasChange("enable_secgroups") {
basiUpdateReq.EnableSecGroups = d.Get("enable_secgroups").(bool)
doBasicUpdate = true
}

View File

@@ -49,7 +49,9 @@ func flattenImage(d *schema.ResourceData, img *image.RecordImage) {
d.Set("size", img.Size)
d.Set("snapshot_id", img.SnapshotID)
d.Set("status", img.Status)
d.Set("storage_policy_id", img.StoragePolicyID)
d.Set("tech_status", img.TechStatus)
d.Set("to_clean", img.ToClean)
d.Set("image_type", img.Type)
d.Set("url", img.URL)
d.Set("username", img.Username)
@@ -128,7 +130,9 @@ func flattenImageList(il *image.ListImages) []map[string]interface{} {
"size": item.Size,
"snapshot_id": item.SnapshotID,
"status": item.Status,
"storage_policy_id": item.StoragePolicyID,
"tech_status": item.TechStatus,
"to_clean": item.ToClean,
"image_type": item.Type,
"url": item.URL,
"username": item.Username,

View File

@@ -48,16 +48,11 @@ func resourceCDROMImageCreate(ctx context.Context, d *schema.ResourceData, m int
log.Debugf("resourceCDROMImageCreate: called for image %s", d.Get("name").(string))
c := m.(*controller.ControllerCfg)
req := image.CreateCDROMImageRequest{
Name: d.Get("name").(string),
URL: d.Get("url").(string),
Name: d.Get("name").(string),
URL: d.Get("url").(string),
StoragePolicyID: uint64(d.Get("storage_policy_id").(int)),
}
drivers := []string{}
for _, driver := range d.Get("drivers").([]interface{}) {
drivers = append(drivers, driver.(string))
}
req.Drivers = drivers
if username, ok := d.GetOk("username_dl"); ok {
req.UsernameDL = username.(string)
}
@@ -168,13 +163,6 @@ func resourceCDROMImageUpdate(ctx context.Context, d *schema.ResourceData, m int
}
}
if d.HasChange("enabled_stacks") {
err := resourceImageUpdateNodes(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChanges("name", "password_dl", "username_dl", "account_id", "bootable", "hot_resize") {
err := resourceImageCDROMEdit(ctx, d, m)
if err != nil {

View File

@@ -204,13 +204,6 @@ func resourceImageUpdate(ctx context.Context, d *schema.ResourceData, m interfac
}
}
if d.HasChange("enabled_stacks") {
err := resourceImageUpdateNodes(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChanges("name", "username", "password", "account_id", "bootable", "hot_resize", "network_interface_naming") {
err := resourceImageEdit(ctx, d, m)
if err != nil {
@@ -327,27 +320,6 @@ func resourceImageChangeComputeci(ctx context.Context, d *schema.ResourceData, m
return nil
}
func resourceImageUpdateNodes(ctx context.Context, d *schema.ResourceData, m interface{}) error {
log.Debugf("resourceImageUpdateNodes: called for %s, id: %s", d.Get("name").(string), d.Id())
c := m.(*controller.ControllerCfg)
req := image.UpdateNodesRequest{
ImageID: uint64(d.Get("image_id").(int)),
}
enabledStacks := []uint64{}
for _, stack := range d.Get("enabled_stacks").([]interface{}) {
enabledStacks = append(enabledStacks, uint64(stack.(int)))
}
req.EnabledStacks = enabledStacks
_, err := c.CloudBroker().Image().UpdateNodes(ctx, req)
if err != nil {
return err
}
return nil
}
func resourceImageEdit(ctx context.Context, d *schema.ResourceData, m interface{}) error {
log.Debugf("resourceImageEdit: called for %s, id: %s", d.Get("name").(string), d.Id())
c := m.(*controller.ControllerCfg)

View File

@@ -235,13 +235,6 @@ func resourceImageFromBlankComputeUpdate(ctx context.Context, d *schema.Resource
}
}
if d.HasChange("enabled_stacks") {
err := resourceImageUpdateNodes(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChanges("name", "username", "password", "account_id", "bootable", "hot_resize", "network_interface_naming") {
err := resourceImageEdit(ctx, d, m)
if err != nil {

View File

@@ -78,11 +78,7 @@ func resourceImageFromPlatformDiskCreate(ctx context.Context, d *schema.Resource
if poolName, ok := d.GetOk("pool_name"); ok {
req.PoolName = poolName.(string)
}
if driversInterface, ok := d.GetOk("drivers"); ok {
for _, d := range driversInterface.([]interface{}) {
req.Drivers = append(req.Drivers, d.(string))
}
}
if hotresize, ok := d.GetOk("hot_resize"); ok {
req.HotResize = hotresize.(bool)
}
@@ -241,13 +237,6 @@ func resourceImageFromPlatformDiskUpdate(ctx context.Context, d *schema.Resource
}
}
if d.HasChange("enabled_stacks") {
err := resourceImageUpdateNodes(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChanges("name", "username", "password", "account_id", "bootable", "hot_resize", "network_interface_naming") {
err := resourceImageEdit(ctx, d, m)
if err != nil {

View File

@@ -49,8 +49,9 @@ func resourceVirtualImageCreate(ctx context.Context, d *schema.ResourceData, m i
c := m.(*controller.ControllerCfg)
req := image.CreateVirtualRequest{
Name: d.Get("name").(string),
TargetID: uint64(d.Get("link_to").(int)),
Name: d.Get("name").(string),
TargetID: uint64(d.Get("link_to").(int)),
AccountID: uint64(d.Get("account_id").(int)),
}
imageId, err := c.CloudBroker().Image().CreateVirtual(ctx, req)
@@ -147,13 +148,6 @@ func resourceVirtualImageUpdate(ctx context.Context, d *schema.ResourceData, m i
}
}
if d.HasChange("enabled_stacks") {
err := resourceImageUpdateNodes(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChanges("name", "username", "password", "account_id", "bootable", "hot_resize") {
err := resourceImageEdit(ctx, d, m)
if err != nil {

View File

@@ -34,7 +34,6 @@ package image
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/statefuncs"
)
func dataSourceImageListStacksSchemaMake() map[string]*schema.Schema {
@@ -404,6 +403,10 @@ func dataSourceImageListSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "find by enabled True or False",
},
"storage_policy_id": {
Type: schema.TypeInt,
Optional: true,
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -624,6 +627,14 @@ func dataSourceImageListSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "status",
},
"storage_policy_id": {
Type: schema.TypeInt,
Computed: true,
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
@@ -882,10 +893,18 @@ func dataSourceImageSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "status",
},
"storage_policy_id": {
Type: schema.TypeInt,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
Description: "tech atatus",
Description: "tech status",
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
"image_type": {
Type: schema.TypeString,
@@ -922,13 +941,10 @@ func resourceCDROMImageSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "URL where to download ISO from",
},
"drivers": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "List of types of compute suitable for image. Example: [ \"KVM_X86\" ]",
"storage_policy_id": {
Type: schema.TypeInt,
Required: true,
Description: "ID of the storage policy",
},
"hot_resize": {
Type: schema.TypeBool,
@@ -996,13 +1012,6 @@ func resourceCDROMImageSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"enabled_stacks": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"unc_path": {
Type: schema.TypeString,
Computed: true,
@@ -1047,6 +1056,13 @@ func resourceCDROMImageSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Boot type of image bios or uefi",
},
"drivers": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"gid": {
Type: schema.TypeInt,
Computed: true,
@@ -1132,6 +1148,10 @@ func resourceCDROMImageSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "tech atatus",
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
"version": {
Type: schema.TypeString,
Computed: true,
@@ -1187,15 +1207,10 @@ func resourceImageSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "Image type linux, windows or other",
},
"drivers": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"KVM_X86"}, false),
},
Description: "List of types of compute suitable for image. Example: [ \"KVM_X86\" ]",
"storage_policy_id": {
Type: schema.TypeInt,
Required: true,
Description: "ID of the storage policy",
},
"hot_resize": {
Type: schema.TypeBool,
@@ -1279,13 +1294,6 @@ func resourceImageSchemaMake() map[string]*schema.Schema {
Default: false,
Description: "Create image from a media identified by URL (in synchronous mode)",
},
"enabled_stacks": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"shared_with": {
Type: schema.TypeList,
Optional: true,
@@ -1329,6 +1337,13 @@ func resourceImageSchemaMake() map[string]*schema.Schema {
},
},
},
"drivers": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"gid": {
Type: schema.TypeInt,
Computed: true,
@@ -1413,6 +1428,10 @@ func resourceImageSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "tech atatus",
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
"version": {
Type: schema.TypeString,
Computed: true,
@@ -1506,13 +1525,6 @@ func resourceVirtualImageSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"enabled_stacks": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"unc_path": {
Type: schema.TypeString,
@@ -1684,6 +1696,10 @@ func resourceVirtualImageSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "tech atatus",
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
"image_type": {
Type: schema.TypeString,
Computed: true,
@@ -1784,13 +1800,6 @@ func resourceImageFromBlankComputeSchemaMake() map[string]*schema.Schema {
Optional: true,
Computed: true,
},
"enabled_stacks": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"shared_with": {
Type: schema.TypeList,
Optional: true,
@@ -1956,6 +1965,10 @@ func resourceImageFromBlankComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
"url": {
Type: schema.TypeString,
Computed: true,
@@ -2018,16 +2031,6 @@ func resourceImageFromPlatformDiskSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "storage endpoint provider ID",
},
"drivers": {
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{
StateFunc: statefuncs.StateFuncToUpper,
ValidateFunc: validation.StringInSlice([]string{"SVA_KVM_X86", "KVM_X86"}, false), // observe case while validating
Type: schema.TypeString,
},
Description: "List of types of compute suitable for image. Example: [ \"KVM_X86\" ]",
},
"pool_name": {
Type: schema.TypeString,
Optional: true,
@@ -2062,13 +2065,6 @@ func resourceImageFromPlatformDiskSchemaMake() map[string]*schema.Schema {
Optional: true,
Computed: true,
},
"enabled_stacks": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"shared_with": {
Type: schema.TypeList,
Optional: true,
@@ -2135,6 +2131,13 @@ func resourceImageFromPlatformDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"drivers": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"gid": {
Type: schema.TypeInt,
Computed: true,
@@ -2223,6 +2226,10 @@ func resourceImageFromPlatformDiskSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
"url": {
Type: schema.TypeString,
Computed: true,

View File

@@ -90,6 +90,9 @@ func utilityImageListCheckPresence(ctx context.Context, d *schema.ResourceData,
if enabled, ok := d.GetOkExists("enabled"); ok {
req.Enabled = enabled.(bool)
}
if storagePolicyID, ok := d.GetOk("storage_policy_id"); ok {
req.StoragePolicyID = uint64(storagePolicyID.(int))
}
log.Debugf("utilityImageListCheckPresence: load image list")
imageList, err := c.CloudBroker().Image().List(ctx, req)
if err != nil {

View File

@@ -40,18 +40,11 @@ import (
func CreateRequest(ctx context.Context, d *schema.ResourceData, m interface{}, url string) (image.CreateRequest, error) {
req := image.CreateRequest{
Name: d.Get("name").(string),
URL: url,
BootType: d.Get("boot_type").(string),
ImageType: d.Get("image_type").(string),
}
if _, ok := d.GetOk("drivers"); ok {
drivers := []string{}
for _, driver := range d.Get("drivers").([]interface{}) {
drivers = append(drivers, driver.(string))
}
req.Drivers = drivers
Name: d.Get("name").(string),
URL: url,
BootType: d.Get("boot_type").(string),
ImageType: d.Get("image_type").(string),
StoragePolicyID: uint64(d.Get("storage_policy_id").(int)),
}
if hotresize, ok := d.GetOk("hot_resize"); ok {

View File

@@ -50,7 +50,6 @@ func flattenK8CIListItems(list *k8ci.ListK8CI) []map[string]interface{} {
"guid": item.GUID,
"k8ci_id": item.ID,
"lb_image_id": item.LBImageID,
"master_driver": item.MasterDriver,
"master_image_id": item.MasterImageID,
"max_master_count": item.MaxMasterCount,
"max_worker_count": item.MaxWorkerCount,
@@ -58,7 +57,6 @@ func flattenK8CIListItems(list *k8ci.ListK8CI) []map[string]interface{} {
"shared_with": item.SharedWith,
"status": item.Status,
"version": item.Version,
"worker_driver": item.WorkerDriver,
"worker_image_id": item.WorkerImageID,
}
res = append(res, temp)
@@ -75,7 +73,6 @@ func flattenK8CIItems(d *schema.ResourceData, data *k8ci.RecordK8CI) error {
d.Set("guid", data.GUID)
d.Set("k8ci_id", data.ID)
d.Set("lb_image_id", data.LBImageID)
d.Set("master_driver", data.MasterDriver)
d.Set("master_image_id", data.MasterImageID)
d.Set("max_master_count", data.MaxMasterCount)
d.Set("max_worker_count", data.MaxWorkerCount)
@@ -85,7 +82,6 @@ func flattenK8CIItems(d *schema.ResourceData, data *k8ci.RecordK8CI) error {
d.Set("shared_with", data.SharedWith)
d.Set("status", data.Status)
d.Set("version", data.Version)
d.Set("worker_driver", data.WorkerDriver)
d.Set("worker_image_id", data.WorkerImageID)
return nil

View File

@@ -59,8 +59,6 @@ func resourceK8CICreate(ctx context.Context, d *schema.ResourceData, m interface
req := k8ci.CreateRequest{
Name: d.Get("name").(string),
Version: d.Get("version").(string),
MasterDriver: d.Get("master_driver").(string),
WorkerDriver: d.Get("worker_driver").(string),
MaxMasterCount: uint64(d.Get("max_master_count").(int)),
MaxWorkerCount: uint64(d.Get("max_worker_count").(int)),
MasterImageID: uint64(d.Get("master_image_id").(int)),

View File

@@ -61,10 +61,6 @@ func dataSourceK8CISchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "LB Image ID",
},
"master_driver": {
Type: schema.TypeString,
Computed: true,
},
"master_image_id": {
Type: schema.TypeInt,
Computed: true,
@@ -137,16 +133,6 @@ func dataSourceK8CIListSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Filter by status",
},
"worker_driver": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by worker driver",
},
"master_driver": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by master driver",
},
"network_plugin": {
Type: schema.TypeString,
Optional: true,
@@ -206,10 +192,6 @@ func dataSourceK8CIListSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "LB Image ID",
},
"master_driver": {
Type: schema.TypeString,
Computed: true,
},
"master_image_id": {
Type: schema.TypeInt,
Computed: true,
@@ -243,10 +225,6 @@ func dataSourceK8CIListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"worker_driver": {
Type: schema.TypeString,
Computed: true,
},
"worker_image_id": {
Type: schema.TypeInt,
Computed: true,
@@ -273,16 +251,6 @@ func dataSourceK8CIListDeletedSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Filter by name",
},
"worker_driver": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by worker driver",
},
"master_driver": {
Type: schema.TypeString,
Optional: true,
Description: "Filter by master driver",
},
"network_plugin": {
Type: schema.TypeString,
Optional: true,
@@ -336,10 +304,6 @@ func dataSourceK8CIListDeletedSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "LB Image ID",
},
"master_driver": {
Type: schema.TypeString,
Computed: true,
},
"master_image_id": {
Type: schema.TypeInt,
Computed: true,
@@ -373,10 +337,6 @@ func dataSourceK8CIListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"worker_driver": {
Type: schema.TypeString,
Computed: true,
},
"worker_image_id": {
Type: schema.TypeInt,
Computed: true,
@@ -402,10 +362,6 @@ func resourceK8CISchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Required: true,
},
"master_driver": {
Type: schema.TypeString,
Required: true,
},
"master_image_id": {
Type: schema.TypeInt,
Required: true,
@@ -422,10 +378,6 @@ func resourceK8CISchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Required: true,
},
"worker_driver": {
Type: schema.TypeString,
Required: true,
},
"network_plugins": {
Type: schema.TypeList,
Required: true,

View File

@@ -56,12 +56,6 @@ func utilityK8CIListCheckPresence(ctx context.Context, d *schema.ResourceData, m
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if worker_driver, ok := d.GetOk("worker_driver"); ok {
req.WorkerDriver = worker_driver.(string)
}
if master_driver, ok := d.GetOk("master_driver"); ok {
req.MasterDriver = master_driver.(string)
}
if network_plugin, ok := d.GetOk("network_plugin"); ok {
req.NetworkPlugins = network_plugin.(string)
}

View File

@@ -53,12 +53,6 @@ func utilityK8CIListDeletedCheckPresence(ctx context.Context, d *schema.Resource
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if worker_driver, ok := d.GetOk("worker_driver"); ok {
req.WorkerDriver = worker_driver.(string)
}
if master_driver, ok := d.GetOk("master_driver"); ok {
req.MasterDriver = master_driver.(string)
}
if network_plugin, ok := d.GetOk("network_plugin"); ok {
req.NetworkPlugins = network_plugin.(string)
}

View File

@@ -68,6 +68,7 @@ func resourceK8sCPCreate(ctx context.Context, d *schema.ResourceData, m interfac
K8CIID: uint64(d.Get("k8sci_id").(int)),
WorkerGroupName: "temp",
NetworkPlugin: d.Get("network_plugin").(string),
StoragePolicyID: uint64(d.Get("storage_policy_id").(int)),
}
if num, ok := d.GetOk("num"); ok {

View File

@@ -58,14 +58,15 @@ func resourceK8sWgCreate(ctx context.Context, d *schema.ResourceData, m interfac
}
req := k8s.WorkersGroupAddRequest{
K8SID: uint64(d.Get("k8s_id").(int)),
Name: d.Get("name").(string),
WorkerNum: uint64(d.Get("num").(int)),
WorkerCPU: uint64(d.Get("cpu").(int)),
WorkerRAM: uint64(d.Get("ram").(int)),
WorkerSEPID: uint64(d.Get("worker_sep_id").(int)),
WorkerSEPPool: d.Get("worker_sep_pool").(string),
Chipset: d.Get("chipset").(string),
K8SID: uint64(d.Get("k8s_id").(int)),
Name: d.Get("name").(string),
WorkerNum: uint64(d.Get("num").(int)),
WorkerCPU: uint64(d.Get("cpu").(int)),
WorkerRAM: uint64(d.Get("ram").(int)),
WorkerSEPID: uint64(d.Get("worker_sep_id").(int)),
WorkerSEPPool: d.Get("worker_sep_pool").(string),
Chipset: d.Get("chipset").(string),
StoragePolicyID: uint64(d.Get("storage_policy_id").(int)),
}
if d.Get("disk") == nil {

View File

@@ -471,6 +471,11 @@ func dataSourceK8sListSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Page size",
},
"zone_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Zone ID",
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -1355,6 +1360,11 @@ func resourceK8sCPSchemaMake() map[string]*schema.Schema {
Description: "Network plugin to be used",
ValidateFunc: validation.StringInSlice([]string{"flannel", "weavenet", "calico"}, true),
},
"storage_policy_id": {
Type: schema.TypeInt,
Required: true,
Description: "ID of the storage policy",
},
"zone_id": {
Type: schema.TypeInt,
Optional: true,
@@ -1771,6 +1781,11 @@ func resourceK8sWgSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "Name of the worker group.",
},
"storage_policy_id": {
Type: schema.TypeInt,
Required: true,
Description: "ID of the storage policy",
},
"num": {
Type: schema.TypeInt,
Optional: true,

View File

@@ -79,6 +79,9 @@ func utilityK8sListCheckPresence(ctx context.Context, d *schema.ResourceData, m
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if zoneID, ok := d.GetOk("zone_id"); ok {
req.ZoneID = uint64(zoneID.(int))
}
k8sList, err := c.CloudBroker().K8S().List(ctx, req)
if err != nil {

View File

@@ -50,6 +50,7 @@ func dataSourceComputeAuditsRead(ctx context.Context, d *schema.ResourceData, m
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenComputeAudits(computeAudits))
d.Set("entry_count", computeAudits.EntryCount)
return nil
}

View File

@@ -39,6 +39,7 @@ func flattenCompute(d *schema.ResourceData, computeRec *compute.RecordCompute, p
d.Set("boot_disk_id", bootDisk.ID)
// we intentionally use the SizeMax field, do not change it until the BootDiskSize field is fixed on the platform
d.Set("boot_disk_size", bootDisk.SizeMax)
d.Set("boot_image_id", bootDisk.ImageID)
d.Set("chipset", computeRec.Chipset)
d.Set("cd_image_id", computeRec.CdImageId)
d.Set("clone_reference", computeRec.CloneReference)
@@ -96,14 +97,16 @@ func flattenCompute(d *schema.ResourceData, computeRec *compute.RecordCompute, p
d.Set("user_managed", computeRec.UserManaged)
d.Set("vnc_password", computeRec.VNCPassword)
d.Set("vgpus", flattenVGPUs(computeRec.VGPUs))
d.Set("virtual_image_id", computeRec.VirtualImageID)
d.Set("virtual_image_name", computeRec.VirtualImageName)
//TODO
// d.Set("virtual_image_id", computeRec.VirtualImageID)
// d.Set("virtual_image_name", computeRec.VirtualImageName)
d.Set("pci_devices", flattenPCI(*pciList))
d.Set("loader_type", computeRec.LoaderType)
d.Set("boot_type", computeRec.BootType)
d.Set("hot_resize", computeRec.HotResize)
d.Set("network_interface_naming", computeRec.NetworkInterfaceNaming)
d.Set("zone_id", computeRec.ZoneID)
d.Set("os_version", computeRec.OSVersion)
return nil
}
@@ -169,6 +172,7 @@ func flattenInterfaces(ifaces compute.ListInterfaces) []map[string]interface{} {
"conn_type": iface.ConnType,
"def_gw": iface.DefGW,
"enabled": iface.Enabled,
"enable_secgroups": iface.EnableSecGroups,
"flip_group_id": iface.FLIPGroupID,
"guid": iface.GUID,
"ip_address": iface.IPAddress,
@@ -183,6 +187,7 @@ func flattenInterfaces(ifaces compute.ListInterfaces) []map[string]interface{} {
"pci_slot": iface.PCISlot,
"qos": flattenQOS(iface.QOS),
"sdn_interface_id": iface.SDNInterfaceID,
"security_groups": iface.SecGroups,
"target": iface.Target,
"type": iface.Type,
"trunk_tags": iface.TrunkTags,
@@ -241,20 +246,22 @@ func flattenComputeDisks(disksList compute.ListDisks, disksBlocks, extraDisks []
nodeIds := disksBlocks[indexDataDisks].(map[string]interface{})["node_ids"].(*schema.Set)
temp := map[string]interface{}{
"disk_name": disk.Name,
"node_ids": nodeIds,
"size": disk.SizeMax,
"sep_id": disk.SEPID,
"disk_type": disk.Type,
"pool": disk.Pool,
"desc": disk.Description,
"image_id": disk.ImageID,
"disk_id": disk.ID,
"shareable": disk.Shareable,
"size_used": disk.SizeUsed,
"size_max": disk.SizeMax,
"permanently": pernamentlyValue,
"present_to": disk.PresentTo,
"disk_name": disk.Name,
"node_ids": nodeIds,
"size": disk.SizeMax,
"sep_id": disk.SEPID,
"disk_type": disk.Type,
"pool": disk.Pool,
"desc": disk.Description,
"image_id": disk.ImageID,
"disk_id": disk.ID,
"shareable": disk.Shareable,
"size_used": disk.SizeUsed,
"size_max": disk.SizeMax,
"permanently": pernamentlyValue,
"present_to": disk.PresentTo,
"storage_policy_id": disk.StoragePolicyID,
"to_clean": disk.ToClean,
}
res = append(res, temp)
indexDataDisks++
@@ -296,77 +303,79 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
devices, _ := json.Marshal(computeItem.Devices)
userData, _ := json.Marshal(computeItem.Userdata)
temp := map[string]interface{}{
"acl": flattenListACLInterface(computeItem.ACL),
"account_id": computeItem.AccountID,
"account_name": computeItem.AccountName,
"affinity_label": computeItem.AffinityLabel,
"affinity_rules": flattenListRules(computeItem.AffinityRules),
"affinity_weight": computeItem.AffinityWeight,
"anti_affinity_rules": flattenListRules(computeItem.AntiAffinityRules),
"arch": computeItem.Arch,
"auto_start_w_node": computeItem.AutoStart,
"chipset": computeItem.Chipset,
"cd_image_id": computeItem.CdImageId,
"boot_order": computeItem.BootOrder,
"bootdisk_size": computeItem.BootDiskSize,
"clone_reference": computeItem.CloneReference,
"clones": computeItem.Clones,
"computeci_id": computeItem.ComputeCIID,
"cpus": computeItem.CPUs,
"created_by": computeItem.CreatedBy,
"created_time": computeItem.CreatedTime,
"custom_fields": string(customFields),
"deleted_by": computeItem.DeletedBy,
"deleted_time": computeItem.DeletedTime,
"desc": computeItem.Description,
"devices": string(devices),
"disks": flattenDisks(computeItem.Disks),
"driver": computeItem.Driver,
"gid": computeItem.GID,
"guid": computeItem.GUID,
"hp_backed": computeItem.HPBacked,
"compute_id": computeItem.ID,
"cpu_pin": computeItem.CPUPin,
"image_id": computeItem.ImageID,
"interfaces": flattenInterfaces(computeItem.Interfaces),
"live_migration_job_id": computeItem.LiveMigrationJobID,
"lock_status": computeItem.LockStatus,
"manager_id": computeItem.ManagerID,
"manager_type": computeItem.ManagerType,
"migrationjob": computeItem.MigrationJob,
"milestones": computeItem.Milestones,
"nid": computeItem.NID,
"name": computeItem.Name,
"need_reboot": computeItem.NeedReboot,
"numa_affinity": computeItem.NumaAffinity,
"numa_node_id": computeItem.NumaNodeId,
"os_users": flattenOSUsers(computeItem.OSUsers),
"pinned": computeItem.PinnedToStack,
"preferred_cpu": computeItem.PreferredCPU,
"qemu_guest": flattenQemuQuest(computeItem.QemuQuest),
"ram": computeItem.RAM,
"reference_id": computeItem.ReferenceID,
"registered": computeItem.Registered,
"res_name": computeItem.ResName,
"reserved_node_cpus": computeItem.ReservedNodeCpus,
"rg_id": computeItem.RGID,
"rg_name": computeItem.RGName,
"snap_sets": flattenSnapSets(computeItem.SnapSets),
"stack_id": computeItem.StackID,
"stack_name": computeItem.StackName,
"stateless_sep_id": computeItem.StatelessSEPID,
"stateless_sep_type": computeItem.StatelessSEPType,
"status": computeItem.Status,
"tags": flattenTags(computeItem.Tags),
"tech_status": computeItem.TechStatus,
"total_disk_size": computeItem.TotalDiskSize,
"updated_by": computeItem.UpdatedBy,
"updated_time": computeItem.UpdatedTime,
"user_data": string(userData),
"user_managed": computeItem.UserManaged,
"vgpus": computeItem.VGPUs,
"vins_connected": computeItem.VINSConnected,
"virtual_image_id": computeItem.VirtualImageID,
"acl": flattenListACLInterface(computeItem.ACL),
"account_id": computeItem.AccountID,
"account_name": computeItem.AccountName,
"affinity_label": computeItem.AffinityLabel,
"affinity_rules": flattenListRules(computeItem.AffinityRules),
"affinity_weight": computeItem.AffinityWeight,
"anti_affinity_rules": flattenListRules(computeItem.AntiAffinityRules),
"arch": computeItem.Arch,
"auto_start_w_node": computeItem.AutoStart,
"chipset": computeItem.Chipset,
"cd_image_id": computeItem.CdImageId,
"boot_order": computeItem.BootOrder,
"boot_image_id": computeItem.BootImageID,
"bootdisk_size": computeItem.BootDiskSize,
"clone_reference": computeItem.CloneReference,
"clones": computeItem.Clones,
"computeci_id": computeItem.ComputeCIID,
"cpus": computeItem.CPUs,
"created_by": computeItem.CreatedBy,
"created_time": computeItem.CreatedTime,
"custom_fields": string(customFields),
"deleted_by": computeItem.DeletedBy,
"deleted_time": computeItem.DeletedTime,
"desc": computeItem.Description,
"devices": string(devices),
"disks": flattenDisks(computeItem.Disks),
"driver": computeItem.Driver,
"gid": computeItem.GID,
"guid": computeItem.GUID,
"hp_backed": computeItem.HPBacked,
"compute_id": computeItem.ID,
"cpu_pin": computeItem.CPUPin,
"interfaces": flattenInterfaces(computeItem.Interfaces),
"live_migration_job_id": computeItem.LiveMigrationJobID,
"lock_status": computeItem.LockStatus,
"manager_id": computeItem.ManagerID,
"manager_type": computeItem.ManagerType,
"migrationjob": computeItem.MigrationJob,
"milestones": computeItem.Milestones,
"nid": computeItem.NID,
"name": computeItem.Name,
"need_reboot": computeItem.NeedReboot,
"numa_affinity": computeItem.NumaAffinity,
"numa_node_id": computeItem.NumaNodeId,
"os_users": flattenOSUsers(computeItem.OSUsers),
"os_version": computeItem.OSVersion,
"pinned": computeItem.PinnedToStack,
"preferred_cpu": computeItem.PreferredCPU,
"qemu_guest": flattenQemuQuest(computeItem.QemuQuest),
"ram": computeItem.RAM,
"reference_id": computeItem.ReferenceID,
"registered": computeItem.Registered,
"res_name": computeItem.ResName,
"reserved_node_cpus": computeItem.ReservedNodeCpus,
"rg_id": computeItem.RGID,
"rg_name": computeItem.RGName,
"snap_sets": flattenSnapSets(computeItem.SnapSets),
"stack_id": computeItem.StackID,
"stack_name": computeItem.StackName,
"stateless_sep_id": computeItem.StatelessSEPID,
"stateless_sep_type": computeItem.StatelessSEPType,
"status": computeItem.Status,
"tags": flattenTags(computeItem.Tags),
"tech_status": computeItem.TechStatus,
"total_disk_size": computeItem.TotalDiskSize,
"updated_by": computeItem.UpdatedBy,
"updated_time": computeItem.UpdatedTime,
"user_data": string(userData),
"user_managed": computeItem.UserManaged,
"vgpus": computeItem.VGPUs,
"vins_connected": computeItem.VINSConnected,
//TODO
// "virtual_image_id": computeItem.VirtualImageID,
"loader_type": computeItem.LoaderType,
"boot_type": computeItem.BootType,
"hot_resize": computeItem.HotResize,
@@ -386,74 +395,78 @@ func flattenDeletedComputeList(computes *compute.ListDeletedComputes) []map[stri
devices, _ := json.Marshal(computeItem.Devices)
userData, _ := json.Marshal(computeItem.Userdata)
temp := map[string]interface{}{
"acl": flattenListACLInterface(computeItem.ACL),
"account_id": computeItem.AccountID,
"account_name": computeItem.AccountName,
"affinity_label": computeItem.AffinityLabel,
"affinity_rules": flattenListRules(computeItem.AffinityRules),
"affinity_weight": computeItem.AffinityWeight,
"anti_affinity_rules": flattenListRules(computeItem.AntiAffinityRules),
"arch": computeItem.Arch,
"auto_start_w_node": computeItem.AutoStart,
"chipset": computeItem.Chipset,
"cd_image_id": computeItem.CdImageId,
"boot_order": computeItem.BootOrder,
"bootdisk_size": computeItem.BootDiskSize,
"clone_reference": computeItem.CloneReference,
"clones": computeItem.Clones,
"computeci_id": computeItem.ComputeCIID,
"cpus": computeItem.CPUs,
"created_by": computeItem.CreatedBy,
"created_time": computeItem.CreatedTime,
"custom_fields": string(customFields),
"deleted_by": computeItem.DeletedBy,
"deleted_time": computeItem.DeletedTime,
"desc": computeItem.Description,
"devices": string(devices),
"disks": flattenDisks(computeItem.Disks),
"driver": computeItem.Driver,
"gid": computeItem.GID,
"guid": computeItem.GUID,
"hp_backed": computeItem.HPBacked,
"compute_id": computeItem.ID,
"cpu_pin": computeItem.CPUPin,
"image_id": computeItem.ImageID,
"interfaces": flattenInterfaces(computeItem.Interfaces),
"lock_status": computeItem.LockStatus,
"manager_id": computeItem.ManagerID,
"manager_type": computeItem.ManagerType,
"migrationjob": computeItem.MigrationJob,
"milestones": computeItem.Milestones,
"name": computeItem.Name,
"need_reboot": computeItem.NeedReboot,
"numa_affinity": computeItem.NumaAffinity,
"numa_node_id": computeItem.NumaNodeId,
"os_users": flattenOSUsers(computeItem.OSUsers),
"pinned": computeItem.PinnedToStack,
"preferred_cpu": computeItem.PreferredCPU,
"ram": computeItem.RAM,
"reference_id": computeItem.ReferenceID,
"registered": computeItem.Registered,
"res_name": computeItem.ResName,
"reserved_node_cpus": computeItem.ReservedNodeCpus,
"rg_id": computeItem.RGID,
"rg_name": computeItem.RGName,
"snap_sets": flattenSnapSets(computeItem.SnapSets),
"stack_id": computeItem.StackID,
"stack_name": computeItem.StackName,
"stateless_sep_id": computeItem.StatelessSEPID,
"stateless_sep_type": computeItem.StatelessSEPType,
"status": computeItem.Status,
"tags": flattenTags(computeItem.Tags),
"tech_status": computeItem.TechStatus,
"total_disk_size": computeItem.TotalDiskSize,
"updated_by": computeItem.UpdatedBy,
"updated_time": computeItem.UpdatedTime,
"user_data": string(userData),
"user_managed": computeItem.UserManaged,
"vgpus": computeItem.VGPUs,
"vins_connected": computeItem.VINSConnected,
"virtual_image_id": computeItem.VirtualImageID,
"acl": flattenListACLInterface(computeItem.ACL),
"account_id": computeItem.AccountID,
"account_name": computeItem.AccountName,
"affinity_label": computeItem.AffinityLabel,
"affinity_rules": flattenListRules(computeItem.AffinityRules),
"affinity_weight": computeItem.AffinityWeight,
"anti_affinity_rules": flattenListRules(computeItem.AntiAffinityRules),
"arch": computeItem.Arch,
"auto_start_w_node": computeItem.AutoStart,
"chipset": computeItem.Chipset,
"cd_image_id": computeItem.CdImageId,
"boot_order": computeItem.BootOrder,
"bootdisk_size": computeItem.BootDiskSize,
"boot_image_id": computeItem.BootImageID,
"clone_reference": computeItem.CloneReference,
"clones": computeItem.Clones,
"computeci_id": computeItem.ComputeCIID,
"cpus": computeItem.CPUs,
"created_by": computeItem.CreatedBy,
"created_time": computeItem.CreatedTime,
"custom_fields": string(customFields),
"deleted_by": computeItem.DeletedBy,
"deleted_time": computeItem.DeletedTime,
"desc": computeItem.Description,
"devices": string(devices),
"disks": flattenDisks(computeItem.Disks),
"driver": computeItem.Driver,
"gid": computeItem.GID,
"guid": computeItem.GUID,
"hp_backed": computeItem.HPBacked,
"compute_id": computeItem.ID,
"cpu_pin": computeItem.CPUPin,
//TODO
// "image_id": computeItem.ImageID,
"interfaces": flattenInterfaces(computeItem.Interfaces),
"lock_status": computeItem.LockStatus,
"manager_id": computeItem.ManagerID,
"manager_type": computeItem.ManagerType,
"migrationjob": computeItem.MigrationJob,
"milestones": computeItem.Milestones,
"name": computeItem.Name,
"need_reboot": computeItem.NeedReboot,
"numa_affinity": computeItem.NumaAffinity,
"numa_node_id": computeItem.NumaNodeId,
"os_users": flattenOSUsers(computeItem.OSUsers),
"os_version": computeItem.OSVersion,
"pinned": computeItem.PinnedToStack,
"preferred_cpu": computeItem.PreferredCPU,
"ram": computeItem.RAM,
"reference_id": computeItem.ReferenceID,
"registered": computeItem.Registered,
"res_name": computeItem.ResName,
"reserved_node_cpus": computeItem.ReservedNodeCpus,
"rg_id": computeItem.RGID,
"rg_name": computeItem.RGName,
"snap_sets": flattenSnapSets(computeItem.SnapSets),
"stack_id": computeItem.StackID,
"stack_name": computeItem.StackName,
"stateless_sep_id": computeItem.StatelessSEPID,
"stateless_sep_type": computeItem.StatelessSEPType,
"status": computeItem.Status,
"tags": flattenTags(computeItem.Tags),
"tech_status": computeItem.TechStatus,
"total_disk_size": computeItem.TotalDiskSize,
"updated_by": computeItem.UpdatedBy,
"updated_time": computeItem.UpdatedTime,
"user_data": string(userData),
"user_managed": computeItem.UserManaged,
"vgpus": computeItem.VGPUs,
"vins_connected": computeItem.VINSConnected,
//TODO
// "virtual_image_id": computeItem.VirtualImageID,
"loader_type": computeItem.LoaderType,
"boot_type": computeItem.BootType,
"hot_resize": computeItem.HotResize,
@@ -544,8 +557,8 @@ func flattenDisks(disks []compute.InfoDisk) []map[string]interface{} {
}
func flattenComputeAudits(computeAudits compute.ListDetailedAudits) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(computeAudits))
for _, computeAudit := range computeAudits {
res := make([]map[string]interface{}, 0, len(computeAudits.Data))
for _, computeAudit := range computeAudits.Data {
temp := map[string]interface{}{
"call": computeAudit.Call,
"responsetime": computeAudit.ResponseTime,
@@ -723,6 +736,7 @@ func flattenDataCompute(d *schema.ResourceData, compFacts *compute.RecordCompute
d.Set("arch", compFacts.Arch)
d.Set("auto_start_w_node", compFacts.AutoStart)
d.Set("boot_order", compFacts.BootOrder)
d.Set("boot_image_id", compFacts.ImageID)
d.Set("chipset", compFacts.Chipset)
d.Set("cd_image_id", compFacts.CdImageId)
d.Set("clone_reference", compFacts.CloneReference)
@@ -785,14 +799,16 @@ func flattenDataCompute(d *schema.ResourceData, compFacts *compute.RecordCompute
d.Set("user_managed", compFacts.UserManaged)
d.Set("vnc_password", compFacts.VNCPassword)
d.Set("vgpus", flattenVGPUs(compFacts.VGPUs))
d.Set("virtual_image_id", compFacts.VirtualImageID)
d.Set("virtual_image_name", compFacts.VirtualImageName)
//TODO
// d.Set("virtual_image_id", compFacts.VirtualImageID)
// d.Set("virtual_image_name", compFacts.VirtualImageName)
d.Set("pci_devices", flattenPCI(*pciList))
d.Set("loader_type", compFacts.LoaderType)
d.Set("boot_type", compFacts.BootType)
d.Set("hot_resize", compFacts.HotResize)
d.Set("network_interface_naming", compFacts.NetworkInterfaceNaming)
d.Set("zone_id", compFacts.ZoneID)
d.Set("os_version", compFacts.OSVersion)
//extra fields setting
bootDisk := findBootDisk(compFacts.Disks)
if bootDisk != nil {
@@ -823,6 +839,7 @@ func parseComputeInterfacesToNetworks(networks []interface{}, ifaces compute.Lis
elem["mtu"] = value.MTU
elem["sdn_interface_id"] = value.SDNInterfaceID
elem["weight"] = flattenNetworkWeight(networks, value.NetID, value.NetType)
elem["enabled"] = value.Enabled
result = append(result, elem)
}
@@ -886,8 +903,10 @@ func flattenDisk(diskList compute.ListDisks) []map[string]interface{} {
"size_used": disk.SizeUsed,
"snapshots": flattendDiskSnapshotList(disk.Snapshots),
"status": disk.Status,
"storage_policy_id": disk.StoragePolicyID,
"tech_status": disk.TechStatus,
"type": disk.Type,
"to_clean": disk.ToClean,
}
res = append(res, temp)
}

View File

@@ -0,0 +1,10 @@
package kvmvm
type updatedNetwork struct {
DetachMap []map[string]interface{}
ChangeIPMap []map[string]interface{}
ChangeMacMap []map[string]interface{}
ChangeMTUMap []map[string]interface{}
AttachMap []map[string]interface{}
EnableMap []map[string]interface{}
}

View File

@@ -34,6 +34,8 @@ package kvmvm
import (
"context"
"errors"
"fmt"
"sort"
"strconv"
"strings"
@@ -116,6 +118,10 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
NetID: uint64(netInterfaceVal["net_id"].(int)),
}
if enabledNetwork(d.GetRawConfig().GetAttr("network"), reqInterface.NetID, reqInterface.NetType) {
reqInterface.Enabled = netInterfaceVal["enabled"].(bool)
}
if reqInterface.NetType == "DPDK" || reqInterface.NetType == "EXTNET" {
reqInterface.MTU = uint64(netInterfaceVal["mtu"].(int))
}
@@ -148,8 +154,9 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
for _, elem := range disks.([]interface{}) {
diskVal := elem.(map[string]interface{})
reqDataDisk := kvmx86.DataDisk{
DiskName: diskVal["disk_name"].(string),
Size: uint64(diskVal["size"].(int)),
DiskName: diskVal["disk_name"].(string),
Size: uint64(diskVal["size"].(int)),
StoragePolicyID: uint64(diskVal["storage_policy_id"].(int)),
}
if sepId, ok := diskVal["sep_id"]; ok {
reqDataDisk.SepID = uint64(sepId.(int))
@@ -178,12 +185,12 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
}
var computeId uint64
driver := d.Get("driver").(string)
createReqX86.RGID = uint64(d.Get("rg_id").(int))
createReqX86.Name = d.Get("name").(string)
createReqX86.CPU = uint64(d.Get("cpu").(int))
createReqX86.RAM = uint64(d.Get("ram").(int))
createReqX86.StoragePolicyID = uint64(d.Get("storage_policy_id").(int))
if image, ok := d.GetOk("image_id"); ok {
createReqX86.ImageID = uint64(image.(int))
@@ -192,8 +199,6 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
createReqX86.WithoutBootDisk = withoutBootDisk.(bool)
}
createReqX86.Driver = driver
if custom_fields, ok := d.GetOk("custom_fields"); ok {
val := custom_fields.(string)
val = strings.ReplaceAll(val, "\\", "")
@@ -221,6 +226,10 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if osVersion, ok := d.GetOk("os_version"); ok {
createReqX86.OSVersion = osVersion.(string)
}
log.Debugf("resourceComputeCreate: creating Compute of type KVM VM x86")
apiResp, err := c.CloudBroker().KVMX86().Create(ctx, createReqX86)
if err != nil {
@@ -260,7 +269,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
loaderType, loaderTypeOk := d.GetOk("loader_type")
bootType, bootTypeOk := d.GetOk("boot_type")
hotResize, hotResizeOk := d.GetOk("hot_resize")
hotResize, hotResizeOk := d.GetOkExists("hot_resize")
networkInterfaceNaming, networkInterfaceNamingOk := d.GetOk("network_interface_naming")
if loaderTypeOk {
@@ -370,6 +379,10 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
break
}
}
if mac == "" {
warnings.Add(errors.New(fmt.Sprintf("add libvirt virtio: Network with type %s and id %d is not connected to the compute %d", netType, netId, computeId)))
continue
}
log.Debugf("resourceComputeCreate: Configure libvirt virtio interface parameters on Network with type %s and id %d", netType, netId)
req := compute.SetNetConfigRequest{
ComputeID: computeId,
@@ -390,6 +403,45 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if secGroups, ok := d.GetOk("security_groups"); ok {
if secGroups.(*schema.Set).Len() > 0 {
sgl := secGroups.(*schema.Set).List()
for _, elem := range sgl {
secGroupsMap := elem.(map[string]interface{})
netType := secGroupsMap["net_type"].(string)
netId := uint64(secGroupsMap["net_id"].(int))
var mac string
for _, iface := range simpleCompRec.Interfaces {
if iface.NetID == netId && iface.NetType == netType {
mac = iface.MAC
break
}
}
if mac == "" {
warnings.Add(errors.New(fmt.Sprintf("add security groups: Network with type %s and id %d is not connected to the compute %d", netType, netId, computeId)))
continue
}
secGroupsIDs := make([]uint64, 0)
for _, id := range secGroupsMap["security_groups"].(*schema.Set).List() {
secGroupsIDs = append(secGroupsIDs, uint64(id.(int)))
}
log.Debugf("resourceComputeCreate: Configure security groups interface parameters on Network with type %s and id %d", netType, netId)
req := compute.ChangeSecGroupsRequest{
ComputeID: computeId,
Interface: mac,
SecGroups: secGroupsIDs,
EnableSecGroups: secGroupsMap["enable_secgroups"].(bool),
}
_, err := c.CloudBroker().Compute().ChangeSecGroups(ctx, req)
if err != nil {
warnings.Add(err)
}
}
}
}
if start, ok := d.GetOk("started"); ok && start.(bool) {
req := compute.StartRequest{ComputeID: computeId}
log.Debugf("resourceComputeCreate: starting Compute ID %d after completing its resource configuration", computeId)
@@ -767,7 +819,8 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
"loader_type",
"boot_type",
"hot_resize",
"network_interface_naming") {
"network_interface_naming",
"os_version") {
if err := utilityComputeUpdate(ctx, d, m); err != nil {
return diag.FromErr(err)
}
@@ -780,6 +833,13 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if d.HasChange("security_groups") {
err = utilityComputeSecGroupsConfigure(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("disks") {
if err := utilityComputeUpdateDisks(ctx, d, m); err != nil {
return diag.FromErr(err)
@@ -938,7 +998,7 @@ func ResourceCompute() *schema.Resource {
CustomizeDiff: func(ctx context.Context, diff *schema.ResourceDiff, i interface{}) error {
if diff.HasChanges() || diff.HasChanges("chipset", "pin_to_stack", "auto_start_w_node", "libvirt_settings", "network", "affinity_rules", "anti_affinity_rules",
"extra_disks", "tags", "port_forwarding", "user_access", "snapshot", "pci_devices", "preferred_cpu") {
"extra_disks", "tags", "port_forwarding", "user_access", "snapshot", "pci_devices", "preferred_cpu", "security_groups") {
diff.SetNewComputed("updated_time")
diff.SetNewComputed("updated_by")
}

View File

@@ -145,6 +145,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
},
},
"boot_image_id": {
Type: schema.TypeInt,
Computed: true,
},
"chipset": {
Type: schema.TypeString,
Computed: true,
@@ -510,6 +514,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"storage_policy_id": {
Type: schema.TypeInt,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
@@ -518,6 +526,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
@@ -577,6 +589,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"enable_secgroups": {
Type: schema.TypeBool,
Computed: true,
},
"flip_group_id": {
Type: schema.TypeInt,
Computed: true,
@@ -702,6 +718,13 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"security_groups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"vnfs": {
Type: schema.TypeList,
Computed: true,
@@ -796,6 +819,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
},
},
},
"os_version": {
Type: schema.TypeString,
Computed: true,
},
"pinned": {
Type: schema.TypeInt,
Computed: true,
@@ -1142,11 +1169,6 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Find by stack ID",
},
"image_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Find by image ID",
},
"cd_image_id": {
Type: schema.TypeInt,
Optional: true,
@@ -1179,6 +1201,11 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Optional: true,
},
"zone_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Zone ID",
},
"ignore_k8s": {
Type: schema.TypeBool,
Optional: true,
@@ -1321,6 +1348,10 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"boot_image_id": {
Type: schema.TypeInt,
Computed: true,
},
"chipset": {
Type: schema.TypeString,
Computed: true,
@@ -1449,6 +1480,10 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"enable_secgroups": {
Type: schema.TypeBool,
Computed: true,
},
"flip_group_id": {
Type: schema.TypeInt,
Computed: true,
@@ -1561,6 +1596,13 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"security_groups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"target": {
Type: schema.TypeString,
Computed: true,
@@ -1651,6 +1693,10 @@ func dataSourceComputeListSchemaMake() map[string]*schema.Schema {
},
},
},
"os_version": {
Type: schema.TypeString,
Computed: true,
},
"pinned": {
Type: schema.TypeInt,
Computed: true,
@@ -2061,6 +2107,10 @@ func dataSourceComputeListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"boot_image_id": {
Type: schema.TypeInt,
Computed: true,
},
"chipset": {
Type: schema.TypeString,
Computed: true,
@@ -2185,6 +2235,10 @@ func dataSourceComputeListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"enable_secgroups": {
Type: schema.TypeBool,
Computed: true,
},
"flip_group_id": {
Type: schema.TypeInt,
Computed: true,
@@ -2297,6 +2351,13 @@ func dataSourceComputeListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"security_groups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"target": {
Type: schema.TypeString,
Computed: true,
@@ -2379,6 +2440,10 @@ func dataSourceComputeListDeletedSchemaMake() map[string]*schema.Schema {
},
},
},
"os_version": {
Type: schema.TypeString,
Computed: true,
},
"pinned": {
Type: schema.TypeInt,
Computed: true,
@@ -2561,6 +2626,42 @@ func dataSourceComputeAuditsSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Required: true,
},
"timestamp_at": {
Type: schema.TypeInt,
Optional: true,
},
"timestamp_to": {
Type: schema.TypeInt,
Optional: true,
},
"user": {
Type: schema.TypeString,
Optional: true,
},
"call": {
Type: schema.TypeString,
Optional: true,
},
"sort_by": {
Type: schema.TypeString,
Optional: true,
},
"page": {
Type: schema.TypeInt,
Optional: true,
},
"size": {
Type: schema.TypeInt,
Optional: true,
},
"min_status_code": {
Type: schema.TypeInt,
Optional: true,
},
"max_status_code": {
Type: schema.TypeInt,
Optional: true,
},
"items": {
Type: schema.TypeList,
@@ -2590,6 +2691,10 @@ func dataSourceComputeAuditsSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
}
@@ -3226,13 +3331,6 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
ValidateFunc: validation.IntAtLeast(1),
Description: "ID of the resource group where this compute should be deployed.",
},
"driver": {
Type: schema.TypeString,
Required: true,
StateFunc: statefuncs.StateFuncToUpper,
ValidateFunc: validation.StringInSlice([]string{"KVM_X86"}, false), // observe case while validating
Description: "Hardware architecture of this compute instance.",
},
"cpu": {
Type: schema.TypeInt,
Required: true,
@@ -3248,6 +3346,11 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
),
Description: "Amount of RAM in MB to allocate to this compute instance.",
},
"storage_policy_id": {
Type: schema.TypeInt,
Required: true,
Description: "Storage policy id of compute. The rules of the specified storage policy will be used.",
},
"image_id": {
Type: schema.TypeInt,
Optional: true,
@@ -3386,6 +3489,12 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
DiffSuppressFunc: networkSubresIPAddreDiffSupperss,
Description: "unique_identifier of LogicalPort on SDN side",
},
"enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "network enable flag",
},
},
},
Description: "Optional network connection(s) for this compute. You may specify several network blocks, one for each connection.",
@@ -3443,6 +3552,40 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Description: "Configure libvirt virtio interface parameters. You can only delete values locally. Data on the platform cannot be deleted.",
},
"security_groups": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"net_type": {
Type: schema.TypeString,
Required: true,
StateFunc: statefuncs.StateFuncToUpper,
ValidateFunc: validation.StringInSlice([]string{"VINS", "EXTNET", "VFNIC", "DPDK", "SDN", "TRUNK"}, false), // observe case while validating
Description: "Type of the network",
},
"net_id": {
Type: schema.TypeInt,
Required: true,
Description: "ID of the network",
},
"security_groups": {
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"enable_secgroups": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
},
Description: "list of security group IDs to apply to this interface",
},
"affinity_label": {
Type: schema.TypeString,
Optional: true,
@@ -3541,6 +3684,11 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "Disk size in GiB",
},
"storage_policy_id": {
Type: schema.TypeInt,
Required: true,
Description: "Storage policy id of disk. The rules of the specified storage policy will be used.",
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,
@@ -3608,6 +3756,10 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"to_clean": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
@@ -3841,6 +3993,12 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
ValidateFunc: validation.StringInSlice([]string{"eth", "ens"}, false),
Description: "Name of netfowrk interface.",
},
"os_version": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "the OS version installed on the VM",
},
// Computed properties
"account_id": {
Type: schema.TypeInt,
@@ -3904,6 +4062,10 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "This compute instance boot disk ID.",
},
"boot_image_id": {
Type: schema.TypeInt,
Computed: true,
},
"cd_image_id": {
Type: schema.TypeInt,
Computed: true,
@@ -3943,6 +4105,10 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"driver": {
Type: schema.TypeString,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
@@ -3980,6 +4146,10 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"enable_secgroups": {
Type: schema.TypeBool,
Computed: true,
},
"flip_group_id": {
Type: schema.TypeInt,
Computed: true,
@@ -4092,6 +4262,13 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"security_groups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"target": {
Type: schema.TypeString,
Computed: true,

View File

@@ -39,6 +39,7 @@ import (
"strconv"
"strings"
"github.com/hashicorp/go-cty/cty"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/disks"
@@ -111,7 +112,13 @@ func utilityComputeResize(ctx context.Context, d *schema.ResourceData, m interfa
c := m.(*controller.ControllerCfg)
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
if d.Get("started").(bool) {
var isStopRequired bool
old, new := d.GetChange("cpu")
if d.Get("started").(bool) && (old.(int) > new.(int)) && d.Get("force_resize").(bool) {
isStopRequired = true
}
if isStopRequired {
stopReq := compute.StopRequest{
ComputeID: computeId,
Force: false,
@@ -176,7 +183,7 @@ func utilityComputeResize(ctx context.Context, d *schema.ResourceData, m interfa
}
}
if d.Get("started").(bool) {
if isStopRequired {
if _, err := c.CloudBroker().Compute().Start(ctx, compute.StartRequest{ComputeID: computeId}); err != nil {
return err
}
@@ -227,6 +234,7 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
addedDisks := make([]interface{}, 0)
resizedDisks := make([]interface{}, 0)
renamedDisks := make([]interface{}, 0)
changeStoragePolicyDisks := make([]interface{}, 0)
presentNewDisks := make([]interface{}, 0)
presentOldDisks := make([]interface{}, 0)
@@ -241,7 +249,7 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
presentOldDisks = append(presentOldDisks, el)
}
// !isRenameDisk(newConv, el) && !isResizeDisk(newConv, el) are required in case two or more disks are being created and their disk_id is the same (=0)
if !isContainsDisk(newConv, el) && !isRenameDisk(newConv, el) && !isResizeDisk(newConv, el) {
if !isContainsDisk(newConv, el) && !isRenameDisk(newConv, el) && !isResizeDisk(newConv, el) && !isChangeStoragePolicy(newConv, el) {
flag := false
extraDisks := d.Get("extra_disks").(*schema.Set).List()
delDisk := el.(map[string]interface{})
@@ -272,19 +280,12 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
if isRenameDisk(oldConv, el) {
renamedDisks = append(renamedDisks, el)
}
if isChangeStoragePolicy(oldConv, el) {
changeStoragePolicyDisks = append(changeStoragePolicyDisks, el)
}
}
if len(deletedDisks) > 0 {
stopReq := compute.StopRequest{
ComputeID: computeId,
Force: false,
}
_, err := c.CloudBroker().Compute().Stop(ctx, stopReq)
if err != nil {
return err
}
for _, disk := range deletedDisks {
diskConv := disk.(map[string]interface{})
if diskConv["disk_type"].(string) == "B" {
@@ -302,14 +303,6 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
return err
}
}
req := compute.StartRequest{
ComputeID: computeId,
AltBootID: 0,
}
_, err = c.CloudBroker().Compute().Start(ctx, req)
if err != nil {
return err
}
}
if len(addedDisks) > 0 {
@@ -319,9 +312,10 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
continue
}
req := compute.DiskAddRequest{
ComputeID: computeId,
DiskName: diskConv["disk_name"].(string),
Size: uint64(diskConv["size"].(int)),
ComputeID: computeId,
DiskName: diskConv["disk_name"].(string),
Size: uint64(diskConv["size"].(int)),
StoragePolicyID: uint64(diskConv["storage_policy_id"].(int)),
}
if diskConv["sep_id"].(int) != 0 {
req.SepID = uint64(diskConv["sep_id"].(int))
@@ -399,6 +393,21 @@ func utilityComputeUpdateDisks(ctx context.Context, d *schema.ResourceData, m in
}
}
}
if len(changeStoragePolicyDisks) > 0 {
for _, disk := range changeStoragePolicyDisks {
diskConv := disk.(map[string]interface{})
req := disks.ChangeDiskStoragePolicyRequest{
DiskID: uint64(diskConv["disk_id"].(int)),
StoragePolicyID: uint64(diskConv["storage_policy_id"].(int)),
}
_, err := c.CloudBroker().Disks().ChangeDiskStoragePolicy(ctx, req)
if err != nil {
return err
}
}
}
for i := range presentNewDisks {
newDisk := presentNewDisks[i].(map[string]interface{})
@@ -589,12 +598,12 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
oldList := oldSet.(*schema.Set).List()
newList := newSet.(*schema.Set).List()
detachMap, changeIpMap, changeMacMap, changeMTUMap, attachMap := differenceNetwork(oldList, newList)
updateNetwork := differenceNetwork(oldList, newList)
apiErrCount := 0
var lastSavedError error
log.Debugf("utilityComputeNetworksConfigure: detach set has %d items for Compute ID %s", len(detachMap), d.Id())
for _, netData := range detachMap {
log.Debugf("utilityComputeNetworksConfigure: detach set has %d items for Compute ID %s", len(updateNetwork.DetachMap), d.Id())
for _, netData := range updateNetwork.DetachMap {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := compute.NetDetachRequest{
ComputeID: computeId,
@@ -611,8 +620,8 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
}
}
log.Debugf("utilityComputeNetworksConfigure: changeIp set has %d items for Compute ID %s", len(changeIpMap), d.Id())
for _, netData := range changeIpMap {
log.Debugf("utilityComputeNetworksConfigure: changeIp set has %d items for Compute ID %s", len(updateNetwork.ChangeIPMap), d.Id())
for _, netData := range updateNetwork.ChangeIPMap {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := compute.ChangeIPRequest{
ComputeID: computeId,
@@ -634,9 +643,9 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
oldLibvirtSet, newLibvirtSet := d.GetChange("libvirt_settings")
addedLibvirtSettings := (newLibvirtSet.(*schema.Set).Difference(oldLibvirtSet.(*schema.Set))).List()
libvirtSettingsMap := addAttachedNetwork(addedLibvirtSettings, newLibvirtSet.(*schema.Set).List(), attachMap)
libvirtSettingsMap := addAttachedNetwork(addedLibvirtSettings, newLibvirtSet.(*schema.Set).List(), updateNetwork.AttachMap)
if oldSet.(*schema.Set).Len() == len(detachMap) || oldSet.(*schema.Set).Len() == 0 || len(libvirtSettingsMap) > 0 || hasDPDKnetwork(attachMap) || len(changeMacMap) > 0 {
if oldSet.(*schema.Set).Len() == len(updateNetwork.DetachMap) || oldSet.(*schema.Set).Len() == 0 || len(libvirtSettingsMap) > 0 || hasDPDKnetwork(updateNetwork.AttachMap) || len(updateNetwork.ChangeMacMap) > 0 {
if err := utilityComputeStop(ctx, d, m); err != nil {
apiErrCount++
lastSavedError = err
@@ -646,8 +655,8 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
}
}
log.Debugf("utilityComputeNetworksConfigure: changeMac set has %d items for Compute ID %s", len(changeMacMap), d.Id())
for _, netData := range changeMacMap {
log.Debugf("utilityComputeNetworksConfigure: changeMac set has %d items for Compute ID %s", len(updateNetwork.ChangeMacMap), d.Id())
for _, netData := range updateNetwork.ChangeMacMap {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := compute.ChangeMACRequest{
ComputeID: computeId,
@@ -664,9 +673,9 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
}
}
sort.Slice(attachMap, func(i, j int) bool {
weightI := attachMap[i]["weight"].(int)
weightJ := attachMap[j]["weight"].(int)
sort.Slice(updateNetwork.AttachMap, func(i, j int) bool {
weightI := updateNetwork.AttachMap[i]["weight"].(int)
weightJ := updateNetwork.AttachMap[j]["weight"].(int)
if weightI == 0 {
return false
}
@@ -675,8 +684,8 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
}
return weightI < weightJ
})
log.Debugf("utilityComputeNetworksConfigure: attach set has %d items for Compute ID %s", len(attachMap), d.Id())
for _, netData := range attachMap {
log.Debugf("utilityComputeNetworksConfigure: attach set has %d items for Compute ID %s", len(updateNetwork.AttachMap), d.Id())
for _, netData := range updateNetwork.AttachMap {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := compute.NetAttachRequest{
ComputeID: computeId,
@@ -696,7 +705,7 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
req.MACAddr = netData["mac"].(string)
}
if req.NetType == "DPDK" {
if req.NetType == "DPDK" || req.NetType == "EXTNET" {
req.MTU = uint64(netData["mtu"].(int))
}
@@ -724,7 +733,7 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
}
if computeRec != nil {
log.Debugf("utilityComputeNetworksConfigure: libvirt virtio set has %d items for Compute ID %s", len(attachMap), d.Id())
log.Debugf("utilityComputeNetworksConfigure: libvirt virtio set has %d items for Compute ID %s", len(libvirtSettingsMap), d.Id())
for _, libvirtSetting := range libvirtSettingsMap {
netType := libvirtSetting["net_type"].(string)
netId := uint64(libvirtSetting["net_id"].(int))
@@ -766,8 +775,8 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
}
}
log.Debugf("utilityComputeNetworksConfigure: changeMTU set has %d items for Compute ID %s", len(changeMTUMap), d.Id())
for _, netData := range changeMTUMap {
log.Debugf("utilityComputeNetworksConfigure: changeMTU set has %d items for Compute ID %s", len(updateNetwork.ChangeMTUMap), d.Id())
for _, netData := range updateNetwork.ChangeMTUMap {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := compute.ChangeMTURequest{
ComputeID: computeId,
@@ -784,6 +793,28 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
}
}
log.Debugf("utilityComputeNetworksConfigure: enableMap set has %d items for Compute ID %s", len(updateNetwork.EnableMap), d.Id())
for _, netData := range updateNetwork.EnableMap {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := compute.ChangeLinkStateRequest{
ComputeID: computeId,
Interface: netData["mac"].(string),
State: "off",
}
if netData["enabled"].(bool) {
req.State = "on"
}
_, err := c.CloudBroker().Compute().ChangeLinkState(ctx, req)
if err != nil {
log.Errorf("utilityComputeNetworksConfigure: failed to change link state network ID %d of type %s from Compute ID %s: %s",
netData["net_id"].(int), netData["net_type"].(string), d.Id(), err)
apiErrCount++
lastSavedError = err
}
}
if apiErrCount > 0 {
log.Errorf("utilityComputeNetworksConfigure: there were %d error(s) when managing networks of Compute ID %s. Last error was: %s",
apiErrCount, d.Id(), lastSavedError)
@@ -793,12 +824,13 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
return nil
}
func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap, changeMacMap, changeMTUMap, attachMap []map[string]interface{}) {
attachMap = make([]map[string]interface{}, 0)
changeIpMap = make([]map[string]interface{}, 0)
changeMacMap = make([]map[string]interface{}, 0)
changeMTUMap = make([]map[string]interface{}, 0)
detachMap = make([]map[string]interface{}, 0)
func differenceNetwork(oldList, newList []interface{}) *updatedNetwork {
attachMap := make([]map[string]interface{}, 0)
changeIpMap := make([]map[string]interface{}, 0)
changeMacMap := make([]map[string]interface{}, 0)
changeMTUMap := make([]map[string]interface{}, 0)
detachMap := make([]map[string]interface{}, 0)
enableMap := make([]map[string]interface{}, 0)
for _, oldNetwork := range oldList {
oldMap := oldNetwork.(map[string]interface{})
found := false
@@ -816,6 +848,13 @@ func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap,
if (newMap["net_type"].(string) == "EXTNET" || newMap["net_type"].(string) == "DPDK") && (newMap["mtu"] != oldMap["mtu"] && newMap["mtu"].(int) != 0) {
changeMTUMap = append(changeMTUMap, newMap)
}
if newMap["enabled"].(bool) != oldMap["enabled"].(bool) {
mac, _ := newMap["mac"].(string)
if mac == "" {
newMap["mac"] = oldMap["mac"]
}
enableMap = append(enableMap, newMap)
}
}
if found {
break
@@ -843,7 +882,16 @@ func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap,
attachMap = append(attachMap, newMap)
}
return
res := updatedNetwork{
DetachMap: detachMap,
ChangeIPMap: changeIpMap,
ChangeMacMap: changeMacMap,
ChangeMTUMap: changeMTUMap,
AttachMap: attachMap,
EnableMap: enableMap,
}
return &res
}
func compareNetwork(newMap, oldMap map[string]interface{}) bool {
@@ -893,6 +941,75 @@ func addAttachedNetwork(addedLibvirtSettings []interface{}, newLibvirtSettings [
return
}
func utilityComputeSecGroupsConfigure(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
simpleCompRec, err := utilityComputeCheckPresence(ctx, d, m)
if err != nil {
return err
}
apiErrCount := 0
var lastSavedError error
oldSecGroups, newSecGroups := d.GetChange("security_groups")
updateSecGroups := (newSecGroups.(*schema.Set).Difference(oldSecGroups.(*schema.Set))).List()
log.Debugf("utilityComputeSecGroupsConfigure: update security groups has %d items for Compute ID %s", len(updateSecGroups), d.Id())
if len(updateSecGroups) > 0 {
for _, elem := range updateSecGroups {
secGroupsMap := elem.(map[string]interface{})
netType := secGroupsMap["net_type"].(string)
netId := uint64(secGroupsMap["net_id"].(int))
var mac string
for _, iface := range simpleCompRec.Interfaces {
if iface.NetID == netId && iface.NetType == netType {
mac = iface.MAC
break
}
}
if mac == "" {
log.Errorf("utilityComputeSecGroupsConfigure: Network with type %s and id %d is not connected to the compute %s",
netType, netId, d.Id())
apiErrCount++
lastSavedError = errors.New(fmt.Sprintf("utilityComputeSecGroupsConfigure: Network with type %s and id %d is not connected to the compute %s",
netType, netId, d.Id()))
continue
}
secGroupsIDs := make([]uint64, 0)
for _, id := range secGroupsMap["security_groups"].(*schema.Set).List() {
secGroupsIDs = append(secGroupsIDs, uint64(id.(int)))
}
log.Debugf("utilityComputeSecGroupsConfigure: Configure security groups interface parameters on Network with type %s and id %d", netType, netId)
req := compute.ChangeSecGroupsRequest{
ComputeID: computeId,
Interface: mac,
SecGroups: secGroupsIDs,
}
if secGroupsMap["enable_secgroups"] != nil {
req.EnableSecGroups = secGroupsMap["enable_secgroups"].(bool)
}
_, err := c.CloudBroker().Compute().ChangeSecGroups(ctx, req)
if err != nil {
apiErrCount++
lastSavedError = err
}
}
}
if apiErrCount > 0 {
log.Errorf("utilityComputeSecGroupsConfigure: there were %d error(s) when managing security groups of Compute ID %s. Last error was: %s",
apiErrCount, d.Id(), lastSavedError)
return lastSavedError
}
return nil
}
func utilityComputeUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
@@ -931,6 +1048,10 @@ func utilityComputeUpdate(ctx context.Context, d *schema.ResourceData, m interfa
req.NetworkInterfaceNaming = d.Get("network_interface_naming").(string)
}
if d.HasChange("os_version") {
req.OSVersion = d.Get("os_version").(string)
}
req.CPUPin = d.Get("cpu_pin").(bool)
req.HPBacked = d.Get("hp_backed").(bool)
req.AutoStart = d.Get("auto_start_w_node").(bool)
@@ -954,7 +1075,7 @@ func utilityComputeUpdate(ctx context.Context, d *schema.ResourceData, m interfa
// Note bene: numa_affinity, cpu_pin and hp_backed are not allowed to be changed for compute in STARTED tech status.
// If STARTED, we need to stop it before update
var isStopRequired bool
if d.HasChanges("numa_affinity", "cpu_pin", "hp_backed", "chipset", "preferred_cpu") && d.Get("started").(bool) {
if d.HasChanges("numa_affinity", "cpu_pin", "hp_backed", "chipset", "preferred_cpu", "hot_resize") && d.Get("started").(bool) {
isStopRequired = true
}
if isStopRequired {
@@ -1597,9 +1718,10 @@ func utilityComputeUpdateImage(ctx context.Context, d *schema.ResourceData, m in
if oldImage.(int) != newImage.(int) {
req := compute.RedeployRequest{
ComputeID: computeId,
ImageID: uint64(newImage.(int)),
DataDisks: "KEEP",
ComputeID: computeId,
ImageID: uint64(newImage.(int)),
DataDisks: "KEEP",
StoragePolicyID: uint64(d.Get("storage_policy_id").(int)),
}
if diskSize, ok := d.GetOk("boot_disk_size"); ok {
@@ -1612,6 +1734,10 @@ func utilityComputeUpdateImage(ctx context.Context, d *schema.ResourceData, m in
req.ForceStop = forceStop.(bool)
}
if osVersion, ok := d.GetOk("os_version"); ok {
req.OSVersion = osVersion.(string)
}
_, err := c.CloudBroker().Compute().Redeploy(ctx, req)
if err != nil {
return err
@@ -1772,6 +1898,18 @@ func isRenameDisk(els []interface{}, el interface{}) bool {
return false
}
func isChangeStoragePolicy(els []interface{}, el interface{}) bool {
for _, elOld := range els {
elOldConv := elOld.(map[string]interface{})
elConv := el.(map[string]interface{})
if elOldConv["disk_id"].(int) == elConv["disk_id"].(int) &&
elOldConv["storage_policy_id"].(int) != elConv["storage_policy_id"].(int) {
return true
}
}
return false
}
func isContainsDisk(els []interface{}, el interface{}) bool {
for _, elOld := range els {
elOldConv := elOld.(map[string]interface{})
@@ -1839,3 +1977,25 @@ func getComputeDiskIDs(disksList compute.ListDisks, disksBlocks, extraDisks []in
return res
}
func enabledNetwork(rawNetworkConfig cty.Value, netID uint64, netType string) bool {
for _, netConfigVal := range rawNetworkConfig.AsValueSlice() {
if netConfigVal.IsNull() {
continue
}
netConfig := netConfigVal.AsValueMap()
tempID, _ := netConfig["net_id"].AsBigFloat().Int64()
configNetID := uint64(tempID)
configNetType := netConfig["net_type"].AsString()
if configNetID == netID && configNetType == netType {
enabledVal := netConfig["enabled"]
return !enabledVal.IsNull()
}
}
return false
}

View File

@@ -45,10 +45,36 @@ func utilityComputeAuditsCheckPresence(ctx context.Context, d *schema.ResourceDa
req := compute.AuditsRequest{
ComputeID: uint64(d.Get("compute_id").(int)),
}
if timestampAt, ok := d.GetOk("timestamp_at"); ok {
req.TimestampAT = uint64(timestampAt.(int))
}
if timestampTo, ok := d.GetOk("timestamp_to"); ok {
req.TimestampTO = uint64(timestampTo.(int))
}
if user, ok := d.GetOk("user"); ok {
req.User = user.(string)
}
if call, ok := d.GetOk("call"); ok {
req.Call = call.(string)
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}
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 minStatusCode, ok := d.GetOk("min_status_code"); ok {
req.MinStatusCode = uint64(minStatusCode.(int))
}
if maxStatusCode, ok := d.GetOk("max_status_code"); ok {
req.MaxStatusCode = uint64(maxStatusCode.(int))
}
computeAudits, err := c.CloudBroker().Compute().Audits(ctx, req)
if err != nil {
return nil, err
return compute.ListDetailedAudits{}, err
}
return computeAudits, nil
return *computeAudits, nil
}

View File

@@ -75,9 +75,6 @@ func utilityDataComputeListCheckPresence(ctx context.Context, d *schema.Resource
if stackName, ok := d.GetOk("stack_name"); ok {
req.StackName = stackName.(string)
}
if imageID, ok := d.GetOk("image_id"); ok {
req.ImageID = imageID.(uint64)
}
if cdImageID, ok := d.GetOk("cd_image_id"); ok {
req.CDImageID = cdImageID.(uint64)
}
@@ -99,6 +96,9 @@ func utilityDataComputeListCheckPresence(ctx context.Context, d *schema.Resource
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if zoneID, ok := d.GetOk("zone_id"); ok {
req.ZoneID = uint64(zoneID.(int))
}
listComputes, err := c.CloudBroker().Compute().List(ctx, req)
if err != nil {

View File

@@ -889,6 +889,11 @@ func dsLBListSchemaMake() map[string]*schema.Schema {
Optional: true,
Default: 0,
},
"zone_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Zone ID",
},
"items": {
Type: schema.TypeList,
Computed: true,

View File

@@ -94,6 +94,10 @@ func utilityLBListCheckPresence(ctx context.Context, d *schema.ResourceData, m i
req.Size = uint64(size.(int))
}
if zoneID, ok := d.GetOk("zone_id"); ok {
req.ZoneID = uint64(zoneID.(int))
}
log.Debugf("utilityLBListCheckPresence: load lb list")
lbList, err := c.CloudBroker().LB().List(ctx, req)
if err != nil {

View File

@@ -86,7 +86,8 @@ func flattenConsumption(info node.ConsumptionInfo) []map[string]interface{} {
}
tempFree := map[string]interface{}{
"ram": info.Free.RAM,
"ram": info.Free.RAM,
"vcpu": info.Free.VCPU,
}
tempRes["free"] = []map[string]interface{}{
tempFree,

View File

@@ -43,6 +43,10 @@ func dataSourceNodeSchemaMake() map[string]*schema.Schema {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"vcpu": {
Type: schema.TypeInt,
Computed: true,
},
"ram": {
Type: schema.TypeInt,
Computed: true,

View File

@@ -41,6 +41,7 @@ func flattenResgroup(d *schema.ResourceData, rgData *rg.RecordRG) {
d.Set("vins", rgData.VINS)
d.Set("computes", rgData.VMs)
d.Set("sdn_access_group_id", rgData.SDNAccessGroupID)
d.Set("storage_policy_ids", rgData.StoragePolicyIDs)
}
func flattenRgAcl(rgACLs rg.ListACL) []map[string]interface{} {
@@ -64,13 +65,14 @@ func flattenRgAcl(rgACLs rg.ListACL) []map[string]interface{} {
func flattenRgResourceLimits(rl rg.ResourceLimits) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"cu_c": rl.CUC,
"cu_d": rl.CuD,
"cu_dm": rl.CUDM,
"cu_i": rl.CUI,
"cu_m": rl.CUM,
"cu_np": rl.CUNP,
"gpu_units": rl.GPUUnits,
"cu_c": rl.CUC,
"cu_d": rl.CuD,
"cu_dm": rl.CUDM,
"cu_i": rl.CUI,
"cu_m": rl.CUM,
"cu_np": rl.CUNP,
"gpu_units": rl.GPUUnits,
"storage_policy": flattenRgStoragePolicy(rl.StoragePolicies),
}
res = append(res, temp)
@@ -413,6 +415,7 @@ func flattenRgList(rgl *rg.ListRG) []map[string]interface{} {
"vins": rg.VINS,
"vms": rg.VMs,
"sdn_access_group_id": rg.SDNAccessGroupID,
"storage_policy_ids": rg.StoragePolicyIDs,
}
res = append(res, temp)
}
@@ -475,6 +478,7 @@ func flattenResourceRG(d *schema.ResourceData, rgData *rg.RecordRG) {
d.Set("gid", rgData.GID)
d.Set("rg_name", rgData.Name)
d.Set("resource_limits", flattenRgResourceLimits(rgData.ResourceLimits))
d.Set("storage_policy", flattenRgStoragePolicy(rgData.ResourceLimits.StoragePolicies))
d.Set("description", rgData.Description)
d.Set("uniq_pools", rgData.UniqPools)
d.Set("cpu_allocation_parameter", rgData.CPUAllocationParameter)
@@ -498,4 +502,19 @@ func flattenResourceRG(d *schema.ResourceData, rgData *rg.RecordRG) {
d.Set("vins", rgData.VINS)
d.Set("vms", rgData.VMs)
d.Set("sdn_access_group_id", rgData.SDNAccessGroupID)
d.Set("storage_policy_ids", rgData.StoragePolicyIDs)
}
func flattenRgStoragePolicy(spList []rg.StoragePolicy) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(spList))
for _, sp := range spList {
temp := map[string]interface{}{
"id": sp.ID,
"limit": sp.Limit,
}
res = append(res, temp)
}
return res
}

View File

@@ -141,6 +141,27 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter
req.SDNAccessGroupID = sdnAccessGroupID.(string)
}
if storagePolicies, ok := d.GetOk("storage_policy"); ok {
var id uint64
var limit int
if storagePolicies.(*schema.Set).Len() > 0 {
spList := storagePolicies.(*schema.Set).List()
for _, spInterface := range spList {
sps := spInterface.(map[string]interface{})
id = uint64(sps["id"].(int))
limit = sps["limit"].(int)
spModel := rg.StoragePolicy{
ID: id,
Limit: limit,
}
req.StoragePolicies = append(req.StoragePolicies, spModel)
}
}
}
rgID, err := c.CloudBroker().RG().Create(ctx, req)
if err != nil {
d.SetId("")
@@ -367,50 +388,52 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter
}
if d.HasChange("resource_limits") {
resLimits := d.Get("resource_limits").([]interface{})[0]
resLimitsConv := resLimits.(map[string]interface{})
if resLimitsConv["cu_m"] != nil {
maxMemCap := int64(resLimitsConv["cu_m"].(float64))
if maxMemCap == 0 {
req.MaxMemoryCapacity = -1
} else {
req.MaxMemoryCapacity = maxMemCap
if _, ok := d.GetOk("resource_limits"); ok {
resLimits := d.Get("resource_limits").([]interface{})[0]
resLimitsConv := resLimits.(map[string]interface{})
if resLimitsConv["cu_m"] != nil {
maxMemCap := int64(resLimitsConv["cu_m"].(float64))
if maxMemCap == 0 {
req.MaxMemoryCapacity = -1
} else {
req.MaxMemoryCapacity = maxMemCap
}
}
}
if resLimitsConv["cu_dm"] != nil {
maxDiskCap := int64(resLimitsConv["cu_dm"].(float64))
if maxDiskCap == 0 {
req.MaxVDiskCapacity = -1
} else {
req.MaxVDiskCapacity = maxDiskCap
if resLimitsConv["cu_dm"] != nil {
maxDiskCap := int64(resLimitsConv["cu_dm"].(float64))
if maxDiskCap == 0 {
req.MaxVDiskCapacity = -1
} else {
req.MaxVDiskCapacity = maxDiskCap
}
}
}
if resLimitsConv["cu_c"] != nil {
maxCPUCap := int64(resLimitsConv["cu_c"].(float64))
if maxCPUCap == 0 {
req.MaxCPUCapacity = -1
} else {
req.MaxCPUCapacity = maxCPUCap
if resLimitsConv["cu_c"] != nil {
maxCPUCap := int64(resLimitsConv["cu_c"].(float64))
if maxCPUCap == 0 {
req.MaxCPUCapacity = -1
} else {
req.MaxCPUCapacity = maxCPUCap
}
}
}
if resLimitsConv["cu_i"] != nil {
maxNumPublicIP := int64(resLimitsConv["cu_i"].(float64))
if maxNumPublicIP == 0 {
req.MaxNumPublicIP = -1
} else {
req.MaxNumPublicIP = maxNumPublicIP
if resLimitsConv["cu_i"] != nil {
maxNumPublicIP := int64(resLimitsConv["cu_i"].(float64))
if maxNumPublicIP == 0 {
req.MaxNumPublicIP = -1
} else {
req.MaxNumPublicIP = maxNumPublicIP
}
}
}
if resLimitsConv["cu_np"] != nil {
maxNP := int64(resLimitsConv["cu_np"].(float64))
if maxNP == 0 {
req.MaxNetworkPeerTransfer = -1
} else {
req.MaxNetworkPeerTransfer = maxNP
if resLimitsConv["cu_np"] != nil {
maxNP := int64(resLimitsConv["cu_np"].(float64))
if maxNP == 0 {
req.MaxNetworkPeerTransfer = -1
} else {
req.MaxNetworkPeerTransfer = maxNP
}
}
}
doGeneralUpdate = true
doGeneralUpdate = true
}
}
if d.HasChange("description") {
@@ -418,6 +441,31 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter
doGeneralUpdate = true
}
if d.HasChange("storage_policy") {
needUpdate, updateEl, err := utilityRGUpdateStPolicy(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
if needUpdate {
// spList := storagePolicies.(*schema.Set).List()
var id uint64
var limit int
for _, spInterface := range updateEl {
// sps := spInterface.(map[string]interface{})
id = uint64(spInterface["id"].(int))
limit = spInterface["limit"].(int)
spModel := rg.StoragePolicy{
ID: id,
Limit: limit,
}
req.StoragePolicies = append(req.StoragePolicies, spModel)
}
doGeneralUpdate = needUpdate
}
}
if d.HasChange("uniq_pools") {
uniqPools := d.Get("uniq_pools").([]interface{})
if len(uniqPools) == 0 {
@@ -721,6 +769,10 @@ func ResourceResgroup() *schema.Resource {
if diff.HasChange("def_net") {
diff.SetNewComputed("def_net_id")
}
if diff.HasChange("storage_policy") {
diff.SetNewComputed("storage_policy_ids")
diff.SetNewComputed("resource_limits")
}
if diff.HasChanges() {
diff.SetNewComputed("updated_by")
diff.SetNewComputed("updated_time")

View File

@@ -152,6 +152,22 @@ func dataSourceRgSchemaMake() map[string]*schema.Schema {
Type: schema.TypeFloat,
Computed: true,
},
"storage_policy": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
"limit": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
},
},
},
@@ -203,6 +219,13 @@ func dataSourceRgSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"storage_policy_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
}
}
@@ -1654,6 +1677,23 @@ func dataSourceRgListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeFloat,
Computed: true,
},
"storage_policy": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Required: true,
},
"limit": {
Type: schema.TypeInt,
Optional: true,
},
},
},
},
},
},
},
@@ -1701,6 +1741,13 @@ func dataSourceRgListDeletedSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
},
},
"storage_policy_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
},
},
},
@@ -1924,6 +1971,23 @@ func dataSourceRgListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeFloat,
Computed: true,
},
"storage_policy": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Required: true,
},
"limit": {
Type: schema.TypeInt,
Optional: true,
},
},
},
},
},
},
},
@@ -1975,6 +2039,13 @@ func dataSourceRgListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"storage_policy_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
},
},
},
@@ -2244,6 +2315,22 @@ func resourceRgSchemaMake() map[string]*schema.Schema {
Type: schema.TypeFloat,
Computed: true,
},
"storage_policy": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
"limit": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
},
},
},
@@ -2392,6 +2479,24 @@ func resourceRgSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "ID of the SDN access group",
},
"storage_policy": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Required: true,
},
"limit": {
Type: schema.TypeInt,
Optional: true,
Default: -1,
},
},
},
},
"acl": {
Type: schema.TypeList,
@@ -2510,6 +2615,14 @@ func resourceRgSchemaMake() map[string]*schema.Schema {
},
Description: "List of VM ids in this resource group.",
},
"storage_policy_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
}
return res

View File

@@ -36,6 +36,7 @@ import (
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
@@ -58,3 +59,92 @@ func utilityResgroupCheckPresence(ctx context.Context, d *schema.ResourceData, m
return rgData, nil
}
func utilityRGUpdateStPolicy(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, []map[string]interface{}, error) {
c := m.(*controller.ControllerCfg)
rgId, _ := strconv.ParseUint(d.Id(), 10, 64)
addSP, delSP, updateSP := utilityGetStoragePolicyUpdate(ctx, d, m)
needUpdate := len(updateSP) > 0
if len(addSP) > 0 {
for _, spMap := range addSP {
req := rg.AddStoragePolicyRequest{
RGID: rgId,
StoragePolicyID: uint64(spMap["id"].(int)),
Limit: spMap["limit"].(int),
}
log.Debugf("utilityRGUpdateStPolicy: starting to add storage policy ID:%d for rg %d", req.StoragePolicyID, req.RGID)
_, err := c.CloudBroker().RG().AddStoragePolicy(ctx, req)
if err != nil {
return needUpdate, updateSP, err
}
}
}
if len(delSP) > 0 {
for _, spMap := range delSP {
req := rg.DelStoragePolicyRequest{
RGID: rgId,
StoragePolicyID: uint64(spMap["id"].(int)),
}
log.Debugf("utilityRGUpdateStPolicy: starting to delete storage policy ID:%d from rg %d", req.StoragePolicyID, req.RGID)
_, err := c.CloudBroker().RG().DelStoragePolicy(ctx, req)
if err != nil {
return needUpdate, updateSP, err
}
}
}
return needUpdate, updateSP, nil
}
func utilityGetStoragePolicyUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) (added, deleted, updated []map[string]interface{}) {
added = make([]map[string]interface{}, 0)
deleted = make([]map[string]interface{}, 0)
updated = make([]map[string]interface{}, 0)
oldSet, newSet := d.GetChange("storage_policy")
oldList := oldSet.(*schema.Set).List()
newList := newSet.(*schema.Set).List()
for _, oldSP := range oldList {
oldMap := oldSP.(map[string]interface{})
found := false
for _, newSP := range newList {
newMap := newSP.(map[string]interface{})
if oldMap["id"] == newMap["id"] {
found = true
if oldMap["limit"] != newMap["limit"] {
updated = append(added, newMap)
}
break
}
if found {
break
}
}
if found {
continue
}
deleted = append(deleted, oldMap)
}
for _, newSP := range newList {
newMap := newSP.(map[string]interface{})
found := false
for _, oldSP := range oldList {
oldMap := oldSP.(map[string]interface{})
if oldMap["id"] == newMap["id"] {
found = true
break
}
}
if found {
continue
}
added = append(added, newMap)
}
return
}

View File

@@ -0,0 +1,38 @@
package secgroup
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceSecurityGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
securityGroup, err := utilitySecurityGroupCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
flattenSecurityGroup(d, securityGroup)
return nil
}
func DataSourceSecurityGroup() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceSecurityGroupRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceSecurityGroupSchemaMake(),
}
}

View File

@@ -0,0 +1,40 @@
package secgroup
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceSecurityGroupListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
storagePolicyList, err := utilitySecurityGroupListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenSecurityGroupList(storagePolicyList))
d.Set("entry_count", storagePolicyList.EntryCount)
return nil
}
func DataSourceSecurityGroupList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceSecurityGroupListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceSecurityGroupListSchemaMake(),
}
}

View File

@@ -0,0 +1,68 @@
package secgroup
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/secgroup"
)
func flattenSecurityGroupResource(d *schema.ResourceData, securityGroup *secgroup.RecordSecurityGroup) {
d.Set("security_group_id", securityGroup.ID)
d.Set("account_id", securityGroup.AccountID)
d.Set("name", securityGroup.Name)
d.Set("description", securityGroup.Description)
d.Set("rules", flattenRules(securityGroup.Rules))
d.Set("created_at", securityGroup.CreatedAt)
d.Set("created_by", securityGroup.CreatedBy)
d.Set("updated_at", securityGroup.UpdatedAt)
d.Set("updated_by", securityGroup.UpdatedBy)
}
func flattenSecurityGroupList(securityGroupList *secgroup.ListSecurityGroups) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(securityGroupList.Data))
for _, v := range securityGroupList.Data {
temp := map[string]interface{}{
"account_id": v.AccountID,
"name": v.Name,
"description": v.Description,
"rules": flattenRules(v.Rules),
"created_at": v.CreatedAt,
"created_by": v.CreatedBy,
"security_group_id": v.ID,
"updated_at": v.UpdatedAt,
"updated_by": v.UpdatedBy,
}
res = append(res, temp)
}
return res
}
func flattenSecurityGroup(d *schema.ResourceData, securityGroup *secgroup.RecordSecurityGroup) {
d.Set("security_group_id", securityGroup.ID)
d.Set("account_id", securityGroup.AccountID)
d.Set("name", securityGroup.Name)
d.Set("description", securityGroup.Description)
d.Set("rules", flattenRules(securityGroup.Rules))
d.Set("created_at", securityGroup.CreatedAt)
d.Set("created_by", securityGroup.CreatedBy)
d.Set("updated_at", securityGroup.UpdatedAt)
d.Set("updated_by", securityGroup.UpdatedBy)
}
func flattenRules(rules secgroup.Rules) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(rules))
for _, rule := range rules {
temp := map[string]interface{}{
"id": rule.ID,
"direction": rule.Direction,
"ethertype": rule.Ethertype,
"protocol": rule.Protocol,
"port_range_min": rule.PortRangeMin,
"port_range_max": rule.PortRangeMax,
"remote_ip_prefix": rule.RemoteIPPrefix,
}
res = append(res, temp)
}
return res
}

View File

@@ -0,0 +1,146 @@
package secgroup
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/secgroup"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
)
func resourceSecurityGroupCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceSecurityGroupCreate: called with account ID %d, name %s", uint64(d.Get("account_id").(int)), d.Get("name").(string))
c := m.(*controller.ControllerCfg)
warnings := dc.Warnings{}
accountID := uint64(d.Get("account_id").(int))
name := d.Get("name").(string)
req := secgroup.CreateRequest{
AccountID: accountID,
Name: name,
}
if description, ok := d.GetOk("description"); ok {
req.Description = description.(string)
}
securityGroupID, err := c.CloudBroker().SecurityGroup().Create(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId(strconv.FormatUint(securityGroupID, 10))
d.Set("security_group_id", securityGroupID)
return append(warnings.Get(), resourceSecurityGroupRead(ctx, d, m)...)
}
func resourceSecurityGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceSecurityGroupRead: called with with account ID %d", uint64(d.Get("account_id").(int)))
w := dc.Warnings{}
securityGroupItem, err := utilitySecurityGroupCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
flattenSecurityGroupResource(d, securityGroupItem)
return w.Get()
}
func resourceSecurityGroupUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
securityGroupID, _ := strconv.ParseUint(d.Id(), 10, 64)
log.Debugf("resourceSecurityGroupUpdate: called security group with id %d", securityGroupID)
c := m.(*controller.ControllerCfg)
_, err := utilitySecurityGroupCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
_, err = strconv.ParseInt(d.Id(), 10, 64)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
if d.HasChanges("name", "description") {
if err := utilitySecurityGroupHandleHasChanges(ctx, d, c, securityGroupID); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("rules") {
if err := utilitySecurityGroupUpdateRules(ctx, d, c, securityGroupID); err != nil {
return diag.FromErr(err)
}
}
return resourceSecurityGroupRead(ctx, d, m)
}
func resourceSecurityGroupDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceSecurityGroupDelete: called with id %s", d.Id())
securityGroupItem, err := utilitySecurityGroupCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
c := m.(*controller.ControllerCfg)
req := secgroup.DeleteRequest{
SecurityGroupID: securityGroupItem.ID,
}
if _, err := c.CloudBroker().SecurityGroup().Delete(ctx, req); err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func ResourceSecurityGroup() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceSecurityGroupCreate,
ReadContext: resourceSecurityGroupRead,
UpdateContext: resourceSecurityGroupUpdate,
DeleteContext: resourceSecurityGroupDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout600s,
Read: &constants.Timeout600s,
Update: &constants.Timeout600s,
Delete: &constants.Timeout600s,
Default: &constants.Timeout600s,
},
Schema: resourceSecurityGroupSchemaMake(),
}
}

View File

@@ -0,0 +1,288 @@
package secgroup
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func resourceSecurityGroupSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"account_id": {
Type: schema.TypeInt,
Required: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
},
"rules": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"direction": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"inbound", "outbound"}, true),
},
"ethertype": {
Type: schema.TypeString,
Optional: true,
Default: "IPv4",
ValidateFunc: validation.StringInSlice([]string{"IPv4", "IPv6"}, true),
},
"protocol": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"icmp", "tcp", "udp"}, true),
},
"port_range_min": {
Type: schema.TypeInt,
Optional: true,
},
"port_range_max": {
Type: schema.TypeInt,
Optional: true,
},
"remote_ip_prefix": {
Type: schema.TypeString,
Optional: true,
},
"id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"security_group_id": {
Type: schema.TypeInt,
Computed: true,
},
"created_at": {
Type: schema.TypeInt,
Computed: true,
},
"updated_at": {
Type: schema.TypeInt,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
}
return res
}
func dataSourceSecurityGroupSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"security_group_id": {
Type: schema.TypeInt,
Required: true,
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"rules": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
"direction": {
Type: schema.TypeString,
Computed: true,
},
"ethertype": {
Type: schema.TypeString,
Computed: true,
},
"protocol": {
Type: schema.TypeString,
Computed: true,
},
"port_range_min": {
Type: schema.TypeInt,
Computed: true,
},
"port_range_max": {
Type: schema.TypeInt,
Computed: true,
},
"remote_ip_prefix": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"created_at": {
Type: schema.TypeInt,
Computed: true,
},
"updated_at": {
Type: schema.TypeInt,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
}
return res
}
func dataSourceSecurityGroupListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"page": {
Type: schema.TypeInt,
Optional: true,
},
"size": {
Type: schema.TypeInt,
Optional: true,
},
"by_id": {
Type: schema.TypeInt,
Optional: true,
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
},
"name": {
Type: schema.TypeString,
Optional: true,
},
"desc": {
Type: schema.TypeString,
Optional: true,
},
"sort_by": {
Type: schema.TypeString,
Optional: true,
},
"created_min": {
Type: schema.TypeInt,
Optional: true,
},
"created_max": {
Type: schema.TypeInt,
Optional: true,
},
"updated_min": {
Type: schema.TypeInt,
Optional: true,
},
"updated_max": {
Type: schema.TypeInt,
Optional: true,
},
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"security_group_id": {
Type: schema.TypeInt,
Computed: true,
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"rules": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
"direction": {
Type: schema.TypeString,
Computed: true,
},
"ethertype": {
Type: schema.TypeString,
Computed: true,
},
"protocol": {
Type: schema.TypeString,
Computed: true,
},
"port_range_min": {
Type: schema.TypeInt,
Computed: true,
},
"port_range_max": {
Type: schema.TypeInt,
Computed: true,
},
"remote_ip_prefix": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"created_at": {
Type: schema.TypeInt,
Computed: true,
},
"updated_at": {
Type: schema.TypeInt,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}

View File

@@ -0,0 +1,95 @@
package secgroup
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/secgroup"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilitySecurityGroupCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*secgroup.RecordSecurityGroup, error) {
c := m.(*controller.ControllerCfg)
req := secgroup.GetRequest{}
if d.Id() != "" {
securityGroupID, _ := strconv.ParseUint(d.Id(), 10, 64)
req.SecurityGroupID = securityGroupID
} else {
req.SecurityGroupID = uint64(d.Get("security_group_id").(int))
}
log.Debugf("utilitySecurityGroupCheckPresence: load security group")
securityGroup, err := c.CloudBroker().SecurityGroup().Get(ctx, req)
if err != nil {
return nil, err
}
return securityGroup, nil
}
func utilitySecurityGroupHandleHasChanges(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, securityGroupID uint64) error {
req := secgroup.UpdateRequest{
SecurityGroupID: securityGroupID,
}
if d.HasChange("name") {
name := d.Get("name").(string)
req.Name = name
}
if d.HasChange("description") {
description := d.Get("description").(string)
req.Description = description
}
if _, err := c.CloudBroker().SecurityGroup().Update(ctx, req); err != nil {
return err
}
return nil
}
func utilitySecurityGroupUpdateRules(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, securityGroupID uint64) error {
oldSet, newSet := d.GetChange("rules")
deletedRules := (oldSet.(*schema.Set).Difference(newSet.(*schema.Set))).List()
for _, deletedInterface := range deletedRules {
deletedItem := deletedInterface.(map[string]interface{})
ruleID := uint64(deletedItem["id"].(int))
req := secgroup.DeleteRuleRequest{
SecurityGroupID: securityGroupID,
RuleID: ruleID,
}
if _, err := c.CloudBroker().SecurityGroup().DeleteRule(ctx, req); err != nil {
return err
}
}
addedRules := (newSet.(*schema.Set).Difference(oldSet.(*schema.Set))).List()
for _, addedInterface := range addedRules {
addedItem := addedInterface.(map[string]interface{})
direction := addedItem["direction"].(string)
ethertype := addedItem["ethertype"].(string)
protocol := addedItem["protocol"].(string)
portRangeMin := uint64(addedItem["port_range_min"].(int))
portRangeMax := uint64(addedItem["port_range_max"].(int))
remoteIPPrefix := addedItem["remote_ip_prefix"].(string)
req := secgroup.CreateRuleRequest{
SecurityGroupID: securityGroupID,
Direction: direction,
Ethertype: ethertype,
Protocol: protocol,
PortRangeMin: portRangeMin,
PortRangeMax: portRangeMax,
RemoteIPPrefix: remoteIPPrefix,
}
if _, err := c.CloudBroker().SecurityGroup().CreateRule(ctx, req); err != nil {
return err
}
}
return nil
}

View File

@@ -0,0 +1,60 @@
package secgroup
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/secgroup"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilitySecurityGroupListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*secgroup.ListSecurityGroups, error) {
c := m.(*controller.ControllerCfg)
req := secgroup.ListRequest{}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if byID, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(byID.(int))
}
if accountID, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountID.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if desc, ok := d.GetOk("desc"); ok {
req.Description = desc.(string)
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}
if createdMin, ok := d.GetOk("created_min"); ok {
req.CreatedMin = uint64(createdMin.(int))
}
if createdMax, ok := d.GetOk("created_max"); ok {
req.CreatedMax = uint64(createdMax.(int))
}
if updatedMin, ok := d.GetOk("updated_min"); ok {
req.UpdatedMin = uint64(updatedMin.(int))
}
if updatedMax, ok := d.GetOk("updated_max"); ok {
req.UpdatedMax = uint64(updatedMax.(int))
}
log.Debugf("utilitySecurityGroupListCheckPresence: load storage policy list")
securityGroupList, err := c.CloudBroker().SecurityGroup().List(ctx, req)
if err != nil {
return nil, err
}
return securityGroupList, nil
}

View File

@@ -0,0 +1,37 @@
package stpolicy
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceStoragePolicyRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
storagePolicy, err := utilityStoragePolicyCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
flattenStoragePolicyData(d, storagePolicy)
return nil
}
func DataSourceStoragePolicy() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceStoragePolicyRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceStoragePolicySchemaMake(),
}
}

View File

@@ -0,0 +1,40 @@
package stpolicy
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceStoragePolicyListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
storagePolicyList, err := utilityStoragePolicyListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenStoragePolicyList(storagePolicyList))
d.Set("entry_count", storagePolicyList.EntryCount)
return nil
}
func DataSourceStoragePolicyList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceStoragePolicyListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceStoragePolicyListSchemaMake(),
}
}

View File

@@ -0,0 +1,74 @@
package stpolicy
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/stpolicy"
)
func flattenStoragePolicyData(d *schema.ResourceData, storagePolicy *stpolicy.InfoStoragePolicy) {
d.Set("storage_policy_id", storagePolicy.ID)
d.Set("description", storagePolicy.Description)
d.Set("guid", storagePolicy.GUID)
d.Set("limit_iops", storagePolicy.LimitIOPS)
d.Set("name", storagePolicy.Name)
d.Set("status", storagePolicy.Status)
d.Set("access_seps_pools", flattenAccessSEPPools(storagePolicy.AccessSEPPools))
d.Set("usage", flattenUsage(storagePolicy.Usage))
}
func flattenAccessSEPPools(accessSEPPools stpolicy.ListAccessSEPPools) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(accessSEPPools))
for _, asp := range accessSEPPools {
temp := map[string]interface{}{
"sep_id": asp.SEPID,
//TODO
//"name": asp.Name,
"pool_names": asp.PoolNames,
}
res = append(res, temp)
}
return res
}
func flattenUsage(usage stpolicy.Usage) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"accounts": usage.Accounts,
"resgroups": usage.Resgroups,
}
res = append(res, temp)
return res
}
func flattenStoragePolicyList(storagePolicyList *stpolicy.ListStoragePolicies) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(storagePolicyList.Data))
for _, v := range storagePolicyList.Data {
temp := map[string]interface{}{
"storage_policy_id": v.ID,
"description": v.Description,
"guid": v.GUID,
"limit_iops": v.LimitIOPS,
"name": v.Name,
"status": v.Status,
"access_seps_pools": flattenAccessSEPPools(v.AccessSEPPools),
"usage": flattenUsage(v.Usage),
}
res = append(res, temp)
}
return res
}
func flattenStoragePolicyResource(d *schema.ResourceData, storagePolicy *stpolicy.InfoStoragePolicy) {
d.Set("storage_policy_id", storagePolicy.ID)
d.Set("description", storagePolicy.Description)
d.Set("guid", storagePolicy.GUID)
d.Set("limit_iops", storagePolicy.LimitIOPS)
d.Set("name", storagePolicy.Name)
d.Set("status", storagePolicy.Status)
d.Set("access_seps_pools", flattenAccessSEPPools(storagePolicy.AccessSEPPools))
d.Set("usage", flattenUsage(storagePolicy.Usage))
}

View File

@@ -0,0 +1,182 @@
package stpolicy
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/stpolicy"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
)
func resourceStoragePolicyCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceTrunkCreate: called with name %s", d.Get("name").(string))
c := m.(*controller.ControllerCfg)
warnings := dc.Warnings{}
name := d.Get("name").(string)
aspRaw := d.Get("access_seps_pools")
aspFromMan := aspRaw.(*schema.Set).List()
aspArray := make([]stpolicy.AccessSEPsPool, 0, len(aspFromMan))
aspMap := make(map[uint64][]string)
for _, aspfm := range aspFromMan {
temp := aspfm.(map[string]interface{})
sepID := uint64(temp["sep_id"].(int))
_, ok := aspMap[sepID]
poolName := temp["pool_name"].(string)
if !ok {
aspMap[sepID] = []string{}
}
aspMap[sepID] = append(aspMap[sepID], poolName)
}
for key, value := range aspMap {
asp := stpolicy.AccessSEPsPool{}
asp.SEPID = key
asp.PoolNames = value
aspArray = append(aspArray, asp)
}
req := stpolicy.CreateRequest{
Name: name,
AccessSEPsPools: aspArray,
}
if description, ok := d.GetOk("description"); ok {
req.Description = description.(string)
}
if limitIOPS, ok := d.GetOk("limit_iops"); ok {
req.LimitIOPS = uint64(limitIOPS.(int))
}
storagePolicyID, err := c.CloudBroker().StPolicy().Create(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId(strconv.FormatUint(storagePolicyID, 10))
d.Set("storage_policy_id", storagePolicyID)
if enabled, ok := d.GetOk("enabled"); ok {
isToEnable := enabled.(bool)
if err := handleStoragePolicyEnabling(ctx, d, c, storagePolicyID, isToEnable); err != nil {
warnings.Add(err)
}
}
return append(warnings.Get(), resourceStoragePolicyRead(ctx, d, m)...)
}
func resourceStoragePolicyRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceStoragePolicyRead: called with name %s", d.Get("name").(string))
w := dc.Warnings{}
storagePolicyItem, err := utilityStoragePolicyCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
flattenStoragePolicyResource(d, storagePolicyItem)
return w.Get()
}
func resourceStoragePolicyUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
storagePolicyID, _ := strconv.ParseUint(d.Id(), 10, 64)
log.Debugf("resourceStoragePolicyUpdate: called storage policy with id %d", storagePolicyID)
c := m.(*controller.ControllerCfg)
_, err := utilityStoragePolicyCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
_, err = strconv.ParseInt(d.Id(), 10, 64)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
if d.HasChanges("name", "limit_iops", "description") {
if err := utilityStoragePolicyHandleHasChanges(ctx, d, c, storagePolicyID); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("enabled") {
enabled := d.Get("enabled")
isToEnable := enabled.(bool)
if err := handleStoragePolicyEnabling(ctx, d, c, storagePolicyID, isToEnable); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("access_seps_pools") {
if err := utilityStoragePolicyUpdateAccessSEPsPools(ctx, d, c, storagePolicyID); err != nil {
return diag.FromErr(err)
}
}
return resourceStoragePolicyRead(ctx, d, m)
}
func resourceStoragePolicyDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceStoragePolicyDelete: called with id %s", d.Id())
storagePolicyItem, err := utilityStoragePolicyCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
c := m.(*controller.ControllerCfg)
req := stpolicy.DeleteRequest{
StoragePolicyID: storagePolicyItem.ID,
}
if _, err := c.CloudBroker().StPolicy().Delete(ctx, req); err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func ResourceStoragePolicy() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceStoragePolicyCreate,
ReadContext: resourceStoragePolicyRead,
UpdateContext: resourceStoragePolicyUpdate,
DeleteContext: resourceStoragePolicyDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout600s,
Read: &constants.Timeout600s,
Update: &constants.Timeout600s,
Delete: &constants.Timeout600s,
Default: &constants.Timeout600s,
},
Schema: resourceStoragePolicySchemaMake(),
}
}

View File

@@ -0,0 +1,281 @@
package stpolicy
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
func resourceStoragePolicySchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"storage_policy_id": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
"access_seps_pools": {
Type: schema.TypeSet,
Required: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"pool_name": {
Type: schema.TypeString,
Required: true,
},
"sep_id": {
Type: schema.TypeInt,
Required: true,
},
},
},
},
"description": {
Type: schema.TypeString,
Optional: true,
},
"limit_iops": {
Type: schema.TypeInt,
Optional: true,
},
"enabled": {
Type: schema.TypeBool,
Default: true,
Optional: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"usage": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"accounts": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"resgroups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
},
},
},
}
return res
}
func dataSourceStoragePolicySchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"storage_policy_id": {
Type: schema.TypeInt,
Required: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"limit_iops": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"access_seps_pools": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"pool_names": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"usage": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"accounts": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"resgroups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
},
},
},
}
return res
}
func dataSourceStoragePolicyListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"account_id": {
Type: schema.TypeInt,
Optional: true,
},
"page": {
Type: schema.TypeInt,
Optional: true,
},
"size": {
Type: schema.TypeInt,
Optional: true,
},
"by_id": {
Type: schema.TypeInt,
Optional: true,
},
"name": {
Type: schema.TypeString,
Optional: true,
},
"status": {
Type: schema.TypeString,
Optional: true,
},
"desc": {
Type: schema.TypeString,
Optional: true,
},
"limit_iops": {
Type: schema.TypeInt,
Optional: true,
},
"sort_by": {
Type: schema.TypeString,
Optional: true,
},
"resgroup_id": {
Type: schema.TypeInt,
Optional: true,
},
"sep_id": {
Type: schema.TypeInt,
Optional: true,
},
"pool_name": {
Type: schema.TypeString,
Optional: true,
},
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"storage_policy_id": {
Type: schema.TypeInt,
Required: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"limit_iops": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"access_seps_pools": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"pool_names": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"usage": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"accounts": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"resgroups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
},
},
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}

View File

@@ -0,0 +1,115 @@
package stpolicy
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/stpolicy"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityStoragePolicyCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*stpolicy.InfoStoragePolicy, error) {
c := m.(*controller.ControllerCfg)
req := stpolicy.GetRequest{}
if d.Id() != "" {
storagePolicyID, _ := strconv.ParseUint(d.Id(), 10, 64)
req.StoragePolicyID = storagePolicyID
} else {
req.StoragePolicyID = uint64(d.Get("storage_policy_id").(int))
}
storagePolicyData, err := c.CloudBroker().StPolicy().Get(ctx, req)
if err != nil {
return nil, err
}
return storagePolicyData, nil
}
func handleStoragePolicyEnabling(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, storagePolicyID uint64, enable bool) error {
if enable {
req := stpolicy.EnableRequest{
StoragePolicyID: storagePolicyID,
}
_, err := c.CloudBroker().StPolicy().Enable(ctx, req)
if err != nil {
return err
}
} else {
req := stpolicy.DisableRequest{
StoragePolicyID: storagePolicyID,
}
_, err := c.CloudBroker().StPolicy().Disable(ctx, req)
if err != nil {
return err
}
}
return nil
}
func utilityStoragePolicyHandleHasChanges(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, storagePolicyID uint64) error {
req := stpolicy.UpdateRequest{
StoragePolicyID: storagePolicyID,
}
if d.HasChange("name") {
name := d.Get("name").(string)
req.Name = name
}
if d.HasChange("limit_iops") {
limitIOPS := uint64(d.Get("limit_iops").(int))
req.LimitIOPS = limitIOPS
}
if d.HasChange("description") {
description := d.Get("description").(string)
req.Description = description
}
if _, err := c.CloudBroker().StPolicy().Update(ctx, req); err != nil {
return err
}
return nil
}
func utilityStoragePolicyUpdateAccessSEPsPools(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, storagePolicyID uint64) error {
oldSet, newSet := d.GetChange("access_seps_pools")
deletedASP := (oldSet.(*schema.Set).Difference(newSet.(*schema.Set))).List()
for _, deletedInterface := range deletedASP {
deletedItem := deletedInterface.(map[string]interface{})
SEPID := uint64(deletedItem["sep_id"].(int))
poolName := deletedItem["pool_name"].(string)
req := stpolicy.DeletePoolRequest{
StoragePolicyID: storagePolicyID,
SEPID: SEPID,
PoolName: poolName,
}
if _, err := c.CloudBroker().StPolicy().DeletePool(ctx, req); err != nil {
return err
}
}
addedASP := (newSet.(*schema.Set).Difference(oldSet.(*schema.Set))).List()
for _, addedInterface := range addedASP {
addedItem := addedInterface.(map[string]interface{})
SEPID := uint64(addedItem["sep_id"].(int))
poolName := addedItem["pool_name"].(string)
req := stpolicy.AddPoolRequest{
StoragePolicyID: storagePolicyID,
SEPID: SEPID,
PoolName: poolName,
}
if _, err := c.CloudBroker().StPolicy().AddPool(ctx, req); err != nil {
return err
}
}
return nil
}

View File

@@ -0,0 +1,70 @@
package stpolicy
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/stpolicy"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityStoragePolicyListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*stpolicy.ListStoragePolicies, error) {
c := m.(*controller.ControllerCfg)
req := stpolicy.ListRequest{}
if accountID, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountID.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if byID, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(byID.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if desc, ok := d.GetOk("desc"); ok {
req.Desc = desc.(string)
}
if limitIOPS, ok := d.GetOk("limit_iops"); ok {
req.LimitIOPS = uint64(limitIOPS.(int))
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}
if resgroupID, ok := d.GetOk("resgroup_id"); ok {
req.ResgroupID = uint64(resgroupID.(int))
}
if SEPID, ok := d.GetOk("sep_id"); ok {
req.SepID = uint64(SEPID.(int))
}
if poolName, ok := d.GetOk("pool_name"); ok {
req.PoolName = poolName.(string)
}
log.Debugf("utilityStoragePolicyListCheckPresence: load storage policy list")
storagePolicyList, err := c.CloudBroker().StPolicy().List(ctx, req)
if err != nil {
return nil, err
}
return storagePolicyList, nil
}

View File

@@ -28,6 +28,9 @@ func utilityTrunkListCheckPresence(ctx context.Context, d *schema.ResourceData,
if trunkTags, ok := d.GetOk("trunk_tags"); ok {
req.TrunkTags = trunkTags.(string)
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}

View File

@@ -113,6 +113,7 @@ func flattenVinsData(d *schema.ResourceData, vinsRecord *vins.RecordVINS) {
d.Set("vxlan_id", vinsRecord.VXLANID)
d.Set("computes", flattenComputes(vinsRecord.Computes))
d.Set("zone_id", vinsRecord.ZoneID)
d.Set("enable_secgroups", vinsRecord.EnableSecGroups)
}
@@ -134,26 +135,28 @@ func flattenLibvirtSettings(libvirtSettings vins.LibvirtSettings) []map[string]i
func flattenVinsVNFDev(vd vins.VNFDev) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"ckey": vd.CKey,
"meta": flattens.FlattenMeta(vd.Meta),
"account_id": vd.AccountID,
"capabilities": vd.Capabilities,
"config": flattenVinsConfig(vd.Config),
"config_saved": vd.ConfigSaved,
"custom_precfg": vd.CustomPreConfig,
"description": vd.Description,
"gid": vd.GID,
"guid": vd.GUID,
"id": vd.ID,
"interfaces": flattenVinsListInterfaces(vd.Interfaces),
"lock_status": vd.LockStatus,
"milestones": vd.Milestones,
"name": vd.Name,
"status": vd.Status,
"tech_status": vd.TechStatus,
"type": vd.Type,
"vnc_password": vd.VNCPassword,
"vins": vd.VINS,
"ckey": vd.CKey,
"meta": flattens.FlattenMeta(vd.Meta),
"account_id": vd.AccountID,
"capabilities": vd.Capabilities,
"config": flattenVinsConfig(vd.Config),
"config_saved": vd.ConfigSaved,
"custom_precfg": vd.CustomPreConfig,
"description": vd.Description,
"gid": vd.GID,
"guid": vd.GUID,
"id": vd.ID,
"interfaces": flattenVinsListInterfaces(vd.Interfaces),
"live_migration_job_id": vd.LiveMigrationJobID,
"lock_status": vd.LockStatus,
"milestones": vd.Milestones,
"name": vd.Name,
"status": vd.Status,
"tech_status": vd.TechStatus,
"type": vd.Type,
"vnc_password": vd.VNCPassword,
"vins": vd.VINS,
"zone_id": vd.ZoneID,
}
res = append(res, temp)
return res
@@ -203,6 +206,7 @@ func flattenVinsRecordDHCP(rv vins.RecordDHCP) []map[string]interface{} {
"status": rv.Status,
"tech_status": rv.TechStatus,
"type": rv.Type,
"zone_id": rv.ZoneID,
}
res = append(res, temp)
return res
@@ -225,9 +229,11 @@ func flattenVinsRecordGW(rg vins.RecordGW) []map[string]interface{} {
"owner_id": rg.OwnerID,
"owner_type": rg.OwnerType,
"pure_virtual": rg.PureVirtual,
"routes": flattenVinsRoutes(rg.Routes),
"status": rg.Status,
"tech_status": rg.TechStatus,
"type": rg.Type,
"zone_id": rg.ZoneID,
}
res = append(res, temp)
return res
@@ -250,9 +256,11 @@ func flattenVinsRecordNAT(rn vins.RecordNAT) []map[string]interface{} {
"owner_id": rn.OwnerID,
"owner_type": rn.OwnerType,
"pure_virtual": rn.PureVirtual,
"routes": flattenVinsRoutes(rn.Routes),
"status": rn.Status,
"tech_status": rn.TechStatus,
"type": rn.Type,
"zone_id": rn.ZoneID,
}
res = append(res, temp)
return res
@@ -425,6 +433,7 @@ func flattenVinsListInterfaces(i vins.ListInterfaces) []map[string]interface{} {
"conn_type": v.ConnType,
"def_gw": v.DefGW,
"enabled": v.Enabled,
"enable_secgroups": v.EnableSecGroups,
"flipgroup_id": v.FLIPGroupID,
"guid": v.GUID,
"ip_address": v.IPAddress,
@@ -439,6 +448,7 @@ func flattenVinsListInterfaces(i vins.ListInterfaces) []map[string]interface{} {
"pci_slot": v.PCISlot,
"bus_number": v.BusNumber,
"qos": flattenVinsQOS(v.QOS),
"security_groups": v.SecGroups,
"sdn_interface_id": v.SDNInterfaceID,
"target": v.Target,
"type": v.Type,
@@ -463,6 +473,7 @@ func flattenVinsList(vl *vins.ListVINS) []map[string]interface{} {
"deleted_by": v.DeletedBy,
"deleted_time": v.DeletedTime,
"description": v.Description,
"enable_secgroups": v.EnableSecGroups,
"external_ip": v.ExternalIP,
"extnet_id": v.ExtnetId,
"free_ips": v.FreeIPs,

View File

@@ -115,6 +115,12 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface
}
}
if d.Get("enable_secgroups").(bool) {
if err := resourceVinsEnableSecgroups(ctx, d, m, vinsID); err != nil {
warnings.Add(err)
}
}
return append(warnings.Get(), resourceVinsRead(ctx, d, m)...)
}
@@ -257,6 +263,13 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
}
}
if d.HasChanges("name", "desc", "enable_secgroups") {
vinsID := uint64(d.Get("vins_id").(int))
if err := utilityUpdateVINS(ctx, d, m, vinsID); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("enable") {
if err := resourceVinsChangeEnabled(ctx, d, m); err != nil {
warnings.Add(err)
@@ -424,6 +437,21 @@ func resourceVinsIpReserve(ctx context.Context, d *schema.ResourceData, m interf
return errs
}
func resourceVinsEnableSecgroups(ctx context.Context, d *schema.ResourceData, m interface{}, vinsID uint64) error {
c := m.(*controller.ControllerCfg)
req := vins.UpdateRequest{
VINSID: vinsID,
EnableSecGroups: true,
}
_, err := c.CloudBroker().VINS().Update(ctx, req)
if err != nil {
return err
}
return nil
}
func resourceVinsNatRuleAdd(ctx context.Context, d *schema.ResourceData, m interface{}, vinsId uint64) []error {
var errs []error
c := m.(*controller.ControllerCfg)

View File

@@ -166,6 +166,10 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "enabled",
},
"enable_secgroups": {
Type: schema.TypeBool,
Computed: true,
},
"flipgroup_id": {
Type: schema.TypeInt,
Computed: true,
@@ -294,6 +298,13 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"security_groups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"target": {
Type: schema.TypeString,
Computed: true,
@@ -315,6 +326,10 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
},
},
},
"live_migration_job_id": {
Type: schema.TypeInt,
Computed: true,
},
"lock_status": {
Type: schema.TypeString,
Computed: true,
@@ -357,6 +372,10 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"zone_id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
@@ -756,6 +775,10 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "type",
},
"zone_id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
@@ -911,6 +934,42 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "pure virtual",
},
"routes": {
Type: schema.TypeList,
Computed: true,
Description: "routes",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"route_id": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"destination": {
Type: schema.TypeString,
Computed: true,
},
"netmask": {
Type: schema.TypeString,
Computed: true,
},
"gateway": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"status": {
Type: schema.TypeString,
Computed: true,
@@ -926,6 +985,10 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "type",
},
"zone_id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
@@ -1095,6 +1158,42 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "pure virtual",
},
"routes": {
Type: schema.TypeList,
Computed: true,
Description: "routes",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"route_id": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"destination": {
Type: schema.TypeString,
Computed: true,
},
"netmask": {
Type: schema.TypeString,
Computed: true,
},
"gateway": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"status": {
Type: schema.TypeString,
Computed: true,
@@ -1110,6 +1209,10 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "type",
},
"zone_id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
@@ -1188,6 +1291,11 @@ func dataSourceVinsListSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "Page size",
},
"zone_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Zone ID",
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -1249,6 +1357,10 @@ func dataSourceVinsListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"enable_secgroups": {
Type: schema.TypeBool,
Computed: true,
},
"external_ip": {
Type: schema.TypeString,
Computed: true,
@@ -1386,7 +1498,7 @@ func dataSourceVinsListSchemaMake() map[string]*schema.Schema {
},
"entry_count": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "entry count",
},
}
@@ -1898,6 +2010,12 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "zone id",
},
"enable_secgroups": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "enable security groups",
},
"gid": {
Type: schema.TypeInt,
Optional: true,
@@ -2276,6 +2394,10 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "enabled",
},
"enable_secgroups": {
Type: schema.TypeBool,
Computed: true,
},
"flipgroup_id": {
Type: schema.TypeInt,
Computed: true,
@@ -2372,9 +2494,8 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
Description: "pci slot",
},
"bus_number": {
Type: schema.TypeInt,
Computed: true,
Description: "bus number",
Type: schema.TypeInt,
Computed: true,
},
"qos": {
Type: schema.TypeList,
@@ -2401,6 +2522,17 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
},
},
},
"sdn_interface_id": {
Type: schema.TypeString,
Computed: true,
},
"security_groups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"target": {
Type: schema.TypeString,
Computed: true,
@@ -2422,6 +2554,10 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
},
},
},
"live_migration_job_id": {
Type: schema.TypeInt,
Computed: true,
},
"lock_status": {
Type: schema.TypeString,
Computed: true,
@@ -2464,6 +2600,10 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"zone_id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
@@ -2751,6 +2891,47 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "prune virtual",
},
"routes": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_ids": {
Type: schema.TypeList,
Computed: true,
Description: "compute ids",
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"route_id": {
Type: schema.TypeInt,
Computed: true,
Description: "route id",
},
"guid": {
Type: schema.TypeString,
Computed: true,
Description: "guid",
},
"destination": {
Type: schema.TypeString,
Computed: true,
Description: "destination",
},
"netmask": {
Type: schema.TypeString,
Computed: true,
Description: "net mask",
},
"gateway": {
Type: schema.TypeString,
Computed: true,
Description: "gateway",
},
},
},
},
"status": {
Type: schema.TypeString,
Computed: true,
@@ -2766,6 +2947,10 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "type",
},
"zone_id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
@@ -2921,6 +3106,42 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "pure virtual",
},
"routes": {
Type: schema.TypeList,
Computed: true,
Description: "routes",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"route_id": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"destination": {
Type: schema.TypeString,
Computed: true,
},
"netmask": {
Type: schema.TypeString,
Computed: true,
},
"gateway": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"status": {
Type: schema.TypeString,
Computed: true,
@@ -2936,6 +3157,10 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "type",
},
"zone_id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
@@ -3105,6 +3330,42 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "pure virtual",
},
"routes": {
Type: schema.TypeList,
Computed: true,
Description: "routes",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"route_id": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"destination": {
Type: schema.TypeString,
Computed: true,
},
"netmask": {
Type: schema.TypeString,
Computed: true,
},
"gateway": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"status": {
Type: schema.TypeString,
Computed: true,
@@ -3120,6 +3381,10 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "type",
},
"zone_id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},

View File

@@ -63,3 +63,27 @@ func utilityVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m int
return vins, nil
}
func utilityUpdateVINS(ctx context.Context, d *schema.ResourceData, m interface{}, vinsID uint64) error {
c := m.(*controller.ControllerCfg)
req := vins.UpdateRequest{
VINSID: vinsID,
}
if d.HasChange("name") {
req.Name = d.Get("name").(string)
}
if d.HasChange("desc") {
req.Desc = d.Get("desc").(string)
}
if d.HasChange("enable_secgroups") {
req.EnableSecGroups = d.Get("enable_secgroups").(bool)
}
_, err := c.CloudBroker().VINS().Update(ctx, req)
if err != nil {
return err
}
return nil
}

View File

@@ -78,6 +78,9 @@ func utilityVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m
if includeDeleted, ok := d.GetOk("include_deleted"); ok {
req.IncludeDeleted = includeDeleted.(bool)
}
if zoneID, ok := d.GetOk("zone_id"); ok {
req.ZoneID = uint64(zoneID.(int))
}
log.Debugf("utilityVinsListCheckPresence")
vinsList, err := c.CloudBroker().VINS().List(ctx, req)

View File

@@ -97,6 +97,55 @@ func dataSourceZoneSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
},
},
"account_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"compute_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"extnet_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"vins_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"lb_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"bservice_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"k8s_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
}
}

View File

@@ -52,6 +52,13 @@ func flattenZone(d *schema.ResourceData, item *zone.RecordZone) error {
d.Set("created_time", item.CreatedTime)
d.Set("updated_time", item.UpdatedTime)
d.Set("node_ids", item.NodeIDs)
d.Set("account_ids", item.AccountIDs)
d.Set("compute_ids", item.ComputeIDs)
d.Set("extnet_ids", item.ExtnetIDs)
d.Set("vins_ids", item.VinsIDs)
d.Set("lb_ids", item.LBIDs)
d.Set("bservice_ids", item.BserviceIDs)
d.Set("k8s_ids", item.K8SIDs)
log.Debugf("flattenZone: decoded RecordZone name %q / ID %d, complete",
item.Name, item.ID)

View File

@@ -113,7 +113,7 @@ func resourceZoneUpdate(ctx context.Context, d *schema.ResourceData, m interface
log.Debugf("resourceZoneUpdate: called Zone with id %d", zoneID)
if d.HasChanges("name,", "description", "node_ids") {
if d.HasChanges("name", "description", "node_ids") {
if err := utilityZoneUpdate(ctx, d, m, zoneID); err != nil {
return diag.FromErr(err)
}

View File

@@ -65,7 +65,7 @@ func utilityZoneCheckPresence(ctx context.Context, d *schema.ResourceData, m int
func utilityZoneUpdate(ctx context.Context, d *schema.ResourceData, m interface{}, zoneID uint64) error {
c := m.(*controller.ControllerCfg)
if d.HasChanges("name,", "description") {
if d.HasChanges("name", "description") {
req := zone.UpdateRequest{
ID: zoneID,
}