4.10.0
This commit is contained in:
@@ -85,6 +85,13 @@ func aclSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"emails": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return res
|
||||
@@ -292,6 +299,26 @@ func dataSourceAccountSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"zone_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"default_zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"acl": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
|
||||
@@ -61,7 +61,7 @@ func flattenAccountList(al *account.ListAccounts) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenRgAcl(rgAcls []account.RecordACL) []map[string]interface{} {
|
||||
func flattenRgAcl(rgAcls []account.ListRecordACL) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, rgAcl := range rgAcls {
|
||||
temp := map[string]interface{}{
|
||||
|
||||
@@ -36,6 +36,8 @@ func flattenAccount(d *schema.ResourceData, acc account.RecordAccount) error {
|
||||
d.Set("machines", flattenAccMachines(acc.Machines))
|
||||
d.Set("cpu_allocation_parameter", acc.CPUAllocationParameter)
|
||||
d.Set("cpu_allocation_ratio", acc.CPUAllocationRatio)
|
||||
d.Set("default_zone_id", acc.DefaultZoneID)
|
||||
d.Set("zone_ids", flattenZones(acc.ZoneIDs))
|
||||
|
||||
if username, ok := d.GetOk("username"); ok {
|
||||
d.Set("username", username)
|
||||
@@ -80,6 +82,7 @@ func flattenAccAcl(acls []account.RecordACL) []map[string]interface{} {
|
||||
"right": acls.Rights,
|
||||
"status": acls.Status,
|
||||
"type": acls.Type,
|
||||
"emails": acls.Emails,
|
||||
"user_group_id": acls.UgroupID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
@@ -165,3 +168,15 @@ func flattenAccResourceConsumption(lrc *account.ListResourceConsumption) []map[s
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenZones(zones []account.ZoneID) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, zone := range zones {
|
||||
temp := map[string]interface{}{
|
||||
"id": zone.ID,
|
||||
"name": zone.Name,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -34,13 +34,16 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"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/cloudapi/account"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/tasks"
|
||||
"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/status"
|
||||
@@ -116,11 +119,32 @@ func resourceAccountDelete(ctx context.Context, d *schema.ResourceData, m interf
|
||||
Permanently: d.Get("permanently").(bool),
|
||||
}
|
||||
|
||||
_, err = c.CloudAPI().Account().Delete(ctx, req)
|
||||
taskID, err := c.CloudAPI().Account().Delete(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
taskReq := tasks.GetRequest{
|
||||
AuditID: strings.Trim(taskID, `"`),
|
||||
}
|
||||
|
||||
for {
|
||||
time.Sleep(time.Second * 5)
|
||||
task, err := c.CloudAPI().Tasks().Get(ctx, taskReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
log.Debugf("resourceAccountDelete: delete account - %s", task.Stage)
|
||||
|
||||
if task.Completed {
|
||||
if task.Error != "" {
|
||||
return diag.FromErr(fmt.Errorf("cannot delete account: %v", task.Error))
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
@@ -153,11 +177,32 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
AccountID: accountId,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().Account().Restore(ctx, req)
|
||||
taskID, err := c.CloudAPI().Account().Restore(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
taskReq := tasks.GetRequest{
|
||||
AuditID: strings.Trim(taskID, `"`),
|
||||
}
|
||||
|
||||
for {
|
||||
time.Sleep(time.Second * 5)
|
||||
task, err := c.CloudAPI().Tasks().Get(ctx, taskReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
log.Debugf("resourceAccountUpdate: restore account - %s", task.Stage)
|
||||
|
||||
if task.Completed {
|
||||
if task.Error != "" {
|
||||
return diag.FromErr(fmt.Errorf("cannot restore account: %v", task.Error))
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
hasChanged = true
|
||||
}
|
||||
case status.Disabled:
|
||||
@@ -176,7 +221,6 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
if d.HasChange("enable") {
|
||||
reqSwitch := account.DisableEnableRequest{
|
||||
AccountID: accountId,
|
||||
Reason: d.Get("reason").(string),
|
||||
}
|
||||
enable := d.Get("enable").(bool)
|
||||
|
||||
@@ -285,6 +329,18 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("default_zone_id") {
|
||||
req.DefaultZoneID = uint64(d.Get("default_zone_id").(int))
|
||||
updated = true
|
||||
}
|
||||
|
||||
if updated {
|
||||
_, err := c.CloudAPI().Account().Update(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("users") {
|
||||
deletedUsers := make([]interface{}, 0)
|
||||
addedUsers := make([]interface{}, 0)
|
||||
@@ -431,10 +487,19 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
|
||||
},
|
||||
},
|
||||
},
|
||||
"reason": {
|
||||
Type: schema.TypeString,
|
||||
"default_zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "reason for deactivation",
|
||||
Computed: true,
|
||||
Description: "email",
|
||||
},
|
||||
"zone_ids": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"restore": {
|
||||
Type: schema.TypeBool,
|
||||
|
||||
@@ -73,6 +73,10 @@ func dataSourceBasicServiceSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"computes": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
|
||||
@@ -68,6 +68,7 @@ func flattenBasicServiceList(bsl *bservice.ListBasicServices) []map[string]inter
|
||||
"updated_by": bs.UpdatedBy,
|
||||
"updated_time": bs.UpdatedTime,
|
||||
"user_managed": bs.UserManaged,
|
||||
"zone_id": bs.ZoneID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
@@ -183,6 +184,10 @@ func dataSourceBasicServiceListSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"groups": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
|
||||
@@ -86,6 +86,7 @@ func flattenService(d *schema.ResourceData, bs *bservice.RecordBasicService) {
|
||||
d.Set("updated_by", bs.UpdatedBy)
|
||||
d.Set("updated_time", bs.UpdatedTime)
|
||||
d.Set("user_managed", bs.UserManaged)
|
||||
d.Set("zone_id", bs.ZoneID)
|
||||
}
|
||||
|
||||
func flattenBasicServiceComputes(bscs bservice.ListComputes) []map[string]interface{} {
|
||||
|
||||
@@ -64,6 +64,9 @@ func resourceBasicServiceCreate(ctx context.Context, d *schema.ResourceData, m i
|
||||
req.Name = d.Get("service_name").(string)
|
||||
req.RGID = uint64(d.Get("rg_id").(int))
|
||||
|
||||
if zoneID, ok := d.GetOk("zone_id"); ok {
|
||||
req.ZoneID = uint64(zoneID.(int))
|
||||
}
|
||||
if sshKey, ok := d.GetOk("ssh_key"); ok {
|
||||
req.SSHKey = sshKey.(string)
|
||||
}
|
||||
@@ -314,6 +317,43 @@ func resourceBasicServiceUpdate(ctx context.Context, d *schema.ResourceData, m i
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("zone_id") {
|
||||
zoneID := uint64(d.Get("zone_id").(int))
|
||||
|
||||
start := d.Get("start").(bool)
|
||||
if start {
|
||||
reqStop := bservice.StopRequest{
|
||||
ServiceID: uint64(d.Get("service_id").(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().BService().Stop(ctx, reqStop)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
req := bservice.MigrateToZoneRequest{
|
||||
ServiceID: uint64(d.Get("service_id").(int)),
|
||||
ZoneID: zoneID,
|
||||
}
|
||||
|
||||
_, err = c.CloudAPI().BService().MigrateToZone(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if start {
|
||||
startReq := bservice.StartRequest{
|
||||
ServiceID: uint64(d.Get("service_id").(int)),
|
||||
}
|
||||
|
||||
_, err = c.CloudAPI().BService().Start(ctx, startReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("start") {
|
||||
if d.Get("start").(bool) {
|
||||
req := bservice.StartRequest{
|
||||
@@ -444,6 +484,12 @@ func resourceBasicServiceSchemaMake() map[string]*schema.Schema {
|
||||
Required: true,
|
||||
Description: "ID of the Resource Group where this service will be placed",
|
||||
},
|
||||
"zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "ID of the zone where this service will be placed",
|
||||
},
|
||||
"ssh_key": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
|
||||
@@ -158,7 +158,7 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "IDs of images using the disk",
|
||||
},
|
||||
|
||||
@@ -221,7 +221,7 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "IDs of images using the disk",
|
||||
},
|
||||
|
||||
@@ -214,7 +214,7 @@ func dataSourceDiskListUnattachedSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "IDs of images using the disk",
|
||||
},
|
||||
|
||||
@@ -175,7 +175,7 @@ func dataSourceDiskReplicationSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "IDs of images using the disk",
|
||||
},
|
||||
|
||||
@@ -211,7 +211,7 @@ func dataSourceDiskDeletedListSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "IDs of images using the disk",
|
||||
},
|
||||
|
||||
@@ -580,7 +580,7 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "IDs of images using the disk",
|
||||
},
|
||||
|
||||
@@ -336,7 +336,7 @@ func resourceDiskReplicationSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "IDs of images using the disk",
|
||||
},
|
||||
|
||||
@@ -167,6 +167,10 @@ func dataSourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"ipcidr": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@@ -183,9 +187,21 @@ func dataSourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"network_id": {
|
||||
Type: schema.TypeInt,
|
||||
"network_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"primary": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"secondary": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"pre_reservations_num": {
|
||||
Type: schema.TypeInt,
|
||||
@@ -277,6 +293,62 @@ func dataSourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"redundant": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"sec_vnfdev_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"mtu": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"pre_reservations": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"client_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"domain_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"hostname": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"mac": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"vm_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func flattenExtnet(d *schema.ResourceData, e *extnet.RecordExtNet) {
|
||||
d.Set("milestones", e.Milestones)
|
||||
d.Set("net_name", e.Name)
|
||||
d.Set("network", e.Network)
|
||||
d.Set("network_id", e.NetworkID)
|
||||
d.Set("network_ids", flattenNetworkIDs(e.NetworkIDs))
|
||||
d.Set("ntp", e.NTP)
|
||||
d.Set("pre_reservations_num", e.PreReservationsNum)
|
||||
d.Set("prefix", e.Prefix)
|
||||
@@ -33,6 +33,11 @@ func flattenExtnet(d *schema.ResourceData, e *extnet.RecordExtNet) {
|
||||
d.Set("status", e.Status)
|
||||
d.Set("vlan_id", e.VLANID)
|
||||
d.Set("vnfs", flattenExtnetVNFS(e.VNFs))
|
||||
d.Set("zone_id", e.ZoneID)
|
||||
d.Set("pre_reservations", flattenExtnetReservations(e.PreReservations))
|
||||
d.Set("sec_vnfdev_id", e.SecVNFDevID)
|
||||
d.Set("redundant", e.Redundant)
|
||||
d.Set("mtu", e.MTU)
|
||||
}
|
||||
|
||||
func flattenExcluded(ex []extnet.Excluded) []map[string]interface{} {
|
||||
@@ -163,3 +168,14 @@ func flattenExtnetReservedIp(el []extnet.RecordReservedIP) []map[string]interfac
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenNetworkIDs(ex extnet.NetworkIDs) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, 1)
|
||||
temp := map[string]interface{}{
|
||||
"primary": ex.Primary,
|
||||
"secondary": ex.Secondary,
|
||||
}
|
||||
res = append(res, temp)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -57,7 +57,6 @@ func resourceFlipgroupCreate(ctx context.Context, d *schema.ResourceData, m inte
|
||||
Name: d.Get("name").(string),
|
||||
NetType: d.Get("net_type").(string),
|
||||
NetID: uint64(d.Get("net_id").(int)),
|
||||
ClientType: d.Get("client_type").(string),
|
||||
IP: d.Get("ip").(string),
|
||||
Description: d.Get("desc").(string),
|
||||
}
|
||||
@@ -72,6 +71,10 @@ func resourceFlipgroupCreate(ctx context.Context, d *schema.ResourceData, m inte
|
||||
|
||||
var warnings dc.Warnings
|
||||
|
||||
if clientType, ok := d.GetOk("client_type"); ok {
|
||||
req.ClientType = clientType.(string)
|
||||
}
|
||||
|
||||
if client_ids, ok := d.GetOk("client_ids"); ok {
|
||||
casted := client_ids.([]interface{})
|
||||
addComputesAfterCreation(ctx, &warnings, c, casted, resp.ID)
|
||||
@@ -180,7 +183,8 @@ func resourceFlipgroupSchemaMake() map[string]*schema.Schema {
|
||||
},
|
||||
"client_type": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Optional: true,
|
||||
Default: "compute",
|
||||
Description: "Type of client, 'compute' ('vins' will be later)",
|
||||
ValidateFunc: validation.StringInSlice([]string{"compute"}, true),
|
||||
},
|
||||
|
||||
@@ -35,6 +35,7 @@ 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 resourceImageSchemaMake(sch map[string]*schema.Schema) map[string]*schema.Schema {
|
||||
@@ -125,19 +126,13 @@ func resourceImageSchemaMake(sch map[string]*schema.Schema) map[string]*schema.S
|
||||
Description: "storage endpoint provider ID",
|
||||
}
|
||||
|
||||
sch["architecture"] = &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"X86_64"}, true),
|
||||
Description: "binary architecture of this image, one of X86_64",
|
||||
}
|
||||
|
||||
sch["drivers"] = &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Required: true,
|
||||
Type: schema.TypeList,
|
||||
Required: true,
|
||||
StateFunc: statefuncs.StateFuncToUpper,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Type: schema.TypeString,
|
||||
ValidateFunc: validation.StringInSlice([]string{"KVM_X86"}, false),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -149,5 +144,12 @@ func resourceImageSchemaMake(sch map[string]*schema.Schema) map[string]*schema.S
|
||||
Description: "select a network interface naming pattern for your Linux machine. eth - onboard, ens - pci slot naming",
|
||||
}
|
||||
|
||||
sch["sync_mode"] = &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "Create image from a media identified by URL (in synchronous mode)",
|
||||
}
|
||||
|
||||
return sch
|
||||
}
|
||||
|
||||
@@ -34,12 +34,16 @@ package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"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/cloudapi/image"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/tasks"
|
||||
"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/status"
|
||||
@@ -94,17 +98,56 @@ func resourceImageCreate(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
if poolName, ok := d.GetOk("pool_name"); ok {
|
||||
req.Pool = poolName.(string)
|
||||
}
|
||||
if architecture, ok := d.GetOk("architecture"); ok {
|
||||
req.Architecture = architecture.(string)
|
||||
}
|
||||
if networkInterfaceNaming, ok := d.GetOk("network_interface_naming"); ok {
|
||||
req.NetworkInterfaceNaming = networkInterfaceNaming.(string)
|
||||
}
|
||||
|
||||
imageId, err := c.CloudAPI().Image().Create(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
syncMode := d.Get("sync_mode").(bool)
|
||||
var imageId uint64
|
||||
|
||||
if syncMode {
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
imageId, err = c.CloudAPI().Image().Create(ctx, req)
|
||||
log.Debugf("resourceImageCreate: imageID = %d", imageId)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
taskID, err := c.CloudAPI().Image().AsyncCreate(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
taskReq := tasks.GetRequest{
|
||||
AuditID: strings.Trim(taskID, `"`),
|
||||
}
|
||||
|
||||
for {
|
||||
time.Sleep(time.Second * 15)
|
||||
task, err := c.CloudAPI().Tasks().Get(ctx, taskReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
log.Debugf("resourceAccountDelete: delete account - %s", task.Stage)
|
||||
|
||||
if task.Completed {
|
||||
if task.Error != "" {
|
||||
return diag.FromErr(fmt.Errorf("cannot delete account: %v", task.Error))
|
||||
}
|
||||
id, err := task.Result.ID()
|
||||
imageId = uint64(id)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
d.SetId(strconv.FormatUint(imageId, 10))
|
||||
|
||||
@@ -76,12 +76,11 @@ func resourceImageFromPlatformDiskCreate(ctx context.Context, d *schema.Resource
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := disks.FromPlatformDiskRequest{
|
||||
DiskID: diskId,
|
||||
Name: name,
|
||||
BootType: d.Get("boot_type").(string),
|
||||
ImageType: d.Get("type").(string),
|
||||
Architecture: d.Get("architecture").(string),
|
||||
Bootable: d.Get("bootable").(bool), // default value - true
|
||||
DiskID: diskId,
|
||||
Name: name,
|
||||
BootType: d.Get("boot_type").(string),
|
||||
ImageType: d.Get("type").(string),
|
||||
Bootable: d.Get("bootable").(bool), // default value - true
|
||||
}
|
||||
|
||||
if username, ok := d.GetOk("username"); ok {
|
||||
@@ -292,13 +291,6 @@ func resourceImageFromPlatformDiskSchemaMake() map[string]*schema.Schema {
|
||||
ValidateFunc: validation.StringInSlice([]string{"linux", "windows", "unknown"}, true),
|
||||
Description: "Image type linux, windows or unknown",
|
||||
},
|
||||
"architecture": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"X86_64"}, true),
|
||||
Description: "binary architecture of this image, one of X86_64",
|
||||
},
|
||||
|
||||
"username": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
@@ -357,6 +349,10 @@ func resourceImageFromPlatformDiskSchemaMake() map[string]*schema.Schema {
|
||||
Description: "create an image in async/sync mode",
|
||||
},
|
||||
|
||||
"architecture": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"image_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
|
||||
@@ -62,10 +62,6 @@ func utilityImageListCheckPresence(ctx context.Context, d *schema.ResourceData,
|
||||
req.Status = status.(string)
|
||||
}
|
||||
|
||||
if architecture, ok := d.GetOk("architecture"); ok {
|
||||
req.Architecture = architecture.(string)
|
||||
}
|
||||
|
||||
if typeImage, ok := d.GetOk("type_image"); ok {
|
||||
req.TypeImage = typeImage.(string)
|
||||
}
|
||||
|
||||
@@ -337,6 +337,10 @@ func dataSourceK8sSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"account_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
|
||||
@@ -217,6 +217,10 @@ func createK8sListSchema() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"ci_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
|
||||
@@ -259,6 +259,7 @@ func flattenK8sData(d *schema.ResourceData, cluster k8s.RecordK8S, masters []com
|
||||
d.Set("address_vip", flattenAddressVIP(cluster.AddressVIP))
|
||||
d.Set("extnet_only", cluster.ExtnetOnly)
|
||||
d.Set("with_lb", cluster.WithLB)
|
||||
d.Set("zone_id", cluster.ZoneID)
|
||||
}
|
||||
|
||||
func flattenAddressVIP(addressVIP k8s.K8SAddressVIP) []map[string]interface{} {
|
||||
@@ -333,6 +334,7 @@ func flattenK8sItems(k8sItems *k8s.ListK8SClusters) []map[string]interface{} {
|
||||
"updated_by": item.UpdatedBy,
|
||||
"updated_time": item.UpdatedTime,
|
||||
"vins_id": item.VINSID,
|
||||
"zone_id": item.ZoneID,
|
||||
"workers_groups": flattenWorkersGroup(item.WorkersGroup),
|
||||
}
|
||||
|
||||
@@ -369,6 +371,7 @@ func flattenResourceK8sCP(d *schema.ResourceData, k8s k8s.RecordK8S, masters []c
|
||||
d.Set("updated_by", k8s.UpdatedBy)
|
||||
d.Set("updated_time", k8s.UpdatedTime)
|
||||
d.Set("network_plugin", k8s.NetworkPlugin)
|
||||
d.Set("zone_id", k8s.ZoneID)
|
||||
|
||||
flattenCPParams(d, k8s.K8SGroups.Masters, masters)
|
||||
}
|
||||
@@ -412,6 +415,7 @@ func flattenResourceK8s(d *schema.ResourceData, k8s k8s.RecordK8S, masters []com
|
||||
d.Set("updated_time", k8s.UpdatedTime)
|
||||
d.Set("default_wg_id", k8s.K8SGroups.Workers[0].ID)
|
||||
d.Set("network_plugin", k8s.NetworkPlugin)
|
||||
d.Set("zone_id", k8s.ZoneID)
|
||||
}
|
||||
|
||||
func flattenWg(d *schema.ResourceData, wg k8s.ItemK8SGroup, computes []compute.RecordCompute) {
|
||||
|
||||
@@ -143,6 +143,10 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{
|
||||
}
|
||||
}
|
||||
|
||||
if zoneID, ok := d.GetOk("zone_id"); ok {
|
||||
createReq.ZoneID = uint64(zoneID.(int))
|
||||
}
|
||||
|
||||
createReq.WithLB = d.Get("with_lb").(bool)
|
||||
|
||||
///4.4.0
|
||||
@@ -514,6 +518,45 @@ func resourceK8sUpdate(ctx context.Context, d *schema.ResourceData, m interface{
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("zone_id") {
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
zoneID := uint64(d.Get("zone_id").(int))
|
||||
|
||||
start := d.Get("start").(bool)
|
||||
|
||||
if start {
|
||||
stopReq := k8s.StopRequest{
|
||||
K8SID: id,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().K8S().Stop(ctx, stopReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
req := k8s.MigrateToZoneRequest{
|
||||
K8SID: id,
|
||||
ZoneID: zoneID,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().K8S().MigrateToZone(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if start {
|
||||
startReq := k8s.StartRequest{
|
||||
K8SID: id,
|
||||
}
|
||||
|
||||
_, err = c.CloudAPI().K8S().Start(ctx, startReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("start") {
|
||||
if d.Get("start").(bool) {
|
||||
if cluster.TechStatus == "STOPPED" {
|
||||
@@ -622,6 +665,12 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
|
||||
Description: "Network plugin to be used",
|
||||
ValidateFunc: validation.StringInSlice([]string{"flannel", "weavenet", "calico"}, true),
|
||||
},
|
||||
"zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "ID of the zone to put the cluster into.",
|
||||
},
|
||||
"labels": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
|
||||
@@ -96,6 +96,10 @@ func resourceK8sCPCreate(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
createReq.WorkerGroupName = "temp"
|
||||
createReq.NetworkPlugin = d.Get("network_plugin").(string)
|
||||
|
||||
if zoneID, ok := d.GetOk("zone_id"); ok {
|
||||
createReq.ZoneID = uint64(zoneID.(int))
|
||||
}
|
||||
|
||||
if num, ok := d.GetOk("num"); ok {
|
||||
createReq.MasterNum = uint(num.(int))
|
||||
} else {
|
||||
@@ -532,6 +536,45 @@ func resourceK8sCPUpdate(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("zone_id") {
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
zoneID := uint64(d.Get("zone_id").(int))
|
||||
|
||||
start := d.Get("start").(bool)
|
||||
|
||||
if start {
|
||||
stopReq := k8s.StopRequest{
|
||||
K8SID: id,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().K8S().Stop(ctx, stopReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
req := k8s.MigrateToZoneRequest{
|
||||
K8SID: id,
|
||||
ZoneID: zoneID,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().K8S().MigrateToZone(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if start {
|
||||
startReq := k8s.StartRequest{
|
||||
K8SID: id,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().K8S().Start(ctx, startReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("num") {
|
||||
oldVal, newVal := d.GetChange("num")
|
||||
|
||||
@@ -637,6 +680,12 @@ func resourceK8sCPSchemaMake() map[string]*schema.Schema {
|
||||
Description: "Network plugin to be used",
|
||||
ValidateFunc: validation.StringInSlice([]string{"flannel", "weavenet", "calico"}, true),
|
||||
},
|
||||
"zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "ID of the zone to put the cluster into.",
|
||||
},
|
||||
"num": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
|
||||
@@ -334,10 +334,6 @@ func computeListDisksSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"order": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"params": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@@ -453,10 +449,6 @@ func computeListDisksSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"vmid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -565,6 +557,10 @@ func computeInterfacesSchemaMake() map[string]*schema.Schema {
|
||||
Schema: computeLibvirtSettingsSchemaMake(),
|
||||
},
|
||||
},
|
||||
"sdn_interface_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"target": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@@ -573,6 +569,10 @@ func computeInterfacesSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"trunk_tags": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"vnfs": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
@@ -826,6 +826,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"live_migration_job_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"manager_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
@@ -896,6 +900,37 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"qemu_guest": {
|
||||
Type: schema.TypeList,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"enabled_agent_features": {
|
||||
Type: schema.TypeList,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"last_update": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"user": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
Computed: true,
|
||||
},
|
||||
"ram": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
@@ -1086,6 +1121,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -237,6 +237,10 @@ func itemComputeSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"live_migration_job_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"manager_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
@@ -280,6 +284,37 @@ func itemComputeSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"qemu_guest": {
|
||||
Type: schema.TypeList,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"enabled_agent_features": {
|
||||
Type: schema.TypeList,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"last_update": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"user": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
Computed: true,
|
||||
},
|
||||
"ram": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
@@ -397,6 +432,10 @@ func itemComputeSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -88,8 +88,10 @@ func flattenInterfaces(interfaces compute.ListInterfaces) []map[string]interface
|
||||
"node_id": interfaceItem.NodeID,
|
||||
"pci_slot": interfaceItem.PCISlot,
|
||||
"qos": flattenQOS(interfaceItem.QOS),
|
||||
"sdn_interface_id": interfaceItem.SDNInterfaceID,
|
||||
"target": interfaceItem.Target,
|
||||
"type": interfaceItem.Type,
|
||||
"trunk_tags": interfaceItem.TrunkTags,
|
||||
"vnfs": interfaceItem.VNFs,
|
||||
"libvirt_settings": flattenLibvirtSettings(interfaceItem.LibvirtSettings),
|
||||
}
|
||||
@@ -175,50 +177,52 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
|
||||
customFields, _ := json.Marshal(compute.CustomFields)
|
||||
devices, _ := json.Marshal(compute.Devices)
|
||||
temp := map[string]interface{}{
|
||||
"acl": flattenListACL(compute.ACL),
|
||||
"account_id": compute.AccountID,
|
||||
"account_name": compute.AccountName,
|
||||
"affinity_label": compute.AffinityLabel,
|
||||
"affinity_rules": flattenListRules(compute.AffinityRules),
|
||||
"affinity_weight": compute.AffinityWeight,
|
||||
"anti_affinity_rules": flattenListRules(compute.AntiAffinityRules),
|
||||
"arch": compute.Architecture,
|
||||
"auto_start_w_node": compute.AutoStart,
|
||||
"boot_order": compute.BootOrder,
|
||||
"bootdisk_size": compute.BootDiskSize,
|
||||
"chipset": compute.Chipset,
|
||||
"cd_image_id": compute.CdImageId,
|
||||
"clone_reference": compute.CloneReference,
|
||||
"clones": compute.Clones,
|
||||
"computeci_id": compute.ComputeCIID,
|
||||
"cpu_pin": compute.CPUPin,
|
||||
"cpus": compute.CPU,
|
||||
"created_by": compute.CreatedBy,
|
||||
"created_time": compute.CreatedTime,
|
||||
"custom_fields": string(customFields),
|
||||
"deleted_by": compute.DeletedBy,
|
||||
"deleted_time": compute.DeletedTime,
|
||||
"desc": compute.Description,
|
||||
"devices": string(devices),
|
||||
"disks": flattenDisks(compute.Disks),
|
||||
"driver": compute.Driver,
|
||||
"gid": compute.GID,
|
||||
"guid": compute.GUID,
|
||||
"hp_backed": compute.HPBacked,
|
||||
"compute_id": compute.ID,
|
||||
"image_id": compute.ImageID,
|
||||
"interfaces": flattenInterfaces(compute.Interfaces),
|
||||
"lock_status": compute.LockStatus,
|
||||
"manager_id": compute.ManagerID,
|
||||
"manager_type": compute.ManagerType,
|
||||
"migrationjob": compute.MigrationJob,
|
||||
"milestones": compute.Milestones,
|
||||
"name": compute.Name,
|
||||
"need_reboot": compute.NeedReboot,
|
||||
"numa_affinity": compute.NumaAffinity,
|
||||
"numa_node_id": compute.NumaNodeId,
|
||||
"acl": flattenListACL(compute.ACL),
|
||||
"account_id": compute.AccountID,
|
||||
"account_name": compute.AccountName,
|
||||
"affinity_label": compute.AffinityLabel,
|
||||
"affinity_rules": flattenListRules(compute.AffinityRules),
|
||||
"affinity_weight": compute.AffinityWeight,
|
||||
"anti_affinity_rules": flattenListRules(compute.AntiAffinityRules),
|
||||
"arch": compute.Architecture,
|
||||
"auto_start_w_node": compute.AutoStart,
|
||||
"boot_order": compute.BootOrder,
|
||||
"bootdisk_size": compute.BootDiskSize,
|
||||
"chipset": compute.Chipset,
|
||||
"cd_image_id": compute.CdImageId,
|
||||
"clone_reference": compute.CloneReference,
|
||||
"clones": compute.Clones,
|
||||
"computeci_id": compute.ComputeCIID,
|
||||
"cpu_pin": compute.CPUPin,
|
||||
"cpus": compute.CPU,
|
||||
"created_by": compute.CreatedBy,
|
||||
"created_time": compute.CreatedTime,
|
||||
"custom_fields": string(customFields),
|
||||
"deleted_by": compute.DeletedBy,
|
||||
"deleted_time": compute.DeletedTime,
|
||||
"desc": compute.Description,
|
||||
"devices": string(devices),
|
||||
"disks": flattenDisks(compute.Disks),
|
||||
"driver": compute.Driver,
|
||||
"gid": compute.GID,
|
||||
"guid": compute.GUID,
|
||||
"hp_backed": compute.HPBacked,
|
||||
"compute_id": compute.ID,
|
||||
"image_id": compute.ImageID,
|
||||
"interfaces": flattenInterfaces(compute.Interfaces),
|
||||
"live_migration_job_id": compute.LiveMigrationJobID,
|
||||
"lock_status": compute.LockStatus,
|
||||
"manager_id": compute.ManagerID,
|
||||
"manager_type": compute.ManagerType,
|
||||
"migrationjob": compute.MigrationJob,
|
||||
"milestones": compute.Milestones,
|
||||
"name": compute.Name,
|
||||
"need_reboot": compute.NeedReboot,
|
||||
"numa_affinity": compute.NumaAffinity,
|
||||
"numa_node_id": compute.NumaNodeId,
|
||||
// "pinned": compute.Pinned,
|
||||
"preferred_cpu": compute.PreferredCPU,
|
||||
"qemu_guest": flattenQemuQuest(compute.QemuQuest),
|
||||
"ram": compute.RAM,
|
||||
"reference_id": compute.ReferenceID,
|
||||
"registered": compute.Registered,
|
||||
@@ -320,12 +324,13 @@ func flattenNetwork(networks []interface{}, interfaces compute.ListInterfaces) [
|
||||
|
||||
for _, network := range interfaces {
|
||||
temp := map[string]interface{}{
|
||||
"net_id": network.NetID,
|
||||
"net_type": network.NetType,
|
||||
"ip_address": network.IPAddress,
|
||||
"mac": network.MAC,
|
||||
"mtu": network.MTU,
|
||||
"weight": flattenNetworkWeight(networks, network.NetID, network.NetType),
|
||||
"net_id": network.NetID,
|
||||
"net_type": network.NetType,
|
||||
"ip_address": network.IPAddress,
|
||||
"mac": network.MAC,
|
||||
"mtu": network.MTU,
|
||||
"sdn_interface_id": network.SDNInterfaceID,
|
||||
"weight": flattenNetworkWeight(networks, network.NetID, network.NetType),
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
@@ -447,6 +452,7 @@ func flattenCompute(d *schema.ResourceData, computeRec compute.RecordCompute, pc
|
||||
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("enabled", false)
|
||||
if computeRec.Status == status.Enabled {
|
||||
@@ -557,7 +563,6 @@ func flattenListComputeDisks(disks compute.ListComputeDisks) []map[string]interf
|
||||
"login": disk.Login,
|
||||
"milestones": disk.Milestones,
|
||||
"name": disk.Name,
|
||||
"order": disk.Order,
|
||||
"params": disk.Params,
|
||||
"parent_id": disk.ParentID,
|
||||
"passwd": disk.Passwd,
|
||||
@@ -578,7 +583,6 @@ func flattenListComputeDisks(disks compute.ListComputeDisks) []map[string]interf
|
||||
"status": disk.Status,
|
||||
"tech_status": disk.TechStatus,
|
||||
"type": disk.Type,
|
||||
"vmid": disk.VMID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
@@ -656,6 +660,7 @@ func flattenDataCompute(d *schema.ResourceData, computeRec compute.RecordCompute
|
||||
d.Set("image_id", computeRec.ImageID)
|
||||
d.Set("image_name", computeRec.ImageName)
|
||||
d.Set("interfaces", flattenInterfaces(computeRec.Interfaces))
|
||||
d.Set("live_migration_job_id", computeRec.LiveMigrationJobID)
|
||||
d.Set("lock_status", computeRec.LockStatus)
|
||||
d.Set("manager_id", computeRec.ManagerID)
|
||||
d.Set("manager_type", computeRec.ManagerType)
|
||||
@@ -671,8 +676,9 @@ func flattenDataCompute(d *schema.ResourceData, computeRec compute.RecordCompute
|
||||
d.Set("natable_vins_network", computeRec.NatableVINSNetwork)
|
||||
d.Set("natable_vins_network_name", computeRec.NatableVINSNetworkName)
|
||||
d.Set("os_users", flattenOsUsers(computeRec.OSUsers))
|
||||
// d.Set("pinned", computeRec.Pinned)
|
||||
d.Set("pinned", computeRec.PinnedToStack)
|
||||
d.Set("preferred_CPU", computeRec.PreferredCPU)
|
||||
d.Set("qemu_guest", flattenQemuQuest(computeRec.QemuQuest))
|
||||
d.Set("ram", computeRec.RAM)
|
||||
d.Set("reference_id", computeRec.ReferenceID)
|
||||
d.Set("registered", computeRec.Registered)
|
||||
@@ -699,6 +705,7 @@ func flattenDataCompute(d *schema.ResourceData, computeRec compute.RecordCompute
|
||||
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)
|
||||
}
|
||||
|
||||
func flattenPCI(pciList compute.ListPCIDevices) []uint64 {
|
||||
@@ -867,3 +874,19 @@ func flattenVGPUs(vgpus []compute.VGPUItem) []map[string]interface{} {
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenQemuQuest(qemuQuest compute.QemuQuest) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
|
||||
temp := map[string]interface{}{
|
||||
"enabled": qemuQuest.Enabled,
|
||||
"enabled_agent_features": qemuQuest.EnabledAgentFeatures,
|
||||
"guid": qemuQuest.GUID,
|
||||
"last_update": uint64(qemuQuest.LastUpdate),
|
||||
"user": qemuQuest.User,
|
||||
}
|
||||
|
||||
res = append(res, temp)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -128,8 +128,8 @@ func networkSubresourceSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
StateFunc: statefuncs.StateFuncToUpper,
|
||||
ValidateFunc: validation.StringInSlice([]string{"EXTNET", "VINS", "VFNIC", "DPDK"}, false), // observe case while validating
|
||||
Description: "Type of the network for this connection, either EXTNET or VINS.",
|
||||
ValidateFunc: validation.StringInSlice([]string{"EXTNET", "VINS", "VFNIC", "DPDK", "SDN", "TRUNK"}, false), // observe case while validating
|
||||
Description: "Type of the network for this connection",
|
||||
},
|
||||
|
||||
"net_id": {
|
||||
@@ -169,6 +169,14 @@ func networkSubresourceSchemaMake() map[string]*schema.Schema {
|
||||
ValidateFunc: validation.IntBetween(1, 9216),
|
||||
Description: "Maximum transmission unit, used only for DPDK type, must be 1-9216",
|
||||
},
|
||||
|
||||
"sdn_interface_id": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
DiffSuppressFunc: networkSubresIPAddreDiffSupperss,
|
||||
Description: "unique_identifier of LogicalPort on SDN side",
|
||||
},
|
||||
}
|
||||
return rets
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/extnet"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/image"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/rg"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/trunk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vfpool"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
@@ -154,7 +155,7 @@ func existDPDKNetId(ctx context.Context, m interface{}, id int) (int, bool) {
|
||||
|
||||
dpdkList, err := c.CloudAPI().DPDKNet().List(ctx, req)
|
||||
if err != nil {
|
||||
log.Debugf("Unable to retrieve vfpool list, %s", err)
|
||||
log.Debugf("Unable to retrieve dpdk list, %s", err)
|
||||
return id, false
|
||||
}
|
||||
|
||||
@@ -165,6 +166,23 @@ func existDPDKNetId(ctx context.Context, m interface{}, id int) (int, bool) {
|
||||
return id, false
|
||||
}
|
||||
|
||||
func existTRUNKId(ctx context.Context, m interface{}, id int) (int, bool) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := trunk.ListRequest{IDs: []uint64{uint64(id)}}
|
||||
|
||||
trunkList, err := c.CloudAPI().Trunk().List(ctx, req)
|
||||
if err != nil {
|
||||
log.Debugf("Unable to retrieve trunk list, %s", err)
|
||||
return id, false
|
||||
}
|
||||
|
||||
if len(trunkList.Data) == 1 {
|
||||
return 0, true
|
||||
}
|
||||
|
||||
return id, false
|
||||
}
|
||||
|
||||
func isMoreThanOneDisksTypeB(ctx context.Context, disks interface{}) bool {
|
||||
count := 0
|
||||
|
||||
|
||||
@@ -78,6 +78,10 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
return diag.Errorf("resourceComputeCreate: can't create Compute because imageID %d is not allowed or does not exist", d.Get("image_id").(int))
|
||||
}
|
||||
|
||||
if zoneID, ok := d.GetOk("zone_id"); ok {
|
||||
createReqX86.ZoneID = uint64(zoneID.(int))
|
||||
}
|
||||
|
||||
if disks, ok := d.GetOk("disks"); ok {
|
||||
if isMoreThanOneDisksTypeB(ctx, disks) {
|
||||
return diag.Errorf("resourceComputeCreate: can't create Compute because block disks have more 1 disk type 'B'")
|
||||
@@ -106,6 +110,12 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
if dpdkId, ok := existDPDKNetId(ctx, m, networkData["net_id"].(int)); !ok {
|
||||
return diag.Errorf("resourceComputeCreate: can't create compute because DPDK ID %d is not allowed or does not exist", dpdkId)
|
||||
}
|
||||
case "TRUNK":
|
||||
if trunkId, ok := existTRUNKId(ctx, m, networkData["net_id"].(int)); !ok {
|
||||
return diag.Errorf("resourceComputeCreate: can't create compute because TRUNK ID %d is not allowed or does not exist", trunkId)
|
||||
}
|
||||
//TODO
|
||||
//SDN check
|
||||
default:
|
||||
continue
|
||||
}
|
||||
@@ -162,7 +172,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
NetID: uint64(netInterfaceVal["net_id"].(int)),
|
||||
}
|
||||
|
||||
if reqInterface.NetType == "DPDK" {
|
||||
if reqInterface.NetType == "DPDK" || reqInterface.NetType == "EXTNET" {
|
||||
reqInterface.MTU = uint64(netInterfaceVal["mtu"].(int))
|
||||
}
|
||||
|
||||
@@ -176,6 +186,11 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
reqInterface.MAC = macaddr.(string)
|
||||
}
|
||||
|
||||
sdnID, sdnSet := netInterfaceVal["sdn_interface_id"]
|
||||
if sdnSet {
|
||||
reqInterface.SDNInterfaceID = sdnID.(string)
|
||||
}
|
||||
|
||||
interfaces = append(interfaces, reqInterface)
|
||||
}
|
||||
|
||||
@@ -693,6 +708,12 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
return diag.Errorf("resourceComputeUpdate: can't update Compute because imageID %d not allowed or does not exist", d.Get("image_id").(int))
|
||||
}
|
||||
|
||||
if d.HasChange("zone_id") {
|
||||
if err := utilityComputeUpdateZoneID(ctx, d, m); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if disks, ok := d.GetOk("disks"); ok {
|
||||
if isMoreThanOneDisksTypeB(ctx, disks) {
|
||||
return diag.Errorf("resourceComputeUpdate: can't update Compute because block disks have more 1 disk type 'B'")
|
||||
@@ -721,6 +742,12 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
if dpdkId, ok := existDPDKNetId(ctx, m, networkData["net_id"].(int)); !ok {
|
||||
return diag.Errorf("resourceComputeCreate: can't create compute because DPDK ID %d is not allowed or does not exist", dpdkId)
|
||||
}
|
||||
case "TRUNK":
|
||||
if trunkId, ok := existTRUNKId(ctx, m, networkData["net_id"].(int)); !ok {
|
||||
return diag.Errorf("resourceComputeCreate: can't create compute because TRUNK ID %d is not allowed or does not exist", trunkId)
|
||||
}
|
||||
//TODO
|
||||
//SDNCheck
|
||||
default:
|
||||
continue
|
||||
}
|
||||
@@ -824,24 +851,6 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
log.Debugf("resourceComputeUpdate: enable=%s Compute ID %v after completing its resource configuration", d.Id(), enabled)
|
||||
}
|
||||
|
||||
if d.HasChange("started") {
|
||||
start := d.Get("started").(bool)
|
||||
if start {
|
||||
req := compute.StartRequest{ComputeID: computeRec.ID}
|
||||
|
||||
if _, err := c.CloudAPI().Compute().Start(ctx, req); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
if !start {
|
||||
req := compute.StopRequest{ComputeID: computeRec.ID}
|
||||
|
||||
if _, err := c.CloudAPI().Compute().Stop(ctx, req); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
oldSize, newSize := d.GetChange("boot_disk_size")
|
||||
if oldSize.(int) < newSize.(int) {
|
||||
req := compute.DiskResizeRequest{ComputeID: computeRec.ID}
|
||||
@@ -901,10 +910,10 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
}
|
||||
|
||||
// Note bene: numa_affinity, cpu_pin and hp_backed, cpu, ram are not allowed to be changed for compute in STARTED tech status.
|
||||
// Note bene: numa_affinity, cpu_pin, cpu, ram 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", "cpu", "ram") && d.Get("started").(bool) {
|
||||
isStopRequired = true
|
||||
}
|
||||
if isStopRequired {
|
||||
@@ -1698,6 +1707,27 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("started") {
|
||||
if d.Get("started").(bool) {
|
||||
req := compute.StartRequest{
|
||||
ComputeID: computeRec.ID,
|
||||
}
|
||||
if !isStopRequired {
|
||||
if _, err := c.CloudAPI().Compute().Start(ctx, req); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
req := compute.StopRequest{
|
||||
ComputeID: computeRec.ID,
|
||||
}
|
||||
if _, err := c.CloudAPI().Compute().Stop(ctx, req); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// we may reuse dataSourceComputeRead here as we maintain similarity
|
||||
// between Compute resource and Compute data source schemas
|
||||
|
||||
@@ -1977,7 +2007,7 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
|
||||
Required: true,
|
||||
// ForceNew: true,
|
||||
StateFunc: statefuncs.StateFuncToUpper,
|
||||
ValidateFunc: validation.StringInSlice([]string{"SVA_KVM_X86", "KVM_X86"}, false), // observe case while validating
|
||||
ValidateFunc: validation.StringInSlice([]string{"KVM_X86"}, false), // observe case while validating
|
||||
Description: "Hardware architecture of this compute instance.",
|
||||
},
|
||||
"cpu": {
|
||||
@@ -2008,6 +2038,11 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
|
||||
//ForceNew: true, //REDEPLOY
|
||||
Description: "ID of the OS image to base this compute instance on.",
|
||||
},
|
||||
"zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"chipset": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
|
||||
@@ -164,7 +164,7 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
|
||||
oldList := oldSet.(*schema.Set).List()
|
||||
newList := newSet.(*schema.Set).List()
|
||||
|
||||
detachMap, changeIpMap, changeMacMap, attachMap := differenceNetwork(oldList, newList)
|
||||
detachMap, changeIpMap, changeMacMap, changeMTUMap, attachMap := differenceNetwork(oldList, newList)
|
||||
|
||||
apiErrCount := 0
|
||||
var lastSavedError error
|
||||
@@ -266,6 +266,10 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
|
||||
req.MACAddr = netData["mac"].(string)
|
||||
}
|
||||
|
||||
if netData["sdn_interface_id"].(string) != "" {
|
||||
req.SDNInterfaceID = netData["sdn_interface_id"].(string)
|
||||
}
|
||||
|
||||
if req.NetType == "DPDK" {
|
||||
req.MTU = uint64(netData["mtu"].(int))
|
||||
}
|
||||
@@ -287,6 +291,24 @@ 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 {
|
||||
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req := compute.ChangeMTURequest{
|
||||
ComputeID: computeId,
|
||||
Interface: netData["mac"].(string),
|
||||
MTU: uint64(netData["mtu"].(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().Compute().ChangeMTU(ctx, req)
|
||||
if err != nil {
|
||||
log.Errorf("utilityComputeNetworksConfigure: failed to change MTU 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)
|
||||
@@ -385,17 +407,18 @@ func utilityComputeUpdatePciDevices(ctx context.Context, d *schema.ResourceData,
|
||||
return nil
|
||||
}
|
||||
|
||||
func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap, changeMacMap, attachMap []map[string]interface{}) {
|
||||
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)
|
||||
for _, oldNetwork := range oldList {
|
||||
oldMap := oldNetwork.(map[string]interface{})
|
||||
found := false
|
||||
for _, newNetwork := range newList {
|
||||
newMap := newNetwork.(map[string]interface{})
|
||||
if newMap["net_type"] == oldMap["net_type"] && newMap["net_id"] == oldMap["net_id"] && newMap["weight"] == oldMap["weight"] && (newMap["mtu"] == oldMap["mtu"] || newMap["mtu"].(int) == 0) {
|
||||
if compareNetwork(newMap, oldMap) {
|
||||
found = true
|
||||
if (newMap["net_type"].(string) == "EXTNET" || newMap["net_type"].(string) == "VINS") && (newMap["ip_address"] != oldMap["ip_address"] && newMap["ip_address"].(string) != "") {
|
||||
changeIpMap = append(changeIpMap, newMap)
|
||||
@@ -404,6 +427,9 @@ func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap,
|
||||
newMap["old_mac"] = oldMap["mac"]
|
||||
changeMacMap = append(changeMacMap, newMap)
|
||||
}
|
||||
if (newMap["net_type"].(string) == "EXTNET" || newMap["net_type"].(string) == "DPDK") && (newMap["mtu"] != oldMap["mtu"] && newMap["mtu"].(int) != 0) {
|
||||
changeMTUMap = append(changeMTUMap, newMap)
|
||||
}
|
||||
}
|
||||
if found {
|
||||
break
|
||||
@@ -420,7 +446,7 @@ func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap,
|
||||
found := false
|
||||
for _, oldNetwork := range oldList {
|
||||
oldMap := oldNetwork.(map[string]interface{})
|
||||
if newMap["net_type"] == oldMap["net_type"] && newMap["net_id"] == oldMap["net_id"] && newMap["weight"] == oldMap["weight"] && (newMap["mtu"] == oldMap["mtu"] || newMap["mtu"].(int) == 0) {
|
||||
if compareNetwork(newMap, oldMap) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
@@ -433,3 +459,29 @@ func differenceNetwork(oldList, newList []interface{}) (detachMap, changeIpMap,
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func compareNetwork(newMap, oldMap map[string]interface{}) bool {
|
||||
return newMap["net_type"] == oldMap["net_type"] && newMap["net_id"] == oldMap["net_id"] && newMap["sdn_interface_id"] == oldMap["sdn_interface_id"] && newMap["weight"] == oldMap["weight"]
|
||||
}
|
||||
|
||||
func utilityComputeUpdateZoneID(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
|
||||
req := compute.MigrateToZoneRequest{
|
||||
ComputeID: computeId,
|
||||
}
|
||||
|
||||
zoneID, ok := d.GetOk("zone_id")
|
||||
if ok {
|
||||
req.ZoneID = uint64(zoneID.(int))
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().Compute().MigrateToZone(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -121,10 +121,12 @@ func flattenResourceLB(d *schema.ResourceData, lb *lb.RecordLB) {
|
||||
d.Set("updated_time", lb.UpdatedTime)
|
||||
d.Set("user_managed", lb.UserManaged)
|
||||
d.Set("vins_id", lb.VINSID)
|
||||
d.Set("zone_id", lb.ZoneID)
|
||||
|
||||
}
|
||||
|
||||
func flattenLB(d *schema.ResourceData, lb *lb.RecordLB) {
|
||||
d.Set("account_id", lb.AccountID)
|
||||
d.Set("ha_mode", lb.HAMode)
|
||||
d.Set("backend_haip", lb.BackendHAIP)
|
||||
d.Set("backends", flattenLBBackends(lb.Backends))
|
||||
@@ -155,6 +157,7 @@ func flattenLB(d *schema.ResourceData, lb *lb.RecordLB) {
|
||||
d.Set("updated_time", lb.UpdatedTime)
|
||||
d.Set("user_managed", lb.UserManaged)
|
||||
d.Set("vins_id", lb.VINSID)
|
||||
d.Set("zone_id", lb.ZoneID)
|
||||
}
|
||||
|
||||
func flattenNode(node lb.RecordNode) []map[string]interface{} {
|
||||
@@ -289,6 +292,7 @@ func flattenLBList(lbl *lb.ListLB) []map[string]interface{} {
|
||||
"user_managed": lb.UserManaged,
|
||||
"vins_id": lb.VINSID,
|
||||
"lb_id": lb.ID,
|
||||
"zone_id": lb.ZoneID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
@@ -40,6 +40,10 @@ func dsLBSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
}
|
||||
sch["zone_id"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
}
|
||||
return sch
|
||||
}
|
||||
|
||||
@@ -191,5 +195,9 @@ func dsLBItemSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
}
|
||||
sch["zone_id"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
}
|
||||
return sch
|
||||
}
|
||||
|
||||
@@ -44,7 +44,11 @@ func lbResourceSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
}
|
||||
|
||||
sch["zone_id"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
}
|
||||
sch["extnet_id"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
@@ -78,7 +82,7 @@ func lbResourceSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
}
|
||||
|
||||
|
||||
sch["safe"] = &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Default: true,
|
||||
|
||||
@@ -36,6 +36,10 @@ import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
|
||||
func createLBSchema() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"ha_mode": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
|
||||
@@ -91,6 +91,9 @@ func resourceLBCreate(ctx context.Context, d *schema.ResourceData, m interface{}
|
||||
if haMode, ok := d.GetOk("ha_mode"); ok {
|
||||
req.HighlyAvailable = haMode.(bool)
|
||||
}
|
||||
if zoneID, ok := d.GetOk("zone_id"); ok {
|
||||
req.ZoneID = uint64(zoneID.(int))
|
||||
}
|
||||
if sysctlParams, ok := d.GetOk("sysctl_params"); ok {
|
||||
syscrlSliceMaps := sysctlParams.([]interface{})
|
||||
res := make([]map[string]interface{}, 0, len(syscrlSliceMaps))
|
||||
@@ -437,6 +440,44 @@ func resourceLBUpdate(ctx context.Context, d *schema.ResourceData, m interface{}
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("zone_id") {
|
||||
start := d.Get("start").(bool)
|
||||
|
||||
if start {
|
||||
reqStop := lb.StopRequest{
|
||||
LBID: uint64(d.Get("lb_id").(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().LB().Stop(ctx, reqStop)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
start = false
|
||||
}
|
||||
|
||||
req := lb.MigrateToZoneRequest{
|
||||
LBID: uint64(d.Get("lb_id").(int)),
|
||||
ZoneID: uint64(d.Get("zone_id").(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().LB().MigrateToZone(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if start {
|
||||
reqStart := lb.StartRequest{
|
||||
LBID: uint64(d.Get("lb_id").(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().LB().Start(ctx, reqStart)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("restart") {
|
||||
restart := d.Get("restart").(bool)
|
||||
if restart {
|
||||
|
||||
@@ -56,6 +56,7 @@ func flattenLocationsList(ll *locations.ListLocations) []map[string]interface{}
|
||||
"id": l.ID,
|
||||
"location_code": l.LocationCode,
|
||||
"name": l.Name,
|
||||
"network_modes": l.NetworkModes,
|
||||
"sdn_support": l.SDNSupport,
|
||||
}
|
||||
res = append(res, temp)
|
||||
@@ -170,6 +171,13 @@ func dataSourceLocationsListSchemaMake() map[string]*schema.Schema {
|
||||
Computed: true,
|
||||
Description: "Location name",
|
||||
},
|
||||
"network_modes": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"sdn_support": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
|
||||
@@ -26,6 +26,8 @@ type Location struct {
|
||||
Guid int `json:"guid"`
|
||||
LocationCode string `json:"locationCode"`
|
||||
Name string `json:"name"`
|
||||
NetworkModes []string `json:"network_modes"`
|
||||
SDNSupport bool `json:"sdn_support"`
|
||||
Flag string `json:"flag"`
|
||||
Meta []interface{} `json:"_meta"`
|
||||
CKey string `json:"_ckey"`
|
||||
|
||||
@@ -414,6 +414,10 @@ func dataSourceRgSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeFloat,
|
||||
Computed: true,
|
||||
},
|
||||
"sdn_access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -261,6 +261,10 @@ func dataSourceRgListSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"sdn_access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -115,6 +115,7 @@ func flattenResgroup(d *schema.ResourceData, details rg.RecordResourceGroup) err
|
||||
d.Set("vins", details.VINS)
|
||||
d.Set("cpu_allocation_parameter", details.CPUAllocationParameter)
|
||||
d.Set("cpu_allocation_ratio", details.CPUAllocationRatio)
|
||||
d.Set("sdn_access_group_id", details.SDNAccessGroupID)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -202,6 +203,7 @@ func flattenRg(d *schema.ResourceData, itemRg rg.RecordResourceGroup) {
|
||||
d.Set("vins", itemRg.VINS)
|
||||
d.Set("cpu_allocation_parameter", itemRg.CPUAllocationParameter)
|
||||
d.Set("cpu_allocation_ratio", itemRg.CPUAllocationRatio)
|
||||
d.Set("sdn_access_group_id", itemRg.SDNAccessGroupID)
|
||||
}
|
||||
|
||||
func flattenRgAudits(rgAudits rg.ListAudits) []map[string]interface{} {
|
||||
@@ -254,6 +256,7 @@ func flattenRgList(rgl *rg.ListResourceGroups) []map[string]interface{} {
|
||||
"uniq_pools": rg.UniqPools,
|
||||
"cpu_allocation_parameter": rg.CPUAllocationParameter,
|
||||
"cpu_allocation_ratio": rg.CPUAllocationRatio,
|
||||
"sdn_access_group_id": rg.SDNAccessGroupID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
@@ -160,6 +160,10 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter
|
||||
req.ExtIP = extIp.(string)
|
||||
}
|
||||
|
||||
if sdnAccessGroupID, ok := d.GetOk("sdn_access_group_id"); ok {
|
||||
req.SDNAccessGroupID = sdnAccessGroupID.(string)
|
||||
}
|
||||
|
||||
apiResp, err := c.CloudAPI().RG().Create(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
@@ -703,6 +707,12 @@ func ResourceRgSchemaMake() map[string]*schema.Schema {
|
||||
Default: true,
|
||||
Description: "flag for enable/disable RG",
|
||||
},
|
||||
"sdn_access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "ID of the SDN access group",
|
||||
},
|
||||
|
||||
"account_name": {
|
||||
Type: schema.TypeString,
|
||||
@@ -731,6 +741,14 @@ func ResourceRgSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"created_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"created_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
|
||||
45
internal/service/cloudapi/trunk/data_source_trunk.go
Normal file
45
internal/service/cloudapi/trunk/data_source_trunk.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package trunk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"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/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
|
||||
)
|
||||
|
||||
func dataSourceTrunkRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
|
||||
log.Debugf("dataSourceTrunkRead: called with name %s", d.Get("name").(string))
|
||||
|
||||
w := dc.Warnings{}
|
||||
trunkItem, err := utilityTrunkCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
flattenTrunk(d, trunkItem)
|
||||
|
||||
return w.Get()
|
||||
}
|
||||
|
||||
func DataSourceTrunk() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceTrunkRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceTrunkSchemaMake(),
|
||||
}
|
||||
}
|
||||
43
internal/service/cloudapi/trunk/data_source_trunk_list.go
Normal file
43
internal/service/cloudapi/trunk/data_source_trunk_list.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package trunk
|
||||
|
||||
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"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
|
||||
)
|
||||
|
||||
func dataSourceTrunkListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
w := dc.Warnings{}
|
||||
trunkList, err := utilityTrunkListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
|
||||
d.Set("items", flattenTrunkList(trunkList))
|
||||
d.Set("entry_count", trunkList.EntryCount)
|
||||
|
||||
return w.Get()
|
||||
}
|
||||
|
||||
func DataSourceTrunkList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceTrunkListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceTrunkListSchemaMake(),
|
||||
}
|
||||
}
|
||||
56
internal/service/cloudapi/trunk/flattens.go
Normal file
56
internal/service/cloudapi/trunk/flattens.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package trunk
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/trunk"
|
||||
)
|
||||
|
||||
func flattenTrunk(d *schema.ResourceData, trunkItem *trunk.ItemTrunk) {
|
||||
log.Debugf("flattenTrunk: decoded Trunk ID %d",
|
||||
trunkItem.ID)
|
||||
|
||||
d.Set("trunk_id", trunkItem.ID)
|
||||
d.Set("guid", trunkItem.GUID)
|
||||
d.Set("name", trunkItem.Name)
|
||||
d.Set("mac", trunkItem.MAC)
|
||||
d.Set("description", trunkItem.Description)
|
||||
d.Set("account_ids", trunkItem.AccountIDs)
|
||||
d.Set("ovs_bridge", trunkItem.OVSBridge)
|
||||
d.Set("native_vlan_id", trunkItem.NativeVLANID)
|
||||
d.Set("status", trunkItem.Status)
|
||||
d.Set("trunk_tags", trunkItem.TrunkTags)
|
||||
d.Set("created_at", trunkItem.CreatedAt)
|
||||
d.Set("created_by", trunkItem.CreatedBy)
|
||||
d.Set("updated_at", trunkItem.UpdatedAt)
|
||||
d.Set("updated_by", trunkItem.UpdatedBy)
|
||||
d.Set("deleted_at", trunkItem.DeletedAt)
|
||||
d.Set("deleted_by", trunkItem.DeletedBy)
|
||||
}
|
||||
|
||||
func flattenTrunkList(trunkList *trunk.ListTrunks) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(trunkList.Data))
|
||||
for _, trunkItem := range trunkList.Data {
|
||||
temp := map[string]interface{}{
|
||||
"account_ids": trunkItem.AccountIDs,
|
||||
"created_at": trunkItem.CreatedAt,
|
||||
"created_by": trunkItem.CreatedBy,
|
||||
"deleted_at": trunkItem.DeletedAt,
|
||||
"deleted_by": trunkItem.DeletedBy,
|
||||
"description": trunkItem.Description,
|
||||
"guid": trunkItem.GUID,
|
||||
"id": trunkItem.ID,
|
||||
"mac": trunkItem.MAC,
|
||||
"name": trunkItem.Name,
|
||||
"native_vlan_id": trunkItem.NativeVLANID,
|
||||
"ovs_bridge": trunkItem.OVSBridge,
|
||||
"status": trunkItem.Status,
|
||||
"trunk_tags": trunkItem.TrunkTags,
|
||||
"updated_at": trunkItem.UpdatedAt,
|
||||
"updated_by": trunkItem.UpdatedBy,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
241
internal/service/cloudapi/trunk/schema.go
Normal file
241
internal/service/cloudapi/trunk/schema.go
Normal file
@@ -0,0 +1,241 @@
|
||||
package trunk
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func dataSourceTrunkSchemaMake() map[string]*schema.Schema {
|
||||
log.Debugf("dataSourceTrunkSchemaMake: invoked")
|
||||
|
||||
res := map[string]*schema.Schema{
|
||||
"trunk_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "trunk id",
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "GUID",
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Name of the trunk",
|
||||
},
|
||||
"mac": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "MAC address",
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Description of the trunk",
|
||||
},
|
||||
"account_ids": {
|
||||
Type: schema.TypeSet,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "List of account IDs with access to this trunk",
|
||||
},
|
||||
"ovs_bridge": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "OVS bridge name",
|
||||
},
|
||||
"native_vlan_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Native VLAN ID",
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "if the trunk is enabled",
|
||||
},
|
||||
"trunk_tags": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "List of trunk tags (values between 1-4095)",
|
||||
},
|
||||
"created_at": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "when the trunk was created",
|
||||
},
|
||||
"created_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "who created the trunk",
|
||||
},
|
||||
"updated_at": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "when the trunk was updated",
|
||||
},
|
||||
"updated_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "who updated the trunk",
|
||||
},
|
||||
"deleted_at": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "when the trunk was updated",
|
||||
},
|
||||
"deleted_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "who updated the trunk",
|
||||
},
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func dataSourceTrunkListSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"trunk_ids": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "ID of the trunk(s) to filter by",
|
||||
},
|
||||
"account_ids": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "Account access ID(s) to filter by",
|
||||
},
|
||||
"trunk_tags": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "Trunk tags to filter by (value between 1-4095)",
|
||||
},
|
||||
"page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "Page number.",
|
||||
},
|
||||
"size": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "Page size.",
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "find by status",
|
||||
},
|
||||
"sort_by": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "Sort by one of supported fields, format ±<field>",
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"account_ids": {
|
||||
Type: schema.TypeSet,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "List of account IDs with access to this trunk",
|
||||
},
|
||||
"created_at": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "when the trunk was created",
|
||||
},
|
||||
"created_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "who created the trunk",
|
||||
},
|
||||
"deleted_at": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "when the trunk was updated",
|
||||
},
|
||||
"deleted_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "who updated the trunk",
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Description of the trunk",
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "GUID",
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Trunk ID",
|
||||
},
|
||||
"mac": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "MAC address",
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Name of the trunk",
|
||||
},
|
||||
"native_vlan_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Native VLAN ID",
|
||||
},
|
||||
"ovs_bridge": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "OVS bridge name",
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "if the trunk is enabled",
|
||||
},
|
||||
"trunk_tags": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "List of trunk tags (values between 1-4095)",
|
||||
},
|
||||
"updated_at": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "when the trunk was updated",
|
||||
},
|
||||
"updated_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "who updated the trunk",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
45
internal/service/cloudapi/trunk/utility_trunk.go
Normal file
45
internal/service/cloudapi/trunk/utility_trunk.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package trunk
|
||||
|
||||
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/cloudapi/trunk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityTrunkCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*trunk.ItemTrunk, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := trunk.GetRequest{}
|
||||
|
||||
if d.Get("trunk_id") != nil {
|
||||
if d.Get("trunk_id").(int) == 0 {
|
||||
id, err := strconv.ParseUint(d.Id(), 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.TrunkID = id
|
||||
} else {
|
||||
req.TrunkID = uint64(d.Get("trunk_id").(int))
|
||||
}
|
||||
} else {
|
||||
id, err := strconv.ParseUint(d.Id(), 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.TrunkID = id
|
||||
}
|
||||
|
||||
log.Debugf("utilityTrunkCheckPresence: get trunk network")
|
||||
|
||||
trunkItem, err := c.CloudAPI().Trunk().Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return trunkItem, nil
|
||||
}
|
||||
48
internal/service/cloudapi/trunk/utility_trunk_list.go
Normal file
48
internal/service/cloudapi/trunk/utility_trunk_list.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package trunk
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/trunk"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityTrunkListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*trunk.ListTrunks, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := trunk.ListRequest{}
|
||||
|
||||
if trunkIDs, ok := d.GetOk("trunk_ids"); ok {
|
||||
IDs := trunkIDs.([]interface{})
|
||||
for _, id := range IDs {
|
||||
req.IDs = append(req.IDs, uint64(id.(int)))
|
||||
}
|
||||
}
|
||||
if accountIDs, ok := d.GetOk("account_ids"); ok {
|
||||
IDs := accountIDs.([]interface{})
|
||||
for _, id := range IDs {
|
||||
req.AccountIDs = append(req.AccountIDs, uint64(id.(int)))
|
||||
}
|
||||
}
|
||||
if trunkTags, ok := d.GetOk("trunk_tags"); ok {
|
||||
req.TrunkTags = trunkTags.(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))
|
||||
}
|
||||
|
||||
log.Debugf("utilityTrunkListCheckPresence: load trunk network list")
|
||||
trunkList, err := c.CloudAPI().Trunk().List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return trunkList, nil
|
||||
}
|
||||
@@ -230,6 +230,10 @@ func vnfInterfaceSchemaMake() map[string]*schema.Schema {
|
||||
Schema: qosSchemaMake(),
|
||||
},
|
||||
},
|
||||
"sdn_interface_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"target": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@@ -674,13 +678,6 @@ func gwSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"routes": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: routesSchemaMake(),
|
||||
},
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@@ -813,13 +810,6 @@ func natSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"routes": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: routesSchemaMake(),
|
||||
},
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@@ -1008,6 +998,10 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return rets
|
||||
}
|
||||
|
||||
@@ -105,6 +105,7 @@ func flattenInterfaces(interfaces []vins.ItemVNFInterface) []map[string]interfac
|
||||
"pci_slot": vnfInterface.PCISlot,
|
||||
"bus_number": vnfInterface.BusNumber,
|
||||
"qos": flattenQOS(vnfInterface.QOS),
|
||||
"sdn_interface_id": vnfInterface.SDNInterfaceID,
|
||||
"target": vnfInterface.Target,
|
||||
"type": vnfInterface.Type,
|
||||
"vnfs": vnfInterface.VNFs,
|
||||
@@ -284,7 +285,6 @@ func flattenGW(gw vins.RecordGW) []map[string]interface{} {
|
||||
"owner_id": gw.OwnerID,
|
||||
"owner_type": gw.OwnerType,
|
||||
"pure_virtual": gw.PureVirtual,
|
||||
"routes": flattenStaticRoute(gw.Routes),
|
||||
"status": gw.Status,
|
||||
"tech_status": gw.TechStatus,
|
||||
"type": gw.Type,
|
||||
@@ -341,7 +341,6 @@ func flattenNAT(nat vins.RecordNAT) []map[string]interface{} {
|
||||
"owner_id": nat.OwnerID,
|
||||
"owner_type": nat.OwnerType,
|
||||
"pure_virtual": nat.PureVirtual,
|
||||
"routes": flattenStaticRoute(nat.Routes),
|
||||
"status": nat.Status,
|
||||
"tech_status": nat.TechStatus,
|
||||
"type": nat.Type,
|
||||
@@ -413,6 +412,7 @@ func flattenVins(d *schema.ResourceData, vins *vins.RecordVINS) {
|
||||
d.Set("vnfs", flattenVNFS(vins.VNFs))
|
||||
d.Set("vxlan_id", vins.VXLANID)
|
||||
d.Set("nat_rule", flattenRuleBlock(vins.VNFs.NAT.Config.Rules))
|
||||
d.Set("zone_id", vins.ZoneID)
|
||||
}
|
||||
|
||||
func flattenVinsData(d *schema.ResourceData, vins *vins.RecordVINS) {
|
||||
@@ -448,6 +448,7 @@ func flattenVinsData(d *schema.ResourceData, vins *vins.RecordVINS) {
|
||||
d.Set("user_managed", vins.UserManaged)
|
||||
d.Set("vnfs", flattenVNFS(vins.VNFs))
|
||||
d.Set("vxlan_id", vins.VXLANID)
|
||||
d.Set("zone_id", vins.ZoneID)
|
||||
}
|
||||
|
||||
func flattenVinsAudits(audits vins.ListAudits) []map[string]interface{} {
|
||||
|
||||
@@ -140,6 +140,10 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
}
|
||||
}
|
||||
|
||||
if zoneID, ok := d.GetOk("zone_id"); ok {
|
||||
req.ZoneID = uint64(zoneID.(int))
|
||||
}
|
||||
|
||||
id, err := c.CloudAPI().VINS().CreateInRG(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
@@ -173,6 +177,10 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
}
|
||||
}
|
||||
|
||||
if zoneID, ok := d.GetOk("zone_id"); ok {
|
||||
req.ZoneID = uint64(zoneID.(int))
|
||||
}
|
||||
|
||||
id, err := c.CloudAPI().VINS().CreateInAccount(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
@@ -676,6 +684,21 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("zone_id") {
|
||||
zoneID := uint64(d.Get("zone_id").(int))
|
||||
|
||||
req := vins.MigrateToZoneRequest{
|
||||
VINSID: vinsData.ID,
|
||||
ZoneID: zoneID,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().VINS().MigrateToZone(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
return append(warnings.Get(), resourceVinsRead(ctx, d, m)...)
|
||||
}
|
||||
|
||||
@@ -879,6 +902,12 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
|
||||
Computed: true,
|
||||
Description: "Unique ID of the ViNS. If ViNS ID is specified, then ViNS name, rg_id and account_id are ignored.",
|
||||
}
|
||||
rets["zone_id"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "ID of the Zone to put ViNS into",
|
||||
}
|
||||
|
||||
return rets
|
||||
}
|
||||
|
||||
116
internal/service/cloudapi/zone/data_source_zone.go
Normal file
116
internal/service/cloudapi/zone/data_source_zone.go
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
Copyright (c) 2019-2024 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package zone
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func dataSourceZoneRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
zone, err := utilityZoneCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("") // ensure ID is empty in this case
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
d.SetId(strconv.Itoa(d.Get("zone_id").(int)))
|
||||
flattenZone(d, zone)
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceZoneSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"deletable": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"created_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"node_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DataSourceZone() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceZoneRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceZoneSchemaMake(),
|
||||
}
|
||||
}
|
||||
182
internal/service/cloudapi/zone/data_source_zone_list.go
Normal file
182
internal/service/cloudapi/zone/data_source_zone_list.go
Normal file
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
Copyright (c) 2019-2024 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package zone
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func dataSourceZoneListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
zoneList, err := utilityZoneListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("") // ensure ID is empty in this case
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenZoneList(zoneList))
|
||||
d.Set("entry_count", zoneList.EntryCount)
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceZoneListSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"by_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "Find by ID",
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "Find by Grid ID",
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "Find by name",
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "Find by description",
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "Find by status",
|
||||
},
|
||||
"deletable": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Description: "Find by deletable",
|
||||
},
|
||||
"node_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "Find by nodeId",
|
||||
},
|
||||
"sort_by": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "sort by one of supported fields, format +|-(field)",
|
||||
},
|
||||
"page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "Page number",
|
||||
},
|
||||
"size": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "Page size",
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"zone_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"deletable": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"created_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"node_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func DataSourceZoneList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceZoneListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceZoneListSchemaMake(),
|
||||
}
|
||||
}
|
||||
82
internal/service/cloudapi/zone/flattens.go
Normal file
82
internal/service/cloudapi/zone/flattens.go
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
Copyright (c) 2019-2024 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package zone
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/zone"
|
||||
)
|
||||
|
||||
func flattenZone(d *schema.ResourceData, item *zone.RecordZone) error {
|
||||
log.Debugf("flattenZone: start decoding RecordZone name %q / ID %d",
|
||||
item.Name, item.ID)
|
||||
|
||||
d.Set("zone_id", int(item.ID))
|
||||
d.Set("guid", int(item.GUID))
|
||||
d.Set("gid", int(item.GID))
|
||||
d.Set("name", item.Name)
|
||||
d.Set("description", item.Description)
|
||||
d.Set("deletable", item.Deletable)
|
||||
d.Set("status", item.Status)
|
||||
d.Set("created_time", item.CreatedTime)
|
||||
d.Set("updated_time", item.UpdatedTime)
|
||||
d.Set("node_ids", item.NodeIDs)
|
||||
|
||||
log.Debugf("flattenZone: decoded RecordZone name %q / ID %d, complete",
|
||||
item.Name, item.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenZoneList(zone *zone.ListZones) []map[string]interface{} {
|
||||
log.Debugf("flattenZoneList start")
|
||||
res := make([]map[string]interface{}, 0, len(zone.Data))
|
||||
for _, zone := range zone.Data {
|
||||
temp := map[string]interface{}{
|
||||
"zone_id": int(zone.ID),
|
||||
"guid": int(zone.GUID),
|
||||
"gid": int(zone.GID),
|
||||
"name": zone.Name,
|
||||
"description": zone.Description,
|
||||
"deletable": zone.Deletable,
|
||||
"status": zone.Status,
|
||||
"created_time": zone.CreatedTime,
|
||||
"updated_time": zone.UpdatedTime,
|
||||
"node_ids": zone.NodeIDs,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
log.Debugf("flattenZoneList end")
|
||||
return res
|
||||
|
||||
}
|
||||
62
internal/service/cloudapi/zone/utility_zone.go
Normal file
62
internal/service/cloudapi/zone/utility_zone.go
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package zone
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/zone"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityZoneCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*zone.RecordZone, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := zone.GetRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
zoneId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.ID = zoneId
|
||||
} else {
|
||||
req.ID = uint64(d.Get("zone_id").(int))
|
||||
}
|
||||
|
||||
zoneData, err := c.CloudAPI().Zone().Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return zoneData, nil
|
||||
}
|
||||
85
internal/service/cloudapi/zone/utility_zone_list.go
Normal file
85
internal/service/cloudapi/zone/utility_zone_list.go
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package zone
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/zone"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityZoneListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*zone.ListZones, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := zone.ListRequest{}
|
||||
|
||||
if byId, ok := d.GetOk("by_id"); ok {
|
||||
req.ByID = uint64(byId.(int))
|
||||
}
|
||||
if gid, ok := d.GetOk("gid"); ok {
|
||||
req.GID = uint64(gid.(int))
|
||||
}
|
||||
if name, ok := d.GetOk("name"); ok {
|
||||
req.Name = name.(string)
|
||||
}
|
||||
if description, ok := d.GetOk("description"); ok {
|
||||
req.Description = description.(string)
|
||||
}
|
||||
if status, ok := d.GetOk("status"); ok {
|
||||
req.Status = status.(string)
|
||||
}
|
||||
if deletable, ok := d.GetOk("deletable"); ok {
|
||||
req.Deletable = deletable.(bool)
|
||||
}
|
||||
if nodeID, ok := d.GetOk("nodeId"); ok {
|
||||
req.NodeID = uint64(nodeID.(int))
|
||||
}
|
||||
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||
req.SortBy = sortBy.(string)
|
||||
}
|
||||
if size, ok := d.GetOk("size"); ok {
|
||||
req.Size = uint64(size.(int))
|
||||
}
|
||||
if page, ok := d.GetOk("page"); ok {
|
||||
req.Page = uint64(page.(int))
|
||||
}
|
||||
|
||||
zoneList, err := c.CloudAPI().Zone().List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return zoneList, nil
|
||||
}
|
||||
Reference in New Issue
Block a user