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

Add raft_snapshot_agent_config resource. #1139

Merged
merged 3 commits into from
Sep 3, 2021

Conversation

mbillow
Copy link
Contributor

@mbillow mbillow commented Aug 6, 2021

Currently the Vault provider does not support managing Raft Snapshot Agent configurations. This change introduces a resource to manage these configurations.

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

Release note for CHANGELOG:

FEATURES:

 -  New Resource `vault_raft_snapshot_agent_config`: Provision [Raft Snapshot Agent Configurations](https://www.vaultproject.io/api-docs/system/storage/raftautosnapshots) in Vault Enterprise.

Output from acceptance testing:

$ TESTARGS="--run RaftSnapshotAgentConfig" make testacc
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./...) -v --run RaftSnapshotAgentConfig -timeout 120m
?       github.com/hashicorp/terraform-provider-vault   [no test files]
?       github.com/hashicorp/terraform-provider-vault/cmd/coverage      [no test files]
?       github.com/hashicorp/terraform-provider-vault/cmd/generate      [no test files]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/codegen   (cached) [no tests to run]
?       github.com/hashicorp/terraform-provider-vault/generated [no test files]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/datasources/transform/decode    (cached) [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/datasources/transform/encode    (cached) [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/resources/transform/alphabet    (cached) [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/resources/transform/role        (cached) [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/resources/transform/template    (cached) [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/resources/transform/transformation      (cached) [no tests to run]
?       github.com/hashicorp/terraform-provider-vault/schema    [no test files]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/util      (cached) [no tests to run]
=== RUN   TestAccRaftSnapshotAgentConfig_basic
    testing.go:669: Step 0 error: errors during apply:
        
        Error: error writing "sys/storage/raft/snapshot-auto/config/tf-test-raft-snapshot-8027668097125168177": Error making API request.
        
        URL: POST http://127.0.0.1:38200/sys/storage/raft/snapshot-auto/config/tf-test-raft-snapshot-8027668097125168177
        Code: 400. Raw Message:
        
        400 Bad Request
        
          on /var/folders/7n/tm_prh_d4y77vd6clypdj3qr0000gp/T/tf-test397001624/main.tf line 2:
          (source code not available)
        
        
--- FAIL: TestAccRaftSnapshotAgentConfig_basic (0.19s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x20a8797]

goroutine 14 [running]:
testing.tRunner.func1.1(0x229d6a0, 0x3069c50)
        /usr/local/go-dists/1.15.2/go/src/testing/testing.go:1076 +0x30d
testing.tRunner.func1(0xc000682780)
        /usr/local/go-dists/1.15.2/go/src/testing/testing.go:1079 +0x41a
panic(0x229d6a0, 0x3069c50)
        /usr/local/go-dists/1.15.2/go/src/runtime/panic.go:969 +0x175
github.com/hashicorp/terraform-provider-vault/vault.testAccRaftSnapshotAgentConfigCheckDestroy(0xc000fc4c60, 0x0, 0x0)
        /Users/mbillow/go/src/github.com/hashicorp/terraform-provider-vault/vault/resource_raft_snapshot_agent_config_test.go:86 +0x97
github.com/hashicorp/terraform-plugin-sdk/helper/resource.testStep(0xc000aac8f0, 0x0, 0xc0007a2458, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, ...)
        /Users/mbillow/go/pkg/mod/github.com/hashicorp/[email protected]/helper/resource/testing_config.go:105 +0xdf8
github.com/hashicorp/terraform-plugin-sdk/helper/resource.Test(0x276a000, 0xc000682780, 0x0, 0xc00021d070, 0xc000790390, 0x0, 0x0, 0x2533db0, 0xc000710340, 0x2, ...)
        /Users/mbillow/go/pkg/mod/github.com/hashicorp/[email protected]/helper/resource/testing.go:728 +0x9c5
github.com/hashicorp/terraform-provider-vault/vault.TestAccRaftSnapshotAgentConfig_basic(0xc000682780)
        /Users/mbillow/go/src/github.com/hashicorp/terraform-provider-vault/vault/resource_raft_snapshot_agent_config_test.go:16 +0x8c5
testing.tRunner(0xc000682780, 0x2532970)
        /usr/local/go-dists/1.15.2/go/src/testing/testing.go:1127 +0xef
created by testing.(*T).Run
        /usr/local/go-dists/1.15.2/go/src/testing/testing.go:1178 +0x386
FAIL    github.com/hashicorp/terraform-provider-vault/vault     1.178s
FAIL
make: *** [testacc] Error 1

...

The tests fail though not because the provider is doing something incorrectly, but because Vault is panicking. 😬

ent-vault-11    | panic: runtime error: invalid memory address or nil pointer dereference
ent-vault-11    | [signal SIGSEGV: segmentation violation code=0x1 addr=0x50 pc=0x1f6a276]
ent-vault-11    |
ent-vault-11    | goroutine 90 [running]:
ent-vault-11    | github.com/hashicorp/vault/vault/autosnapshots.(*SnapshotManager).run(0xc0000dec80)
ent-vault-11    | 	/gopath/src/github.com/hashicorp/vault/vault/autosnapshots/autosnapshots_ent.go:250 +0xa96
ent-vault-11    | created by github.com/hashicorp/vault/vault/autosnapshots.(*SnapshotManager).Start
ent-vault-11    | 	/gopath/src/github.com/hashicorp/vault/vault/autosnapshots/autosnapshots_ent.go:172 +0x7f
ent-vault-11 exited with code 2

Upon restarting Vault, you can see that the resource is created correctly.

$ vault list sys/storage/raft/snapshot-auto/config
Keys
----
tf-test-raft-snapshot-8959155357738393146

$ vault read sys/storage/raft/snapshot-auto/config/tf-test-raft-snapshot-8959155357738393146
Key                Value
---                -----
file_prefix        vault-snapshot
interval           7200
local_max_space    4096
path_prefix        /tmp
retain             1
storage_type       local

Copy link
Contributor

@vinay-gopalan vinay-gopalan left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! Looks great! Left a few comments :)

vault/provider.go Outdated Show resolved Hide resolved
vault/resource_raft_snapshot_agent_config.go Show resolved Hide resolved
vault/resource_raft_snapshot_agent_config.go Show resolved Hide resolved
@mbillow
Copy link
Contributor Author

mbillow commented Sep 2, 2021

Thanks for the review @vinay-gopalan. I fixed most of the issues you pointed out and commented on the rest. 😄 Let me know know how you want to proceed on those fronts or if you need anything else from me.

@vinay-gopalan
Copy link
Contributor

Also @mbillow I looked into the panic, and it seems like Vault's update method for the Raft Snapshot config endpoint was erroring out and causing the panic. This should be fixed because of this merge yesterday: https://github.com/hashicorp/vault-enterprise/pull/2143/files

If it still persists, please let us know by opening an issue! Thanks

Copy link
Contributor

@vinay-gopalan vinay-gopalan left a comment

Choose a reason for hiding this comment

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

Thanks for the PR and for making the changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants