Skip to content

Commit 3575502

Browse files
committed
update FileSystem Size to GB
1 parent 3d23c29 commit 3575502

File tree

5 files changed

+149
-141
lines changed

5 files changed

+149
-141
lines changed

internal/services/file/filesystem.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ func ResourceFileSystemCreate(ctx context.Context, d *schema.ResourceData, m any
9191
Tags: types.ExpandStrings(d.Get("tags")),
9292
}
9393

94+
if size, ok := d.GetOk("size_in_gb"); ok {
95+
sizeInGB := size.(int)
96+
sizeInBytes := uint64(sizeInGB) * uint64(scw.GB)
97+
req.Size = sizeInBytes
98+
}
99+
94100
file, err := api.CreateFileSystem(req, scw.WithContext(ctx))
95101
if err != nil {
96102
return diag.FromErr(err)
@@ -128,7 +134,8 @@ func ResourceFileSystemRead(ctx context.Context, d *schema.ResourceData, m any)
128134
_ = d.Set("region", fileSystem.Region)
129135
_ = d.Set("organization_id", fileSystem.OrganizationID)
130136
_ = d.Set("status", fileSystem.Status)
131-
_ = d.Set("size_in_gb", int64(fileSystem.Size))
137+
_ = d.Set("size_in_gb", int(fileSystem.Size/scw.GB))
138+
)
132139
_ = d.Set("tags", fileSystem.Tags)
133140
_ = d.Set("created_at", fileSystem.CreatedAt.Format(time.RFC3339))
134141
_ = d.Set("updated_at", fileSystem.UpdatedAt.Format(time.RFC3339))
@@ -164,7 +171,8 @@ func ResourceFileSystemUpdate(ctx context.Context, d *schema.ResourceData, m any
164171
}
165172

166173
if d.HasChange("size_in_gb") {
167-
req.Size = types.ExpandUint64Ptr(d.Get("size_in_gb"))
174+
sizeInGB := uint64(d.Get("size_in_gb").(int)) * uint64(scw.GB)
175+
req.Size = types.ExpandUint64Ptr(sizeInGB)
168176
}
169177

170178
if d.HasChange("tags") {

internal/services/file/filesystem_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestAccFileSystem_Basic(t *testing.T) {
2020

2121
fileSystemName := "TestAccFileSystem_Basic"
2222
fileSystemNameUpdated := "TestAccFileSystem_BasicUpdate"
23-
sizeInGB := int64(100_000_000_000)
23+
sizeInGB := 100
2424

2525
resource.ParallelTest(t, resource.TestCase{
2626
PreCheck: func() { acctest.PreCheck(t) },
@@ -37,7 +37,7 @@ func TestAccFileSystem_Basic(t *testing.T) {
3737
Check: resource.ComposeTestCheckFunc(
3838
testAccCheckFileSystemExists(tt, "scaleway_file_filesystem.fs"),
3939
resource.TestCheckResourceAttr("scaleway_file_filesystem.fs", "name", fileSystemName),
40-
resource.TestCheckResourceAttr("scaleway_file_filesystem.fs", "size_in_gb", strconv.FormatInt(sizeInGB, 10)),
40+
resource.TestCheckResourceAttr("scaleway_file_filesystem.fs", "size_in_gb", strconv.Itoa(sizeInGB)),
4141
),
4242
},
4343
{
@@ -49,7 +49,7 @@ func TestAccFileSystem_Basic(t *testing.T) {
4949
`, fileSystemNameUpdated, sizeInGB),
5050
Check: resource.ComposeTestCheckFunc(
5151
testAccCheckFileSystemExists(tt, "scaleway_file_filesystem.fs"),
52-
resource.TestCheckResourceAttr("scaleway_file_filesystem.fs", "size_in_gb", strconv.FormatInt(sizeInGB, 10)),
52+
resource.TestCheckResourceAttr("scaleway_file_filesystem.fs", "size_in_gb", strconv.Itoa(sizeInGB)),
5353
),
5454
},
5555
},
@@ -61,7 +61,7 @@ func TestAccFileSystem_SizeTooSmallFails(t *testing.T) {
6161
defer tt.Cleanup()
6262

6363
fileSystemName := "TestAccFileSystem_SizeTooSmallFails"
64-
sizeInGB := int64(10_000_000_000)
64+
sizeInGB := 10
6565

6666
resource.ParallelTest(t, resource.TestCase{
6767
PreCheck: func() { acctest.PreCheck(t) },
@@ -86,7 +86,7 @@ func TestAccFileSystem_InvalidSizeGranularityFails(t *testing.T) {
8686
defer tt.Cleanup()
8787

8888
fileSystemName := "TestAccFileSystem_InvalidSizeGranularityFails"
89-
sizeInGB := int64(25_000_000_000)
89+
sizeInGB := 250
9090

9191
resource.ParallelTest(t, resource.TestCase{
9292
PreCheck: func() { acctest.PreCheck(t) },
@@ -100,7 +100,7 @@ func TestAccFileSystem_InvalidSizeGranularityFails(t *testing.T) {
100100
size_in_gb = %d
101101
}
102102
`, fileSystemName, sizeInGB),
103-
ExpectError: regexp.MustCompile("size_in_gb must be greater or equal to 100000000000"),
103+
ExpectError: regexp.MustCompile("size does not respect constraint, size must be a multiple of 100000000000"),
104104
},
105105
},
106106
})

0 commit comments

Comments
 (0)