diff --git a/docs/resources/vserver_server.md b/docs/resources/vserver_server.md index c9e53a3..a41f074 100644 --- a/docs/resources/vserver_server.md +++ b/docs/resources/vserver_server.md @@ -44,7 +44,6 @@ The following arguments are supported: - **action** (String, Optional) Action with server. It can be `stop`, `start` and `reboot`. - **attach_floating** (Boolean, Optional) Is Server attach a floating IP. - **expire_password** (Boolean, Optional) Skip change password: false, else: true -- **is_poc** (Boolean, Optional) POC wallet. - **os_licence** (Boolean, Optional) Licence of OS. - **root_disk_encryption_type** (String, Optional) Type encryption of boot volume. - **security_group** (List of String, Optional) ID of the SecGroups. @@ -81,8 +80,6 @@ In addition to all arguments above, the following attributes are exported: - **subnet_uuid** (String) - **type** (String) - **os_info** (String) Info OS. -- **owner_email** (String) Email owner of Server. -- **share** (Boolean) Is Server Shared? - **ssh_key_name** (String) Name of SSH Key. diff --git a/docs/resources/vserver_volume.md b/docs/resources/vserver_volume.md index e71b190..429f5d2 100644 --- a/docs/resources/vserver_volume.md +++ b/docs/resources/vserver_volume.md @@ -30,15 +30,12 @@ The following arguments are supported: - **size** (Number, Required) Size of Volume. - **volume_type_id** (String, Required) ID of Volume's Type - **encryption_type** (String, Optional) Type encryption of volume. -- **is_poc** (Boolean, Optional) POC wallet. ## Attributes Reference In addition to all arguments above, the following attributes are exported: - **id** (String) The ID of this Volume. -- **owner_email** (String) Email owner of this Volume. -- **share** (Boolean) Is volume shared? -- **bootable** (Boolean, Required) Bootbale of Volume +- **bootable** (Boolean, Required) Bootable of Volume diff --git a/resource/vserver/resource_server.go b/resource/vserver/resource_server.go index e887d55..b94e271 100644 --- a/resource/vserver/resource_server.go +++ b/resource/vserver/resource_server.go @@ -94,7 +94,7 @@ func ResourceServer() *schema.Resource { Elem: &schema.Schema{ Type: schema.TypeString, }, - Optional: true, + Required: true, }, "source_type": { Type: schema.TypeString, @@ -191,11 +191,6 @@ func resourceServerStateRefreshFunc(cli *client.Client, serverID string, project } func resourceServerCreate(d *schema.ResourceData, m interface{}) error { projectID := d.Get("project_id").(string) - securityGroupInterface := d.Get("security_group").([]interface{}) - var securityGroup []string - for _, s := range securityGroupInterface { - securityGroup = append(securityGroup, s.(string)) - } if _, ok := d.GetOk("root_disk_size"); !ok { return fmt.Errorf(`The argument "root_disk_size" is required, but no definition was found.`) } @@ -208,6 +203,14 @@ func resourceServerCreate(d *schema.ResourceData, m interface{}) error { return fmt.Errorf(`The argument "user data" is set, the argument "user data base64 encode" is required, but no definition was found.`) } } + securityGroupInterface := d.Get("security_group").([]interface{}) + var securityGroup []string + for _, s := range securityGroupInterface { + securityGroup = append(securityGroup, s.(string)) + } + if len(securityGroup) == 0 { + return fmt.Errorf(`The argument "security_group" must not be empty.`) + } server := vserver.CreateServerRequest{ AttachFloating: d.Get("attach_floating").(bool), EncryptionVolume: d.Get("encryption_volume").(bool), @@ -317,6 +320,11 @@ func resourceServerRead(d *schema.ResourceData, m interface{}) error { externalInterfaces = append(externalInterfaces, externalInterfaceMap) } d.Set("external_interfaces", externalInterfaces) + var securityGroups []string + for _, secGroup := range server.SecGroups { + securityGroups = append(securityGroups, secGroup.Uuid) + } + d.Set("security_group", securityGroups) return nil } @@ -504,6 +512,9 @@ func resourceServerUpdateSecgroup(d *schema.ResourceData, m interface{}) error { for _, s := range securityGroupInterface { securityGroup = append(securityGroup, s.(string)) } + if len(securityGroup) == 0 { + return fmt.Errorf(`The argument "security_group" must not be empty.`) + } serverChangeSecGroup := vserver.ChangeSecGroupRequest{ ServerId: d.Id(), SecurityGroup: securityGroup, diff --git a/resource/vserver/resource_volume.go b/resource/vserver/resource_volume.go index aeea816..68d80ef 100644 --- a/resource/vserver/resource_volume.go +++ b/resource/vserver/resource_volume.go @@ -62,6 +62,11 @@ func ResourceVolume() *schema.Resource { Type: schema.TypeBool, Computed: true, }, + "multi_attach": { + Type: schema.TypeBool, + Optional: true, + ForceNew: true, + }, }, } } @@ -86,6 +91,7 @@ func resourceVolumeCreate(d *schema.ResourceData, m interface{}) error { Name: d.Get("name").(string), Size: int32(d.Get("size").(int)), VolumeTypeId: d.Get("volume_type_id").(string), + MultiAttach: d.Get("multi_attach").(bool), } cli := m.(*client.Client) resp, httpResponse, err := cli.VserverClient.VolumeRestControllerApi.CreateVolumeUsingPOST1(context.TODO(), a, projectID) diff --git a/resource/vserver/util.go b/resource/vserver/util.go index 6768536..d721036 100644 --- a/resource/vserver/util.go +++ b/resource/vserver/util.go @@ -15,5 +15,9 @@ func CheckErrorResponse(httpResponse *http.Response) bool { func GetResponseBody(httpResponse *http.Response) string { localVarBody, _ := io.ReadAll(httpResponse.Body) - return fmt.Sprint("Status Code: ", httpResponse.StatusCode, " , ", string(localVarBody)) + responseMessage := string(localVarBody) + if httpResponse.StatusCode == 403 { + responseMessage = "You don't have permission to do this action" + } + return fmt.Sprint("Status Code: ", httpResponse.StatusCode, ", ", responseMessage) }