Terraform provider debugging problems

Hi there,

I am trying to debug locally a terraform provider. Thus I have set in my IDE a go build configuration as follows:

The build is successful, and after setting in my terminal the environment variable TF_REATTACH_PROVIDERS to what is shown in the debug console, I proceed to run in the terminal the terraform init and plan commands.

At this point, I would expect the execution to stop on the breakpoint I have set previously, but it doesn’t. A closer look to the terraform log shows me that instead of using my local build, terraform has downloaded and used the latest provider from github - this is why my breakpoints are not taken into account.

Having said all that as background, I cannot understand why terraform is downloading the provider instead of using the one I am building. Could you please point me in the right direction? Thanks.

This is the simple tf file which I am using:

terraform {
  required_providers {
    akamai = {
      source = "akamai/akamai"
    }
  }
  required_version = ">= 0.13"
}

provider "akamai" {
  edgerc = "../../config/edgerc"
  property_section = "default"
}

data "akamai_groups" "grps" {
}

output "groups" {
  value = data.akamai_groups.grps.groups
}

And here an extract of my terraform log, which shows that it is using the downloaded provider:

2021/05/20 10:19:50 [DEBUG] Starting graph walk: walkPlan
2021-05-20T10:19:50.778+0200 [INFO]  plugin: configuring client automatic mTLS
2021-05-20T10:19:50.806+0200 [DEBUG] plugin: starting plugin: path=.terraform/plugins/registry.terraform.io/akamai/akamai/1.5.1/darwin_amd64/terraform-provider-akamai_v1.5.1 args=[.terraform/plugins/registry.terraform.io/akamai/akamai/1.5.1/darwin_amd64/terraform-provider-akamai_v1.5.1]
2021-05-20T10:19:50.809+0200 [DEBUG] plugin: plugin started: path=.terraform/plugins/registry.terraform.io/akamai/akamai/1.5.1/darwin_amd64/terraform-provider-akamai_v1.5.1 pid=30244
2021-05-20T10:19:50.809+0200 [DEBUG] plugin: waiting for RPC address: path=.terraform/plugins/registry.terraform.io/akamai/akamai/1.5.1/darwin_amd64/terraform-provider-akamai_v1.5.1
2021-05-20T10:19:50.839+0200 [INFO]  plugin.terraform-provider-akamai_v1.5.1: configuring server automatic mTLS: timestamp=2021-05-20T10:19:50.839+0200
2021-05-20T10:19:50.866+0200 [DEBUG] plugin: using plugin: version=5
2021-05-20T10:19:50.867+0200 [DEBUG] plugin.terraform-provider-akamai_v1.5.1: plugin address: network=unix address=/var/folders/57/ynjmgg1949d40hv2xz3t9v8h0000gq/T/plugin441308499 timestamp=2021-05-20T10:19:50.866+0200
2021-05-20T10:19:50.941+0200 [DEBUG] plugin.terraform-provider-akamai_v1.5.1: 2021/05/20 10:19:50 [DEBUG] START Configure: OperationID=cb443ae4-372f-4cf0-abe4-af751151659f
2021-05-20T10:19:50.941+0200 [DEBUG] plugin.terraform-provider-akamai_v1.5.1: 2021/05/20 10:19:50 [DEBUG] START Configure: OperationID=cb443ae4-372f-4cf0-abe4-af751151659f
2021-05-20T10:19:50.941+0200 [DEBUG] plugin.terraform-provider-akamai_v1.5.1: 2021/05/20 10:19:50 [DEBUG] START Configure: OperationID=cb443ae4-372f-4cf0-abe4-af751151659f
2021-05-20T10:19:50.941+0200 [DEBUG] plugin.terraform-provider-akamai_v1.5.1: 2021/05/20 10:19:50 [DEBUG] START Configure: OperationID=cb443ae4-372f-4cf0-abe4-af751151659f
2021-05-20T10:19:50.941+0200 [DEBUG] plugin.terraform-provider-akamai_v1.5.1: 2021/05/20 10:19:50 [DEBUG] START Configure: OperationID=cb443ae4-372f-4cf0-abe4-af751151659f
2021/05/20 10:19:50 [DEBUG] ReferenceTransformer: "data.akamai_groups.grps" references: []
2021-05-20T10:19:50.947+0200 [WARN]  plugin.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing"
2021-05-20T10:19:50.951+0200 [DEBUG] plugin: plugin process exited: path=.terraform/plugins/registry.terraform.io/akamai/akamai/1.5.1/darwin_amd64/terraform-provider-akamai_v1.5.1 pid=30244
2021-05-20T10:19:50.951+0200 [DEBUG] plugin: plugin exited
2021/05/20 10:19:50 [INFO] backend/local: plan operation completed

Hi,

I am answering my own post, as I finally found out which was the issue. Probably it will help someone else.

As a fish shell user, and I was setting the TF_REATTACH_PROVIDERS environment variable making use of the set command instead of the standard export. I thought it was just the same, but apparently not as when I switched to the standard export the debug session started working as expected.

Noob issue, I guess.

Cheers!