4.13.0
This commit is contained in:
@@ -37,6 +37,7 @@ import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
|
||||
)
|
||||
|
||||
func flattenListExtnet(extList *extnet.ListExtNet) []map[string]interface{} {
|
||||
@@ -129,8 +130,10 @@ func flattenRecordExtnetResource(d *schema.ResourceData, recNet *extnet.RecordEx
|
||||
d.Set("ovs_bridge", recNet.OVSBridge)
|
||||
d.Set("pre_reservations_num", recNet.PreReservationsNum)
|
||||
d.Set("pri_vnfdev_id", recNet.PriVNFDevID)
|
||||
d.Set("sec_vnfdev_id", recNet.SecVNFDevID)
|
||||
d.Set("shared_with", recNet.SharedWith)
|
||||
d.Set("status", recNet.Status)
|
||||
d.Set("enable", recNet.Status == status.Enabled)
|
||||
d.Set("vlan_id", recNet.VLANID)
|
||||
d.Set("check_ips", recNet.CheckIPs)
|
||||
d.Set("dns", recNet.DNS)
|
||||
@@ -146,9 +149,8 @@ func flattenRecordExtnetResource(d *schema.ResourceData, recNet *extnet.RecordEx
|
||||
d.Set("routes", flattenStaticRouteList(staticRouteList))
|
||||
d.Set("zone_id", recNet.ZoneID)
|
||||
d.Set("enable_secgroups", recNet.EnableSecGroups)
|
||||
d.Set("sec_vnfdev_id", recNet.SecVNFDevID)
|
||||
d.Set("highly_available", recNet.Redundant)
|
||||
d.Set("mtu", recNet.MTU)
|
||||
d.Set("highly_available", recNet.Redundant)
|
||||
}
|
||||
|
||||
func flattenExtnetExcluded(ers extnet.ListReservations) []map[string]interface{} {
|
||||
|
||||
@@ -93,15 +93,6 @@ func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interfa
|
||||
req.DNS = res
|
||||
}
|
||||
|
||||
if ntp, ok := d.GetOk("ntp"); ok {
|
||||
res := make([]string, 0)
|
||||
for _, elem := range ntp.([]interface{}) {
|
||||
res = append(res, elem.(string))
|
||||
}
|
||||
|
||||
req.NTP = res
|
||||
}
|
||||
|
||||
if check_ips, ok := d.GetOk("check_ips"); ok {
|
||||
res := make([]string, 0)
|
||||
for _, elem := range check_ips.([]interface{}) {
|
||||
@@ -111,9 +102,7 @@ func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interfa
|
||||
req.CheckIPs = res
|
||||
}
|
||||
|
||||
if virtual, ok := d.GetOk("virtual"); ok {
|
||||
req.Virtual = virtual.(bool)
|
||||
}
|
||||
req.Virtual = d.Get("virtual").(bool)
|
||||
|
||||
if zoneID, ok := d.GetOk("zone_id"); ok {
|
||||
req.ZoneID = uint64(zoneID.(int))
|
||||
@@ -139,9 +128,7 @@ func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interfa
|
||||
req.OVSBridge = ovs_bridge.(string)
|
||||
}
|
||||
|
||||
if highly_available, ok := d.GetOk("highly_available"); ok {
|
||||
req.HAMode = highly_available.(bool)
|
||||
}
|
||||
req.HAMode = d.Get("highly_available").(bool)
|
||||
|
||||
if sec_vnfdev_ip, ok := d.GetOk("sec_vnfdev_ip"); ok {
|
||||
req.SecVNFDevIP = sec_vnfdev_ip.(string)
|
||||
@@ -227,6 +214,12 @@ func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interfa
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := d.GetOk("ntp"); ok {
|
||||
if err := handleNTPUpdate(ctx, d, c, &extnet.RecordExtNet{ID: netID}); err != nil {
|
||||
w.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
if qos, ok := d.GetOk("default_qos"); ok && len(qos.([]interface{})) > 0 {
|
||||
if err := handleDefaultQOSUpdate(ctx, d, c, &extnet.RecordExtNet{ID: netID}); err != nil {
|
||||
w.Add(err)
|
||||
|
||||
@@ -686,12 +686,12 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "Grid (platform) ID",
|
||||
Description: "Grid platform ID",
|
||||
},
|
||||
"ipcidr": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
// ForceNew: true,
|
||||
// ForceNew: true,?
|
||||
Description: "IP network CIDR",
|
||||
ValidateFunc: validation.IsCIDR,
|
||||
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
|
||||
@@ -724,7 +724,7 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "enable security groups",
|
||||
Description: "Enable security groups",
|
||||
},
|
||||
"dns": {
|
||||
Type: schema.TypeList,
|
||||
@@ -754,12 +754,12 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
ValidateFunc: validation.IsIPAddress,
|
||||
},
|
||||
Description: "IPs to check network availability",
|
||||
Description: "IPs checking network availability",
|
||||
},
|
||||
"virtual": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Description: "If true - platform DHCP server will not be created",
|
||||
Description: "True disables platform DHCP server creation",
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
@@ -770,44 +770,44 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
"start_ip": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "Start of IP range to be explicitly included",
|
||||
Description: "Explicitly included IP range start",
|
||||
ValidateFunc: validation.IsIPAddress,
|
||||
},
|
||||
"end_ip": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "End of IP range to be explicitly included",
|
||||
Description: "Explicitly included IP range end",
|
||||
ValidateFunc: validation.IsIPAddress,
|
||||
},
|
||||
"vnfdev_ip": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "IP to create VNFDev with",
|
||||
Description: "VNFDev creation IP",
|
||||
ValidateFunc: validation.IsIPAddress,
|
||||
},
|
||||
"pre_reservations_num": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Number of pre created reservations",
|
||||
Description: "Number of pre-created reservations",
|
||||
},
|
||||
"ovs_bridge": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "OpenvSwith bridge name for ExtNet connection",
|
||||
Description: "OpenvSwitch bridge name ExtNet connection",
|
||||
},
|
||||
"enable": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: true,
|
||||
Description: "Disable/Enable extnet",
|
||||
Description: "Toggle extnet status",
|
||||
},
|
||||
"set_default": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "Set current extnet as default (can not be undone)",
|
||||
Description: "Set current extnet as default permanent action",
|
||||
},
|
||||
"excluded_ips": {
|
||||
Type: schema.TypeSet,
|
||||
@@ -816,7 +816,7 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
ValidateFunc: validation.IsIPAddress,
|
||||
},
|
||||
Description: "IPs to exclude in current extnet pool",
|
||||
Description: "IPs excluded extnet pool",
|
||||
},
|
||||
"excluded_ips_range": {
|
||||
Type: schema.TypeSet,
|
||||
@@ -835,7 +835,7 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
},
|
||||
},
|
||||
},
|
||||
Description: "Range of IPs to exclude in current extnet pool",
|
||||
Description: "Range of IPs excluded extnet pool",
|
||||
},
|
||||
"default_qos": {
|
||||
Type: schema.TypeList,
|
||||
@@ -869,7 +869,7 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
"restart": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Description: "restart extnet vnf device",
|
||||
Description: "Restart extnet vnf device",
|
||||
},
|
||||
"migrate": {
|
||||
Type: schema.TypeInt,
|
||||
@@ -920,9 +920,10 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
ValidateFunc: validation.IsIPAddress,
|
||||
},
|
||||
"mtu": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ValidateFunc: validation.IntBetween(1500, 9216),
|
||||
},
|
||||
"ckey": {
|
||||
Type: schema.TypeString,
|
||||
@@ -934,7 +935,7 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Description: "meta",
|
||||
Description: "Meta information",
|
||||
},
|
||||
"default": {
|
||||
Type: schema.TypeBool,
|
||||
@@ -1044,7 +1045,42 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"pre_reservations": {
|
||||
"routes": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"compute_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"destination": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"gateway": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"netmask": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"route_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"reservations": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
@@ -1088,42 +1124,7 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
},
|
||||
},
|
||||
},
|
||||
"routes": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"compute_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"destination": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"gateway": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"netmask": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"route_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"reservations": {
|
||||
"pre_reservations": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
|
||||
@@ -122,19 +122,32 @@ func handleBasicUpdate(ctx context.Context, d *schema.ResourceData, c *controlle
|
||||
basiUpdateReq.MTU = uint64(d.Get("mtu").(int))
|
||||
doBasicUpdate = true
|
||||
}
|
||||
if d.HasChange("enable_secgroups") {
|
||||
changingSecGroups := d.HasChange("enable_secgroups")
|
||||
if changingSecGroups {
|
||||
basiUpdateReq.EnableSecGroups = d.Get("enable_secgroups").(bool)
|
||||
doBasicUpdate = true
|
||||
}
|
||||
|
||||
if doBasicUpdate {
|
||||
_, err := c.CloudBroker().ExtNet().Update(ctx, basiUpdateReq)
|
||||
if err != nil {
|
||||
if !doBasicUpdate {
|
||||
return nil
|
||||
}
|
||||
|
||||
wasEnabled := changingSecGroups && recNet.Status == status.Enabled
|
||||
if wasEnabled {
|
||||
if _, err := c.CloudBroker().ExtNet().Disable(ctx, extnet.DisableRequest{NetID: recNet.ID}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
_, err := c.CloudBroker().ExtNet().Update(ctx, basiUpdateReq)
|
||||
|
||||
if wasEnabled {
|
||||
if _, enableErr := c.CloudBroker().ExtNet().Enable(ctx, extnet.EnableRequest{NetID: recNet.ID}); enableErr != nil {
|
||||
return errors.Join(err, enableErr)
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func handleEnableUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
|
||||
Reference in New Issue
Block a user