This commit is contained in:
2026-06-02 11:28:16 +03:00
parent af79f6ab3e
commit c734dcfff7
254 changed files with 10439 additions and 3751 deletions

View File

@@ -37,3 +37,4 @@ func DataSourceAccessGroupList() *schema.Resource {
Schema: dataSourceAccessGroupListSchemaMake(),
}
}

View File

@@ -54,6 +54,10 @@ func dataSourceAccessGroupListSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "filter by the upper limit of the creation date",
},
"owner_display_name": {
Type: schema.TypeString,
Optional: true,
},
"items": {
Type: schema.TypeList,
Computed: true,

View File

@@ -40,6 +40,9 @@ func utilityAccessGroupListCheckPresence(ctx context.Context, d *schema.Resource
if createdTo, ok := d.GetOk("created_to"); ok {
req.CreatedTo = createdTo.(string)
}
if ownerDisplayName, ok := d.GetOk("owner_display_name"); ok {
req.OwnerDisplayName = ownerDisplayName.(string)
}
log.Debugf("utilityAccessGroupListCheckPresence")
accessGroupList, err := c.SDN().AccessGroups().List(ctx, req)

View File

@@ -37,3 +37,4 @@ func DataSourceDefaultSecurityPolicyList() *schema.Resource {
Schema: dataSourceDefaultSecurityPolicyListSchemaMake(),
}
}

View File

@@ -366,3 +366,4 @@ func dataSourceDefaultSecurityPolicyListSchemaMake() map[string]*schema.Schema {
return res
}

View File

@@ -37,3 +37,4 @@ func utilityDefaultSecurityPolicyListCheckPresence(ctx context.Context, d *schem
return defaultSecurityPolicyList, nil
}

View File

@@ -0,0 +1,36 @@
package hypervisors
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceHypervisorRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
hypervisor, err := utilityHypervisorCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
flattenHypervisorDataSource(d, hypervisor)
d.SetId(hypervisor.Name)
return nil
}
func DataSourceHypervisor() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceHypervisorRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceHypervisorSchemaMake(),
}
}

View File

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

View File

@@ -0,0 +1,75 @@
package hypervisors
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/hypervisors"
)
func flattenHypervisorResource(d *schema.ResourceData, hypervisor *hypervisors.RecordHypervisor) {
d.Set("display_name", hypervisor.DisplayName)
d.Set("hostname", hypervisor.Hostname)
d.Set("ip", hypervisor.IP)
d.Set("name", hypervisor.Name)
d.Set("ports", flattenPorts(hypervisor.Ports))
d.Set("status", hypervisor.Status)
d.Set("created_at", hypervisor.CreatedAt)
d.Set("synced_at", hypervisor.SyncedAt)
}
func flattenHypervisorListDataSource(hypervisorList hypervisors.HypervisorsList) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(hypervisorList))
for _, v := range hypervisorList {
temp := map[string]interface{}{
"display_name": v.DisplayName,
"hostname": v.Hostname,
"ip": v.IP,
"name": v.Name,
"ports": flattenPorts(v.Ports),
"status": v.Status,
"created_at": v.CreatedAt,
"synced_at": v.SyncedAt,
}
res = append(res, temp)
}
return res
}
func flattenHypervisorDataSource(d *schema.ResourceData, hypervisor *hypervisors.RecordHypervisor) {
d.Set("display_name", hypervisor.DisplayName)
d.Set("hostname", hypervisor.Hostname)
d.Set("ip", hypervisor.IP)
d.Set("name", hypervisor.Name)
d.Set("ports", flattenPorts(hypervisor.Ports))
d.Set("status", hypervisor.Status)
d.Set("created_at", hypervisor.CreatedAt)
d.Set("synced_at", hypervisor.SyncedAt)
}
func flattenPorts(ports hypervisors.Ports) []map[string]interface{} {
final := make([]map[string]interface{}, 0)
res := map[string]interface{}{}
data := make([]map[string]interface{}, 0)
info := map[string]interface{}{}
for _, v := range ports.Data {
temp := map[string]interface{}{
"id": v.ID,
"unique_identifier": v.UniqueIdentifier,
"display_name": v.DisplayName,
"up": v.UP,
}
data = append(data, temp)
}
info["active_ports"] = ports.Info.ActivePorts
info["total_ports"] = ports.Info.TotalPorts
res["data"] = data
res["info"] = []interface{}{info}
final = append(final, res)
return final
}

View File

@@ -0,0 +1,87 @@
package hypervisors
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/hypervisors"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func resourceHypervisorCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
return diag.Errorf(
"It's impossible to create a hypervisor from terraform")
}
func resourceHypervisorRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
hypervisor, err := utilityHypervisorCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
flattenHypervisorResource(d, hypervisor)
d.SetId(hypervisor.Name)
return nil
}
func resourceHypervisorUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*controller.ControllerCfg)
req := hypervisors.UpdateDisplayNameRequest{
Name: d.Get("name").(string),
DisplayName: d.Get("display_name").(string),
}
_, err := c.SDN().Hypervisors().UpdateDisplayName(ctx, req)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
return resourceHypervisorRead(ctx, d, m)
}
func resourceHypervisorDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*controller.ControllerCfg)
req := hypervisors.DeleteRequest{
Name: d.Get("name").(string),
}
_, err := c.SDN().Hypervisors().Delete(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func ResourceHypervisor() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceHypervisorCreate,
ReadContext: resourceHypervisorRead,
UpdateContext: resourceHypervisorUpdate,
DeleteContext: resourceHypervisorDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout600s,
Read: &constants.Timeout300s,
Update: &constants.Timeout600s,
Delete: &constants.Timeout300s,
Default: &constants.Timeout300s,
},
Schema: resourceHypervisorSchemaMake(),
}
}

View File

@@ -0,0 +1,320 @@
package hypervisors
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func resourceHypervisorSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"display_name": {
Type: schema.TypeString,
Required: true,
},
"hostname": {
Type: schema.TypeString,
Computed: true,
},
"ip": {
Type: schema.TypeString,
Computed: true,
},
"ports": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"data": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"unique_identifier": {
Type: schema.TypeString,
Computed: true,
},
"display_name": {
Type: schema.TypeString,
Computed: true,
},
"up": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
"info": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"active_ports": {
Type: schema.TypeInt,
Computed: true,
},
"total_ports": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
},
},
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"created_at": {
Type: schema.TypeString,
Computed: true,
},
"synced_at": {
Type: schema.TypeString,
Computed: true,
},
}
return res
}
func dataSourceHypervisorListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"page": {
Type: schema.TypeInt,
Optional: true,
},
"per_page": {
Type: schema.TypeInt,
Optional: true,
},
"sort_by": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"name", "hostname", "last_sync",
"display_name", "ip", "created_at", "updated_at"}, false),
},
"sort_order": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"asc", "desc"}, false),
},
"port_info": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"detailed", "general"}, false),
},
"hostname": {
Type: schema.TypeString,
Optional: true,
},
"display_name": {
Type: schema.TypeString,
Optional: true,
},
"ip": {
Type: schema.TypeString,
Optional: true,
},
"created_from": {
Type: schema.TypeString,
Optional: true,
},
"created_to": {
Type: schema.TypeString,
Optional: true,
},
"updated_from": {
Type: schema.TypeString,
Optional: true,
},
"updated_to": {
Type: schema.TypeString,
Optional: true,
},
"items": {
Type: schema.TypeList,
Computed: true,
Description: "List of hypervisors",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"display_name": {
Type: schema.TypeString,
Computed: true,
},
"hostname": {
Type: schema.TypeString,
Computed: true,
},
"ip": {
Type: schema.TypeString,
Computed: true,
},
"ports": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"data": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"unique_identifier": {
Type: schema.TypeString,
Computed: true,
},
"display_name": {
Type: schema.TypeString,
Computed: true,
},
"up": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
"info": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"active_ports": {
Type: schema.TypeInt,
Computed: true,
},
"total_ports": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
},
},
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"created_at": {
Type: schema.TypeString,
Computed: true,
},
"synced_at": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
}
return res
}
func dataSourceHypervisorSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"port_info": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"detailed", "general"}, false),
},
"display_name": {
Type: schema.TypeString,
Computed: true,
},
"hostname": {
Type: schema.TypeString,
Computed: true,
},
"ip": {
Type: schema.TypeString,
Computed: true,
},
"ports": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"data": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"unique_identifier": {
Type: schema.TypeString,
Computed: true,
},
"display_name": {
Type: schema.TypeString,
Computed: true,
},
"up": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
"info": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"active_ports": {
Type: schema.TypeInt,
Computed: true,
},
"total_ports": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
},
},
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"created_at": {
Type: schema.TypeString,
Computed: true,
},
"synced_at": {
Type: schema.TypeString,
Computed: true,
},
}
return res
}

View File

@@ -0,0 +1,32 @@
package hypervisors
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/hypervisors"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityHypervisorCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*hypervisors.RecordHypervisor, error) {
c := m.(*controller.ControllerCfg)
req := hypervisors.GetRequest{}
if d.Id() != "" {
req.Name = d.Id()
} else {
req.Name = d.Get("name").(string)
}
if portInfo, ok := d.GetOk("port_info"); ok {
req.PortInfo = portInfo.(string)
}
hypervisor, err := c.SDN().Hypervisors().Get(ctx, req)
if err != nil {
return nil, err
}
return hypervisor, nil
}

View File

@@ -0,0 +1,69 @@
package hypervisors
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/hypervisors"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityHypervisorListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (hypervisors.HypervisorsList, error) {
c := m.(*controller.ControllerCfg)
req := hypervisors.ListRequest{}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if perPage, ok := d.GetOk("per_page"); ok {
req.PerPage = uint64(perPage.(int))
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}
if sortOrder, ok := d.GetOk("sort_order"); ok {
req.SortOrder = sortOrder.(string)
}
if portInfo, ok := d.GetOk("port_info"); ok {
req.PortInfo = portInfo.(string)
}
if hostname, ok := d.GetOk("hostname"); ok {
req.Hostname = hostname.(string)
}
if displayName, ok := d.GetOk("display_name"); ok {
req.DisplayName = displayName.(string)
}
if ip, ok := d.GetOk("ip"); ok {
req.IP = ip.(string)
}
if createdFrom, ok := d.GetOk("created_from"); ok {
req.CreatedFrom = createdFrom.(string)
}
if createdTo, ok := d.GetOk("created_to"); ok {
req.CreatedTo = createdTo.(string)
}
if updatedFrom, ok := d.GetOk("updated_from"); ok {
req.UpdatedFrom = updatedFrom.(string)
}
if updatedTo, ok := d.GetOk("updated_to"); ok {
req.UpdatedTo = updatedTo.(string)
}
hypervisorList, err := c.SDN().Hypervisors().List(ctx, req)
if err != nil {
return nil, err
}
return hypervisorList, nil
}

View File

@@ -14,6 +14,7 @@ func flattenLogicalPortResource(d *schema.ResourceData, logicalPort *logicalport
d.Set("description", logicalPort.Description)
d.Set("display_name", logicalPort.DisplayName)
d.Set("enabled", logicalPort.Enabled)
d.Set("external_network_id", logicalPort.ExternalNetworkID)
d.Set("hypervisor", logicalPort.Hypervisor)
d.Set("hypervisor_display_name", logicalPort.HypervisorDisplayName)
d.Set("live_migration_target_hv", logicalPort.LiveMigrationTargetHV)
@@ -21,6 +22,7 @@ func flattenLogicalPortResource(d *schema.ResourceData, logicalPort *logicalport
d.Set("unique_identifier", logicalPort.UniqueIdentifier)
d.Set("version_id", logicalPort.VersionID)
d.Set("bindings", flattenBindings(logicalPort.Bindings))
d.Set("labels", flattenLabels(logicalPort.Labels))
d.Set("created_at", logicalPort.CreatedAt)
}
@@ -38,11 +40,13 @@ func flattenLogicalPortList(lpl *logicalports.LogicalPortsList) []map[string]int
"enabled": v.Enabled,
"hypervisor": v.Hypervisor,
"hypervisor_display_name": v.HypervisorDisplayName,
"external_network_id": v.ExternalNetworkID,
"live_migration_target_hv": v.LiveMigrationTargetHV,
"status": flattenStatus(v.Status),
"unique_identifier": v.UniqueIdentifier,
"version_id": v.VersionID,
"bindings": flattenBindings(v.Bindings),
"labels": flattenLabels(v.Labels),
"created_at": v.CreatedAt,
"updated_at": v.UpdatedAt,
}
@@ -60,6 +64,7 @@ func flattenLogicalPort(d *schema.ResourceData, logicalPort *logicalports.Logica
d.Set("description", logicalPort.Description)
d.Set("display_name", logicalPort.DisplayName)
d.Set("enabled", logicalPort.Enabled)
d.Set("external_network_id", logicalPort.ExternalNetworkID)
d.Set("hypervisor", logicalPort.Hypervisor)
d.Set("hypervisor_display_name", logicalPort.HypervisorDisplayName)
d.Set("live_migration_target_hv", logicalPort.LiveMigrationTargetHV)
@@ -67,32 +72,63 @@ func flattenLogicalPort(d *schema.ResourceData, logicalPort *logicalports.Logica
d.Set("unique_identifier", logicalPort.UniqueIdentifier)
d.Set("version_id", logicalPort.VersionID)
d.Set("bindings", flattenBindings(logicalPort.Bindings))
d.Set("labels", flattenLabels(logicalPort.Labels))
d.Set("created_at", logicalPort.CreatedAt)
d.Set("updated_at", logicalPort.UpdatedAt)
}
func flattenLabels(labels logicalports.Labels) []map[string]interface{} {
if labels.VMID == "" && labels.VMName == "" {
return []map[string]interface{}{}
}
return []map[string]interface{}{
{
"vm_id": labels.VMID,
"vm_name": labels.VMName,
},
}
}
func flattenBindings(bindings logicalports.Bindings) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"id": bindings.ID,
"segment_id": bindings.SegmentID,
"segment_display_name": bindings.SegmentDisplayName,
"port_security": bindings.PortSecurity,
"address_detection": bindings.AddressDetection,
"is_excluded_from_firewall": bindings.IsExcludedFromFirewall,
"version_id": bindings.VersionID,
"created_at": bindings.CreatedAt,
"updated_at": bindings.UpdatedAt,
"id": bindings.ID,
"segment_id": bindings.SegmentID,
"segment_display_name": bindings.SegmentDisplayName,
"port_security": bindings.PortSecurity,
"address_detection": bindings.AddressDetection,
"version_id": bindings.VersionID,
"created_at": bindings.CreatedAt,
"updated_at": bindings.UpdatedAt,
"logical_port_addresses": flattenLogicalPortAddresses(bindings.LogicalPortAddresses),
}
res = append(res, temp)
return res
}
func flattenLogicalPortAddresses(addrs []logicalports.LogicalPortAddress) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(addrs))
for _, a := range addrs {
res = append(res, map[string]interface{}{
"ip": a.IP,
"ip_type": a.IPType,
"mac": a.MAC,
"id": a.ID,
"logical_port_id": a.LogicalPortID,
"assigned_at": a.AssignedAt,
"is_discovered": a.IsDiscovered,
"is_primary": a.IsPrimary,
})
}
return res
}
func flattenStatus(status logicalports.Status) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"common": status.Common,
"hypervisors": flattenHypervisors(status.Hypervisors),
"operation_status": status.OperationStatus,
"hypervisor_status": status.HypervisorStatus,
"hypervisors": flattenHypervisors(status.Hypervisors),
}
res = append(res, temp)
return res
@@ -102,7 +138,7 @@ func flattenHypervisors(hv []logicalports.HypervisorStatus) []map[string]interfa
res := make([]map[string]interface{}, 0, len(hv))
for _, v := range hv {
temp := map[string]interface{}{
"status": v.Status,
"operation_status": v.OperationStatus,
"name": v.Name,
"display_name": v.DisplayName,
"hypervisor_status": v.HypervisorStatus,

View File

@@ -17,14 +17,13 @@ func resourceLogicalPortCreate(ctx context.Context, d *schema.ResourceData, m in
c := m.(*controller.ControllerCfg)
req := logicalports.CreateRequest{
AccessGroupID: d.Get("access_group_id").(string),
Description: d.Get("description").(string),
DisplayName: d.Get("display_name").(string),
Enabled: d.Get("enabled").(bool),
IsExcludedFromFirewall: d.Get("is_excluded_from_firewall").(bool),
Hypervisor: d.Get("hypervisor").(string),
PortSecurity: d.Get("port_security").(bool),
SegmentID: d.Get("segment_id").(string),
AccessGroupID: d.Get("access_group_id").(string),
Description: d.Get("description").(string),
DisplayName: d.Get("display_name").(string),
Enabled: d.Get("enabled").(bool),
Hypervisor: d.Get("hypervisor").(string),
PortSecurity: d.Get("port_security").(bool),
SegmentID: d.Get("segment_id").(string),
}
if adapterMAC, ok := d.GetOk("adapter_mac"); ok {
@@ -33,6 +32,16 @@ func resourceLogicalPortCreate(ctx context.Context, d *schema.ResourceData, m in
if uniqueID, ok := d.GetOk("unique_identifier"); ok {
req.UniqueIdentifier = uniqueID.(string)
}
if labelsRaw, ok := d.GetOk("labels"); ok {
labelsList := labelsRaw.([]interface{})
if len(labelsList) > 0 {
labelsMap := labelsList[0].(map[string]interface{})
req.Labels = logicalports.CreateLabels{
VMID: labelsMap["vm_id"].(string),
VMName: labelsMap["vm_name"].(string),
}
}
}
if logicalPortAddresses, ok := d.GetOk("logical_port_addresses"); ok {
logicalPortAddressesList := logicalPortAddresses.([]interface{})
logicalPortsAddressesArr := make([]logicalports.LogicalPortAddress, 0)
@@ -46,7 +55,7 @@ func resourceLogicalPortCreate(ctx context.Context, d *schema.ResourceData, m in
if isDiscovered, ok := logicalPortAddressMap["is_discovered"]; ok {
logicalPortAddress.IsDiscovered = isDiscovered.(bool)
}
if mac, ok := logicalPortAddressMap["mac_address"]; ok {
if mac, ok := logicalPortAddressMap["mac"]; ok {
logicalPortAddress.MAC = mac.(string)
}
logicalPortsAddressesArr = append(logicalPortsAddressesArr, logicalPortAddress)
@@ -84,17 +93,37 @@ func resourceLogicalPortUpdate(ctx context.Context, d *schema.ResourceData, m in
log.Debugf("resourceLogicalPortUpdate: called logical port with id %s", d.Id())
c := m.(*controller.ControllerCfg)
migrate := d.Get("migrate").(bool)
req := logicalports.UpdateRequest{
LogicalPortID: d.Id(),
VersionID: uint64(d.Get("version_id").(int)),
AdapterMAC: d.Get("adapter_mac").(string),
Description: d.Get("description").(string),
DisplayName: d.Get("display_name").(string),
Enabled: d.Get("enabled").(bool),
Hypervisor: d.Get("hypervisor").(string),
PortSecurity: d.Get("port_security").(bool),
IsExcludedFromFirewall: d.Get("is_excluded_from_firewall").(bool),
SegmentID: d.Get("segment_id").(string),
LogicalPortID: d.Id(),
VersionID: uint64(d.Get("version_id").(int)),
AdapterMAC: d.Get("adapter_mac").(string),
Description: d.Get("description").(string),
DisplayName: d.Get("display_name").(string),
Enabled: d.Get("enabled").(bool),
PortSecurity: d.Get("port_security").(bool),
SegmentID: d.Get("segment_id").(string),
}
if !migrate {
req.Hypervisor = d.Get("hypervisor").(string)
} else {
old, _ := d.GetChange("hypervisor")
req.Hypervisor = old.(string)
}
if d.HasChange("labels") {
if labelsRaw, ok := d.GetOk("labels"); ok {
labelsList := labelsRaw.([]interface{})
if len(labelsList) > 0 {
labelsMap := labelsList[0].(map[string]interface{})
req.Labels = logicalports.UpdateLabels{
VMID: labelsMap["vm_id"].(string),
VMName: labelsMap["vm_name"].(string),
}
}
}
}
if d.HasChange("logical_port_addresses") {
@@ -112,7 +141,7 @@ func resourceLogicalPortUpdate(ctx context.Context, d *schema.ResourceData, m in
if isDiscovered, ok := logicalPortAddressMap["is_discovered"]; ok {
logicalPortAddress.IsDiscovered = isDiscovered.(bool)
}
if mac, ok := logicalPortAddressMap["mac_address"]; ok {
if mac, ok := logicalPortAddressMap["mac"]; ok {
logicalPortAddress.MAC = mac.(string)
}
oldAddressesMap[logicalPortAddress.IP] = logicalPortAddress
@@ -128,19 +157,19 @@ func resourceLogicalPortUpdate(ctx context.Context, d *schema.ResourceData, m in
if isDiscovered, ok := logicalPortAddressMap["is_discovered"]; ok {
logicalPortAddress.IsDiscovered = isDiscovered.(bool)
}
if mac, ok := logicalPortAddressMap["mac_address"]; ok {
if mac, ok := logicalPortAddressMap["mac"]; ok {
logicalPortAddress.MAC = mac.(string)
}
newAddressesMap[logicalPortAddress.IP] = logicalPortAddress
}
for addressIP, _ := range oldAddressesMap {
removeAddresses := make([]string, 0)
removeAddresses := make([]string, 0)
for addressIP := range oldAddressesMap {
if _, exists := newAddressesMap[addressIP]; !exists {
removeAddresses = append(removeAddresses, addressIP)
}
req.RemoveAddresses = removeAddresses
}
req.RemoveAddresses = removeAddresses
for addressIP, address := range newAddressesMap {
if oldAddressIP, exists := oldAddressesMap[addressIP]; !exists || address != oldAddressIP {
@@ -174,6 +203,34 @@ func resourceLogicalPortUpdate(ctx context.Context, d *schema.ResourceData, m in
return diag.FromErr(err)
}
if migrate {
if targetHV, ok := d.GetOk("hypervisor"); ok {
// Re-read version_id
lp, err := utilityLogicalPortCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
migrateReq := logicalports.MigrateStartRequest{
LogicalPortID: d.Id(),
VersionID: lp.VersionID,
TargetHypervisor: targetHV.(string),
}
_, err = c.SDN().LogicalPorts().StartMigrate(ctx, migrateReq)
if err != nil {
return diag.FromErr(err)
}
// to prevent drift on the next plan
diags := resourceLogicalPortRead(ctx, d, m)
if diags.HasError() {
return diags
}
d.Set("hypervisor", targetHV.(string))
return diags
}
}
return resourceLogicalPortRead(ctx, d, m)
}

View File

@@ -5,6 +5,49 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func logicalPortAddressesSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ip": {
Type: schema.TypeString,
Computed: true,
},
"ip_type": {
Type: schema.TypeString,
Computed: true,
},
"mac": {
Type: schema.TypeString,
Computed: true,
},
"id": {
Type: schema.TypeString,
Computed: true,
},
"logical_port_id": {
Type: schema.TypeString,
Computed: true,
},
"assigned_at": {
Type: schema.TypeString,
Computed: true,
},
"is_discovered": {
Type: schema.TypeBool,
Computed: true,
},
"is_primary": {
Type: schema.TypeBool,
Computed: true,
},
},
},
}
}
func resourceLogicalPortSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"access_group_id": {
@@ -27,10 +70,6 @@ func resourceLogicalPortSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "Whether the logical port should be enabled",
},
"is_excluded_from_firewall": {
Type: schema.TypeBool,
Required: true,
},
"hypervisor": {
Type: schema.TypeString,
Required: true,
@@ -61,6 +100,12 @@ func resourceLogicalPortSchemaMake() map[string]*schema.Schema {
Optional: true,
Default: false,
},
"migrate": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "If true, triggers live migration to the hypervisor specified in the 'hypervisor' field. If false, hypervisor changes are applied via the regular update endpoint.",
},
"logical_port_addresses": {
Type: schema.TypeList,
Optional: true,
@@ -127,20 +172,25 @@ func resourceLogicalPortSchemaMake() map[string]*schema.Schema {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"common": {
"operation_status": {
Type: schema.TypeString,
Computed: true,
Description: "Common status",
Description: "Operation status",
},
"hypervisor_status": {
Type: schema.TypeString,
Computed: true,
Description: "Hypervisor status",
},
"hypervisors": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"status": {
"operation_status": {
Type: schema.TypeString,
Computed: true,
Description: "Status of the hypervisor",
Description: "Operation status of the hypervisor",
},
"name": {
Type: schema.TypeString,
@@ -198,10 +248,6 @@ func resourceLogicalPortSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "If the adapter address detection is enabled",
},
"is_excluded_from_firewall": {
Type: schema.TypeBool,
Computed: true,
},
"version_id": {
Type: schema.TypeInt,
Computed: true,
@@ -217,6 +263,7 @@ func resourceLogicalPortSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Update time of the binding",
},
"logical_port_addresses": logicalPortAddressesSchema(),
},
},
},
@@ -225,6 +272,29 @@ func resourceLogicalPortSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Version ID of the logical port",
},
"labels": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"vm_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "VM ID label",
},
"vm_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "VM name label",
},
},
},
Description: "Labels",
},
}
return res
}
@@ -322,6 +392,21 @@ func dataSourceLogicalPortListSchemaMake() map[string]*schema.Schema {
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"asc", "dec"}, false),
},
"operation_status": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"Idle", "SynchronizingAtCore", "SynchronizingAtOVN",
"Synchronized", "NoHypervisorAtOVN", "FailedAtCore", "TemporaryFailedAtCore",
}, false),
Description: "Filter by operation status",
},
"hypervisor_status": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"Up", "Warning", "Error"}, false),
Description: "Filter by hypervisor status",
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -377,6 +462,10 @@ func dataSourceLogicalPortListSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Display name of the hypervisor",
},
"external_network_id": {
Type: schema.TypeString,
Computed: true,
},
"live_migration_target_hv": {
Type: schema.TypeString,
Computed: true,
@@ -386,20 +475,25 @@ func dataSourceLogicalPortListSchemaMake() map[string]*schema.Schema {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"common": {
"operation_status": {
Type: schema.TypeString,
Computed: true,
Description: "Common status",
Description: "Operation status",
},
"hypervisor_status": {
Type: schema.TypeString,
Computed: true,
Description: "Hypervisor status",
},
"hypervisors": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"status": {
"operation_status": {
Type: schema.TypeString,
Computed: true,
Description: "Status of the hypervisor",
Description: "Operation status of the hypervisor",
},
"name": {
Type: schema.TypeString,
@@ -467,10 +561,6 @@ func dataSourceLogicalPortListSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "If the adapter address detection is enabled",
},
"is_excluded_from_firewall": {
Type: schema.TypeBool,
Computed: true,
},
"version_id": {
Type: schema.TypeInt,
Computed: true,
@@ -486,6 +576,7 @@ func dataSourceLogicalPortListSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Update time of the binding",
},
"logical_port_addresses": logicalPortAddressesSchema(),
},
},
},
@@ -499,6 +590,25 @@ func dataSourceLogicalPortListSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Update time the logical port",
},
"labels": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"vm_id": {
Type: schema.TypeString,
Computed: true,
Description: "VM ID label",
},
"vm_name": {
Type: schema.TypeString,
Computed: true,
Description: "VM name label",
},
},
},
Description: "Labels",
},
},
},
},
@@ -558,6 +668,10 @@ func dataSourceLogicalPortByUniqueIDSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Display name of the hypervisor",
},
"external_network_id": {
Type: schema.TypeString,
Computed: true,
},
"live_migration_target_hv": {
Type: schema.TypeString,
Computed: true,
@@ -567,20 +681,25 @@ func dataSourceLogicalPortByUniqueIDSchemaMake() map[string]*schema.Schema {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"common": {
"operation_status": {
Type: schema.TypeString,
Computed: true,
Description: "Common status",
Description: "Operation status",
},
"hypervisor_status": {
Type: schema.TypeString,
Computed: true,
Description: "Hypervisor status",
},
"hypervisors": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"status": {
"operation_status": {
Type: schema.TypeString,
Computed: true,
Description: "Status of the hypervisor",
Description: "Operation status of the hypervisor",
},
"name": {
Type: schema.TypeString,
@@ -643,10 +762,6 @@ func dataSourceLogicalPortByUniqueIDSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "If the adapter address detection is enabled",
},
"is_excluded_from_firewall": {
Type: schema.TypeBool,
Computed: true,
},
"version_id": {
Type: schema.TypeInt,
Computed: true,
@@ -662,6 +777,7 @@ func dataSourceLogicalPortByUniqueIDSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Update time of the binding",
},
"logical_port_addresses": logicalPortAddressesSchema(),
},
},
},
@@ -675,6 +791,25 @@ func dataSourceLogicalPortByUniqueIDSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Update time the logical port",
},
"labels": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"vm_id": {
Type: schema.TypeString,
Computed: true,
Description: "VM ID label",
},
"vm_name": {
Type: schema.TypeString,
Computed: true,
Description: "VM name label",
},
},
},
Description: "Labels",
},
}
return res
}
@@ -731,6 +866,10 @@ func dataSourceLogicalPortSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Display name of the hypervisor",
},
"external_network_id": {
Type: schema.TypeString,
Computed: true,
},
"live_migration_target_hv": {
Type: schema.TypeString,
Computed: true,
@@ -740,20 +879,25 @@ func dataSourceLogicalPortSchemaMake() map[string]*schema.Schema {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"common": {
"operation_status": {
Type: schema.TypeString,
Computed: true,
Description: "Common status",
Description: "Operation status",
},
"hypervisor_status": {
Type: schema.TypeString,
Computed: true,
Description: "Hypervisor status",
},
"hypervisors": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"status": {
"operation_status": {
Type: schema.TypeString,
Computed: true,
Description: "Status of the hypervisor",
Description: "Operation status of the hypervisor",
},
"name": {
Type: schema.TypeString,
@@ -821,10 +965,6 @@ func dataSourceLogicalPortSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "If the adapter address detection is enabled",
},
"is_excluded_from_firewall": {
Type: schema.TypeBool,
Computed: true,
},
"version_id": {
Type: schema.TypeInt,
Computed: true,
@@ -840,6 +980,7 @@ func dataSourceLogicalPortSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Update time of the binding",
},
"logical_port_addresses": logicalPortAddressesSchema(),
},
},
},
@@ -853,6 +994,25 @@ func dataSourceLogicalPortSchemaMake() map[string]*schema.Schema {
Computed: true,
Description: "Update time the logical port",
},
"labels": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"vm_id": {
Type: schema.TypeString,
Computed: true,
Description: "VM ID label",
},
"vm_name": {
Type: schema.TypeString,
Computed: true,
Description: "VM name label",
},
},
},
Description: "Labels",
},
}
return res
}

View File

@@ -69,6 +69,12 @@ func utilityLogicalPortListCheckPresence(ctx context.Context, d *schema.Resource
if sortOrder, ok := d.GetOk("sort_order"); ok {
req.SortOrder = sortOrder.(string)
}
if operationStatus, ok := d.GetOk("operation_status"); ok {
req.OperationStatus = operationStatus.(string)
}
if hypervisorStatus, ok := d.GetOk("hypervisor_status"); ok {
req.HypervisorStatus = hypervisorStatus.(string)
}
logicalPortList, err := c.SDN().LogicalPorts().List(ctx, req)
if err != nil {

View File

@@ -0,0 +1,572 @@
/*
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 netobjgroups
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func hypervisorsInfoComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"operation_status": {Type: schema.TypeString, Computed: true},
"name": {Type: schema.TypeString, Computed: true},
"display_name": {Type: schema.TypeString, Computed: true},
"hypervisor_status": {Type: schema.TypeString, Computed: true},
"synced_at": {Type: schema.TypeString, Computed: true},
},
},
}
}
func statusComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"operation_status": {Type: schema.TypeString, Computed: true},
"hypervisor_status": {Type: schema.TypeString, Computed: true},
"hypervisors": hypervisorsInfoComputedSchema(),
},
},
}
}
func logicalPortAddressesComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ip": {Type: schema.TypeString, Computed: true},
"ip_type": {Type: schema.TypeString, Computed: true},
"is_discovered": {Type: schema.TypeBool, Computed: true},
"is_primary": {Type: schema.TypeBool, Computed: true},
"mac": {Type: schema.TypeString, Computed: true},
"id": {Type: schema.TypeString, Computed: true},
"logical_port_id": {Type: schema.TypeString, Computed: true},
"assigned_at": {Type: schema.TypeString, Computed: true},
},
},
}
}
func bindingsComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {Type: schema.TypeString, Computed: true},
"segment_display_name": {Type: schema.TypeString, Computed: true},
"segment_id": {Type: schema.TypeString, Computed: true},
"port_security": {Type: schema.TypeBool, Computed: true},
"address_detection": {Type: schema.TypeBool, Computed: true},
"version_id": {Type: schema.TypeInt, Computed: true},
"created_at": {Type: schema.TypeString, Computed: true},
"updated_at": {Type: schema.TypeString, Computed: true},
"logical_port_addresses": logicalPortAddressesComputedSchema(),
},
},
}
}
func excludeFirewallComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"exclusion_reason": {Type: schema.TypeString, Computed: true},
"logical_port_addresses_excluded": {Type: schema.TypeBool, Computed: true},
"logical_port_excluded": {Type: schema.TypeBool, Computed: true},
},
},
}
}
func labelsComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"vm_id": {Type: schema.TypeString, Computed: true},
"vm_name": {Type: schema.TypeString, Computed: true},
},
},
}
}
func ipv6ConfigComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"address_mode": {Type: schema.TypeString, Computed: true},
"enable_periodic_ra": {Type: schema.TypeBool, Computed: true},
"interval_ra": {Type: schema.TypeInt, Computed: true},
"router_preference": {Type: schema.TypeString, Computed: true},
},
},
}
}
func routerGatewayPortComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"created_at": {Type: schema.TypeString, Computed: true},
"description": {Type: schema.TypeString, Computed: true},
"id": {Type: schema.TypeString, Computed: true},
"router_display_name": {Type: schema.TypeString, Computed: true},
"router_id": {Type: schema.TypeString, Computed: true},
"snat_enabled": {Type: schema.TypeBool, Computed: true},
"updated_at": {Type: schema.TypeString, Computed: true},
},
},
}
}
func logicalPortSchemaFields() map[string]*schema.Schema {
return map[string]*schema.Schema{
"id": {Type: schema.TypeString, Computed: true},
"access_group_id": {Type: schema.TypeString, Computed: true},
"access_group_name": {Type: schema.TypeString, Computed: true},
"adapter_mac": {Type: schema.TypeString, Computed: true},
"address_detection": {Type: schema.TypeBool, Computed: true},
"description": {Type: schema.TypeString, Computed: true},
"created_at": {Type: schema.TypeString, Computed: true},
"display_name": {Type: schema.TypeString, Computed: true},
"enabled": {Type: schema.TypeBool, Computed: true},
"exclude_firewall": excludeFirewallComputedSchema(),
"external_network_id": {Type: schema.TypeString, Computed: true},
"hypervisor": {Type: schema.TypeString, Computed: true},
"hypervisor_display_name": {Type: schema.TypeString, Computed: true},
"labels": labelsComputedSchema(),
"live_migration_target_hv": {Type: schema.TypeString, Computed: true},
"status": statusComputedSchema(),
"bindings": bindingsComputedSchema(),
"unique_identifier": {Type: schema.TypeString, Computed: true},
"updated_at": {Type: schema.TypeString, Computed: true},
"version_id": {Type: schema.TypeInt, Computed: true},
}
}
func logicalPortsComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: logicalPortSchemaFields(),
},
}
}
func l2ExternalNetworkComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"bridge_network_name": {Type: schema.TypeString, Computed: true},
"created_at": {Type: schema.TypeString, Computed: true},
"description": {Type: schema.TypeString, Computed: true},
"display_name": {Type: schema.TypeString, Computed: true},
"hypervisors": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"id": {Type: schema.TypeString, Computed: true},
"updated_at": {Type: schema.TypeString, Computed: true},
"version_id": {Type: schema.TypeInt, Computed: true},
"vlan_tag": {Type: schema.TypeInt, Computed: true},
},
},
}
}
func l2ConnectionPortsComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {Type: schema.TypeString, Computed: true},
"access_group_id": {Type: schema.TypeString, Computed: true},
"created_at": {Type: schema.TypeString, Computed: true},
"updated_at": {Type: schema.TypeString, Computed: true},
"version_id": {Type: schema.TypeInt, Computed: true},
"l2_external_network": l2ExternalNetworkComputedSchema(),
},
},
}
}
func appliedNetObjectGroupsComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {Type: schema.TypeString, Computed: true},
"name": {Type: schema.TypeString, Computed: true},
"version_id": {Type: schema.TypeInt, Computed: true},
},
},
}
}
func securityRuleNetObjectComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"display_name": {Type: schema.TypeString, Computed: true},
"net_address_pool_id": {Type: schema.TypeString, Computed: true},
"net_object_group_id": {Type: schema.TypeString, Computed: true},
},
},
}
}
func securityRuleFiltersComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"all": {Type: schema.TypeBool, Computed: true},
"arp": {Type: schema.TypeBool, Computed: true},
"dhcp": {Type: schema.TypeBool, Computed: true},
"expression": {Type: schema.TypeString, Computed: true},
"icmp": {Type: schema.TypeBool, Computed: true},
"ip": {Type: schema.TypeBool, Computed: true},
"ip_v4": {Type: schema.TypeBool, Computed: true},
"ip_v6": {Type: schema.TypeBool, Computed: true},
"keep_opened_sessions": {Type: schema.TypeBool, Computed: true},
"nd": {Type: schema.TypeBool, Computed: true},
"tcp": {Type: schema.TypeBool, Computed: true},
"tcp_dst_ports": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"udp": {Type: schema.TypeBool, Computed: true},
"udp_dst_ports": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
}
}
func securityRuleFilterComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {Type: schema.TypeString, Computed: true},
"filters": securityRuleFiltersComputedSchema(),
},
},
}
}
func securityRulesComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"access_group_id": {Type: schema.TypeString, Computed: true},
"action": {Type: schema.TypeString, Computed: true},
"description": {Type: schema.TypeString, Computed: true},
"destination_net_object": securityRuleNetObjectComputedSchema(),
"direction": {Type: schema.TypeString, Computed: true},
"display_name": {Type: schema.TypeString, Computed: true},
"enabled": {Type: schema.TypeBool, Computed: true},
"filter": securityRuleFilterComputedSchema(),
"id": {Type: schema.TypeString, Computed: true},
"log_enabled": {Type: schema.TypeBool, Computed: true},
"log_name": {Type: schema.TypeString, Computed: true},
"log_severity": {Type: schema.TypeString, Computed: true},
"priority": {Type: schema.TypeInt, Computed: true},
"security_policy_id": {Type: schema.TypeString, Computed: true},
"source_net_object": securityRuleNetObjectComputedSchema(),
"statistics_enabled": {Type: schema.TypeBool, Computed: true},
"type": {Type: schema.TypeString, Computed: true},
"version_id": {Type: schema.TypeInt, Computed: true},
},
},
}
}
func securityPoliciesComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"access_group_id": {Type: schema.TypeString, Computed: true},
"access_group_name": {Type: schema.TypeString, Computed: true},
"applied_net_object_groups": appliedNetObjectGroupsComputedSchema(),
"created_at": {Type: schema.TypeString, Computed: true},
"description": {Type: schema.TypeString, Computed: true},
"display_name": {Type: schema.TypeString, Computed: true},
"enabled": {Type: schema.TypeBool, Computed: true},
"end_priority": {Type: schema.TypeInt, Computed: true},
"id": {Type: schema.TypeString, Computed: true},
"security_rules": securityRulesComputedSchema(),
"start_priority": {Type: schema.TypeInt, Computed: true},
"status": statusComputedSchema(),
"type": {Type: schema.TypeString, Computed: true},
"version_id": {Type: schema.TypeInt, Computed: true},
"updated_at": {Type: schema.TypeString, Computed: true},
},
},
}
}
func gateawayPortsComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"created_at": {Type: schema.TypeString, Computed: true},
"description": {Type: schema.TypeString, Computed: true},
"external_l4_port_max": {Type: schema.TypeInt, Computed: true},
"external_l4_port_min": {Type: schema.TypeInt, Computed: true},
"id": {Type: schema.TypeString, Computed: true},
"snat_enabled": {Type: schema.TypeBool, Computed: true},
"status": statusComputedSchema(),
"updated_at": {Type: schema.TypeString, Computed: true},
"version_id": {Type: schema.TypeInt, Computed: true},
},
},
}
}
func policiesComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"action": {Type: schema.TypeString, Computed: true},
"created_at": {Type: schema.TypeString, Computed: true},
"display_name": {Type: schema.TypeString, Computed: true},
"enabled": {Type: schema.TypeBool, Computed: true},
"id": {Type: schema.TypeString, Computed: true},
"match": {Type: schema.TypeString, Computed: true},
"next_ipv4_address": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"next_ipv6_address": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"priority": {Type: schema.TypeInt, Computed: true},
"updated_at": {Type: schema.TypeString, Computed: true},
"version_id": {Type: schema.TypeInt, Computed: true},
},
},
}
}
func segmentComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"access_group_id": {Type: schema.TypeString, Computed: true},
"access_group_name": {Type: schema.TypeString, Computed: true},
"created_at": {Type: schema.TypeString, Computed: true},
"description": {Type: schema.TypeString, Computed: true},
"display_name": {Type: schema.TypeString, Computed: true},
"enabled": {Type: schema.TypeBool, Computed: true},
"id": {Type: schema.TypeString, Computed: true},
"subnet_v4": {Type: schema.TypeString, Computed: true},
"subnet_v6": {Type: schema.TypeString, Computed: true},
"updated_at": {Type: schema.TypeString, Computed: true},
"version_id": {Type: schema.TypeInt, Computed: true},
},
},
}
}
func routerPortsComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"created_at": {Type: schema.TypeString, Computed: true},
"description": {Type: schema.TypeString, Computed: true},
"enabled": {Type: schema.TypeBool, Computed: true},
"id": {Type: schema.TypeString, Computed: true},
"ipv4_address": {Type: schema.TypeString, Computed: true},
"ipv6_address": {Type: schema.TypeString, Computed: true},
"ipv6_config": ipv6ConfigComputedSchema(),
"mac": {Type: schema.TypeString, Computed: true},
"segment_id": {Type: schema.TypeString, Computed: true},
"segment": segmentComputedSchema(),
"status": statusComputedSchema(),
"updated_at": {Type: schema.TypeString, Computed: true},
"version_id": {Type: schema.TypeInt, Computed: true},
},
},
}
}
func routerComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"access_group_id": {Type: schema.TypeString, Computed: true},
"access_group_name": {Type: schema.TypeString, Computed: true},
"created_at": {Type: schema.TypeString, Computed: true},
"description": {Type: schema.TypeString, Computed: true},
"display_name": {Type: schema.TypeString, Computed: true},
"enabled": {Type: schema.TypeBool, Computed: true},
"gateaway_ports": gateawayPortsComputedSchema(),
"id": {Type: schema.TypeString, Computed: true},
"policies": policiesComputedSchema(),
"ports": routerPortsComputedSchema(),
"status": statusComputedSchema(),
"updated_at": {Type: schema.TypeString, Computed: true},
"version_id": {Type: schema.TypeInt, Computed: true},
},
},
}
}
func floatingIPComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"access_group_id": {Type: schema.TypeString, Computed: true},
"access_group_name": {Type: schema.TypeString, Computed: true},
"created_at": {Type: schema.TypeString, Computed: true},
"updated_at": {Type: schema.TypeString, Computed: true},
"version_id": {Type: schema.TypeInt, Computed: true},
"logical_port": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: logicalPortSchemaFields(),
},
},
"router": routerComputedSchema(),
},
},
}
}
func externalNetworkPortFieldsComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"access_group_id": {Type: schema.TypeString, Computed: true},
"access_group_name": {Type: schema.TypeString, Computed: true},
"comment": {Type: schema.TypeString, Computed: true},
"display_name": {Type: schema.TypeString, Computed: true},
"enabled": {Type: schema.TypeBool, Computed: true},
"ipv4": {Type: schema.TypeString, Computed: true},
"ipv6": {Type: schema.TypeString, Computed: true},
"ipv6_config": ipv6ConfigComputedSchema(),
"mac": {Type: schema.TypeString, Computed: true},
"router_gateaway_port": routerGatewayPortComputedSchema(),
"floating_ip": floatingIPComputedSchema(),
},
},
}
}
func externalNetworkPortsComputedSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {Type: schema.TypeString, Computed: true},
"access_group_id": {Type: schema.TypeString, Computed: true},
"access_group_name": {Type: schema.TypeString, Computed: true},
"bridge_network_name": {Type: schema.TypeString, Computed: true},
"comment": {Type: schema.TypeString, Computed: true},
"default_gateway_ipv4": {Type: schema.TypeString, Computed: true},
"default_gateway_ipv6": {Type: schema.TypeString, Computed: true},
"description": {Type: schema.TypeString, Computed: true},
"enabled": {Type: schema.TypeBool, Computed: true},
"external_network_ports": externalNetworkPortFieldsComputedSchema(),
"hypervisors": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"ipv4": {Type: schema.TypeString, Computed: true},
"status": statusComputedSchema(),
"version_id": {Type: schema.TypeInt, Computed: true},
"subnet_v4": {Type: schema.TypeString, Computed: true},
"subnet_v6": {Type: schema.TypeString, Computed: true},
"created_at": {Type: schema.TypeString, Computed: true},
"updated_at": {Type: schema.TypeString, Computed: true},
"vlan_tag": {Type: schema.TypeInt, Computed: true},
"mac": {Type: schema.TypeString, Computed: true},
},
},
}
}

View File

@@ -0,0 +1,178 @@
/*
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 netobjgroups
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceNetworkObjectGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
rec, err := utilityNetworkObjectGroupCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
flattenNetworkObjectGroupDataSource(d, rec)
d.SetId(rec.ID)
return nil
}
func dataSourceNetworkObjectGroupSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"net_object_group_id": {
Type: schema.TypeString,
Required: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"access_group_id": {
Type: schema.TypeString,
Computed: true,
},
"access_group_name": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"purpose": {
Type: schema.TypeString,
Computed: true,
},
"version_id": {
Type: schema.TypeInt,
Computed: true,
},
"created_at": {
Type: schema.TypeString,
Computed: true,
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
},
"addresses": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"net_address_type": {
Type: schema.TypeString,
Computed: true,
},
"ip_addr": {
Type: schema.TypeString,
Computed: true,
},
"ip_addr_range_end": {
Type: schema.TypeString,
Computed: true,
},
"ip_prefix": {
Type: schema.TypeString,
Computed: true,
},
"mac_addr": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"counters": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"addresses_count": {
Type: schema.TypeInt,
Computed: true,
},
"l2_connection_ports_count": {
Type: schema.TypeInt,
Computed: true,
},
"logical_ports_count": {
Type: schema.TypeInt,
Computed: true,
},
"security_policies_count": {
Type: schema.TypeInt,
Computed: true,
},
"security_rules_count": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"l2_connection_ports": l2ConnectionPortsComputedSchema(),
"logical_ports": logicalPortsComputedSchema(),
"external_network_ports": externalNetworkPortsComputedSchema(),
"security_policies": securityPoliciesComputedSchema(),
}
}
func DataSourceNetworkObjectGroup() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceNetworkObjectGroupRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceNetworkObjectGroupSchemaMake(),
}
}

View File

@@ -0,0 +1,233 @@
/*
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 netobjgroups
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceNetworkObjectGroupListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
list, err := utilityNetworkObjectGroupListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenNetworkObjectGroupList(list))
d.Set("entry_count", len(list.Objects))
return nil
}
func dataSourceNetworkObjectGroupListSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
},
"access_group_id": {
Type: schema.TypeString,
Optional: true,
},
"page": {
Type: schema.TypeInt,
Optional: true,
},
"per_page": {
Type: schema.TypeInt,
Optional: true,
},
"sort_by": {
Type: schema.TypeString,
Optional: true,
},
"sort_order": {
Type: schema.TypeString,
Optional: true,
},
"created_from": {
Type: schema.TypeString,
Optional: true,
},
"created_to": {
Type: schema.TypeString,
Optional: true,
},
"updated_from": {
Type: schema.TypeString,
Optional: true,
},
"updated_to": {
Type: schema.TypeString,
Optional: true,
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"access_group_id": {
Type: schema.TypeString,
Computed: true,
},
"access_group_name": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"purpose": {
Type: schema.TypeString,
Computed: true,
},
"version_id": {
Type: schema.TypeInt,
Computed: true,
},
"created_at": {
Type: schema.TypeString,
Computed: true,
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
},
"addresses": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"net_address_type": {
Type: schema.TypeString,
Computed: true,
},
"ip_addr": {
Type: schema.TypeString,
Computed: true,
},
"ip_addr_range_end": {
Type: schema.TypeString,
Computed: true,
},
"ip_prefix": {
Type: schema.TypeString,
Computed: true,
},
"mac_addr": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"counters": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"addresses_count": {
Type: schema.TypeInt,
Computed: true,
},
"l2_connection_ports_count": {
Type: schema.TypeInt,
Computed: true,
},
"logical_ports_count": {
Type: schema.TypeInt,
Computed: true,
},
"security_policies_count": {
Type: schema.TypeInt,
Computed: true,
},
"security_rules_count": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"l2_connection_ports": l2ConnectionPortsComputedSchema(),
"logical_ports": logicalPortsComputedSchema(),
"external_network_ports": externalNetworkPortsComputedSchema(),
"security_policies": securityPoliciesComputedSchema(),
},
},
},
}
}
func DataSourceNetworkObjectGroupList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceNetworkObjectGroupListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceNetworkObjectGroupListSchemaMake(),
}
}

View File

@@ -0,0 +1,581 @@
/*
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 netobjgroups
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/netobjgroups"
)
func flattenNetworkObjectGroupResource(d *schema.ResourceData, rec *netobjgroups.RecordNetObjGroup) {
d.Set("name", rec.Name)
d.Set("access_group_id", rec.AccessGroupID)
d.Set("access_group_name", rec.AccessGroupName)
d.Set("description", rec.Description)
d.Set("type", rec.Type)
d.Set("purpose", rec.Purpose)
d.Set("version_id", int(rec.VersionID))
d.Set("addresses", flattenAddresses(rec.Addresses))
d.Set("counters", flattenCounters(rec.Counters))
d.Set("l2_connection_ports", flattenL2ConnectionPorts(rec.L2ConnectionPorts))
d.Set("logical_ports", flattenLogicalPorts(rec.LogicalPorts))
d.Set("external_network_ports", flattenExternalNetworkPorts(rec.ExternalNetworkPorts))
d.Set("security_policies", flattenSecurityPolicies(rec.SecurityPolicies))
}
func flattenNetworkObjectGroupDataSource(d *schema.ResourceData, rec *netobjgroups.RecordNetObjGroup) {
d.Set("name", rec.Name)
d.Set("access_group_id", rec.AccessGroupID)
d.Set("access_group_name", rec.AccessGroupName)
d.Set("description", rec.Description)
d.Set("type", rec.Type)
d.Set("purpose", rec.Purpose)
d.Set("version_id", int(rec.VersionID))
d.Set("created_at", rec.CreatedAt)
d.Set("updated_at", rec.UpdatedAt)
d.Set("addresses", flattenAddresses(rec.Addresses))
d.Set("counters", flattenCounters(rec.Counters))
d.Set("l2_connection_ports", flattenL2ConnectionPorts(rec.L2ConnectionPorts))
d.Set("logical_ports", flattenLogicalPorts(rec.LogicalPorts))
d.Set("external_network_ports", flattenExternalNetworkPorts(rec.ExternalNetworkPorts))
d.Set("security_policies", flattenSecurityPolicies(rec.SecurityPolicies))
}
func flattenAddresses(addrs netobjgroups.NetAddresses) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(addrs))
for _, a := range addrs {
res = append(res, map[string]interface{}{
"id": a.ID,
"net_address_type": a.NetAddressType,
"ip_addr": a.IPAddr,
"ip_addr_range_end": a.IPAddrRangeEnd,
"ip_prefix": a.IPPrefix,
"mac_addr": a.MACAddr,
})
}
return res
}
func flattenCounters(c netobjgroups.Counter) []map[string]interface{} {
return []map[string]interface{}{
{
"addresses_count": int(c.AddressesCount),
"l2_connection_ports_count": int(c.L2ConnectionPortsCount),
"logical_ports_count": int(c.LogicalPortsCount),
"security_policies_count": int(c.SecurityPoliciesCount),
"security_rules_count": int(c.SecurityRulesCount),
},
}
}
func flattenStatus(s netobjgroups.Status) []map[string]interface{} {
return []map[string]interface{}{
{
"operation_status": s.OperationStatus,
"hypervisor_status": s.HypervisorStatus,
"hypervisors": flattenHypervisorsInfo(s.Hypervisors),
},
}
}
func flattenHypervisorsInfo(hvs netobjgroups.HypervisorsInfo) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(hvs))
for _, hv := range hvs {
res = append(res, map[string]interface{}{
"operation_status": hv.OperationStatus,
"name": hv.Name,
"display_name": hv.DisplayName,
"hypervisor_status": hv.HypervisorStatus,
"synced_at": hv.SyncedAt,
})
}
return res
}
func flattenLogicalPortAddresses(addrs netobjgroups.LogicalPortAddresses) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(addrs))
for _, a := range addrs {
res = append(res, map[string]interface{}{
"ip": a.IP,
"ip_type": a.IPType,
"is_discovered": a.IsDiscovered,
"is_primary": a.IsPrimary,
"mac": a.MAC,
"id": a.ID,
"logical_port_id": a.LogicalPortID,
"assigned_at": a.AssignedAt,
})
}
return res
}
func flattenBindings(b netobjgroups.Bindings) []map[string]interface{} {
return []map[string]interface{}{
{
"id": b.ID,
"segment_display_name": b.SegmentDisplayName,
"segment_id": b.SegmentID,
"port_security": b.PortSecurity,
"address_detection": b.AddressDetection,
"version_id": int(b.VersionID),
"created_at": b.CreatedAt,
"updated_at": b.UpdatedAt,
"logical_port_addresses": flattenLogicalPortAddresses(b.LogicalPortAddresses),
},
}
}
func flattenExcludeFirewall(e netobjgroups.ExcludeFirewall) []map[string]interface{} {
return []map[string]interface{}{
{
"exclusion_reason": e.ExclusionReason,
"logical_port_addresses_excluded": e.LogicalPortAddressesExcluded,
"logical_port_excluded": e.LogicalPortExcluded,
},
}
}
func flattenLabels(l netobjgroups.Labels) []map[string]interface{} {
return []map[string]interface{}{
{
"vm_id": l.VMID,
"vm_name": l.VMName,
},
}
}
func flattenLogicalPort(lp netobjgroups.LogicalPort) map[string]interface{} {
return map[string]interface{}{
"id": lp.ID,
"access_group_id": lp.AccessGroupID,
"access_group_name": lp.AccessGroupName,
"adapter_mac": lp.AdapterMAC,
"address_detection": lp.AddressDetection,
"description": lp.Description,
"created_at": lp.CreatedAt,
"display_name": lp.DisplayName,
"enabled": lp.Enabled,
"exclude_firewall": flattenExcludeFirewall(lp.ExcludeFirewall),
"external_network_id": lp.ExternalNetworkID,
"hypervisor": lp.Hypervisor,
"hypervisor_display_name": lp.HypervisorDisplayName,
"labels": flattenLabels(lp.Labels),
"live_migration_target_hv": lp.LiveMigrationTargetHV,
"status": flattenStatus(lp.Status),
"bindings": flattenBindings(lp.Bindings),
"unique_identifier": lp.UniqueIdentifier,
"updated_at": lp.UpdatedAt,
"version_id": int(lp.VersionID),
}
}
func flattenLogicalPorts(ports netobjgroups.LogicalPorts) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(ports))
for _, lp := range ports {
res = append(res, flattenLogicalPort(lp))
}
return res
}
func flattenL2ExternalNetwork(n netobjgroups.L2ExternalNetwork) []map[string]interface{} {
hypervisors := make([]interface{}, 0, len(n.Hypervisors))
for _, h := range n.Hypervisors {
hypervisors = append(hypervisors, h)
}
vlanTag := 0
if n.VLANTag != nil {
vlanTag = *n.VLANTag
}
return []map[string]interface{}{
{
"bridge_network_name": n.BridgeNetworkName,
"created_at": n.CreatedAt,
"description": n.Description,
"display_name": n.DisplayName,
"hypervisors": hypervisors,
"id": n.ID,
"updated_at": n.UpdatedAt,
"version_id": int(n.VersionID),
"vlan_tag": vlanTag,
},
}
}
func flattenL2ConnectionPorts(ports netobjgroups.L2ConnectionPorts) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(ports))
for _, p := range ports {
res = append(res, map[string]interface{}{
"id": p.ID,
"access_group_id": p.AccessGroupID,
"created_at": p.CreatedAt,
"updated_at": p.UpdatedAt,
"version_id": int(p.VersionID),
"l2_external_network": flattenL2ExternalNetwork(p.L2ExternalNetwork),
})
}
return res
}
func flattenIPv6Config(c netobjgroups.IPv6Config) []map[string]interface{} {
return []map[string]interface{}{
{
"address_mode": c.AddressMode,
"enable_periodic_ra": c.EnablePeriodicRA,
"interval_ra": int(c.IntervalRA),
"router_preference": c.RouterPreference,
},
}
}
func flattenRouterGatewayPort(r netobjgroups.RouterGateawayPort) []map[string]interface{} {
return []map[string]interface{}{
{
"created_at": r.CreatedAt,
"description": r.Description,
"id": r.ID,
"router_display_name": r.RouterDisplayName,
"router_id": r.RouterID,
"snat_enabled": r.SNATEnabled,
"updated_at": r.UpdatedAt,
},
}
}
func flattenSegment(s netobjgroups.Segment) []map[string]interface{} {
return []map[string]interface{}{
{
"access_group_id": s.AccessGroupID,
"access_group_name": s.AccessGroupName,
"created_at": s.CreatedAt,
"description": s.Description,
"display_name": s.DisplayName,
"enabled": s.Enabled,
"id": s.ID,
"subnet_v4": s.SubnetV4,
"subnet_v6": s.SubnetV6,
"updated_at": s.UpdatedAt,
"version_id": int(s.VersionID),
},
}
}
func flattenRouter(r netobjgroups.Router) []map[string]interface{} {
gateawayPorts := make([]map[string]interface{}, 0, len(r.GateawayPorts))
for _, gp := range r.GateawayPorts {
gateawayPorts = append(gateawayPorts, map[string]interface{}{
"created_at": gp.CreatedAt,
"description": gp.Description,
"external_l4_port_max": int(gp.ExternalL4PortMax),
"external_l4_port_min": int(gp.ExternalL4PortMin),
"id": gp.ID,
"snat_enabled": gp.SNATEnabled,
"status": flattenStatus(gp.Status),
"updated_at": gp.UpdatedAt,
"version_id": int(gp.VersionID),
})
}
policies := make([]map[string]interface{}, 0, len(r.Policies))
for _, pol := range r.Policies {
nextIPv4 := make([]interface{}, 0, len(pol.NextIPv4Address))
for _, ip := range pol.NextIPv4Address {
nextIPv4 = append(nextIPv4, ip)
}
nextIPv6 := make([]interface{}, 0, len(pol.NextIPv6Address))
for _, ip := range pol.NextIPv6Address {
nextIPv6 = append(nextIPv6, ip)
}
policies = append(policies, map[string]interface{}{
"action": pol.Action,
"created_at": pol.CreatedAt,
"display_name": pol.DisplayName,
"enabled": pol.Enabled,
"id": pol.ID,
"match": pol.Match,
"next_ipv4_address": nextIPv4,
"next_ipv6_address": nextIPv6,
"priority": pol.Priority,
"updated_at": pol.UpdatedAt,
"version_id": int(pol.VersionID),
})
}
ports := make([]map[string]interface{}, 0, len(r.Port))
for _, port := range r.Port {
ports = append(ports, map[string]interface{}{
"created_at": port.CreatedAt,
"description": port.Description,
"enabled": port.Enabled,
"id": port.ID,
"ipv4_address": port.IPv4Address,
"ipv6_address": port.IPv6Address,
"ipv6_config": flattenIPv6Config(port.IPv6Config),
"mac": port.MAC,
"segment_id": port.SegmentID,
"segment": flattenSegment(port.Segment),
"status": flattenStatus(port.Status),
"updated_at": port.UpdatedAt,
"version_id": int(port.VersionID),
})
}
return []map[string]interface{}{
{
"access_group_id": r.AccessGroupID,
"access_group_name": r.AccessGroupName,
"created_at": r.CreatedAt,
"description": r.Description,
"display_name": r.DisplayName,
"enabled": r.Enabled,
"gateaway_ports": gateawayPorts,
"id": r.ID,
"policies": policies,
"ports": ports,
"status": flattenStatus(r.Status),
"updated_at": r.UpdatedAt,
"version_id": int(r.VersionID),
},
}
}
func flattenFloatingIP(f netobjgroups.FloatingIP) []map[string]interface{} {
return []map[string]interface{}{
{
"access_group_id": f.AccessGroupID,
"access_group_name": f.AccessGroupName,
"created_at": f.CreatedAt,
"updated_at": f.UpdatedAt,
"version_id": int(f.VersionID),
"logical_port": []map[string]interface{}{flattenLogicalPort(f.LogicalPort)},
"router": flattenRouter(f.Router),
},
}
}
func flattenExternalNetworkPortFields(ports netobjgroups.ExternalNetworkPortsField) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(ports))
for _, p := range ports {
res = append(res, map[string]interface{}{
"access_group_id": p.AccessGroupID,
"access_group_name": p.AccessGroupName,
"comment": p.Comment,
"display_name": p.DisplayName,
"enabled": p.Enabled,
"ipv4": p.IPv4,
"ipv6": p.IPv6,
"ipv6_config": flattenIPv6Config(p.IPv6Config),
"mac": p.MAC,
"router_gateaway_port": flattenRouterGatewayPort(p.RouterGateawayPort),
"floating_ip": flattenFloatingIP(p.FloatingIP),
})
}
return res
}
func flattenExternalNetworkPorts(ports netobjgroups.ExternalNetworkPorts) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(ports))
for _, p := range ports {
hypervisors := make([]interface{}, 0, len(p.Hypervisors))
for _, h := range p.Hypervisors {
hypervisors = append(hypervisors, h)
}
res = append(res, map[string]interface{}{
"id": p.ID,
"access_group_id": p.AccessGroupID,
"access_group_name": p.AccessGroupName,
"bridge_network_name": p.BridgeNetworkName,
"comment": p.Comment,
"default_gateway_ipv4": p.DefaultGatewayIPv4,
"default_gateway_ipv6": p.DefaultGatewayIPv6,
"description": p.Description,
"enabled": p.Enabled,
"external_network_ports": flattenExternalNetworkPortFields(p.ExternalNetworkPorts),
"hypervisors": hypervisors,
"ipv4": p.IPv4,
"status": flattenStatus(p.Status),
"version_id": int(p.VersionID),
"subnet_v4": p.SubnetV4,
"subnet_v6": p.SubnetV6,
"created_at": p.CreatedAt,
"updated_at": p.UpdatedAt,
"vlan_tag": p.VLANTag,
"mac": p.MAC,
})
}
return res
}
func flattenAppliedNetObjectGroups(groups netobjgroups.AppliedNetObjectGroups) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(groups))
for _, g := range groups {
res = append(res, map[string]interface{}{
"id": g.ID,
"name": g.Name,
"version_id": int(g.VersionID),
})
}
return res
}
func flattenSecurityRules(rules netobjgroups.SecurityRules) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(rules))
for _, r := range rules {
srcNetObj := []map[string]interface{}{}
if r.SourceNetObject != nil {
srcNetObj = []map[string]interface{}{
{
"display_name": r.SourceNetObject.DisplayName,
"net_address_pool_id": r.SourceNetObject.NetAddressPoolID,
"net_object_group_id": r.SourceNetObject.NetObjectGroupID,
},
}
}
dstNetObj := []map[string]interface{}{}
if r.DestinationNetObject != nil {
dstNetObj = []map[string]interface{}{
{
"display_name": r.DestinationNetObject.DisplayName,
"net_address_pool_id": r.DestinationNetObject.NetAddressPoolID,
"net_object_group_id": r.DestinationNetObject.NetObjectGroupID,
},
}
}
filter := []map[string]interface{}{}
if r.Filter != nil {
tcpDstPorts := make([]interface{}, 0, len(r.Filter.Filters.TCPDstPorts))
for _, p := range r.Filter.Filters.TCPDstPorts {
tcpDstPorts = append(tcpDstPorts, p)
}
udpDstPorts := make([]interface{}, 0, len(r.Filter.Filters.UDPDstPorts))
for _, p := range r.Filter.Filters.UDPDstPorts {
udpDstPorts = append(udpDstPorts, p)
}
filter = []map[string]interface{}{
{
"name": r.Filter.Name,
"filters": []map[string]interface{}{
{
"all": r.Filter.Filters.All,
"arp": r.Filter.Filters.ARP,
"dhcp": r.Filter.Filters.DHCP,
"expression": r.Filter.Filters.Expression,
"icmp": r.Filter.Filters.ICMP,
"ip": r.Filter.Filters.IP,
"ip_v4": r.Filter.Filters.IPv4,
"ip_v6": r.Filter.Filters.IPv6,
"keep_opened_sessions": r.Filter.Filters.KeepOpenedSessions,
"nd": r.Filter.Filters.ND,
"tcp": r.Filter.Filters.TCP,
"tcp_dst_ports": tcpDstPorts,
"udp": r.Filter.Filters.UDP,
"udp_dst_ports": udpDstPorts,
},
},
},
}
}
res = append(res, map[string]interface{}{
"access_group_id": r.AccessGroupID,
"action": r.Action,
"description": r.Description,
"destination_net_object": dstNetObj,
"direction": r.Direction,
"display_name": r.DisplayName,
"enabled": r.Enabled,
"filter": filter,
"id": r.ID,
"log_enabled": r.LogEnabled,
"log_name": r.LogName,
"log_severity": r.LogSeverity,
"priority": r.Priority,
"security_policy_id": r.SecurityPolicyID,
"source_net_object": srcNetObj,
"statistics_enabled": r.StatisticsEnabled,
"type": r.Type,
"version_id": int(r.VersionID),
})
}
return res
}
func flattenSecurityPolicies(policies netobjgroups.SecurityPolicies) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(policies))
for _, p := range policies {
res = append(res, map[string]interface{}{
"access_group_id": p.AccessGroupID,
"access_group_name": p.AccessGroupName,
"applied_net_object_groups": flattenAppliedNetObjectGroups(p.AppliedNetObjectGroups),
"created_at": p.CreatedAt,
"description": p.Description,
"display_name": p.DisplayName,
"enabled": p.Enabled,
"end_priority": int(p.EndPriority),
"id": p.ID,
"security_rules": flattenSecurityRules(p.SecurityRules),
"start_priority": int(p.StartPriority),
"status": flattenStatus(p.Status),
"type": p.Type,
"version_id": int(p.VersionID),
"updated_at": p.UpdatedAt,
})
}
return res
}
func flattenNetworkObjectGroupList(list *netobjgroups.NetObjGroupList) []map[string]interface{} {
if list == nil {
return []map[string]interface{}{}
}
res := make([]map[string]interface{}, 0, len(list.Objects))
for _, v := range list.Objects {
res = append(res, map[string]interface{}{
"id": v.ID,
"name": v.Name,
"access_group_id": v.AccessGroupID,
"access_group_name": v.AccessGroupName,
"description": v.Description,
"type": v.Type,
"purpose": v.Purpose,
"version_id": int(v.VersionID),
"created_at": v.CreatedAt,
"updated_at": v.UpdatedAt,
"addresses": flattenAddresses(v.Addresses),
"counters": flattenCounters(v.Counters),
"l2_connection_ports": flattenL2ConnectionPorts(v.L2ConnectionPorts),
"logical_ports": flattenLogicalPorts(v.LogicalPorts),
"external_network_ports": flattenExternalNetworkPorts(v.ExternalNetworkPorts),
"security_policies": flattenSecurityPolicies(v.SecurityPolicies),
})
}
return res
}

View File

@@ -0,0 +1,322 @@
/*
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 netobjgroups
import (
"context"
"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/sdn/netobjgroups"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func resourceNetworkObjectGroupCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceNetworkObjectGroupCreate: called with name %s", d.Get("name").(string))
c := m.(*controller.ControllerCfg)
req := netobjgroups.CreateRequest{
AccessGroupID: d.Get("access_group_id").(string),
Description: d.Get("description").(string),
Name: d.Get("name").(string),
}
if addrRaw, ok := d.GetOk("addresses"); ok {
req.Addresses = buildAddressesRequest(addrRaw.([]interface{}))
}
if l2Raw, ok := d.GetOk("l2_connection_ports_bindings"); ok {
req.L2ConnectionPortsBindings = buildL2PortsBindingsRequest(l2Raw.([]interface{}))
}
rec, err := c.SDN().NetworkObjectGroups().Create(ctx, req)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
d.SetId(rec.ID)
return resourceNetworkObjectGroupRead(ctx, d, m)
}
func resourceNetworkObjectGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceNetworkObjectGroupRead: called with id %s", d.Id())
rec, err := utilityNetworkObjectGroupCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
flattenNetworkObjectGroupResource(d, rec)
d.SetId(rec.ID)
return nil
}
func resourceNetworkObjectGroupUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceNetworkObjectGroupUpdate: called with id %s", d.Id())
c := m.(*controller.ControllerCfg)
req := netobjgroups.UpdateRequest{
ObjectGroupID: d.Id(),
VersionID: uint64(d.Get("version_id").(int)),
AccessGroupID: d.Get("access_group_id").(string),
Description: d.Get("description").(string),
Name: d.Get("name").(string),
}
if addrRaw, ok := d.GetOk("addresses"); ok {
req.Addresses = buildAddressesRequest(addrRaw.([]interface{}))
}
rec, err := c.SDN().NetworkObjectGroups().Update(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId(rec.ID)
return resourceNetworkObjectGroupRead(ctx, d, m)
}
func resourceNetworkObjectGroupDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceNetworkObjectGroupDelete: called with id %s", d.Id())
c := m.(*controller.ControllerCfg)
req := netobjgroups.DeleteRequest{
ObjectGroupID: d.Id(),
VersionID: uint64(d.Get("version_id").(int)),
}
_, err := c.SDN().NetworkObjectGroups().Delete(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func buildL2PortsBindingsRequest(raw []interface{}) []netobjgroups.LogicalPortsBindings {
result := make([]netobjgroups.LogicalPortsBindings, 0, len(raw))
for _, item := range raw {
m := item.(map[string]interface{})
result = append(result, netobjgroups.LogicalPortsBindings{
PortID: m["port_id"].(string),
PortVersion: uint64(m["port_version"].(int)),
})
}
return result
}
func buildAddressesRequest(raw []interface{}) []netobjgroups.NetAddressRequest {
result := make([]netobjgroups.NetAddressRequest, 0, len(raw))
for _, item := range raw {
addrMap := item.(map[string]interface{})
addr := netobjgroups.NetAddressRequest{
NetAddressType: addrMap["net_address_type"].(string),
}
if v, ok := addrMap["ip_addr"].(string); ok && v != "" {
addr.IPAddr = v
}
if v, ok := addrMap["ip_addr_range_end"].(string); ok && v != "" {
addr.IPAddrRangeEnd = v
}
if v, ok := addrMap["ip_prefix"].(string); ok && v != "" {
addr.IPPrefix = v
}
if v, ok := addrMap["mac_addr"].(string); ok && v != "" {
addr.MACAddr = v
}
result = append(result, addr)
}
return result
}
func resourceNetworkObjectGroupSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"access_group_id": {
Type: schema.TypeString,
Required: true,
},
"description": {
Type: schema.TypeString,
Required: true,
},
"addresses": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"net_address_type": {
Type: schema.TypeString,
Required: true,
},
"ip_addr": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"ip_addr_range_end": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"ip_prefix": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"mac_addr": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
},
},
"l2_connection_ports_bindings": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"port_id": {
Type: schema.TypeString,
Required: true,
},
"port_version": {
Type: schema.TypeInt,
Required: true,
},
},
},
},
"access_group_name": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"purpose": {
Type: schema.TypeString,
Computed: true,
},
"version_id": {
Type: schema.TypeInt,
Computed: true,
},
"counters": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"addresses_count": {
Type: schema.TypeInt,
Computed: true,
},
"l2_connection_ports_count": {
Type: schema.TypeInt,
Computed: true,
},
"logical_ports_count": {
Type: schema.TypeInt,
Computed: true,
},
"security_policies_count": {
Type: schema.TypeInt,
Computed: true,
},
"security_rules_count": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"l2_connection_ports": l2ConnectionPortsComputedSchema(),
"logical_ports": logicalPortsComputedSchema(),
"external_network_ports": externalNetworkPortsComputedSchema(),
"security_policies": securityPoliciesComputedSchema(),
}
}
func ResourceNetworkObjectGroup() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceNetworkObjectGroupCreate,
ReadContext: resourceNetworkObjectGroupRead,
UpdateContext: resourceNetworkObjectGroupUpdate,
DeleteContext: resourceNetworkObjectGroupDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
CustomizeDiff: func(ctx context.Context, diff *schema.ResourceDiff, i interface{}) error {
changedKeys := diff.GetChangedKeysPrefix("")
if len(changedKeys) > 0 {
diff.SetNewComputed("version_id")
}
return nil
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout600s,
Read: &constants.Timeout300s,
Update: &constants.Timeout600s,
Delete: &constants.Timeout300s,
Default: &constants.Timeout300s,
},
Schema: resourceNetworkObjectGroupSchemaMake(),
}
}

View File

@@ -3,6 +3,7 @@ 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.
@@ -29,42 +30,31 @@ builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package segments
package netobjgroups
import (
"context"
"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"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/netobjgroups"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func dataSourceSegmentGetStatusRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
status, err := utilitySegmentGetStatusCheckPresence(ctx, d, m)
func utilityNetworkObjectGroupCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*netobjgroups.RecordNetObjGroup, error) {
c := m.(*controller.ControllerCfg)
req := netobjgroups.GetRequest{}
if d.Id() != "" {
req.NetObjGroupID = d.Id()
} else {
req.NetObjGroupID = d.Get("net_object_group_id").(string)
}
netObjGroup, err := c.SDN().NetworkObjectGroups().Get(ctx, req)
if err != nil {
d.SetId("")
return diag.FromErr(err)
return nil, err
}
if d.Id() == "" {
d.SetId(d.Get("segment_id").(string))
}
d.Set("status", status)
return nil
}
func DataSourceSegmentGetStatus() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceSegmentGetStatusRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceSegmentGetStatusSchemaMake(),
}
return netObjGroup, nil
}

View File

@@ -0,0 +1,87 @@
/*
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 netobjgroups
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/netobjgroups"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityNetworkObjectGroupListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*netobjgroups.NetObjGroupList, error) {
c := m.(*controller.ControllerCfg)
req := netobjgroups.ListRequest{}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if accessGroupID, ok := d.GetOk("access_group_id"); ok {
req.AccessGroupID = accessGroupID.(string)
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if perPage, ok := d.GetOk("per_page"); ok {
req.PerPage = uint64(perPage.(int))
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}
if sortOrder, ok := d.GetOk("sort_order"); ok {
req.SortOrder = sortOrder.(string)
}
if createdFrom, ok := d.GetOk("created_from"); ok {
req.CreatedFrom = createdFrom.(string)
}
if createdTo, ok := d.GetOk("created_to"); ok {
req.CreatedTo = createdTo.(string)
}
if updatedFrom, ok := d.GetOk("updated_from"); ok {
req.UpdatedFrom = updatedFrom.(string)
}
if updatedTo, ok := d.GetOk("updated_to"); ok {
req.UpdatedTo = updatedTo.(string)
}
log.Debugf("utilityNetworkObjectGroupListCheckPresence")
list, err := c.SDN().NetworkObjectGroups().List(ctx, req)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -14,11 +14,13 @@ func flattenSegment(d *schema.ResourceData, segmentRecord *segments.SegmentRespo
d.Set("dhcp_v6", flattenDHCPv6(segmentRecord.DHCPv6))
d.Set("display_name", segmentRecord.DisplayName)
d.Set("enabled", segmentRecord.Enabled)
d.Set("l2_connection_port", flattenL2ConnectionPort(segmentRecord.L2ConnectionPort))
d.Set("logical_ports_info", flattenEntity(segmentRecord.LogicalPortsInfo))
d.Set("routers_info", flattenEntity(segmentRecord.RoutersInfo))
d.Set("status", flattenStatus(segmentRecord.Status))
d.Set("subnet_v4", segmentRecord.SubnetV4)
d.Set("subnet_v6", segmentRecord.SubnetV6)
d.Set("type", segmentRecord.Type)
d.Set("updated_at", segmentRecord.UpdatedAt.String())
d.Set("version_id", segmentRecord.VersionID)
}
@@ -26,8 +28,8 @@ func flattenSegment(d *schema.ResourceData, segmentRecord *segments.SegmentRespo
func flattenStatus(s segments.Status) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"common": s.Common,
"hypervisors": flattenHypervisors(s.Hypervisors),
"operation_status": s.OperationStatus,
"hypervisors": flattenHypervisors(s.Hypervisors),
}
res = append(res, temp)
return res
@@ -37,7 +39,7 @@ func flattenHypervisors(hv []segments.HypervisorStatus) []map[string]interface{}
res := make([]map[string]interface{}, 0, len(hv))
for _, v := range hv {
temp := map[string]interface{}{
"status": v.Status,
"operation_status": v.OperationStatus,
"name": v.Name,
"display_name": v.DisplayName,
"hypervisor_status": v.HypervisorStatus,
@@ -90,6 +92,42 @@ func flattenDHCPv6(dchp segments.DHCPv6Config) []map[string]interface{} {
return res
}
func flattenL2ExternalNetwork(net segments.L2ExternalNetwork) []map[string]interface{} {
return []map[string]interface{}{
{
"id": net.ID,
"display_name": net.DisplayName,
"description": net.Description,
"bridge_network_name": net.BridgeNetworkName,
"hypervisors": net.Hypervisors,
"vlan_tag": net.VLANTag,
"version_id": net.VersionID,
"created_at": net.CreatedAt.String(),
"created_by": net.CreatedBy,
"updated_at": net.UpdatedAt.String(),
"updated_by": net.UpdatedBy,
},
}
}
func flattenL2ConnectionPort(port *segments.L2ConnectionPort) []map[string]interface{} {
if port == nil {
return nil
}
return []map[string]interface{}{
{
"id": port.ID,
"access_group_id": port.AccessGroupID,
"version_id": port.VersionID,
"created_at": port.CreatedAt.String(),
"created_by": port.CreatedBy,
"updated_at": port.UpdatedAt.String(),
"updated_by": port.UpdatedBy,
"l2_external_network": flattenL2ExternalNetwork(port.L2ExternalNetwork),
},
}
}
func flattenSegmentList(sl *segments.ListSegment) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(*sl))
for _, v := range *sl {
@@ -102,12 +140,14 @@ func flattenSegmentList(sl *segments.ListSegment) []map[string]interface{} {
"dhcp_v6": flattenDHCPv6(v.DHCPv6),
"display_name": v.DisplayName,
"enabled": v.Enabled,
"l2_connection_port": flattenL2ConnectionPort(v.L2ConnectionPort),
"logical_ports_info": flattenEntity(v.LogicalPortsInfo),
"routers_info": flattenEntity(v.RoutersInfo),
"status": flattenStatus(v.Status),
"id": v.ID,
"subnet_v4": v.SubnetV4,
"subnet_v6": v.SubnetV6,
"type": v.Type,
"updated_at": v.UpdatedAt.String(),
"version_id": v.VersionID,
}

View File

@@ -61,6 +61,10 @@ func resourceSegmentCreate(ctx context.Context, d *schema.ResourceData, m interf
Enabled: d.Get("enabled").(bool),
}
if t, ok := d.GetOk("type"); ok {
req.Type = t.(string)
}
if v4ok {
req.SubnetV4 = subnetV4.(string)
}
@@ -192,10 +196,14 @@ func resourceSegmentUpdate(ctx context.Context, d *schema.ResourceData, m interf
Enabled: d.Get("enabled").(bool),
}
if d.HasChanges("access_group_id", "description", "display_name", "enabled") {
if d.HasChanges("access_group_id", "description", "display_name", "enabled", "type") {
needUpdate = true
}
if t, ok := d.GetOk("type"); ok {
req.Type = t.(string)
}
if v4ok {
req.SubnetV4 = subnetV4.(string)
}

View File

@@ -5,6 +5,98 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func l2ExternalNetworkSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"display_name": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"bridge_network_name": {
Type: schema.TypeString,
Computed: true,
},
"hypervisors": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"vlan_tag": {
Type: schema.TypeInt,
Computed: true,
},
"version_id": {
Type: schema.TypeInt,
Computed: true,
},
"created_at": {
Type: schema.TypeString,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
}
}
func l2ConnectionPortSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"access_group_id": {
Type: schema.TypeString,
Computed: true,
},
"version_id": {
Type: schema.TypeInt,
Computed: true,
},
"created_at": {
Type: schema.TypeString,
Computed: true,
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"l2_external_network": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: l2ExternalNetworkSchema(),
},
},
}
}
func dataSourceSegmentSchemaMake() map[string]*schema.Schema {
sch := map[string]*schema.Schema{
"segment_id": {
@@ -117,6 +209,13 @@ func dataSourceSegmentSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"l2_connection_port": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: l2ConnectionPortSchema(),
},
},
"logical_ports_info": {
Type: schema.TypeList,
Computed: true,
@@ -154,7 +253,7 @@ func dataSourceSegmentSchemaMake() map[string]*schema.Schema {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"common": {
"operation_status": {
Type: schema.TypeString,
Computed: true,
},
@@ -163,7 +262,7 @@ func dataSourceSegmentSchemaMake() map[string]*schema.Schema {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"status": {
"operation_status": {
Type: schema.TypeString,
Computed: true,
},
@@ -197,6 +296,10 @@ func dataSourceSegmentSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
@@ -278,6 +381,12 @@ func dataSourceSegmentListSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "find by updated date",
},
"operation_status": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"Idle", "SynchronizingAtCore", "SynchronizingAtOVN", "Synchronized", "NoHypervisorAtOVN", "FailedAtCore", "TemporaryFailedAtCore"}, false),
Description: "filter by operation status",
},
"items": {
Type: schema.TypeList,
Computed: true,
@@ -392,6 +501,13 @@ func dataSourceSegmentListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"l2_connection_port": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: l2ConnectionPortSchema(),
},
},
"logical_ports_info": {
Type: schema.TypeList,
Computed: true,
@@ -429,7 +545,7 @@ func dataSourceSegmentListSchemaMake() map[string]*schema.Schema {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"common": {
"operation_status": {
Type: schema.TypeString,
Computed: true,
},
@@ -438,7 +554,7 @@ func dataSourceSegmentListSchemaMake() map[string]*schema.Schema {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"status": {
"operation_status": {
Type: schema.TypeString,
Computed: true,
},
@@ -472,6 +588,10 @@ func dataSourceSegmentListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
@@ -492,28 +612,6 @@ func dataSourceSegmentListSchemaMake() map[string]*schema.Schema {
return res
}
func dataSourceSegmentGetStatusSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"segment_id": {
Type: schema.TypeString,
Required: true,
},
"version_id": {
Type: schema.TypeInt,
Optional: true,
},
"detailed": {
Type: schema.TypeBool,
Optional: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
}
return res
}
func resourceSegmentSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"access_group_id": {
@@ -646,6 +744,13 @@ func resourceSegmentSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"l2_connection_port": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: l2ConnectionPortSchema(),
},
},
"logical_ports_info": {
Type: schema.TypeList,
Computed: true,
@@ -683,7 +788,7 @@ func resourceSegmentSchemaMake() map[string]*schema.Schema {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"common": {
"operation_status": {
Type: schema.TypeString,
Computed: true,
},
@@ -692,7 +797,7 @@ func resourceSegmentSchemaMake() map[string]*schema.Schema {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"status": {
"operation_status": {
Type: schema.TypeString,
Computed: true,
},
@@ -718,6 +823,11 @@ func resourceSegmentSchemaMake() map[string]*schema.Schema {
},
},
},
"type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"updated_at": {
Type: schema.TypeString,
Computed: true,

View File

@@ -1,36 +0,0 @@
package segments
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/segments"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilitySegmentGetStatusCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
c := m.(*controller.ControllerCfg)
req := segments.GetStatusRequest{}
if d.Id() != "" {
req.SegmentID = d.Id()
} else {
req.SegmentID = d.Get("segment_id").(string)
}
if version, ok := d.GetOk("version"); ok {
req.VersionID = uint64(version.(int))
}
if detailed, ok := d.GetOk("detailed"); ok {
req.Detailed = detailed.(bool)
}
segment, err := c.SDN().Segments().GetStatus(ctx, req)
if err != nil {
return "", err
}
return segment, nil
}

View File

@@ -29,7 +29,7 @@ func utilitySegmentListCheckPresence(ctx context.Context, d *schema.ResourceData
req.Enabled = enabled.(bool)
}
if isSynced, ok := d.GetOk("is_synced"); ok {
req.Enabled = isSynced.(bool)
req.IsSynced = isSynced.(bool)
}
if displayName, ok := d.GetOk("display_name"); ok {
req.DisplayName = displayName.(string)
@@ -47,11 +47,14 @@ func utilitySegmentListCheckPresence(ctx context.Context, d *schema.ResourceData
req.CreatedTo = createdTo.(string)
}
if updatedFrom, ok := d.GetOk("updated_from"); ok {
req.UpdatedTo = updatedFrom.(string)
req.UpdatedFrom = updatedFrom.(string)
}
if updatedTo, ok := d.GetOk("updated_to"); ok {
req.UpdatedTo = updatedTo.(string)
}
if operationStatus, ok := d.GetOk("operation_status"); ok {
req.OperationStatus = operationStatus.(string)
}
log.Debugf("utilitySegmentListCheckPresence")
segmentList, err := c.SDN().Segments().List(ctx, req)