|
| 1 | +package file |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" |
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 8 | + file "github.com/scaleway/scaleway-sdk-go/api/file/v1alpha1" |
| 9 | + "github.com/scaleway/scaleway-sdk-go/scw" |
| 10 | + "github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional" |
| 11 | + "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/account" |
| 12 | + "github.com/scaleway/terraform-provider-scaleway/v2/internal/types" |
| 13 | +) |
| 14 | + |
| 15 | +func ResourceFile() *schema.Resource { |
| 16 | + return &schema.Resource{ |
| 17 | + CreateContext: ResourceFileCreate, |
| 18 | + ReadContext: ResourceFileRead, |
| 19 | + UpdateContext: ResourceFileUpdate, |
| 20 | + DeleteContext: ResourceFileDelete, |
| 21 | + Importer: &schema.ResourceImporter{ |
| 22 | + StateContext: schema.ImportStatePassthroughContext, |
| 23 | + }, |
| 24 | + Timeouts: &schema.ResourceTimeout{ |
| 25 | + Create: schema.DefaultTimeout(defaultFileTimeout), |
| 26 | + Read: schema.DefaultTimeout(defaultFileTimeout), |
| 27 | + Delete: schema.DefaultTimeout(defaultFileTimeout), |
| 28 | + Default: schema.DefaultTimeout(defaultFileTimeout), |
| 29 | + }, |
| 30 | + SchemaVersion: 0, |
| 31 | + Schema: map[string]*schema.Schema{ |
| 32 | + "name": { |
| 33 | + Type: schema.TypeString, |
| 34 | + Computed: true, |
| 35 | + Optional: true, |
| 36 | + Description: "The name of the filesystem", |
| 37 | + }, |
| 38 | + "size": { |
| 39 | + Type: schema.TypeInt, |
| 40 | + Required: true, |
| 41 | + 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.", |
| 42 | + }, |
| 43 | + "tags": { |
| 44 | + Type: schema.TypeList, |
| 45 | + Elem: &schema.Schema{ |
| 46 | + Type: schema.TypeString, |
| 47 | + }, |
| 48 | + Optional: true, |
| 49 | + Description: "The list of tags assigned to the filesystem", |
| 50 | + }, |
| 51 | + "project_id": account.ProjectIDSchema(), |
| 52 | + "organization_id": account.OrganizationIDSchema(), |
| 53 | + "region": regional.Schema(), |
| 54 | + "status": { |
| 55 | + Type: schema.TypeString, |
| 56 | + Computed: true, |
| 57 | + Description: "The Current status of the filesystem (e.g. creating, available, ...)", |
| 58 | + }, |
| 59 | + "number_of_attachements": { |
| 60 | + Type: schema.TypeInt, |
| 61 | + Computed: true, |
| 62 | + Description: "The current number of attachments (mounts) that the filesystem has", |
| 63 | + }, |
| 64 | + "created_at": { |
| 65 | + Type: schema.TypeString, |
| 66 | + Computed: true, |
| 67 | + Description: "The creation date of the filesystem", |
| 68 | + }, |
| 69 | + "updated_at": { |
| 70 | + Type: schema.TypeString, |
| 71 | + Computed: true, |
| 72 | + Description: "The last update date of the properties of the filesystem", |
| 73 | + }, |
| 74 | + }, |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +func ResourceFileCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { |
| 79 | + api, region, err := fileAPIWithZone(d, m) |
| 80 | + if err != nil { |
| 81 | + return diag.FromErr(err) |
| 82 | + } |
| 83 | + |
| 84 | + req := &file.CreateFileSystemRequest{ |
| 85 | + Region: region, |
| 86 | + Name: types.ExpandOrGenerateString(d.Get("name").(string), "file"), |
| 87 | + ProjectID: d.Get("project_id").(string), |
| 88 | + Size: *types.ExpandUint64Ptr(d.Get("size")), |
| 89 | + Tags: types.ExpandStrings(d.Get("tags")), |
| 90 | + } |
| 91 | + |
| 92 | + file, err := api.CreateFileSystem(req, scw.WithContext(ctx)) |
| 93 | + if err != nil { |
| 94 | + return diag.FromErr(err) |
| 95 | + } |
| 96 | + |
| 97 | + d.SetId(regional.NewIDString(region, file.ID)) |
| 98 | + |
| 99 | + //TODO waitForFile |
| 100 | + |
| 101 | + return ResourceFileRead(ctx, d, m) |
| 102 | +} |
| 103 | + |
| 104 | +func ResourceFileRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { |
| 105 | + |
| 106 | + return nil |
| 107 | +} |
| 108 | + |
| 109 | +func ResourceFileUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { |
| 110 | + |
| 111 | + return ResourceFileRead(ctx, d, m) |
| 112 | +} |
| 113 | + |
| 114 | +func ResourceFileDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { |
| 115 | + |
| 116 | + return nil |
| 117 | +} |
0 commit comments