Skip to content

Commit 664e7ea

Browse files
Expose TF schema versions for PF during tfgen (#3038)
This PR exposes the TF schema versions to PF during tfgen. This allows us to implement tfgen-time checks for downgrades. related to #3037 related to pulumi/pulumi-cloudflare#1156
1 parent 802dd0d commit 664e7ea

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

pkg/pf/internal/schemashim/datasource.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ func (r *schemaOnlyDataSource) Schema() shim.SchemaMap {
2929
return r.tf.Shim()
3030
}
3131

32-
func (*schemaOnlyDataSource) SchemaVersion() int {
33-
panic("DataSource SchemaVersion() should not be called during schema generation")
32+
func (r *schemaOnlyDataSource) SchemaVersion() int {
33+
panic("datasources do not have schema versions")
3434
}
3535

3636
func (r *schemaOnlyDataSource) DeprecationMessage() string {

pkg/pf/internal/schemashim/resource.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ func (r *schemaOnlyResource) Schema() shim.SchemaMap {
2929
return r.tf.Shim()
3030
}
3131

32-
func (*schemaOnlyResource) SchemaVersion() int {
33-
panic("SchemaVersion() should not be called on a Resource during schema generation")
32+
func (r *schemaOnlyResource) SchemaVersion() int {
33+
return int(r.tf.ResourceSchemaVersion())
3434
}
3535

3636
func (r *schemaOnlyResource) DeprecationMessage() string {

pkg/pf/tests/schemashim_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,3 +1157,24 @@ func stdProvider(resourceSchema schema.Schema) *pb.Provider {
11571157
}},
11581158
}
11591159
}
1160+
1161+
func TestSchemaVersionAccessible(t *testing.T) {
1162+
t.Parallel()
1163+
1164+
res := pb.NewResource(pb.NewResourceArgs{
1165+
Name: "r1",
1166+
ResourceSchema: schema.Schema{
1167+
Version: 2,
1168+
},
1169+
})
1170+
1171+
provider := pb.NewProvider(pb.NewProviderArgs{
1172+
TypeName: "testprov",
1173+
AllResources: []pb.Resource{res},
1174+
})
1175+
1176+
shimmedProvider := schemashim.ShimSchemaOnlyProvider(context.Background(), provider)
1177+
1178+
schemaVersion := shimmedProvider.ResourcesMap().Get("testprov_r1").SchemaVersion()
1179+
require.Equal(t, 2, schemaVersion)
1180+
}

0 commit comments

Comments
 (0)