Git Product home page Git Product logo

tf-sdk-migrator's Introduction

tf-sdk-migrator

ARCHIVED: This project has been archived since there are no more plans for feature work. Provider developers wishing to migrate their SDK from terraform to terraform-plugin-sdk or from terraform-plugin-sdk v1 to v2 can still automate part of those processes using this tool.

The Terraform provider plugin SDK, previously part of the github.com/hashicorp/terraform "Core" Go module, has been moved to a new Go module, github.com/hashicorp/terraform-plugin-sdk. Terraform providers should now import hashicorp/terraform-plugin-sdk.

tf-sdk-migrator is a CLI tool which will migrate a Terraform provider to the new SDK module by rewriting import paths. tf-sdk-migrator check checks the eligibility of the Provider for migration.

Installation

go install github.com/hashicorp/tf-sdk-migrator
$GOBIN/tf-sdk-migrator

tf-sdk-migrator check: check eligibility for migration

Checks whether a Terraform provider is ready to migrate to the newly extracted Terraform SDK package.

tf-sdk-migrator check [--help] [--csv] PATH

Outputs a report containing:

  • Go version used in provider (soft requirement)
  • Whether the provider uses Go modules
  • Version of hashicorp/terraform used
  • Whether the provider uses any hashicorp/terraform packages that are not in hashicorp/terraform-plugin-sdk

The --csv flag will output values in CSV format.

Exits 0 if the provider meets all the hard requirements, 1 otherwise.

The Go version requirement is a "soft" requirement: it is strongly recommended to upgrade to Go version 1.12+ before migrating to the new SDK, but the migration can still be performed if this requirement is not met.

tf-sdk-migrator migrate: migrate to standalone SDK

Migrates the Terraform provider to the new extracted SDK (github.com/hashicorp/terraform-plugin-sdk), replacing references to the old SDK (github.com/hashicorp/terraform).

Note: No backup is made before modifying files. Please make sure your VCS staging area is clean.

tf-sdk-migrator migrate [--help] PATH

The eligibility check will be run first: migration will not proceed if this check fails.

The migration tool will then make the following changes:

  • go.mod: replace github.com/hashicorp/terraform dependency with github.com/hashicorp/terraform-plugin-sdk
  • rewrite import paths in all provider .go files (except in vendor/) accordingly
  • run go mod tidy

If you use vendored Go dependencies, you should run go mod vendor afterwards.

tf-sdk-migrator v2upgrade: migrate from SDKv1 to SDKv2

Migrates a Terraform provider using version 1.x of the standalone SDK to version 2.x of the standalone SDK, updating package import paths.

tf-sdk-migrator v2upgrade

Optionally, --sdk-version may be passed, which is parsed as a Go module release version. For example tf-sdk-migrator v2upgrade --sdk-version v2.0.0-rc.1.

This command rewrites go.mod and updates package import paths, but does not replace deprecated identifiers, so it is likely that the provider will not compile after upgrading. Please follow the steps in the Terraform Plugin SDK v2 Upgrade Guide after running this command.

tf-sdk-migrator's People

Contributors

appilon avatar bflad avatar kmoe avatar pdecat avatar radeksimko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tf-sdk-migrator's Issues

Return human-readable message for migrated providers and non-providers

This is what happens when I try to re-run migrate on already migrated provider:

tf-sdk-migrator migrate --sdk-version=master
Checking Go runtime version ...
Go version 1.12.9: OK.
Checking whether provider uses Go modules...
Go modules in use: OK.
Checking version of github.com/hashicorp/terraform SDK used in provider...
SDK version could not be determined. Provider must use hashicorp/terraform SDK.
[WARN] Error getting SDK version for provider /Users/radeksimko/gopath/src/github.com/terraform-providers/terraform-provider-dns: 2 errors occurred:
	* require statement with path "github.com/hashicorp/terraform" not found
	* could not read SDK version from go.mod file for provider/Users/radeksimko/gopath/src/github.com/terraform-providers/terraform-provider-dns


Provider failed eligibility check for migration to the new SDK. Please see warnings above.

As a user I would expect the migrator to check:

  1. If there's already github.com/hashicorp/terraform-plugin-sdk >= 1.0 in go.mod, then just print success/info message Provider already migrated
  2. If there isn't terraform-plugin-sdk, print error message %s [path] doesn't look like a path to Terraform provider as it doesn't import github.com/hashicorp/terraform

cmd/check: Use `go` to find imported packages

While I appreciate the aim of keeping the implementation simple, I'm afraid we may miss some important implementation details of go list when we launch this tool into the wild.

e.g. testdata directories are generally not meant to be imported (and so we shouldn't parse them when scanning for all eligible *.go files to find imports in), packages may be imported under different names, which go-refs doesn't handle etc. Who knows what other weird edge cases we may bump into...

I'm aware that calling out to go via shell comes at the cost of increased complexity, but I think the cost is ok, if we get better accuracy?

Just food for thought ๐Ÿฅ˜ ๐Ÿ’ญ

SDK version should be a flag

I would make the sdk version an arg/flag so it can be forced to a particular version or master which is convenient in testing.

$ tf-sdk-migrator migrate -to master

Add `go version` check; remove other Go version checks

Checking the Go version for eligibility has one major purpose: ensuring modules are resolved correctly when running tf-sdk-migrator migrate, which we believe will happen with a Go version of >=1.12.

The tf-sdk-migrator check currently reads the Go version from .go-version, go.mod, and .travis.yml, which is a poor proxy for the version of Go that will be used to perform the actual migration.

We can just call go version during the eligibility check instead.

Not documented deprecation notice

Hello,
Thanks for this great tool that you are giving us.
I've been struggling with this deprecation notice : after running
tf-sdk-migrator check github.com/Telmate/terraform-provider-proxmox

Checking Go runtime version ...
Go version 1.14.6: OK.
Checking whether provider uses Go modules...
Go modules in use: OK.
Checking version of github.com/hashicorp/terraform-plugin-sdk to determine if provider was already migrated...
Checking version of github.com/hashicorp/terraform used in provider...
Terraform version 0.12.10: OK.
Checking whether provider uses deprecated SDK packages or identifiers...
Deprecated SDK packages in use:
 * github.com/hashicorp/terraform/communicator/remote
 * github.com/hashicorp/terraform/communicator

Some constraints not satisfied. Please resolve these before migrating to the new SDK.

I have search for this in the git repo but not found any clues. And the communicator package seems OK

Please help me understand why ๐Ÿ‘

It is not my provider I'm just trying to migrate from legacy sdk.

Multiple runs results in multiple `/v2/`s appending to paths

While attempting the V2 upgrade, I ran tf-sdk-migrator v2upgrade and hit some issues to fix. As the output wasn't entirely clear, I ran it again after fixing the issues resulting in paths that duplicated the v2/ portion of the module name.

--- cloudflare/data_source_zone_dnssec.go
+++ cloudflare/data_source_zone_dnssec.go
@@ -6,7 +6,7 @@ import (
        "log"

        "github.com/cloudflare/cloudflare-go"
-       "github.com/hashicorp/terraform-plugin-sdk/helper/schema"
+       "github.com/hashicorp/terraform-plugin-sdk/v2/v2/helper/schema"
 )

This wasn't too problematic to fix however it was unexpected and thought I'd document the issue for others.

The usage path I followed probably wasn't correct however perhaps a warning that the v2/ rewrite had already happened and either halt or skip would be useful?

Warn users to run tidy/vendor

Most if not all providers are still vendoring dependencies. I don't think the migrator should necessarily run go mod vendor for them. I think it should run go mod tidy after the migration, mention that it did, and then mention

If you are vendoring dependencies, remember to run go mod vendor

Or something along those lines.

Go version check

The aws provider is a rare provider with no .go-version, no go version in the go.mod file, and a travis file with an unexpected format:

Checking Go version used in provider...
2019/08/27 19:22:40 no Go version found in .go-version file for /Users/alex/git/go/src/github.com/terraform-providers/terraform-provider-aws: open /Users/alex/git/go/src/github.com/terraform-providers/terraform-provider-aws/.go-version: no such file or directory
2019/08/27 19:22:40 no go version found in go.mod file for /Users/alex/git/go/src/github.com/terraform-providers/terraform-provider-aws: go statement not found
2019/08/27 19:22:40 no go version found in Travis config file for /Users/alex/git/go/src/github.com/terraform-providers/terraform-provider-aws: Malformed version: include:
2019/08/27 19:22:40 failed to detect Go version for provider /Users/alex/git/go/src/github.com/terraform-providers/terraform-provider-aws
Go version does not satisfy constraint >=1.12. Found Go version: .

I had some questions/suggestions
Should we make only the use of go modules and currently being on v0.12 of TF a requirement, and the others just warnings? Are deprecated identifiers a blocker? Could we have the migrator skip rewriting the imports of the affect files and allow the import to exist. I can't recall the rationale for requiring go1.12, would being on modules not be enough? Certainly being on 1.12+ is a nice to have.

EDIT:
It appears only the deprecated identifiers is a blocker, you can likely close this issue, you may want to see the AWS providers travis file to see if can still be parsed, in general though the go version seems low priority/concern

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.