4.12.0
This commit is contained in:
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package segments
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
func dataSourceSegmentGetStatusRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
status, err := utilitySegmentGetStatusCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(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(),
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user