Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

Find imported packages and identifiers via go list #6

Merged
merged 3 commits into from
Aug 29, 2019

Conversation

kmoe
Copy link
Member

@kmoe kmoe commented Aug 15, 2019

fixes #4

This PR does two main things: I've bundled them together as they are both based on the output of go list -json:

  • reimplement check for imported SDK packages so it uses go list instead of filepath.Walk
  • add check for deprecated identifiers (e.g. UserAgentString)
    • this incorporates work from @radeksimko's f-sdk-refs branch

UX

The user will now see the following output (with ANSI colours) if removed identifiers are used in the provider:

$ ./tf-sdk-migrator check github.com/terraform-providers/terraform-provider-azurerm
Checking Go version used in provider...
2019/08/15 11:41:14 no Go version found in .go-version file for /home/katy/dev/go/src/github.com/terraform-providers/terraform-provider-azurerm: open /home/katy/dev/go/src/github.com/terraform-providers/terraform-provider-azurerm/.go-version: no such file or directory
2019/08/15 11:41:14 no go version found in go.mod file for /home/katy/dev/go/src/github.com/terraform-providers/terraform-provider-azurerm: go statement not found
Go version 1.12.0: 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 0.12.0: OK.
Checking whether provider uses packages or identifiers removed from the new SDK...
Removed SDK packages in use: []
Removed SDK idents in use: [Ident UserAgentString from package github.com/hashicorp/terraform/httpclient is used at [/home/katy/dev/go/src/github.com/terraform-providers/terraform-provider-azurerm/azurerm/config.go:279:28 /home/katy/dev/go/src/github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common/client.go:46:28]]

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

TODO

  • consistent vocabulary for "removed SDK identifiers" - we could just say "deprecated functions"?
  • extract go list functionality to separate module

@radeksimko
Copy link
Member

This looks very good!

Just a few things to note:

It would be great to log executed go commands, especially because this may take some time on bigger repositories and/or when packages are missing in modcache and need to be downloaded. I think you mentioned you wanted to extract the go list logic into a separate module - which is a good idea - so this probably applies to that extracted code.

Regarding documentation and wording for each check - I think in the near future we could have part of our docs focused just on explaining each check briefly on website (why is it being reported and how to fix it) and then this tool could be spitting out links without having to go too much into detail.

@kmoe
Copy link
Member Author

kmoe commented Aug 29, 2019

I've extracted the go list code to https://github.com/kmoe/go-list.

Definitely agree with the idea to link to website documentation for more involved output - I think for now it will be fine to log some more nicely formatted output for the deprecated identifiers found, which I'll open another PR for as this one is big enough.

@kmoe kmoe force-pushed the find-imported-packages-via-go-list branch from 36d0611 to 429c383 Compare August 29, 2019 15:10
@kmoe kmoe merged commit 3156391 into master Aug 29, 2019
@kmoe kmoe deleted the find-imported-packages-via-go-list branch August 29, 2019 15:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cmd/check: Use go to find imported packages
2 participants