Skip to content

Add support for vault_quota_rate_limit interval and block_interval - #1084

Merged
benashz merged 3 commits into
hashicorp:mainfrom
mdgreenfield:quota-rate-limit-changes
Jun 6, 2022
Merged

Add support for vault_quota_rate_limit interval and block_interval#1084
benashz merged 3 commits into
hashicorp:mainfrom
mdgreenfield:quota-rate-limit-changes

Conversation

@mdgreenfield

Copy link
Copy Markdown
Contributor

Allows users to specify either in terms of duration or number of
seconds utilizing Vault's parseutil.ParseDurationSecond logic. See
https://github.com/hashicorp/vault/blob/ed33ed1a0a5ecb9d41ab22b4899aa318239ac031/sdk/helper/parseutil/parseutil.go#L96-L147

Closes #1049

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:

Add support for `vault_quota_rate_limit` `interval` and `block_interval`

Output from acceptance testing:

$ ➜  terraform-provider-vault git:(quota-rate-limit-changes) make testacc TESTARGS='-run=TestQuotaRateLimit'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run=TestQuotaRateLimit -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]
WARNING: Package "github.com/golang/protobuf/protoc-gen-go/generator" is deprecated.
        A future release of golang/protobuf will delete this package,
        which has long been excluded from the compatibility promise.

testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/datasources/transform/decode    0.622s [no tests to run]
WARNING: Package "github.com/golang/protobuf/protoc-gen-go/generator" is deprecated.
        A future release of golang/protobuf will delete this package,
        which has long been excluded from the compatibility promise.

testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/datasources/transform/encode    0.846s [no tests to run]
WARNING: Package "github.com/golang/protobuf/protoc-gen-go/generator" is deprecated.
        A future release of golang/protobuf will delete this package,
        which has long been excluded from the compatibility promise.

testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/resources/transform/alphabet    1.799s [no tests to run]
WARNING: Package "github.com/golang/protobuf/protoc-gen-go/generator" is deprecated.
        A future release of golang/protobuf will delete this package,
        which has long been excluded from the compatibility promise.

testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/resources/transform/role        0.477s [no tests to run]
WARNING: Package "github.com/golang/protobuf/protoc-gen-go/generator" is deprecated.
        A future release of golang/protobuf will delete this package,
        which has long been excluded from the compatibility promise.

testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/resources/transform/template    1.562s [no tests to run]
WARNING: Package "github.com/golang/protobuf/protoc-gen-go/generator" is deprecated.
        A future release of golang/protobuf will delete this package,
        which has long been excluded from the compatibility promise.

testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/resources/transform/transformation      1.101s [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]
WARNING: Package "github.com/golang/protobuf/protoc-gen-go/generator" is deprecated.
        A future release of golang/protobuf will delete this package,
        which has long been excluded from the compatibility promise.

=== RUN   TestQuotaRateLimit
vault_quota_rate_limit.foobar:
  ID = tf-test-5534064214137632519
  provider = provider.vault
  block_interval = 0
  interval = 1
  name = tf-test-5534064214137632519
  path =
  rate = 157
vault_quota_rate_limit.foobar:
  ID = tf-test-5534064214137632519
  provider = provider.vault
  block_interval = 0
  interval = 1
  name = tf-test-5534064214137632519
  path =
  rate = 157
vault_quota_rate_limit.foobar:
  ID = tf-test-5534064214137632519
  provider = provider.vault
  block_interval = 0
  interval = 1
  name = tf-test-5534064214137632519
  path =
  rate = 157
vault_quota_rate_limit.foobar:
  ID = tf-test-5534064214137632519
  provider = provider.vault
  block_interval = 0
  interval = 1
  name = tf-test-5534064214137632519
  path =
  rate = 157
vault_quota_rate_limit.foobar:
  ID = tf-test-5534064214137632519
  provider = provider.vault
  block_interval = 0
  interval = 1
  name = tf-test-5534064214137632519
  path =
  rate = 157
vault_quota_rate_limit.foobar:
  ID = tf-test-5534064214137632519
  provider = provider.vault
  block_interval = 120
  interval = 60
  name = tf-test-5534064214137632519
  path =
  rate = 525.3
vault_quota_rate_limit.foobar:
  ID = tf-test-5534064214137632519
  provider = provider.vault
  block_interval = 120
  interval = 60
  name = tf-test-5534064214137632519
  path =
  rate = 525.3
vault_quota_rate_limit.foobar:
  ID = tf-test-5534064214137632519
  provider = provider.vault
  block_interval = 120
  interval = 60
  name = tf-test-5534064214137632519
  path =
  rate = 525.3
vault_quota_rate_limit.foobar:
  ID = tf-test-5534064214137632519
  provider = provider.vault
  block_interval = 120
  interval = 60
  name = tf-test-5534064214137632519
  path =
  rate = 525.3
vault_quota_rate_limit.foobar:
  ID = tf-test-5534064214137632519
  provider = provider.vault
  block_interval = 120
  interval = 60
  name = tf-test-5534064214137632519
  path =
  rate = 525.3
vault_quota_rate_limit.foobar:
  ID = tf-test-5534064214137632519
  provider = provider.vault
  block_interval = 60
  interval = 120
  name = tf-test-5534064214137632519
  path = sys/
  rate = 525.3
vault_quota_rate_limit.foobar:
  ID = tf-test-5534064214137632519
  provider = provider.vault
  block_interval = 60
  interval = 120
  name = tf-test-5534064214137632519
  path = sys/
  rate = 525.3
vault_quota_rate_limit.foobar:
  ID = tf-test-5534064214137632519
  provider = provider.vault
  block_interval = 60
  interval = 120
  name = tf-test-5534064214137632519
  path = sys/
  rate = 525.3
vault_quota_rate_limit.foobar:
  ID = tf-test-5534064214137632519
  provider = provider.vault
  block_interval = 60
  interval = 120
  name = tf-test-5534064214137632519
  path = sys/
  rate = 525.3
vault_quota_rate_limit.foobar:
  ID = tf-test-5534064214137632519
  provider = provider.vault
  block_interval = 60
  interval = 120
  name = tf-test-5534064214137632519
  path = sys/
  rate = 525.3
--- PASS: TestQuotaRateLimit (0.60s)
PASS
ok      github.com/hashicorp/terraform-provider-vault/vault     1.018s

Comment thread util/util.go Outdated
Comment thread vault/resource_quota_rate_limit.go Outdated
Type: schema.TypeString,
Optional: true,
Description: "If set, when a client reaches a rate limit threshold, the client will be prohibited from any further requests until after the 'block_interval' has elapsed.",
StateFunc: durationSecond,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because read requests return these values in seconds and not a duration the configuration value must be computed in terms of seconds to prevent a perpetual diff.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since vault converts the duration strings to seconds (int), we prefer to only support schema.TypeInt for these sorts of Vault fields. This should greatly simplify your PR.

@hashicorp-cla

hashicorp-cla commented Mar 12, 2022

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@benashz benashz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the contribution. We can scale down this PR by making interval and block_interval schema.TypeInt.

Comment thread vault/resource_quota_rate_limit.go Outdated
Type: schema.TypeString,
Optional: true,
Description: "If set, when a client reaches a rate limit threshold, the client will be prohibited from any further requests until after the 'block_interval' has elapsed.",
StateFunc: durationSecond,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since vault converts the duration strings to seconds (int), we prefer to only support schema.TypeInt for these sorts of Vault fields. This should greatly simplify your PR.

@benashz

benashz commented May 30, 2022

Copy link
Copy Markdown
Collaborator

@mdgreenfield please let us know if you have spare cycles to work on this PR. If not we would be happy to take it over.

Thanks,

Ben

@benashz benashz self-assigned this May 30, 2022
@benashz benashz added this to the 3.7.0 milestone May 30, 2022
@mdgreenfield

Copy link
Copy Markdown
Contributor Author

Hi @benashz I can address the comments in the next day or two.

@mdgreenfield
mdgreenfield force-pushed the quota-rate-limit-changes branch from 65c4767 to bbb5741 Compare June 1, 2022 21:17
@github-actions github-actions Bot added size/M and removed size/L labels Jun 1, 2022
@mdgreenfield
mdgreenfield force-pushed the quota-rate-limit-changes branch 4 times, most recently from 3875b7b to d2c5ba3 Compare June 1, 2022 21:27
@mdgreenfield
mdgreenfield force-pushed the quota-rate-limit-changes branch from d2c5ba3 to 2d8f99c Compare June 1, 2022 21:29
@mdgreenfield

Copy link
Copy Markdown
Contributor Author

@benashz I've updated the PR switching to schema.TypeInt.

I did notice that some fields, e.g. the TTL fields on the auth mount resource, use schema.TypeString and make use of validateDuration in the vault package. That may predate the move towards using schema.TypeInt and I suspect we can't really just go back and update it to schema.TypeInt without being backwards incompatible.

@mdgreenfield

Copy link
Copy Markdown
Contributor Author

The updated acceptance testing output:

$ make testacc TESTARGS='-run=TestQuotaRateLimit'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test -v -run=TestQuotaRateLimit -timeout 30m ./...
?       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   0.415s [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    1.823s [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/datasources/transform/encode    1.803s [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/resources/transform/alphabet    1.801s [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/resources/transform/role        0.941s [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/resources/transform/template    1.073s [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/generated/resources/transform/transformation      2.053s [no tests to run]
?       github.com/hashicorp/terraform-provider-vault/helper    [no test files]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/internal/identity/entity  1.038s [no tests to run]
?       github.com/hashicorp/terraform-provider-vault/schema    [no test files]
?       github.com/hashicorp/terraform-provider-vault/testutil  [no test files]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vault/util      0.946s [no tests to run]
=== RUN   TestQuotaRateLimit
--- PASS: TestQuotaRateLimit (81.98s)
PASS
ok      github.com/hashicorp/terraform-provider-vault/vault     83.321s

@benashz benashz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good! I added a few minor suggestions that should be addressed.

rateLimt := fmt.Sprintf("%.1f", whole+decimal)
// Vault retuns floats with trailing zeros trimmed
return strings.TrimRight(strings.TrimRight(rateLimt, "0"), ".")
rateLimit := fmt.Sprintf("%.1f", whole+decimal)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍

Comment thread vault/resource_quota_rate_limit.go Outdated
Comment thread vault/resource_quota_rate_limit.go Outdated
Comment thread vault/resource_quota_rate_limit.go Outdated
Comment thread vault/resource_quota_rate_limit.go Outdated
Comment thread website/docs/r/quota_rate_limit.md Outdated
Comment thread vault/resource_quota_rate_limit.go Outdated
Co-authored-by: Ben Ash <32777270+benashz@users.noreply.github.com>
@mdgreenfield

Copy link
Copy Markdown
Contributor Author

Thanks @benashz for the review. I learned a few things about writing Terraform providers from your comments.

Changes have been added to the PR.

@benashz benashz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

Thank you for you contribution to HashiCorp!

@benashz
benashz merged commit 19ea794 into hashicorp:main Jun 6, 2022
marcboudreau pushed a commit to marcboudreau/terraform-provider-vault that referenced this pull request Nov 6, 2022
…ashicorp#1084)


Co-authored-by: Ben Ash <32777270+benashz@users.noreply.github.com>
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.

Add support for vault_quota_rate_limit interval and block_interval

3 participants