This commit is contained in:
2024-11-12 13:41:38 +03:00
parent 040af43607
commit 36879efd58
517 changed files with 37877 additions and 1900 deletions

View File

@@ -475,7 +475,6 @@ func flattenResourceRG(d *schema.ResourceData, rgData *rg.RecordRG) {
d.Set("gid", rgData.GID)
d.Set("rg_name", rgData.Name)
d.Set("resource_limits", flattenRgResourceLimits(rgData.ResourceLimits))
d.Set("def_net_type", rgData.DefNetType)
d.Set("description", rgData.Description)
d.Set("register_computes", rgData.RegisterComputes)
d.Set("uniq_pools", rgData.UniqPools)

View File

@@ -77,7 +77,6 @@ type ResgroupUpdateParam struct {
Disk int `json:"maxVDiskCapacity"`
Cpu int `json:"maxCPUCapacity"`
NetTraffic int `json:"maxNetworkPeerTransfer"`
Reason string `json:"reason"`
}
type AccountAclRecord struct {

View File

@@ -117,18 +117,10 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter
req.DefNet = defNetType.(string)
}
if ipcidr, ok := d.GetOk("ipcidr"); ok {
req.IPCIDR = ipcidr.(string)
}
if description, ok := d.GetOk("description"); ok {
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))
}
@@ -211,7 +203,6 @@ func resourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interfa
d.Get("rg_name").(string), d.Get("account_id").(int))
//c := m.(*controller.ControllerCfg)
rgData, err := utilityResgroupCheckPresence(ctx, d, m)
if err != nil {
d.SetId("") // ensure ID is empty
@@ -301,8 +292,7 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter
restore, ok := d.GetOk("restore")
if ok && restore.(bool) {
restoreReq := rg.RestoreRequest{
RGID: rgData.ID,
Reason: "automatic restore of resource by terraform",
RGID: rgData.ID,
}
_, err := c.CloudBroker().RG().Restore(ctx, restoreReq)
@@ -316,8 +306,7 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter
enable, ok := d.GetOk("enable")
if ok && enable.(bool) {
enableReq := rg.EnableRequest{
RGID: rgData.ID,
Reason: "automatic enable of resource by terraform",
RGID: rgData.ID,
}
_, err = c.CloudBroker().RG().Enable(ctx, enableReq)
@@ -349,20 +338,12 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter
/* NOTE: we do not allow changing the following attributes of an existing RG via terraform:
- def_net_type
- ipcidr
- ext_net_id
- ext_ip
The following code fragment checks if any of these have been changed and generates error.
*/
if ok := d.HasChange("def_net"); ok {
_, 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"} {
for _, attr := range []string{"def_net_type", "ext_ip"} {
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))
@@ -444,6 +425,9 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter
if d.HasChange("uniq_pools") {
uniqPools := d.Get("uniq_pools").([]interface{})
if len(uniqPools) == 0 {
req.ClearUniqPools = true
}
for _, pool := range uniqPools {
req.UniqPools = append(req.UniqPools, pool.(string))
}
@@ -468,6 +452,13 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter
}
if d.HasChange("def_net") {
oldDefNet, _ := d.GetChange("def_net")
if oldDefNet.(*schema.Set).Len() > 0 {
_, err := c.CloudBroker().RG().RemoveDefNet(ctx, rg.RemoveDefNetRequest{RGID: rgData.ID})
if err != nil {
return diag.FromErr(err)
}
}
if err := resourceRGSetDefNet(ctx, d, m); err != nil {
return diag.FromErr(err)
}
@@ -520,9 +511,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)
}
c := m.(*controller.ControllerCfg)
_, err = c.CloudBroker().RG().Delete(ctx, req)
@@ -559,10 +547,6 @@ func resourceRGAccessGrant(ctx context.Context, d *schema.ResourceData, m interf
Right: right,
}
if reason, ok := access["reason"]; ok {
req.Reason = reason.(string)
}
if _, err := c.CloudBroker().RG().AccessGrant(ctx, req); err != nil {
errs = append(errs, err)
}
@@ -593,9 +577,6 @@ func resourceRGSetDefNet(ctx context.Context, d *schema.ResourceData, m interfac
if netID, ok := defNetItem["net_id"]; ok {
req.NetID = uint64(netID.(int))
}
if reason, ok := defNetItem["reason"]; ok {
req.Reason = reason.(string)
}
_, err := c.CloudBroker().RG().SetDefNet(ctx, req)
return err
@@ -651,10 +632,6 @@ func resourceRGChangeAccess(ctx context.Context, d *schema.ResourceData, m inter
User: user,
}
if reason, ok := deleteItem["reason"]; ok {
reqRevoke.Reason = reason.(string)
}
_, err := c.CloudBroker().RG().AccessRevoke(ctx, reqRevoke)
if err != nil {
return err
@@ -673,10 +650,6 @@ func resourceRGChangeAccess(ctx context.Context, d *schema.ResourceData, m inter
Right: right,
}
if reason, ok := addedItem["reason"]; ok {
reqGrant.Reason = reason.(string)
}
_, err := c.CloudBroker().RG().AccessGrant(ctx, reqGrant)
if err != nil {
return err
@@ -749,6 +722,17 @@ func ResourceResgroup() *schema.Resource {
StateContext: schema.ImportStatePassthroughContext,
},
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
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout600s,
Read: &constants.Timeout300s,

View File

@@ -11,10 +11,7 @@ func dataSourceRgSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Required: true,
},
"reason": {
Type: schema.TypeString,
Optional: true,
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
@@ -739,10 +736,6 @@ func dataSourceRgUsageSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Required: true,
},
"reason": {
Type: schema.TypeString,
Optional: true,
},
"cpu": {
Type: schema.TypeInt,
@@ -2268,7 +2261,6 @@ func resourceRgSchemaMake() map[string]*schema.Schema {
"def_net_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
// Default: "PRIVATE",
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.",
@@ -2287,11 +2279,6 @@ func resourceRgSchemaMake() map[string]*schema.Schema {
Description: "User-defined text description of this resource group.",
},
"reason": {
Type: schema.TypeString,
Optional: true,
},
"ext_net_id": {
Type: schema.TypeInt,
Optional: true,
@@ -2337,11 +2324,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",
},
},
},
},
@@ -2364,11 +2346,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",
},
},
},
},

View File

@@ -50,9 +50,6 @@ func utilityResgroupCheckPresence(ctx context.Context, d *schema.ResourceData, m
} else {
req.RGID = uint64(d.Get("rg_id").(int))
}
if reason, ok := d.GetOk("reason"); ok {
req.Reason = reason.(string)
}
rgData, err := c.CloudBroker().RG().Get(ctx, req)
if err != nil {

View File

@@ -46,10 +46,6 @@ func utilityDataRgUsageCheckPresence(ctx context.Context, d *schema.ResourceData
RGID: uint64(d.Get("rg_id").(int)),
}
if reason, ok := d.GetOk("reason"); ok {
req.Reason = reason.(string)
}
usage, err := c.CloudBroker().RG().Usage(ctx, req)
if err != nil {
return nil, err