@@ -35,11 +35,12 @@ func resourceScalewayInstanceSnapshot() *schema.Resource {
3535 Description : "The name of the snapshot" ,
3636 },
3737 "volume_id" : {
38- Type : schema .TypeString ,
39- Required : true ,
40- ForceNew : true ,
41- Description : "ID of the volume to take a snapshot from" ,
42- ValidateFunc : validationUUIDorUUIDWithLocality (),
38+ Type : schema .TypeString ,
39+ Optional : true ,
40+ ForceNew : true ,
41+ Description : "ID of the volume to take a snapshot from" ,
42+ ValidateFunc : validationUUIDorUUIDWithLocality (),
43+ ConflictsWith : []string {"import" },
4344 },
4445 "type" : {
4546 Type : schema .TypeString ,
@@ -67,6 +68,28 @@ func resourceScalewayInstanceSnapshot() *schema.Resource {
6768 Optional : true ,
6869 Description : "The tags associated with the snapshot" ,
6970 },
71+ "import" : {
72+ Type : schema .TypeList ,
73+ ForceNew : true ,
74+ MaxItems : 1 ,
75+ Elem : & schema.Resource {
76+ Schema : map [string ]* schema.Schema {
77+ "bucket" : {
78+ Type : schema .TypeString ,
79+ Required : true ,
80+ Description : "Bucket containing qcow" ,
81+ },
82+ "key" : {
83+ Type : schema .TypeString ,
84+ Required : true ,
85+ Description : "Key of the qcow file in the specified bucket" ,
86+ },
87+ },
88+ },
89+ Optional : true ,
90+ Description : "Import snapshot from a qcow" ,
91+ ConflictsWith : []string {"volume_id" },
92+ },
7093 "created_at" : {
7194 Type : schema .TypeString ,
7295 Computed : true ,
@@ -86,10 +109,9 @@ func resourceScalewayInstanceSnapshotCreate(ctx context.Context, d *schema.Resou
86109 }
87110
88111 req := & instance.CreateSnapshotRequest {
89- Zone : zone ,
90- Project : expandStringPtr (d .Get ("project_id" )),
91- Name : expandOrGenerateString (d .Get ("name" ), "snap" ),
92- VolumeID : expandZonedID (d .Get ("volume_id" ).(string )).ID ,
112+ Zone : zone ,
113+ Project : expandStringPtr (d .Get ("project_id" )),
114+ Name : expandOrGenerateString (d .Get ("name" ), "snap" ),
93115 }
94116
95117 if volumeType , ok := d .GetOk ("type" ); ok {
@@ -101,6 +123,15 @@ func resourceScalewayInstanceSnapshotCreate(ctx context.Context, d *schema.Resou
101123 req .Tags = tags
102124 }
103125
126+ if volumeID , volumeIDExist := d .GetOk ("volume_id" ); volumeIDExist {
127+ req .VolumeID = expandZonedID (volumeID ).ID
128+ }
129+
130+ if _ , isImported := d .GetOk ("import" ); isImported {
131+ req .Bucket = expandStringPtr (d .Get ("import.0.bucket" ))
132+ req .Key = expandStringPtr (d .Get ("import.0.key" ))
133+ }
134+
104135 res , err := instanceAPI .CreateSnapshot (req , scw .WithContext (ctx ))
105136 if err != nil {
106137 return diag .FromErr (err )
0 commit comments