-
Notifications
You must be signed in to change notification settings - Fork 132
feat(file): add support v1beta1 #3141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
remyleone
merged 16 commits into
scaleway:master
from
Laure-di:filestorage-implementation
Jun 11, 2025
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e232623
feat(file): add support v1beta1
Laure-di a07cfb1
Create, Read and Update function
Laure-di 2deb8e4
Delete Methode
Laure-di f56f23c
add tests
Laure-di 4e63e19
fix date issue and register cassettes
Laure-di bd6cca0
doc: create and update documentation
Laure-di 48f0f22
doc: create and update documentation
Laure-di 5f93d30
chore: tidy Go modules and update go.sum
Laure-di dfb9c15
test: fix filesystem size assertion by using strconv.FormatInt
Laure-di 7073523
doc: error checking file contents fix
Laure-di 380b3b7
test: add validation for filesystem size granularity
Laure-di e845b2f
fix: convertion
Laure-di b6db4d0
chore: add file to github action
Laure-di a94dcce
test: add testing files to exceptionsCassettesCases
Laure-di 5b3a36a
test: add testing files to exceptionsCassettesCases
Laure-di b2295b5
Update docs/resources/file_filesystem.md
Laure-di File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ jobs: | |
- cockpit | ||
- container | ||
- domain | ||
- file | ||
- flexibleip | ||
- function | ||
- iam | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
subcategory: "File" | ||
page_title: "Scaleway: scaleway_file_filesystem" | ||
--- | ||
|
||
# Resource: scaleway_file_filesystem | ||
|
||
Creates and manages a Scaleway File Storage (NFS) filesystem in a specific region. A filesystem is a scalable storage resource that can be mounted on Compute instances and is typically used for shared, persistent storage. | ||
|
||
This resource allows you to define and manage the size, tags, and region of a filesystem, and track its creation and update timestamps, current status, and number of active attachments. | ||
|
||
## Example Usage | ||
|
||
### Basic | ||
|
||
```terraform | ||
resource scaleway_file_filesystem file { | ||
name = "my-nfs-filesystem" | ||
size = 100000000000 # 100 GB | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
- `name` - (Optional) The name of the filesystem. If not provided, a random name will be generated. | ||
- `size` - (Required) The size of the filesystem in bytes, with a granularity of 100 GB (10¹¹ bytes). | ||
- Minimum: 100 GB (100000000000 bytes) | ||
- Maximum: 10 TB (10000000000000 bytes) | ||
- `tags` - (Optional) A list of tags associated with the filesystem. | ||
- `region` - (Defaults to [provider](../index.md#region) `region`) The region where the filesystem will be created (e.g., fr-par, nl-ams). | ||
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the server is | ||
associated with. | ||
- `organization_id` - (Defaults to [provider](../index.md#organization_id) `organization_id`) The ID of the organization the user is associated with. | ||
|
||
## Attributes Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
- `id` - The ID of the filesystem. | ||
- `status` - The current status of the filesystem. Possible values include creating, available, etc. | ||
- `number_of_attachments` - The number of active attachments (mounts) on the filesystem. | ||
- `created_at` - The date and time when the File Storage filesystem was created. | ||
- `updated_at` - The date and time of the last update to the File Storage filesystem. | ||
|
||
## Import | ||
|
||
|
||
File Storage filesystems can be imported using the `{region}/{id}`, e.g. | ||
|
||
```bash | ||
terraform import scaleway_file_filesystem.main fr-par/11111111-1111-1111-1111-111111111111 | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
package file | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
file "github.com/scaleway/scaleway-sdk-go/api/file/v1alpha1" | ||
"github.com/scaleway/scaleway-sdk-go/scw" | ||
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors" | ||
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional" | ||
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/account" | ||
"github.com/scaleway/terraform-provider-scaleway/v2/internal/types" | ||
) | ||
|
||
func ResourceFileSystem() *schema.Resource { | ||
return &schema.Resource{ | ||
CreateContext: ResourceFileSystemCreate, | ||
ReadContext: ResourceFileSystemRead, | ||
UpdateContext: ResourceFileSystemUpdate, | ||
DeleteContext: ResourceFileSystemDelete, | ||
Importer: &schema.ResourceImporter{ | ||
StateContext: schema.ImportStatePassthroughContext, | ||
}, | ||
Timeouts: &schema.ResourceTimeout{ | ||
Create: schema.DefaultTimeout(defaultFileSystemTimeout), | ||
Read: schema.DefaultTimeout(defaultFileSystemTimeout), | ||
Delete: schema.DefaultTimeout(defaultFileSystemTimeout), | ||
Default: schema.DefaultTimeout(defaultFileSystemTimeout), | ||
}, | ||
SchemaVersion: 0, | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Optional: true, | ||
Description: "The name of the filesystem", | ||
}, | ||
"size": { | ||
Type: schema.TypeInt, | ||
Required: true, | ||
Description: "The Filesystem size in bytes, with a granularity of 100 GB (10^11 bytes). Must be compliant with the minimum (100 GB) and maximum (10 TB) allowed size.", | ||
}, | ||
"tags": { | ||
Type: schema.TypeList, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
Optional: true, | ||
Description: "The list of tags assigned to the filesystem", | ||
}, | ||
"project_id": account.ProjectIDSchema(), | ||
"organization_id": account.OrganizationIDSchema(), | ||
"region": regional.Schema(), | ||
"status": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The Current status of the filesystem (e.g. creating, available, ...)", | ||
}, | ||
"number_of_attachments": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "The current number of attachments (mounts) that the filesystem has", | ||
}, | ||
"created_at": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The creation date of the filesystem", | ||
}, | ||
"updated_at": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The last update date of the properties of the filesystem", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func ResourceFileSystemCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
api, region, err := fileSystemAPIWithZone(d, m) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
req := &file.CreateFileSystemRequest{ | ||
Region: region, | ||
Name: types.ExpandOrGenerateString(d.Get("name").(string), "file"), | ||
ProjectID: d.Get("project_id").(string), | ||
Size: *types.ExpandUint64Ptr(d.Get("size")), | ||
Tags: types.ExpandStrings(d.Get("tags")), | ||
} | ||
|
||
file, err := api.CreateFileSystem(req, scw.WithContext(ctx)) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.SetId(regional.NewIDString(region, file.ID)) | ||
|
||
_, err = waitForFileSystem(ctx, api, region, file.ID, d.Timeout(schema.TimeoutCreate)) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return ResourceFileSystemRead(ctx, d, m) | ||
} | ||
|
||
func ResourceFileSystemRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
api, region, id, err := NewAPIWithRegionAndID(m, d.Id()) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
fileSystem, err := waitForFileSystem(ctx, api, region, id, d.Timeout(schema.TimeoutRead)) | ||
if err != nil { | ||
if httperrors.Is404(err) { | ||
d.SetId("") | ||
|
||
return nil | ||
} | ||
|
||
return diag.FromErr(err) | ||
} | ||
|
||
_ = d.Set("name", fileSystem.Name) | ||
_ = d.Set("project_id", fileSystem.ProjectID) | ||
_ = d.Set("region", fileSystem.Region) | ||
_ = d.Set("organization_id", fileSystem.OrganizationID) | ||
_ = d.Set("status", fileSystem.Status) | ||
_ = d.Set("size", int64(fileSystem.Size)) | ||
_ = d.Set("tags", fileSystem.Tags) | ||
_ = d.Set("created_at", fileSystem.CreatedAt.Format(time.RFC3339)) | ||
_ = d.Set("updated_at", fileSystem.UpdatedAt.Format(time.RFC3339)) | ||
_ = d.Set("number_of_attachments", int64(fileSystem.NumberOfAttachments)) | ||
|
||
return nil | ||
} | ||
|
||
func ResourceFileSystemUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
api, region, id, err := NewAPIWithRegionAndID(m, d.Id()) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
fileSystem, err := waitForFileSystem(ctx, api, region, id, d.Timeout(schema.TimeoutUpdate)) | ||
if err != nil { | ||
if httperrors.Is404(err) { | ||
d.SetId("") | ||
|
||
return nil | ||
} | ||
|
||
return diag.FromErr(err) | ||
} | ||
|
||
req := &file.UpdateFileSystemRequest{ | ||
Region: region, | ||
FilesystemID: fileSystem.ID, | ||
} | ||
|
||
if d.HasChange("name") { | ||
req.Name = types.ExpandUpdatedStringPtr(d.Get("name")) | ||
} | ||
|
||
if d.HasChange("size") { | ||
req.Size = types.ExpandUint64Ptr(d.Get("size")) | ||
} | ||
|
||
if d.HasChange("tags") { | ||
req.Tags = types.ExpandStringsPtr(d.Get("tags")) | ||
} | ||
|
||
if _, err := api.UpdateFileSystem(req, scw.WithContext(ctx)); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return ResourceFileSystemRead(ctx, d, m) | ||
} | ||
|
||
func ResourceFileSystemDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
api, region, id, err := NewAPIWithRegionAndID(m, d.Id()) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
_, err = waitForFileSystem(ctx, api, region, id, d.Timeout(schema.TimeoutDelete)) | ||
if err != nil { | ||
if httperrors.Is404(err) { | ||
d.SetId("") | ||
|
||
return nil | ||
} | ||
|
||
return diag.FromErr(err) | ||
} | ||
|
||
err = api.DeleteFileSystem(&file.DeleteFileSystemRequest{ | ||
Region: region, | ||
FilesystemID: id, | ||
}, scw.WithContext(ctx)) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
_, err = waitForFileSystem(ctx, api, region, id, d.Timeout(schema.TimeoutDelete)) | ||
if err != nil && !httperrors.Is404(err) { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.