|
|
|
|
@@ -45,7 +45,6 @@ import (
|
|
|
|
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
|
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
|
|
|
|
)
|
|
|
|
|
@@ -139,8 +138,6 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter
|
|
|
|
|
}
|
|
|
|
|
if defNetType, ok := d.GetOk("def_net_type"); ok {
|
|
|
|
|
req.DefNet = defNetType.(string) // NOTE: in API default network type is set by "def_net" parameter
|
|
|
|
|
} else {
|
|
|
|
|
d.Set("def_net_type", "PRIVATE")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if owner, ok := d.GetOk("owner"); ok {
|
|
|
|
|
@@ -155,10 +152,6 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter
|
|
|
|
|
req.Description = description.(string)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if reason, ok := d.GetOk("reason"); ok {
|
|
|
|
|
req.Reason = reason.(string)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if extNetId, ok := d.GetOk("ext_net_id"); ok {
|
|
|
|
|
req.ExtNetID = uint64(extNetId.(int))
|
|
|
|
|
}
|
|
|
|
|
@@ -195,10 +188,6 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter
|
|
|
|
|
Right: right,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if reason, ok := d.GetOk("reason"); ok {
|
|
|
|
|
req.Reason = reason.(string)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := c.CloudAPI().RG().AccessGrant(ctx, req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
w.Add(err)
|
|
|
|
|
@@ -222,16 +211,12 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter
|
|
|
|
|
if netID, ok := defNetItem["net_id"]; ok {
|
|
|
|
|
req.NetID = uint64(netID.(int))
|
|
|
|
|
}
|
|
|
|
|
if reason, ok := defNetItem["reason"]; ok {
|
|
|
|
|
req.Reason = reason.(string)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := c.CloudAPI().RG().SetDefNet(ctx, req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
w.Add(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d.Set("def_net_type", netType)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@@ -242,10 +227,6 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter
|
|
|
|
|
RGID: apiResp,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if reason, ok := d.GetOk("reason"); ok {
|
|
|
|
|
req.Reason = reason.(string)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := c.CloudAPI().RG().Enable(ctx, req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
w.Add(err)
|
|
|
|
|
@@ -255,10 +236,6 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter
|
|
|
|
|
RGID: apiResp,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if reason, ok := d.GetOk("reason"); ok {
|
|
|
|
|
req.Reason = reason.(string)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := c.CloudAPI().RG().Disable(ctx, req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
w.Add(err)
|
|
|
|
|
@@ -287,7 +264,6 @@ func resourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interfa
|
|
|
|
|
case status.Modeled:
|
|
|
|
|
return diag.Errorf("The resource group is in status: %s, please, contact support for more information", rgData.Status)
|
|
|
|
|
case status.Created:
|
|
|
|
|
case status.Enabled:
|
|
|
|
|
case status.Deleted:
|
|
|
|
|
// restoreReq := rg.RestoreRequest{RGID: rgData.ID}
|
|
|
|
|
// enableReq := rg.EnableRequest{RGID: rgData.ID}
|
|
|
|
|
@@ -374,10 +350,6 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter
|
|
|
|
|
if restore, ok := d.GetOk("restore"); ok && restore.(bool) {
|
|
|
|
|
restoreReq := rg.RestoreRequest{RGID: rgData.ID}
|
|
|
|
|
|
|
|
|
|
if reason, ok := d.GetOk("reason"); ok {
|
|
|
|
|
restoreReq.Reason = reason.(string)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := c.CloudAPI().RG().Restore(ctx, restoreReq)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return diag.FromErr(err)
|
|
|
|
|
@@ -386,9 +358,6 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter
|
|
|
|
|
if enable, ok := d.GetOk("enable"); ok && enable.(bool) {
|
|
|
|
|
enableReq := rg.EnableRequest{RGID: rgData.ID}
|
|
|
|
|
|
|
|
|
|
if reason, ok := d.GetOk("reason"); ok {
|
|
|
|
|
enableReq.Reason = reason.(string)
|
|
|
|
|
}
|
|
|
|
|
_, err = c.CloudAPI().RG().Enable(ctx, enableReq)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return diag.FromErr(err)
|
|
|
|
|
@@ -423,26 +392,19 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter
|
|
|
|
|
|
|
|
|
|
The following code fragment checks if any of these have been changed and generates error.
|
|
|
|
|
*/
|
|
|
|
|
if d.HasChange("def_net") {
|
|
|
|
|
_, newDefNet := d.GetChange("def_net")
|
|
|
|
|
if newDefNet.(*schema.Set).Len() == 0 {
|
|
|
|
|
return diag.Errorf("resourceResgroupUpdate: block def_net must not be empty")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, attr := range []string{"def_net_type", "ipcidr", "ext_ip"} {
|
|
|
|
|
attr_new, attr_old := d.GetChange("def_net_type")
|
|
|
|
|
if attr_new.(string) != attr_old.(string) {
|
|
|
|
|
attrNew, attrOld := d.GetChange(attr)
|
|
|
|
|
if attrNew.(string) != attrOld.(string) {
|
|
|
|
|
return diag.FromErr(fmt.Errorf("resourceResgroupUpdate: RG ID %s: changing %s for existing RG is not allowed", d.Id(), attr))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attrNew, attrOld := d.GetChange("ext_net_id")
|
|
|
|
|
if attrNew.(int) != attrOld.(int) {
|
|
|
|
|
if d.HasChange("ext_net_id") {
|
|
|
|
|
return diag.FromErr(fmt.Errorf("resourceResgroupUpdate: RG ID %s: changing ext_net_id for existing RG is not allowed", d.Id()))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if d.HasChanges("name", "quota", "description", "register_computes") {
|
|
|
|
|
if d.HasChanges("name", "quota", "description", "register_computes", "uniq_pools") {
|
|
|
|
|
if err := utilityUpdateRG(ctx, d, m, rgData.ID); err != nil {
|
|
|
|
|
return diag.FromErr(err)
|
|
|
|
|
}
|
|
|
|
|
@@ -477,9 +439,6 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter
|
|
|
|
|
RGID: rgData.ID,
|
|
|
|
|
User: user,
|
|
|
|
|
}
|
|
|
|
|
if reason, ok := d.GetOk("reason"); ok {
|
|
|
|
|
req.Reason = reason.(string)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := c.CloudAPI().RG().AccessRevoke(ctx, req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
@@ -499,10 +458,6 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter
|
|
|
|
|
Right: right,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if reason, ok := d.GetOk("reason"); ok {
|
|
|
|
|
req.Reason = reason.(string)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := c.CloudAPI().RG().AccessGrant(ctx, req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return diag.FromErr(err)
|
|
|
|
|
@@ -511,30 +466,31 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if d.HasChange("def_net") {
|
|
|
|
|
if ok := d.HasChange("def_net"); ok {
|
|
|
|
|
oldDefNet, newDefNet := d.GetChange("def_net")
|
|
|
|
|
if newDefNet.(*schema.Set).Len() > 0 {
|
|
|
|
|
changedDefNet := (newDefNet.(*schema.Set).Difference(oldDefNet.(*schema.Set))).List()
|
|
|
|
|
for _, changedDefNetInterface := range changedDefNet {
|
|
|
|
|
defNetItem := changedDefNetInterface.(map[string]interface{})
|
|
|
|
|
netType := defNetItem["net_type"].(string)
|
|
|
|
|
oldDefNet, newDefNet := d.GetChange("def_net")
|
|
|
|
|
if oldDefNet.(*schema.Set).Len() > 0 {
|
|
|
|
|
_, err := c.CloudAPI().RG().RemoveDefNet(ctx, rg.RemoveDefNetRequest{RGID: rgData.ID})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return diag.FromErr(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if newDefNet.(*schema.Set).Len() > 0 {
|
|
|
|
|
changedDefNet := (newDefNet.(*schema.Set).Difference(oldDefNet.(*schema.Set))).List()
|
|
|
|
|
for _, changedDefNetInterface := range changedDefNet {
|
|
|
|
|
defNetItem := changedDefNetInterface.(map[string]interface{})
|
|
|
|
|
netType := defNetItem["net_type"].(string)
|
|
|
|
|
|
|
|
|
|
req := rg.SetDefNetRequest{
|
|
|
|
|
RGID: rgData.ID,
|
|
|
|
|
NetType: netType,
|
|
|
|
|
}
|
|
|
|
|
req := rg.SetDefNetRequest{
|
|
|
|
|
RGID: rgData.ID,
|
|
|
|
|
NetType: netType,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if netID, ok := defNetItem["net_id"]; ok {
|
|
|
|
|
req.NetID = uint64(netID.(int))
|
|
|
|
|
}
|
|
|
|
|
if reason, ok := defNetItem["reason"]; ok {
|
|
|
|
|
req.Reason = reason.(string)
|
|
|
|
|
}
|
|
|
|
|
if netID, ok := defNetItem["net_id"]; ok {
|
|
|
|
|
req.NetID = uint64(netID.(int))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := c.CloudAPI().RG().SetDefNet(ctx, req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return diag.FromErr(err)
|
|
|
|
|
}
|
|
|
|
|
_, err := c.CloudAPI().RG().SetDefNet(ctx, req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return diag.FromErr(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -559,9 +515,6 @@ func resourceResgroupDelete(ctx context.Context, d *schema.ResourceData, m inter
|
|
|
|
|
if permanently, ok := d.GetOk("permanently"); ok {
|
|
|
|
|
req.Permanently = permanently.(bool)
|
|
|
|
|
}
|
|
|
|
|
if reason, ok := d.GetOk("reason"); ok {
|
|
|
|
|
req.Reason = reason.(string)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err := c.CloudAPI().RG().Delete(ctx, req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
@@ -598,7 +551,6 @@ func ResourceRgSchemaMake() map[string]*schema.Schema {
|
|
|
|
|
"def_net_type": {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Optional: true,
|
|
|
|
|
Computed: true,
|
|
|
|
|
ValidateFunc: validation.StringInSlice([]string{"PRIVATE", "PUBLIC", "NONE"}, false),
|
|
|
|
|
Description: "Type of the network, which this resource group will use as default for its computes - PRIVATE or PUBLIC or NONE.",
|
|
|
|
|
},
|
|
|
|
|
@@ -700,11 +652,6 @@ func ResourceRgSchemaMake() map[string]*schema.Schema {
|
|
|
|
|
Required: true,
|
|
|
|
|
Description: "Access rights to set, one of 'R', 'RCX' or 'ARCXDU'",
|
|
|
|
|
},
|
|
|
|
|
"reason": {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Optional: true,
|
|
|
|
|
Description: "Reason for action",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
@@ -727,11 +674,6 @@ func ResourceRgSchemaMake() map[string]*schema.Schema {
|
|
|
|
|
Default: 0,
|
|
|
|
|
Description: "Network segment ID. If netType is PUBLIC and netId is 0 then default external network segment will be selected. If netType is PRIVATE and netId=0, the first ViNS defined for this RG will be selected. Otherwise, netId identifies either existing external network segment or ViNS.",
|
|
|
|
|
},
|
|
|
|
|
"reason": {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Optional: true,
|
|
|
|
|
Description: "Reason for action",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
@@ -754,11 +696,6 @@ func ResourceRgSchemaMake() map[string]*schema.Schema {
|
|
|
|
|
Default: false,
|
|
|
|
|
Description: "Set to True if you want force delete non-empty RG",
|
|
|
|
|
},
|
|
|
|
|
"reason": {
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Optional: true,
|
|
|
|
|
Description: "Set to True if you want force delete non-empty RG",
|
|
|
|
|
},
|
|
|
|
|
"register_computes": {
|
|
|
|
|
Type: schema.TypeBool,
|
|
|
|
|
Optional: true,
|
|
|
|
|
@@ -876,6 +813,7 @@ func ResourceRgSchemaMake() map[string]*schema.Schema {
|
|
|
|
|
},
|
|
|
|
|
"uniq_pools": {
|
|
|
|
|
Type: schema.TypeList,
|
|
|
|
|
Optional: true,
|
|
|
|
|
Computed: true,
|
|
|
|
|
Elem: &schema.Schema{
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
@@ -913,25 +851,18 @@ func ResourceResgroup() *schema.Resource {
|
|
|
|
|
Default: &constants.Timeout300s,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
CustomizeDiff: func(ctx context.Context, diff *schema.ResourceDiff, i interface{}) error {
|
|
|
|
|
if diff.HasChange("def_net") {
|
|
|
|
|
diff.SetNewComputed("def_net_id")
|
|
|
|
|
}
|
|
|
|
|
if diff.HasChanges() {
|
|
|
|
|
diff.SetNewComputed("updated_by")
|
|
|
|
|
diff.SetNewComputed("updated_time")
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
Schema: ResourceRgSchemaMake(),
|
|
|
|
|
CustomizeDiff: customdiff.All(
|
|
|
|
|
customdiff.IfValueChange("def_net",
|
|
|
|
|
func(ctx context.Context, oldValue, newValue, meta interface{}) bool {
|
|
|
|
|
return true
|
|
|
|
|
},
|
|
|
|
|
func(ctx context.Context, d *schema.ResourceDiff, m interface{}) error {
|
|
|
|
|
oldValue, newValue := d.GetChange("def_net")
|
|
|
|
|
|
|
|
|
|
old := len(oldValue.(*schema.Set).List())
|
|
|
|
|
new_ := len(newValue.(*schema.Set).List())
|
|
|
|
|
|
|
|
|
|
if old == 1 && new_ == 0 {
|
|
|
|
|
return fmt.Errorf("CustomizeDiff: block def_net must not be empty")
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
StateUpgraders: []schema.StateUpgrader{
|
|
|
|
|
{
|
|
|
|
|
Type: resourceRGResourceV1().CoreConfigSchema().ImpliedType(),
|
|
|
|
|
|