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

Unable to use debugger #286

Closed
MacLikorne opened this issue Apr 8, 2022 · 3 comments
Closed

Unable to use debugger #286

MacLikorne opened this issue Apr 8, 2022 · 3 comments
Labels
bug Something isn't working waiting-response Issues or pull requests waiting for an external response

Comments

@MacLikorne
Copy link

MacLikorne commented Apr 8, 2022

Module version

v0.6.1

Relevant provider source code

func main() {
	opts := tfsdk.ServeOpts{
		Name: "qovery",
		Debug: true,
	}

	if err := tfsdk.Serve(context.Background(), qovery.New(version), opts); err != nil {
		log.Fatal(err)
	}
}

Terraform Configuration Files

provider_installation {

  dev_overrides {
      "qovery.com/api/qovery" = "/home/likornus/go/bin"
  }

  direct {}
  
}

Debug Output

When running Intellij Ultimate in debug:

GOROOT=/usr/lib/go #gosetup
GOPATH=/home/likornus/go #gosetup
/usr/lib/go/bin/go build -o /home/likornus/go/bin/terraform-provider-qovery -gcflags all=-N -l terraform-provider-qovery #gosetup
/home/likornus/.local/share/JetBrains/IntelliJIdea2021.3/go/lib/dlv/linux/dlv --listen=127.0.0.1:46351 --headless=true --api-version=2 --check-go-version=false --only-same-user=false exec /home/likornus/go/bin/terraform-provider-qovery --
API server listening at: 127.0.0.1:46351
{"@level":"debug","@message":"plugin address","@timestamp":"2022-04-08T09:39:12.508366+02:00","address":"/tmp/plugin913228467","network":"unix"}
Provider started. To attach Terraform CLI, set the TF_REATTACH_PROVIDERS environment variable with the following:

        TF_REATTACH_PROVIDERS='{"qovery":{"Protocol":"grpc","ProtocolVersion":6,"Pid":2572864,"Test":true,"Addr":{"Network":"unix","String":"/tmp/plugin913228467"}}}'

When running a Terraform command:

2022-04-08T09:44:20.499+0200 [INFO]  Terraform version: 1.1.7
2022-04-08T09:44:20.499+0200 [INFO]  Go runtime version: go1.17.2
2022-04-08T09:44:20.499+0200 [INFO]  CLI args: []string{"/var/lib/tfenv/versions/1.1.7/terraform", "apply"}
2022-04-08T09:44:20.499+0200 [TRACE] Stdout is a terminal of width 211
2022-04-08T09:44:20.499+0200 [TRACE] Stderr is a terminal of width 211
2022-04-08T09:44:20.499+0200 [TRACE] Stdin is a terminal
2022-04-08T09:44:20.499+0200 [DEBUG] Attempting to open CLI config file: /home/likornus/.terraformrc
2022-04-08T09:44:20.499+0200 [INFO]  Loading CLI configuration from /home/likornus/.terraformrc
2022-04-08T09:44:20.499+0200 [DEBUG] checking for credentials in "/home/likornus/.terraform.d/plugins"
2022-04-08T09:44:20.499+0200 [DEBUG] Explicit provider installation configuration is set
2022-04-08T09:44:20.499+0200 [TRACE] Selected provider installation method cliconfig.ProviderInstallationDirect with includes [] and excludes []
2022-04-08T09:44:20.500+0200 [INFO]  CLI command args: []string{"apply"}
2022-04-08T09:44:20.501+0200 [TRACE] Meta.Backend: no config given or present on disk, so returning nil config
2022-04-08T09:44:20.501+0200 [TRACE] Meta.Backend: backend has not previously been initialized in this working directory
2022-04-08T09:44:20.501+0200 [DEBUG] New state was assigned lineage "20500502-8e9a-9487-bf46-310ac24521b2"
2022-04-08T09:44:20.501+0200 [TRACE] Meta.Backend: using default local state only (no backend configuration, and no existing initialized backend)
2022-04-08T09:44:20.501+0200 [TRACE] Meta.Backend: instantiated backend of type <nil>
2022-04-08T09:44:20.501+0200 [DEBUG] Provider qovery.com/api/qovery is overridden by dev_overrides
2022-04-08T09:44:20.501+0200 [DEBUG] Provider registry.terraform.io/hashicorp/qovery is overridden as an "unmanaged provider"
2022-04-08T09:44:20.501+0200 [DEBUG] Provider qovery.com/api/qovery is overridden to load from /home/likornus/go/bin
2022-04-08T09:44:20.501+0200 [DEBUG] checking for provisioner in "."
2022-04-08T09:44:20.501+0200 [DEBUG] checking for provisioner in "/var/lib/tfenv/versions/1.1.7"
2022-04-08T09:44:20.501+0200 [DEBUG] checking for provisioner in "/home/likornus/.terraform.d/plugins"
2022-04-08T09:44:20.501+0200 [TRACE] Meta.Backend: backend <nil> does not support operations, so wrapping it in a local backend
2022-04-08T09:44:20.501+0200 [DEBUG] Provider qovery.com/api/qovery is overridden by dev_overrides
2022-04-08T09:44:20.501+0200 [DEBUG] Provider registry.terraform.io/hashicorp/qovery is overridden as an "unmanaged provider"
╷
│ Warning: Provider development overrides are in effect
│ 
│ The following provider development overrides are set in the CLI configuration:
│  - qovery.com/api/qovery in /home/likornus/go/bin
│ 
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.
╵
2022-04-08T09:44:20.501+0200 [INFO]  backend/local: starting Apply operation
2022-04-08T09:44:20.501+0200 [TRACE] backend/local: requesting state manager for workspace "default"
2022-04-08T09:44:20.501+0200 [TRACE] backend/local: state manager for workspace "default" will:
 - read initial snapshot from terraform.tfstate
 - write new snapshots to terraform.tfstate
 - create any backup at terraform.tfstate.backup
2022-04-08T09:44:20.501+0200 [TRACE] backend/local: requesting state lock for workspace "default"
2022-04-08T09:44:20.501+0200 [TRACE] statemgr.Filesystem: preparing to manage state snapshots at terraform.tfstate
2022-04-08T09:44:20.501+0200 [TRACE] statemgr.Filesystem: no previously-stored snapshot exists
2022-04-08T09:44:20.501+0200 [TRACE] statemgr.Filesystem: locking terraform.tfstate using fcntl flock
2022-04-08T09:44:20.501+0200 [TRACE] statemgr.Filesystem: writing lock metadata to .terraform.tfstate.lock.info
2022-04-08T09:44:20.501+0200 [TRACE] backend/local: reading remote state for workspace "default"
2022-04-08T09:44:20.501+0200 [TRACE] statemgr.Filesystem: reading latest snapshot from terraform.tfstate
2022-04-08T09:44:20.501+0200 [TRACE] statemgr.Filesystem: snapshot file has nil snapshot, but that's okay
2022-04-08T09:44:20.501+0200 [TRACE] statemgr.Filesystem: read nil snapshot
2022-04-08T09:44:20.501+0200 [TRACE] backend/local: populating backend.LocalRun for current working directory
2022-04-08T09:44:20.501+0200 [DEBUG] Config.VerifyDependencySelections: skipping qovery.com/api/qovery because it's overridden by a special configuration setting
2022-04-08T09:44:20.501+0200 [TRACE] terraform.NewContext: starting
2022-04-08T09:44:20.501+0200 [TRACE] terraform.NewContext: complete
2022-04-08T09:44:20.501+0200 [TRACE] backend/local: requesting interactive input, if necessary
2022-04-08T09:44:20.501+0200 [TRACE] LoadSchemas: retrieving schema for provider type "qovery.com/api/qovery"
2022-04-08T09:44:20.501+0200 [TRACE] terraform.contextPlugins: Initializing provider "qovery.com/api/qovery" to read its schema
2022-04-08T09:44:20.501+0200 [DEBUG] created provider logger: level=trace
2022-04-08T09:44:20.501+0200 [INFO]  provider: configuring client automatic mTLS
2022-04-08T09:44:20.510+0200 [DEBUG] provider: starting plugin: path=/home/likornus/go/bin/terraform-provider-qovery args=[/home/likornus/go/bin/terraform-provider-qovery]
2022-04-08T09:44:20.510+0200 [DEBUG] provider: plugin started: path=/home/likornus/go/bin/terraform-provider-qovery pid=2575127
2022-04-08T09:44:20.510+0200 [DEBUG] provider: waiting for RPC address: path=/home/likornus/go/bin/terraform-provider-qovery
2022-04-08T09:44:20.515+0200 [INFO]  provider.terraform-provider-qovery: configuring server automatic mTLS: timestamp=2022-04-08T09:44:20.514+0200
2022-04-08T09:44:20.585+0200 [DEBUG] provider.terraform-provider-qovery: plugin address: network=unix address=/tmp/plugin172277024 timestamp=2022-04-08T09:44:20.585+0200
2022-04-08T09:44:20.585+0200 [TRACE] statemgr.Filesystem: removing lock metadata file .terraform.tfstate.lock.info
2022-04-08T09:44:20.585+0200 [TRACE] statemgr.Filesystem: unlocking terraform.tfstate using fcntl flock
╷
│ Error: Failed to load plugin schemas
│ 
│ Error while loading schemas for plugin components: Failed to obtain provider schema: Could not load the schema for provider qovery.com/api/qovery: failed to instantiate provider "qovery.com/api/qovery" to
│ obtain schema: Unrecognized remote plugin message: Provider started. To attach Terraform CLI, set the TF_REATTACH_PROVIDERS environment variable with the following:
│ 
│ This usually means that the plugin is either invalid or simply
│ needs to be recompiled to support the latest protocol...
╵
2022-04-08T09:44:20.585+0200 [WARN]  provider: plugin failed to exit gracefully
2022-04-08T09:44:20.586+0200 [DEBUG] provider: plugin process exited: path=/home/likornus/go/bin/terraform-provider-qovery pid=2575127 error="signal: killed"

Expected Behavior

I was expecting to get IDE's breakpoints triggered when executing a CLI command.

Actual Behavior

I got the error shown in log output.

Steps to Reproduce

  1. Set the debug mode to true in main provider call.
  2. Run the IDE's debugger
  3. export the TF_REATTACH_PROVIDERS variable
  4. execute terraform apply or terraform plan

Actually, I already tried to remove the dev_overrides from terraform config but it doesn't change anything.

I also tried with and without --debug flag.

I noticed that the file in /tmp used by terraform on command execution is not the same than the one in the Addr of the TF_REATTACH_PROVIDERS variable. In the logs you can see /tmp/plugin913228467 in the variable and /tmp/plugin172277024 in the debug log.

I work with fish terminal and tried to export TF_REATTACH_PROVIDERS in every possible way.

UPDATE: tried this way and got the same error.

References

@MacLikorne MacLikorne added the bug Something isn't working label Apr 8, 2022
@bflad
Copy link
Member

bflad commented Apr 20, 2022

Hi @MacLikorne 👋 Thank you for raising this and sorry you ran into trouble here.

Does it help if you set ServeOpts.Name to the full provider address? e.g. Name: "qovery.com/api/qovery" This should cause the full provider address to be part of the reattach configuration.

Terraform CLI should not be attempting to start the provider when there is an available reattach configuration. I believe the logic that determines whether the reattach configuration applies to a certain provider is based on the full provider address.

@bflad bflad added the waiting-response Issues or pull requests waiting for an external response label Apr 21, 2022
@bflad
Copy link
Member

bflad commented Apr 28, 2022

In v0.7.0 (just released), you should be able to setup the provider serving via the new providerserver package, which explicitly requires the full provider address, e.g. updating the issue description code

func main() {
	opts := providerserver.ServeOpts{
		Address: "qovery.com/api/qovery",
		Debug:   true,
	}

	if err := providerserver.Serve(context.Background(), qovery.New(version), opts); err != nil {
		log.Fatal(err)
	}
}

If you are still having trouble (using a full provider address with Name in v0.6.1 or Address in v0.7.0), please reach out and we can continue looking into this. Thanks.

@bflad bflad closed this as completed Apr 28, 2022
@github-actions
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 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working waiting-response Issues or pull requests waiting for an external response
Projects
None yet
Development

No branches or pull requests

2 participants