Skip to content

Commit

Permalink
Migration to remove explicit SDK dependencies for python and JS (#1092)
Browse files Browse the repository at this point in the history
This adds a migration for providers to remove the explicit SDK
dependencies for python and javascript.

this should solve #1091 for tier
2+ providers

I've tested this on pulumi-cloudflare and pulumi-random. I've also
tested it doesn't do anything the second time around.
  • Loading branch information
VenelinMartinov authored Oct 2, 2024
1 parent 1886199 commit 8a60afb
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
29 changes: 28 additions & 1 deletion tools/sourcemigrator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,33 @@ function run(command: string): shell.ShellString {
// };
// }

function removeExplicitSDKDependency(): SourceMigration {
return {
name: "Respect Schema Version",
async execute(context) {
const patchPath = fs.realpathSync("removeExplicitSDKdependency.patch");
shell.pushd(context.dir);
try {
// Apply patch
run(
`go run github.com/uber-go/[email protected] -p "${patchPath}" ./provider/resources.go`
);
// Format the code - twice to ensure that the code is formatted correctly
run(`go install mvdan.cc/gofumpt@latest`);
run(`gofumpt -w ./provider/resources.go`);
run(`gofumpt -w ./provider/resources.go`);
// Check if we've made changes
const gitStatus = run(`git status --porcelain`).stdout;
if (gitStatus.includes("provider/resources.go")) {
run(`make tfgen build_sdks`);
}
} finally {
shell.popd();
}
},
};
}

async function runMigrations(
context: MigrateContext,
migrations: SourceMigration[]
Expand All @@ -110,7 +137,7 @@ async function runMigrations(
}

function allMigrations(): SourceMigration[] {
return [];
return [removeExplicitSDKDependency()];
}

async function main() {
Expand Down
55 changes: 55 additions & 0 deletions tools/sourcemigrator/removeExplicitSDKdependency.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
@@
// JS: Remove explicit SDK dependency
var tfbridge identifier
@@
import tfbridge "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"

tfbridge.JavaScriptInfo{
...,
Dependencies: map[string]string{
...,
- "@pulumi/pulumi": "^3.0.0",
...,
},
...,
}

@@
// JS: Remove empty Dependencies
var tfbridge identifier
@@
import tfbridge "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"

tfbridge.JavaScriptInfo{
...,
- Dependencies: map[string]string{},
...,
}

@@
// Py: Remove explicit SDK dependency
var tfbridge identifier
@@
import tfbridge "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"

tfbridge.PythonInfo{
...,
Requires: map[string]string{
...,
- "pulumi": ">=3.0.0,<4.0.0",
...,
},
...,
}

@@
// Py: Remove empty Requires
var tfbridge identifier
@@
import tfbridge "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"

tfbridge.PythonInfo{
...,
- Requires: map[string]string{},
...,
}

0 comments on commit 8a60afb

Please sign in to comment.