Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: Plugin module addressing #53

Closed
independentid opened this issue Jun 5, 2022 · 7 comments
Closed

Documentation: Plugin module addressing #53

independentid opened this issue Jun 5, 2022 · 7 comments

Comments

@independentid
Copy link

I had substantial difficulty figuring out how terraform locates plugin and understanding "Address" in ServeOpts works in plugin discovery and initialization.

The relationship between the top-level project (e.g. github project name), the ServeOpts address, and the go modules were unclear in the documentation and tutorial. For example when building the project, if the last plugin name is "abc", then terraform seems to look for: terraform-provider-abc in the go bin directory (apparently requiring the GO project to be called terraform-provider-abc) and the last segment of the Address needs to be "abc".

The server opts address value in main.go, .terraformrc, and project name need to "align" (but not equal).

This was difficult because the current hashicups example tutorial does not use the current plugin framework scaffolding and uses a different plugin start procedure avoiding the ServeOpts Address value.

Hashicups:

func main() {
	tfsdk.Serve(context.Background(), hashicups.New, tfsdk.ServeOpts{
		Name: "hashicups",
	})
}

Plugin Scaffolding Framework:

func main() {
	var debug bool

	flag.BoolVar(&debug, "debug", false, "set to true to run the provider with support for debuggers like delve")
	flag.Parse()

	opts := providerserver.ServeOpts{
		// TODO: Update this string with the published name of your provider.
		Address: "registry.terraform.io/hashicorp/scaffolding",
		Debug:   debug,
	}

	err := providerserver.Serve(context.Background(), provider.New(version), opts)

	if err != nil {
		log.Fatal(err.Error())
	}
}
@bflad
Copy link
Member

bflad commented Oct 4, 2022

Hi @independentid 👋 Are you still having trouble with this?

The code in the hashicups-pf provider has since been upgraded to providerserver.ServeOpts, e.g.

https://github.com/hashicorp/terraform-provider-hashicups-pf/blob/12e9150e4df62eb6f86dd074936f2c6155865ce5/main.go#L14-L21

The full address is required because it gets mapped to the TF_REATTACH_CONFIG environment variable when starting up providers in debug mode. Most providers tend to use provider names without dashes after the terraform-provider- conventional prefix, which simplifies things between running go build or go install without special flags. In general and if possible, that is typically the recommendation, however with these two providers they were written as a "new" version of the existing scaffolding/hashicups providers, so they wound up with the extra suffixes.

@independentid
Copy link
Author

I found out later (can't remember the issue), that this issue arrises when there is a dash/underscore in the organization name.

For example:
"hashicorp.com/university-edu/hashicups-pf"
Will not be handled correctly.

I incorrectly had concluded the issue was related to how packages names and go module names needed to align. It turns out that too was just another issue.

When I switched to universityedu as org name the problem went away.

@bflad
Copy link
Member

bflad commented Oct 5, 2022

@independentid thank you for that additional context. Can you recall what exactly didn't work with provider addresses with dashes/underscores in the namespace? e.g. running the provider locally with a dev_overrides configuration, running the provider locally in debug mode, a Registry issue, etc. I'm just trying to determine if there is something to do in this codebase, improve/fix the framework/Terraform/Registry, or update documentation somewhere. Thanks!

@independentid
Copy link
Author

independentid commented Oct 5, 2022 via email

@bflad
Copy link
Member

bflad commented Oct 5, 2022

However tests will not run until dash removed from organization name.

Ah ha! Thank you for the clue there. I will create a terraform-plugin-sdk GitHub issue to investigate that further.

I have noticed in general that dashes and underscores in terraform cause a lot of unexpected problems in various parts of terraform. I tend to avoid them everywhere now.

Unfortunately, that does tend to be the case depending on the Terraform component involved since many things have conventionally not included them, but there is also not much feedback from core or the provider frameworks about potential issues when they are used. It'd be great to start patching up non-compliant components or enforce validation against it if necessary.


Since I'm not sure there's anything specific to do in this repository, I'm going to close this particular issue for now. If you have specific feedback about a specific component (hashicorp/terraform, hashicorp/terraform-plugin-framework, etc.), we would love to hear about that in a GitHub issue in the relevant repository. Thank you again for the report and sorry for the trouble it caused you in the past.

@bflad
Copy link
Member

bflad commented Oct 5, 2022

Acceptance testing issue created: hashicorp/terraform-plugin-sdk#1075

Copy link

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants