Skip to content

Commit

Permalink
Seamlessly Migrate from name to dbName (#2834)
Browse files Browse the repository at this point in the history
Fixes #2823 
Depends on pulumi/pulumi-terraform-bridge#1400
in the bridge.
  • Loading branch information
iwahbe authored Sep 27, 2023
1 parent d7021d8 commit eae27fd
Show file tree
Hide file tree
Showing 8 changed files with 657 additions and 409 deletions.
144 changes: 143 additions & 1 deletion examples/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ func replay(t *testing.T, sequence string) {
// This replicates the diff when running `pulumi preview` on a aws.rds.Instance with
// pulumi-aws v6.0.0 and state from pulumi-aws 5.42.0.
//
// This ensures we don't regress on https://github.com/pulumi/pulumi-aws/issues/2682
// The first test ensures we don't regress on https://github.com/pulumi/pulumi-aws/issues/2682
//
// The second test is when upgrading from pulumi-aws version <5.0.0 to v6.x.x, and
// prevents regressions on https://github.com/pulumi/pulumi-aws/issues/2823.
func TestMigrateRdsInstance(t *testing.T) {
replay(t, `[
{
Expand Down Expand Up @@ -250,6 +253,145 @@ func TestMigrateRdsInstance(t *testing.T) {
"mode": "client",
"name": "aws"
}
},
{
"method": "/pulumirpc.ResourceProvider/Diff",
"request": {
"id": "rds2f5ed54",
"urn": "urn:pulumi:exp2::secret-random-yaml::aws:rds/instance:Instance::rds",
"olds": {
"__meta": "{\"e2bfb730-ecaa-11e6-8f88-34363bc7c4c0\":{\"create\":2400000000000,\"delete\":3600000000000,\"update\":4800000000000},\"schema_version\":\"1\"}",
"address": "rds2f5ed54.c1xxca33i6kr.us-east-2.rds.amazonaws.com",
"allocatedStorage": 16,
"arn": "arn:aws:rds:us-east-2:616138583583:db:rds2f5ed54",
"autoMinorVersionUpgrade": true,
"availabilityZone": "us-east-2c",
"backupRetentionPeriod": 0,
"backupWindow": "07:34-08:04",
"caCertIdentifier": "rds-ca-2019",
"copyTagsToSnapshot": false,
"dbSubnetGroupName": "default",
"deleteAutomatedBackups": true,
"deletionProtection": false,
"domain": "",
"domainIamRoleName": "",
"enabledCloudwatchLogsExports": [],
"endpoint": "rds2f5ed54.c1xxca33i6kr.us-east-2.rds.amazonaws.com:3306",
"engine": "mysql",
"engineVersion": "8.0.33",
"hostedZoneId": "Z2XHWR1WZ565X2",
"iamDatabaseAuthenticationEnabled": false,
"id": "rds2f5ed54",
"identifier": "rds2f5ed54",
"instanceClass": "db.t3.micro",
"iops": 0,
"kmsKeyId": "",
"latestRestorableTime": "0001-01-01T00:00:00Z",
"licenseModel": "general-public-license",
"maintenanceWindow": "sun:03:59-sun:04:29",
"maxAllocatedStorage": 0,
"monitoringInterval": 0,
"monitoringRoleArn": "",
"multiAz": false,
"name": "name",
"optionGroupName": "default:mysql-8-0",
"parameterGroupName": "default.mysql8.0",
"password": "FOO-BAR-FIZZ1!2",
"performanceInsightsEnabled": false,
"performanceInsightsKmsKeyId": "",
"performanceInsightsRetentionPeriod": 0,
"port": 3306,
"publiclyAccessible": false,
"replicas": [],
"replicateSourceDb": "",
"resourceId": "db-N57SF65OZ5KO3TPK73R7DQMLZA",
"securityGroupNames": [],
"skipFinalSnapshot": true,
"status": "available",
"storageEncrypted": false,
"storageType": "gp2",
"tags": {
"some": "change"
},
"timezone": "",
"username": "root",
"vpcSecurityGroupIds": [
"sg-1928d262"
]
},
"news": {
"__defaults": [
"applyImmediately",
"autoMinorVersionUpgrade",
"copyTagsToSnapshot",
"deleteAutomatedBackups",
"identifier",
"monitoringInterval",
"performanceInsightsEnabled",
"publiclyAccessible"
],
"allocatedStorage": 16,
"applyImmediately": false,
"autoMinorVersionUpgrade": true,
"copyTagsToSnapshot": false,
"dbName": "name",
"deleteAutomatedBackups": true,
"engine": "mysql",
"identifier": "rds2f5ed54",
"instanceClass": "db.t3.micro",
"monitoringInterval": 0,
"password": "FOO-BAR-FIZZ1!2",
"performanceInsightsEnabled": false,
"publiclyAccessible": false,
"skipFinalSnapshot": true,
"tags": {
"__defaults": [],
"some": "change"
},
"username": "root"
},
"oldInputs": {
"__defaults": [
"applyImmediately",
"autoMinorVersionUpgrade",
"copyTagsToSnapshot",
"deleteAutomatedBackups",
"identifier",
"monitoringInterval",
"performanceInsightsEnabled",
"publiclyAccessible"
],
"allocatedStorage": 16,
"applyImmediately": false,
"autoMinorVersionUpgrade": true,
"copyTagsToSnapshot": false,
"deleteAutomatedBackups": true,
"engine": "mysql",
"identifier": "rds2f5ed54",
"instanceClass": "db.t3.micro",
"monitoringInterval": 0,
"name": "name",
"password": "FOO-BAR-FIZZ1!2",
"performanceInsightsEnabled": false,
"publiclyAccessible": false,
"skipFinalSnapshot": true,
"tags": {
"__defaults": [],
"some": "change"
},
"username": "root"
}
},
"response": {
"stables": "*",
"changes": "DIFF_NONE",
"hasDetailedDiff": true
},
"metadata": {
"kind": "resource",
"mode": "client",
"name": "aws"
}
}
]`)
}
Expand Down
6 changes: 3 additions & 3 deletions examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.21
require (
github.com/aws/aws-sdk-go v1.45.14
github.com/pulumi/pulumi-aws/provider/v6 v6.0.0-00010101000000-000000000000
github.com/pulumi/pulumi-terraform-bridge/pf v0.16.2-0.20230920005537-64af66358186
github.com/pulumi/pulumi-terraform-bridge/testing v0.0.1
github.com/pulumi/pulumi-terraform-bridge/pf v0.16.2-0.20230927165309-e3fd9503f2d3
github.com/pulumi/pulumi-terraform-bridge/testing v0.0.2-0.20230927165309-e3fd9503f2d3
github.com/pulumi/pulumi/pkg/v3 v3.81.0
github.com/pulumi/pulumi/sdk/v3 v3.81.0
github.com/stretchr/testify v1.8.4
Expand Down Expand Up @@ -263,7 +263,7 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/term v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pulumi/pulumi-terraform-bridge/v3 v3.60.2-0.20230922172747-b0e78c54cff8 // indirect
github.com/pulumi/pulumi-terraform-bridge/v3 v3.60.2-0.20230927165309-e3fd9503f2d3 // indirect
github.com/pulumi/pulumi-terraform-bridge/x/muxer v0.0.7-0.20230801203955-5d215c892096 // indirect
github.com/pulumi/terraform-diff-reader v0.0.2 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
Expand Down
12 changes: 6 additions & 6 deletions examples/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2331,12 +2331,12 @@ github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
github.com/prometheus/prometheus v0.35.0/go.mod h1:7HaLx5kEPKJ0GDgbODG0fZgXbQ8K/XjZNJXQmbmgQlY=
github.com/prometheus/prometheus v0.37.0/go.mod h1:egARUgz+K93zwqsVIAneFlLZefyGOON44WyAp4Xqbbk=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/pulumi/pulumi-terraform-bridge/pf v0.16.2-0.20230920005537-64af66358186 h1:5asorGOvKtS+Z9fKyYAmNnWM9i1LbfTjQ+xnwIXLCnM=
github.com/pulumi/pulumi-terraform-bridge/pf v0.16.2-0.20230920005537-64af66358186/go.mod h1:NptD1F0yCzgtLptN9OoDQGcejAHSI9LcX1NW2GrxIS0=
github.com/pulumi/pulumi-terraform-bridge/testing v0.0.1 h1:SCg1gjfY9N4yn8U8peIUYATifjoDABkyR7H9lmefsfc=
github.com/pulumi/pulumi-terraform-bridge/testing v0.0.1/go.mod h1:7OeUPH8rpt5ipyj9EFcnXpuzQ8SHL0dyqdfa8nOacdk=
github.com/pulumi/pulumi-terraform-bridge/v3 v3.60.2-0.20230922172747-b0e78c54cff8 h1:eeM+dHNUB/M6kn7tcuJBa8v3HmaaCWzQuyLeBtHWuC4=
github.com/pulumi/pulumi-terraform-bridge/v3 v3.60.2-0.20230922172747-b0e78c54cff8/go.mod h1:o0Vfch2UXtHOnGYpNElzGg4htT6B8X8hS9fa5AguP7g=
github.com/pulumi/pulumi-terraform-bridge/pf v0.16.2-0.20230927165309-e3fd9503f2d3 h1:yzYF58gLZ2aSzI/gPtBMniXZjsXl+ADyqxraI58Pq1A=
github.com/pulumi/pulumi-terraform-bridge/pf v0.16.2-0.20230927165309-e3fd9503f2d3/go.mod h1:NptD1F0yCzgtLptN9OoDQGcejAHSI9LcX1NW2GrxIS0=
github.com/pulumi/pulumi-terraform-bridge/testing v0.0.2-0.20230927165309-e3fd9503f2d3 h1:bBWWeAtSPPYpKYlPZr2h0BiYgWQpHRIk0HO/MQmB+jc=
github.com/pulumi/pulumi-terraform-bridge/testing v0.0.2-0.20230927165309-e3fd9503f2d3/go.mod h1:vAQ7DeddebQ7FHdRaSG6ijuS28FS9PC4j8Y9wUuue0c=
github.com/pulumi/pulumi-terraform-bridge/v3 v3.60.2-0.20230927165309-e3fd9503f2d3 h1:tMkrGh9mfSyYi7Ncwo/79ivqLqgzwVf/G93lcMSP4iM=
github.com/pulumi/pulumi-terraform-bridge/v3 v3.60.2-0.20230927165309-e3fd9503f2d3/go.mod h1:o0Vfch2UXtHOnGYpNElzGg4htT6B8X8hS9fa5AguP7g=
github.com/pulumi/pulumi-terraform-bridge/x/muxer v0.0.7-0.20230801203955-5d215c892096 h1:1nzT9XuyTHdcWJboYNMPPdW0B0mQdXYg8Az5tF96MXY=
github.com/pulumi/pulumi-terraform-bridge/x/muxer v0.0.7-0.20230801203955-5d215c892096/go.mod h1:1pLAP9kryYta3Xrw99oh7BmxY6PYb+z2m7ENNCJMIRQ=
github.com/pulumi/pulumi/pkg/v3 v3.81.0 h1:6rf2farQLszi8inHCu9YdJtDvK0fqNguix51b3FEDRQ=
Expand Down
4 changes: 2 additions & 2 deletions provider/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ require (
github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0
github.com/hashicorp/terraform-provider-aws v1.60.1-0.20220923175450-ca71523cdc36
github.com/mitchellh/go-homedir v1.1.0
github.com/pulumi/pulumi-terraform-bridge/pf v0.16.2-0.20230920005537-64af66358186
github.com/pulumi/pulumi-terraform-bridge/v3 v3.60.2-0.20230922172747-b0e78c54cff8
github.com/pulumi/pulumi-terraform-bridge/pf v0.16.2-0.20230927165309-e3fd9503f2d3
github.com/pulumi/pulumi-terraform-bridge/v3 v3.60.2-0.20230927165309-e3fd9503f2d3
github.com/pulumi/pulumi/pkg/v3 v3.81.0
github.com/pulumi/pulumi/sdk/v3 v3.81.0
github.com/stretchr/testify v1.8.4
Expand Down
8 changes: 4 additions & 4 deletions provider/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2353,12 +2353,12 @@ github.com/prometheus/prometheus v0.37.0/go.mod h1:egARUgz+K93zwqsVIAneFlLZefyGO
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/pulumi/pulumi-java/pkg v0.9.6 h1:UJrOAsYHRchwb4QlfI9Q224qg1TOI3rIsI6DDTUnn30=
github.com/pulumi/pulumi-java/pkg v0.9.6/go.mod h1:c6rSw/+q4O0IImgJ9axxoC6QesbPYWBaG5gimbHouUQ=
github.com/pulumi/pulumi-terraform-bridge/pf v0.16.2-0.20230920005537-64af66358186 h1:5asorGOvKtS+Z9fKyYAmNnWM9i1LbfTjQ+xnwIXLCnM=
github.com/pulumi/pulumi-terraform-bridge/pf v0.16.2-0.20230920005537-64af66358186/go.mod h1:NptD1F0yCzgtLptN9OoDQGcejAHSI9LcX1NW2GrxIS0=
github.com/pulumi/pulumi-terraform-bridge/pf v0.16.2-0.20230927165309-e3fd9503f2d3 h1:yzYF58gLZ2aSzI/gPtBMniXZjsXl+ADyqxraI58Pq1A=
github.com/pulumi/pulumi-terraform-bridge/pf v0.16.2-0.20230927165309-e3fd9503f2d3/go.mod h1:NptD1F0yCzgtLptN9OoDQGcejAHSI9LcX1NW2GrxIS0=
github.com/pulumi/pulumi-terraform-bridge/testing v0.0.1 h1:SCg1gjfY9N4yn8U8peIUYATifjoDABkyR7H9lmefsfc=
github.com/pulumi/pulumi-terraform-bridge/testing v0.0.1/go.mod h1:7OeUPH8rpt5ipyj9EFcnXpuzQ8SHL0dyqdfa8nOacdk=
github.com/pulumi/pulumi-terraform-bridge/v3 v3.60.2-0.20230922172747-b0e78c54cff8 h1:eeM+dHNUB/M6kn7tcuJBa8v3HmaaCWzQuyLeBtHWuC4=
github.com/pulumi/pulumi-terraform-bridge/v3 v3.60.2-0.20230922172747-b0e78c54cff8/go.mod h1:o0Vfch2UXtHOnGYpNElzGg4htT6B8X8hS9fa5AguP7g=
github.com/pulumi/pulumi-terraform-bridge/v3 v3.60.2-0.20230927165309-e3fd9503f2d3 h1:tMkrGh9mfSyYi7Ncwo/79ivqLqgzwVf/G93lcMSP4iM=
github.com/pulumi/pulumi-terraform-bridge/v3 v3.60.2-0.20230927165309-e3fd9503f2d3/go.mod h1:o0Vfch2UXtHOnGYpNElzGg4htT6B8X8hS9fa5AguP7g=
github.com/pulumi/pulumi-terraform-bridge/x/muxer v0.0.7-0.20230801203955-5d215c892096 h1:1nzT9XuyTHdcWJboYNMPPdW0B0mQdXYg8Az5tF96MXY=
github.com/pulumi/pulumi-terraform-bridge/x/muxer v0.0.7-0.20230801203955-5d215c892096/go.mod h1:1pLAP9kryYta3Xrw99oh7BmxY6PYb+z2m7ENNCJMIRQ=
github.com/pulumi/pulumi-yaml v1.2.2 h1:W6BeUBLhDrJ2GSU0em1AUVelG9PBI4ABY61DdhJOO3E=
Expand Down
14 changes: 14 additions & 0 deletions provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -2868,6 +2868,20 @@ func Provider() *tfbridge.ProviderInfo {
}
return config, nil
},
TransformFromState: func(ctx context.Context, state resource.PropertyMap) (resource.PropertyMap, error) {
if _, ok := state["dbName"]; ok {
return state, nil
}
name, ok := state["name"]
if !ok {
// It's seems like inputs are not in a valid state
return state, nil
}
tfbridge.GetLogger(ctx).Debug(`migrating from "name" to "dbName"`)
state["dbName"] = name
delete(state, "name")
return state, nil
},
},
"aws_db_option_group": {
Tok: awsResource(rdsMod, "OptionGroup"),
Expand Down
Loading

0 comments on commit eae27fd

Please sign in to comment.