Skip to content

Commit

Permalink
Directly inject aws:rds:Instance.name into the schema (#4086)
Browse files Browse the repository at this point in the history
This bypasses the need to call `shim.SchemaMap.Set` which has been
removed in the latest version of the bridge. Since `"name"` is *never*
witnessed by the underlying provider, it should not matter that the
provider doesn't have the phony "name" field in it's map anymore.

Fixes pulumi/pulumi-terraform-bridge#2101
  • Loading branch information
iwahbe authored Jun 17, 2024
1 parent 56a8fd3 commit 5f48e07
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
2 changes: 2 additions & 0 deletions provider/cmd/pulumi-tfgen-aws/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import (
func main() {
info := aws.ProviderFromMeta(tfbridge.NewProviderMetadata(locateMetadata()))

postProcessor := info.SchemaPostProcessor
info.SchemaPostProcessor = func(spec *schema.PackageSpec) {
postProcessor(spec)
replaceWafV2TypesWithRecursive(spec)
}

Expand Down
40 changes: 22 additions & 18 deletions provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (

"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
awsbase "github.com/hashicorp/aws-sdk-go-base/v2"
tfschema "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/mitchellh/go-homedir"
"github.com/pulumi/pulumi-aws/provider/v6/pkg/batch"
"github.com/pulumi/pulumi-aws/provider/v6/pkg/rds"
Expand Down Expand Up @@ -847,6 +846,28 @@ func ProviderFromMeta(metaInfo *tfbridge.MetadataInfo) *tfbridge.ProviderInfo {
GenerateRuntimeMetadata: true,

MetadataInfo: metaInfo,
SchemaPostProcessor: func(spec *schema.PackageSpec) {
r, ok := spec.Resources["aws:rds/instance:Instance"]
contract.Assertf(ok, "could not find rds:Instance")
_, ok = r.InputProperties["name"]
contract.Assertf(!ok, `expected that RDS does not have a "name" property already.
If it does, then we need to consider if we should keep the current name property for
backwards compatibility and rename the new property or remove the current backwards
compatibility shim in favor of the new "name" field.`)
r.InputProperties["name"] = schema.PropertySpec{
TypeSpec: schema.TypeSpec{Type: "string"},
WillReplaceOnChanges: true,
DeprecationMessage: "This property has been deprecated. Please use 'dbName' instead.",
}
_, ok = r.Properties["name"]
contract.Assertf(!ok, "rds:Instance already has an output called name")
r.Properties["name"] = schema.PropertySpec{
TypeSpec: schema.TypeSpec{Type: "string"},
DeprecationMessage: "This property has been deprecated. Please use 'dbName' instead.",
}
r.StateInputs.Properties["name"] = r.InputProperties["name"]
},

Config: map[string]*tfbridge.SchemaInfo{
"region": {
Expand Down Expand Up @@ -3077,23 +3098,6 @@ func ProviderFromMeta(metaInfo *tfbridge.MetadataInfo) *tfbridge.ProviderInfo {
Type: "string",
AltTypes: []tokens.Type{awsType(rdsMod, "StorageType", "StorageType")},
},
"name": {
Name: func() string {
// We inject `name` into the underlying provider so it shows
// up in the schema. It is never observed non-nil by the
// upstream provider and we warn when you set it.

p.ResourcesMap().Get("aws_db_instance").Schema().
Set("name", shimv2.NewSchema(&tfschema.Schema{
Type: tfschema.TypeString,
Optional: true,
ForceNew: true,
}))
return "name"
}(),
DeprecationMessage: "This property has been deprecated. " +
"Please use 'dbName' instead.",
},
},
PreCheckCallback: func(
ctx context.Context, config resource.PropertyMap, meta resource.PropertyMap,
Expand Down

0 comments on commit 5f48e07

Please sign in to comment.