hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.61k stars 9k forks source link

Not possible to import v2 with go modules #7872

Closed akerl closed 4 years ago

akerl commented 5 years ago

Community Note

Expected Behavior

I'm trying to import this codebase into another project. With the addition of go modules, major versions are expected to be differentiated by import path: https://github.com/golang/go/wiki/Modules#releasing-modules-v2-or-higher

As such, I'd expect to import v2 with the import path github.com/terraform-providers/terraform-provider-aws/v2/aws

Actual Behavior

Importing github.com/terraform-providers/terraform-provider-aws/v2/aws returns the following:

❯ go get github.com/terraform-providers/terraform-provider-aws/v2/aws
go: finding github.com/hashicorp/go-hclog v0.8.0
go: finding github.com/hashicorp/go-getter v1.2.0
go: finding github.com/hashicorp/hcl2 v0.0.0-20190305174554-fdf8e232b64f
go: finding github.com/terraform-providers/terraform-provider-aws/v2/aws latest
go: finding github.com/terraform-providers/terraform-provider-aws/v2 v2.1.0
go: downloading github.com/terraform-providers/terraform-provider-aws/v2 v2.1.0
go get github.com/terraform-providers/terraform-provider-aws/v2/aws: go.mod has non-.../v2 module path "github.com/terraform-providers/terraform-provider-aws" (and .../v2/go.mod does not exist) at revision v2.1.0

Importing without the v2 gets the latest v1 version available.

Steps to Reproduce

  1. mkdir tmprepo
  2. cd tmprepo
  3. go mod init example.com/test
  4. go get github.com/terraform-providers/terraform-provider-aws/v2/aws
akerl commented 5 years ago

Ping @bflad ; without this meta change, the library remains un-importable with go mod.

paultyng commented 5 years ago

Hi, thanks for reaching out. This repository is not intended to be used as a library. The versioning on the provider is about the HCL contract with Terraform users, it is not semantic versioning of the Go contract, so applying Go module versioning rules to it will not work the way the Go modules workflows intend. Over time our intent is to move more of the provider code to an internal package to explicitly indicate our non-support for external consumers.

That being said, if you want to use this code in your own projects, you can feel free. These changes are not meant to stop anyone from reusing it, merely to indicate that its unsupported and we make no guarantees against drastically changing things without any sort of warning or notification.

I am curious what your use case is, could you expand on it?

akerl commented 5 years ago

I maintain a terraform provider that's build as a lightweight shim around this provider ( https://github.com/armorfret/terraform-provider-awscreds ). The goal is to work around an issue with the stock provider handling of the iam_access_key resource, where the secret key gets stored in the statefile.

My goal was to modify the behavior with the minimum necessary code duplication, and so my provider instantiates a copy official provider under-the-hood and just modifies the resulting objects as necessary to remove secret keys.

peikk0 commented 4 years ago

Same issue with the same use case here, we have a custom provider extending this one with additional resources and we can't import v2 properly with go mod.

aeschright commented 4 years ago

Hi folks! Since importing the provider as a module is not a supported feature for this project, I'm going to close this issue. If you want to discuss things more, you might find other interested people on the community forums: https://discuss.hashicorp.com/c/terraform-providers

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!