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

Using oauth_client_credentials.endpoint_params leads to “panic: Unknown validation type: 6” #202

Open
devopsix opened this issue Dec 2, 2022 · 2 comments

Comments

@devopsix
Copy link

devopsix commented Dec 2, 2022

Using oauth_client_credentials.endpoint_params in the provider configuration leads to “panic: Unknown validation type: 6”.

Steps to Reproduce

  1. Create main.tf with this content:

    terraform {
      required_providers {
        restapi = {
          source = "Mastercard/restapi"
          version = "1.18.0"
        }
      }
    }
    
    provider "restapi" {
      uri = "https://api.example.com"
      oauth_client_credentials {
        oauth_client_id = "id"
        oauth_client_secret = "secret"
        oauth_token_endpoint = "https://id.example.com/oauth2/token"
        endpoint_params = {
          myparam = ["myvalue"]
        }
      }
    }
    
    resource "restapi_object" "api_resource" {
      path = "/thing"
      data = jsonencode({id = "1"})
    }
  2. Start Terraform 1.3.6 container:

    docker run -it --rm -v "$(pwd)/main.tf:/main.tf:ro" --entrypoint /bin/sh hashicorp/terraform:1.3.6
  3. Run this command:

    terraform init && terraform plan

Expected: terraform plan succeeds.

Actual: terraform plan terminates with exit code 1 and the below output is logged.

Initializing the backend...

Initializing provider plugins...
- Finding mastercard/restapi versions matching "1.18.0"...
- Installing mastercard/restapi v1.18.0...
- Installed mastercard/restapi v1.18.0 (self-signed, key ID 12575FB7060C00C1)

Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/cli/plugins/signing.html

Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
╷
│ Error: Request cancelled
│
│   with provider["registry.terraform.io/mastercard/restapi"],
│   on main.tf line 10, in provider "restapi":
│   10:     provider "restapi" {
│
│ The plugin.(*GRPCProvider).ValidateProviderConfig request was cancelled.
╵

Stack trace from the terraform-provider-restapi_v1.18.0 plugin:

panic: Unknown validation type: 6

goroutine 42 [running]:
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.validateMapValues({0xc0002840c0, 0x2a}, 0xc000500640, 0xc0003f2280, {0xc000538380, 0x3, 0x4})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/schema.go:1909 +0x969
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMap.validateMap(0xa65a20, {0xc0002840c0, 0x2a}, {0xa65a20, 0xc000254300}, 0x8210ac, 0xc0000a2ad8, {0xc000538380, 0x3, 0x4})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/schema.go:1816 +0x271
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMap.validateType(0xc00027a640, {0xc0002840c0, 0x77788a}, {0xa65a20, 0xc000254300}, 0xc0003f2280, 0xc00007fee0, {0xc000538380, 0x3, 0x4})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/schema.go:2106 +0x174
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMap.validate(0xa794e0, {0xc0002840c0, 0x2a}, 0xc0003f2280, 0x2, {0xc000538380, 0x3, 0x4})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/schema.go:1531 +0x71a
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMap.validateObject(0xa794e0, {0xc00003d800, 0x1a}, 0x2, 0x2, {0xc000041bc0, 0x15, 0x194})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/schema.go:1967 +0x585
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMap.validateList(0x0, {0xb29de3, 0x18}, {0xa2b3c0, 0xc00000d3f8}, 0xc0003f23c0, 0xa65a20, {0xc00027a040, 0x1, 0x1})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/schema.go:1756 +0xb4e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMap.validateType(0xc000225960, {0xb29de3, 0x77788a}, {0xa2b3c0, 0xc00000d3f8}, 0xc0003f23c0, 0xa57cc0, {0xc00027a040, 0x1, 0x1})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/schema.go:2096 +0x1a5
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMap.validate(0xa794e0, {0xb29de3, 0x18}, 0xc0003f23c0, 0xb1f346, {0xc00027a040, 0x1, 0x1})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/schema.go:1531 +0x71a
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMap.validateObject(0xc000384050, {0x0, 0x0}, 0xc0002541b0, 0xc0004fbc80, {0x10b1af8, 0xa65a20, 0xc000288188})
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/[email protected]/server.go:857 +0x294

Error: The terraform-provider-restapi_v1.18.0 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.
@dlozynski
Copy link

dlozynski commented Mar 15, 2023

I have the same error. I tried different formatting but no success.
I was trying to change grant type like this

endpoint_params = {
      grant_type = ["authorization_code"]
}

Looks like default grant type is like client_credentials and I get error "Invalid grant_type: client_credentials"

I was calling google api

oauth_client_credentials {
        oauth_client_id = google_iap_client.dataflow_client.client_id
        oauth_client_secret = google_iap_client.dataflow_client.secret
        oauth_token_endpoint = "https://oauth2.googleapis.com/token"
        oauth_scopes = ["https://www.googleapis.com/auth/cloud-platform"]
}

@harshavmb
Copy link

I hit the same issue today. Tried hard to fix it locally. No matter what I do, the error appeared in or the other form.

Even though the panic is fixed, the endpointParams attribute passed to go oauth2 SDK only accepts list of strings. Nevertheless, Azure management API expects resource to be passed to token endpoint as a string rather list(string).

Having said this, in the current form, irrespective of Terraform SDK validation limitations, I don't find this attribute being useful as it never worked.

For these complex Object types, Terraform recommends diabling the validation by SDK & delegating it to api backend service. Link to the conversation [here].(hashicorp/terraform-plugin-sdk#62 (comment))

harshavmb added a commit to harshavmb/terraform-provider-restapi that referenced this issue Aug 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants