Skip to content

Commit

Permalink
Add support for missing max_retries param
Browse files Browse the repository at this point in the history
  • Loading branch information
Zlaticanin committed Jun 12, 2024
1 parent 8677f60 commit 48453e4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions internal/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ const (
FieldDelegatedAuthAccessors = "delegated_auth_accessors"
FieldPluginVersion = "plugin_version"
FieldUseMSGraphAPI = "use_microsoft_graph_api"
FieldMaxRetries = "max_retries"

/*
common environment variables
Expand Down
11 changes: 9 additions & 2 deletions vault/resource_aws_auth_backend_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ func awsAuthBackendClientResource() *schema.Resource {
Computed: true,
Description: "The TTL of generated identity tokens in seconds.",
},
consts.FieldMaxRetries: {
Type: schema.TypeInt,
Default: -1,
Optional: true,
Description: "Number of max retries the client should use for recoverable errors.",
},
},
}
}
Expand All @@ -119,11 +125,10 @@ func awsAuthBackendWrite(ctx context.Context, d *schema.ResourceData, meta inter
stsEndpoint := d.Get(consts.FieldSTSEndpoint).(string)
stsRegion := d.Get(consts.FieldSTSRegion).(string)
stsRegionFromClient := d.Get(useSTSRegionFromClient).(bool)

identityTokenAud := d.Get(consts.FieldIdentityTokenAudience).(string)
roleArn := d.Get(consts.FieldRoleArn).(string)
identityTokenTTL := d.Get(consts.FieldIdentityTokenTTL).(int)

maxRetries := d.Get(consts.FieldMaxRetries).(int)
iamServerIDHeaderValue := d.Get(consts.FieldIAMServerIDHeaderValue).(string)

path := awsAuthBackendClientPath(backend)
Expand All @@ -134,6 +139,7 @@ func awsAuthBackendWrite(ctx context.Context, d *schema.ResourceData, meta inter
consts.FieldSTSEndpoint: stsEndpoint,
consts.FieldSTSRegion: stsRegion,
consts.FieldIAMServerIDHeaderValue: iamServerIDHeaderValue,
consts.FieldMaxRetries: maxRetries,
}

if d.HasChange(consts.FieldAccessKey) || d.HasChange(consts.FieldSecretKey) {
Expand Down Expand Up @@ -204,6 +210,7 @@ func awsAuthBackendRead(ctx context.Context, d *schema.ResourceData, meta interf
consts.FieldSTSEndpoint,
consts.FieldSTSRegion,
consts.FieldIAMServerIDHeaderValue,
consts.FieldMaxRetries,
}
for _, k := range fields {
if v, ok := secret.Data[k]; ok {
Expand Down
15 changes: 12 additions & 3 deletions vault/resource_aws_auth_backend_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
package vault

import (
"encoding/json"
"fmt"

"regexp"
"testing"

Expand Down Expand Up @@ -240,13 +240,20 @@ func testAccAWSAuthBackendClientCheck_attrs(backend string) resource.TestCheckFu
consts.FieldSTSEndpoint: consts.FieldSTSEndpoint,
consts.FieldSTSRegion: consts.FieldSTSRegion,
consts.FieldIAMServerIDHeaderValue: consts.FieldIAMServerIDHeaderValue,
consts.FieldMaxRetries: consts.FieldMaxRetries,
}
for stateAttr, apiAttr := range attrs {
if resp.Data[apiAttr] == nil && instanceState.Attributes[stateAttr] == "" {
continue
}
if resp.Data[apiAttr] != instanceState.Attributes[stateAttr] {
return fmt.Errorf("expected %s (%s) of %q to be %q, got %q", apiAttr, stateAttr, endpoint, instanceState.Attributes[stateAttr], resp.Data[apiAttr])
if apiAttr == consts.FieldMaxRetries {
if resp.Data[apiAttr].(json.Number).String() != instanceState.Attributes[stateAttr] {
return fmt.Errorf("expected %s (%s) of %q to be %q, got %q", apiAttr, stateAttr, endpoint, instanceState.Attributes[stateAttr], resp.Data[apiAttr].(json.Number).String())
}
} else {
if resp.Data[apiAttr] != instanceState.Attributes[stateAttr] {
return fmt.Errorf("expected %s (%s) of %q to be %q, got %q", apiAttr, stateAttr, endpoint, instanceState.Attributes[stateAttr], resp.Data[apiAttr])
}
}
}
return nil
Expand Down Expand Up @@ -302,6 +309,7 @@ resource "vault_aws_auth_backend_client" "client" {
sts_endpoint = "http://vault.test/sts"
sts_region = "vault-test"
iam_server_id_header_value = "vault.test"
max_retries = "-1"
}
`, backend)
}
Expand All @@ -323,6 +331,7 @@ resource "vault_aws_auth_backend_client" "client" {
sts_endpoint = "http://updated.vault.test/sts"
sts_region = "updated-vault-test"
iam_server_id_header_value = "updated.vault.test"
max_retries = "0"
}`, backend)
}

Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/aws_auth_backend_client.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ The following arguments are supported:
`X-Vault-AWS-IAM-Server-ID` header as part of `GetCallerIdentity` requests
that are used in the IAM auth method.

* `max_retries` - (Optional) Number of max retries the client should use for recoverable errors.
The default `-1` falls back to the AWS SDK's default behavior.

## Attributes Reference

No additional attributes are exported by this resource.
Expand Down

0 comments on commit 48453e4

Please sign in to comment.