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

Fix "panic: interface conversion" #250

Merged
merged 1 commit into from
Dec 18, 2018
Merged

Fix "panic: interface conversion" #250

merged 1 commit into from
Dec 18, 2018

Conversation

ashemedai
Copy link
Contributor

@ashemedai ashemedai commented Dec 3, 2018

The max_connection_lifetime parameter is defined in the schema as an TypeInt, however, the Vault API expects it as a string (time.Duration) representation.

Parse the string as a time.Duration and use the representation in seconds.

Resolves: #114 #117 #152 #154

The max_connection_lifetime parameter in the Vault API is configured
according to number + s, e.g. "100s". The code didn't strip the
trailing s from the number prior to casting. This problem was only
noticable when doing an update.
@ghost ghost added the size/M label Dec 3, 2018
@tyrannosaurus-becks tyrannosaurus-becks self-assigned this Dec 10, 2018
@tyrannosaurus-becks
Copy link
Contributor

@ashemedai thank you for working on this! Is this a dupe of #117? When I run the database connection tests, for me they pass right now.

@cvbarros
Copy link
Contributor

cvbarros commented Dec 10, 2018

@tyrannosaurus-becks I think it is. However, the issue still remains it's easily reproducible whenever vault_database_secret_backend_connection resource needs to be updated (a plan generates a diff).

EDIT: This happens with Version 1.3.1 of the provider, we didn't build from master.

@ashemedai
Copy link
Contributor Author

ashemedai commented Dec 11, 2018

@tyrannosaurus-becks The difference with the #117 is that that PR's tests are comparing what's expected to Duration type results, whereas they should remain integers, as that is what the schema definition defines.

@jhmartin
Copy link

jhmartin commented Dec 11, 2018

I'm seeing this panic on master as well:
plugin.terraform-provider-vault: panic: interface conversion: interface {} is string, not json.Number

2018-12-11T10:02:35.630-0800 [DEBUG] plugin.terraform-provider-vault: 2018/12/11 10:02:35 [DEBUG] Read database connection config "REDACTED"
2018-12-11T10:02:35.632-0800 [DEBUG] plugin.terraform-provider-vault: panic: interface conversion: interface {} is string, not json.Number
2018-12-11T10:02:35.632-0800 [DEBUG] plugin.terraform-provider-vault:
2018-12-11T10:02:35.632-0800 [DEBUG] plugin.terraform-provider-vault: goroutine 108 [running]:
2018-12-11T10:02:35.632-0800 [DEBUG] plugin.terraform-provider-vault: github.com/terraform-providers/terraform-provider-vault/vault.getConnectionDetailsFromResponse(0xc420471a40, 0x1912a12, 0x8, 0xc4204fc3c0, 0x1, 0x0, 0xc420407668)
2018-12-11T10:02:35.632-0800 [DEBUG] plugin.terraform-provider-vault:   /Users/jhmartin/GO/src/github.com/terraform-providers/terraform-provider-vault/vault/resource_database_secret_backend_connection.go:393 +0x98e
2018-12-11T10:02:35.632-0800 [DEBUG] plugin.terraform-provider-vault: github.com/terraform-providers/terraform-provider-vault/vault.databaseSecretBackendConnectionRead(0xc420471a40, 0x18f97e0, 0xc420211ce0, 0x0, 0x0)
2018-12-11T10:02:35.632-0800 [DEBUG] plugin.terraform-provider-vault:   /Users/jhmartin/GO/src/github.com/terraform-providers/terraform-provider-vault/vault/resource_database_secret_backend_connection.go:552 +0x9b2
2018-12-11T10:02:35.632-0800 [DEBUG] plugin.terraform-provider-vault: github.com/terraform-providers/terraform-provider-vault/vendor/github.com/hashicorp/terraform/helper/schema.(*Resource).Refresh(0xc4204fd1a0, 0xc42015b950, 0x18f97e0, 0xc420211ce0, 0xc4201a86e0, 0x1, 0x80020484480)
2018-12-11T10:02:35.632-0800 [DEBUG] plugin.terraform-provider-vault:   /Users/jhmartin/GO/src/github.com/terraform-providers/terraform-provider-vault/vendor/github.com/hashicorp/terraform/helper/schema/resource.go:321 +0x199
2018-12-11T10:02:35.632-0800 [DEBUG] plugin.terraform-provider-vault: github.com/terraform-providers/terraform-provider-vault/vendor/github.com/hashicorp/terraform/helper/schema.(*Provider).Refresh(0xc420211340, 0xc42015b900, 0xc42015b950, 0x50106c8, 0x0, 0x15ea26a)
2018-12-11T10:02:35.632-0800 [DEBUG] plugin.terraform-provider-vault:   /Users/jhmartin/GO/src/github.com/terraform-providers/terraform-provider-vault/vendor/github.com/hashicorp/terraform/helper/schema/provider.go:284 +0x9a
2018-12-11T10:02:35.632-0800 [DEBUG] plugin.terraform-provider-vault: github.com/terraform-providers/terraform-provider-vault/vendor/github.com/hashicorp/terraform/plugin.(*ResourceProviderServer).Refresh(0xc420285260, 0xc420440100, 0xc4204401d0, 0x0, 0x0)
2018-12-11T10:02:35.633-0800 [DEBUG] plugin.terraform-provider-vault:   /Users/jhmartin/GO/src/github.com/terraform-providers/terraform-provider-vault/vendor/github.com/hashicorp/terraform/plugin/resource_provider.go:510 +0x4e
2018-12-11T10:02:35.633-0800 [DEBUG] plugin.terraform-provider-vault: reflect.Value.call(0xc420318480, 0xc420156130, 0x13, 0x190e7ce, 0x4, 0xc4202e5f20, 0x3, 0x3, 0x0, 0x1e2c840, ...)
2018-12-11T10:02:35.633-0800 [DEBUG] plugin.terraform-provider-vault:   /usr/local/Cellar/go/1.9.2/libexec/src/reflect/value.go:434 +0x905
2018-12-11T10:02:35.633-0800 [DEBUG] plugin.terraform-provider-vault: reflect.Value.Call(0xc420318480, 0xc420156130, 0x13, 0xc420324f20, 0x3, 0x3, 0x1, 0x0, 0x0)
2018-12-11T10:02:35.633-0800 [DEBUG] plugin.terraform-provider-vault:   /usr/local/Cellar/go/1.9.2/libexec/src/reflect/value.go:302 +0xa4
2018-12-11T10:02:35.633-0800 [DEBUG] plugin.terraform-provider-vault: net/rpc.(*service).call(0xc42036a180, 0xc420474000, 0xc4201508e0, 0xc42013e480, 0xc420285fe0, 0x1797b80, 0xc420440100, 0x16, 0x1797bc0, 0xc4204401d0, ...)
2018-12-11T10:02:35.633-0800 [DEBUG] plugin.terraform-provider-vault:   /usr/local/Cellar/go/1.9.2/libexec/src/net/rpc/server.go:381 +0x142
2018-12-11T10:02:35.633-0800 [DEBUG] plugin.terraform-provider-vault: created by net/rpc.(*Server).ServeCodec
2018-12-11T10:02:35.633-0800 [DEBUG] plugin.terraform-provider-vault:   /usr/local/Cellar/go/1.9.2/libexec/src/net/rpc/server.go:475 +0x36b
2018/12/11 10:02:35 [ERROR] root: eval: *terraform.EvalRefresh, err: vault_database_secret_backend_connection.cms: unexpected EOF
2018/12/11 10:02:35 [ERROR] root: eval: *terraform.EvalSequence, err: vault_database_secret_backend_connection.cms: unexpected EOF
2018/12/11 10:02:35 [TRACE] [walkRefresh] Exiting eval tree: vault_database_secret_backend_connection.cms

Applying this patch fixed my crash. It'd be really nice to get this into a released version.

Copy link
Contributor

@tyrannosaurus-becks tyrannosaurus-becks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. Thank you @ashemedai and everyone!

@tyrannosaurus-becks tyrannosaurus-becks merged commit 91a9af5 into hashicorp:master Dec 18, 2018
OperationalDev pushed a commit to OperationalDev/terraform-provider-vault that referenced this pull request Dec 24, 2018
Fix "panic: interface conversion"
dandandy pushed a commit to dandandy/terraform-provider-vault that referenced this pull request Jun 17, 2021
Fix "panic: interface conversion"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants