Skip to content

Commit 810228f

Browse files
committed
Fix reuse between data source and ressource
1 parent afc4bf9 commit 810228f

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

internal/services/block/snapshot.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,25 @@ func ResourceBlockSnapshotRead(ctx context.Context, d *schema.ResourceData, m an
203203

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

206+
diags := applySnapshotIdentity(d, snapshot.ID, zone)
207+
if diags != nil {
208+
return diags
209+
}
210+
211+
return nil
212+
}
213+
214+
func applySnapshotIdentity(d *schema.ResourceData, snapshotID string, zone scw.Zone) diag.Diagnostics {
206215
identity, err := d.Identity()
207216
if err != nil {
208217
return diag.FromErr(err)
209218
}
210219

211-
if err = identity.Set("snapshot_id", snapshot.ID); err != nil {
220+
if err = identity.Set("snapshot_id", snapshotID); err != nil {
212221
return diag.FromErr(err)
213222
}
214223

215-
if err = identity.Set("zone", snapshot.Zone); err != nil {
224+
if err = identity.Set("zone", zone); err != nil {
216225
return diag.FromErr(err)
217226
}
218227

internal/services/block/snapshot_data_source.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,7 @@ func DataSourceBlockSnapshotRead(ctx context.Context, d *schema.ResourceData, m
8282
return diag.Errorf("snapshot (%s) not found", zoneID)
8383
}
8484

85+
applySnapshotIdentity(d, snapshotID.(string), zone)
86+
8587
return nil
8688
}

internal/services/block/volume.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,16 +207,25 @@ func ResourceBlockVolumeRead(ctx context.Context, d *schema.ResourceData, m any)
207207

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

210+
diags := applyVolumeIdentity(d, volume.ID, zone)
211+
if diags != nil {
212+
return diags
213+
}
214+
215+
return nil
216+
}
217+
218+
func applyVolumeIdentity(d *schema.ResourceData, volumeID string, zone scw.Zone) diag.Diagnostics {
210219
identity, err := d.Identity()
211220
if err != nil {
212221
return diag.FromErr(err)
213222
}
214223

215-
if err = identity.Set("volume_id", volume.ID); err != nil {
224+
if err = identity.Set("volume_id", volumeID); err != nil {
216225
return diag.FromErr(err)
217226
}
218227

219-
if err = identity.Set("zone", volume.Zone); err != nil {
228+
if err = identity.Set("zone", zone); err != nil {
220229
return diag.FromErr(err)
221230
}
222231

internal/services/block/volume_data_source.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,7 @@ func DataSourceBlockVolumeRead(ctx context.Context, d *schema.ResourceData, m an
8181
return diag.Errorf("volume (%s) not found", zoneID)
8282
}
8383

84+
applyVolumeIdentity(d, volumeID.(string), zone)
85+
8486
return nil
8587
}

0 commit comments

Comments
 (0)