Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ website:
.PHONY: build test testacc vet fmt fmtcheck errcheck test-compile website

tfproviderlint:
go tool tfproviderlint -R014=false -AT001.ignored-filename-suffixes=_data_source_test.go ./...
go tool tfproviderlint -R014=false -S013=false -AT001.ignored-filename-suffixes=_data_source_test.go ./...

tfproviderdocs:
go tool tfproviderdocs check -provider-name scaleway -enable-contents-check

tfproviderlintx:
go tool tfproviderlintx -XR001=false -XS002=false ./...
go tool tfproviderlintx -XR001=false -S013=false -XS002=false ./...
48 changes: 48 additions & 0 deletions internal/services/block/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func ResourceSnapshot() *schema.Resource {
Default: schema.DefaultTimeout(defaultBlockTimeout),
},
SchemaVersion: 0,
Identity: blockIdentity(),
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -151,6 +152,11 @@ func ResourceBlockSnapshotCreate(ctx context.Context, d *schema.ResourceData, m

d.SetId(zonal.NewIDString(zone, snapshot.ID))

diags := applySnapshotIdentity(d, snapshot.ID, zone)
if diags != nil {
return diags
}

_, err = waitForBlockSnapshot(ctx, api, zone, snapshot.ID, d.Timeout(schema.TimeoutCreate))
if err != nil {
return diag.FromErr(err)
Expand Down Expand Up @@ -202,6 +208,28 @@ func ResourceBlockSnapshotRead(ctx context.Context, d *schema.ResourceData, m an

_ = d.Set("tags", snapshot.Tags)

diags := applySnapshotIdentity(d, snapshot.ID, zone)
if diags != nil {
return diags
}

return nil
}

func applySnapshotIdentity(d *schema.ResourceData, snapshotID string, zone scw.Zone) diag.Diagnostics {
identity, err := d.Identity()
if err != nil {
return diag.FromErr(err)
}

if err = identity.Set("snapshot_id", snapshotID); err != nil {
return diag.FromErr(err)
}

if err = identity.Set("zone", zone); err != nil {
return diag.FromErr(err)
}

return nil
}

Expand Down Expand Up @@ -282,3 +310,23 @@ func ResourceBlockSnapshotDelete(ctx context.Context, d *schema.ResourceData, m

return nil
}

func blockIdentity() *schema.ResourceIdentity {
return &schema.ResourceIdentity{
Version: 0,
SchemaFunc: func() map[string]*schema.Schema {
return map[string]*schema.Schema{
"snapshot_id": {
Type: schema.TypeString,
RequiredForImport: true,
Description: "Snapshot ID",
},
"zone": {
Type: schema.TypeString,
RequiredForImport: true,
Description: "Zone ID",
},
}
},
}
}
48 changes: 48 additions & 0 deletions internal/services/block/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func ResourceVolume() *schema.Resource {
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Identity: volumeIdentity(),
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(defaultBlockTimeout),
Read: schema.DefaultTimeout(defaultBlockTimeout),
Expand Down Expand Up @@ -83,6 +84,26 @@ func ResourceVolume() *schema.Resource {
}
}

func volumeIdentity() *schema.ResourceIdentity {
return &schema.ResourceIdentity{
Version: 0,
SchemaFunc: func() map[string]*schema.Schema {
return map[string]*schema.Schema{
"volume_id": {
Type: schema.TypeString,
RequiredForImport: true,
Description: "Volume ID",
},
"zone": {
Type: schema.TypeString,
RequiredForImport: true,
Description: "Zone",
},
}
},
}
}

func ResourceBlockVolumeCreate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
api, zone, err := instancehelpers.InstanceAndBlockAPIWithZone(d, m)
if err != nil {
Expand Down Expand Up @@ -136,6 +157,11 @@ func ResourceBlockVolumeCreate(ctx context.Context, d *schema.ResourceData, m an

d.SetId(zonal.NewIDString(zone, volume.ID))

diags := applyVolumeIdentity(d, volume.ID, zone)
if diags != nil {
return diags
}

_, err = waitForBlockVolume(ctx, api.BlockAPI, zone, volume.ID, d.Timeout(schema.TimeoutCreate))
if err != nil {
return diag.FromErr(err)
Expand Down Expand Up @@ -186,6 +212,28 @@ func ResourceBlockVolumeRead(ctx context.Context, d *schema.ResourceData, m any)

_ = d.Set("snapshot_id", snapshotID)

diags := applyVolumeIdentity(d, volume.ID, zone)
if diags != nil {
return diags
}

return nil
}

func applyVolumeIdentity(d *schema.ResourceData, volumeID string, zone scw.Zone) diag.Diagnostics {
identity, err := d.Identity()
if err != nil {
return diag.FromErr(err)
}

if err = identity.Set("volume_id", volumeID); err != nil {
return diag.FromErr(err)
}

if err = identity.Set("zone", zone); err != nil {
return diag.FromErr(err)
}

return nil
}

Expand Down
Loading