Skip to content

Commit

Permalink
Prioritize Pulumi-supplied deprecation message over any TF ones
Browse files Browse the repository at this point in the history
  • Loading branch information
guineveresaenger committed Dec 14, 2024
1 parent f94f380 commit ed0ba61
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
8 changes: 4 additions & 4 deletions pkg/tfgen/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,14 +634,14 @@ func (v *variable) Name() string { return v.name }
func (v *variable) Doc() string { return v.doc }

func (v *variable) deprecationMessage() string {
if v.schema != nil && v.schema.Deprecated() != "" {
return v.schema.Deprecated()
}

if v.info != nil && v.info.DeprecationMessage != "" {
return v.info.DeprecationMessage
}

if v.schema != nil && v.schema.Deprecated() != "" {
return v.schema.Deprecated()
}

return ""
}

Expand Down
41 changes: 35 additions & 6 deletions pkg/tfgen/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,44 @@ import (
shimv1 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v1"
)

func Test_DeprecationFromTFSchema(t *testing.T) {
func Test_DeprecationMessage(t *testing.T) {
t.Parallel()
v := &variable{
name: "v",
schema: shimv1.NewSchema(&schema.Schema{Type: schema.TypeString, Deprecated: "This is deprecated"}),

cases := []struct {
name string
variable *variable
expectedMessage string
}{
{
name: "From TF Schema",
variable: &variable{
schema: shimv1.NewSchema(&schema.Schema{Deprecated: "Terraform says this is deprecated"}),
},
expectedMessage: "Terraform says this is deprecated",
},
{
name: "From Pulumi Resources File",
variable: &variable{
schema: shimv1.NewSchema(&schema.Schema{Deprecated: "Pulumi says this is deprecated"}),
},
expectedMessage: "Pulumi says this is deprecated",
},
{
name: "From Pulumi Resources File Overrides TF Schema",
variable: &variable{
info: &tfbridge.SchemaInfo{DeprecationMessage: "Pulumi says this is deprecated"},
schema: shimv1.NewSchema(&schema.Schema{Deprecated: "Terraform says this is deprecated"}),
},
expectedMessage: "Pulumi says this is deprecated",
},
}

deprecationMessage := v.deprecationMessage()
assert.Equal(t, "This is deprecated", deprecationMessage)
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
deprecationMessage := tc.variable.deprecationMessage()
assert.Equal(t, tc.expectedMessage, deprecationMessage)
})
}
}

func Test_ForceNew(t *testing.T) {
Expand Down

0 comments on commit ed0ba61

Please sign in to comment.