-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23077 from hashicorp/f-provider-assume-role-durat…
…ion-changes provider: add `assume_role.0.duration` and deprecate `assume_role.0.duration_seconds`
- Loading branch information
Showing
6 changed files
with
119 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
```release-note:note | ||
provider: The `assume_role.duration_seconds` argument has been deprecated. All configurations using `assume_role.duration_seconds` should be updated to use the new `assume_role.duration` argument instead. | ||
``` | ||
|
||
```release-note:enhancement | ||
provider: Add `duration` argument to the `assume_role` configuration block | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package provider | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
// ValidAssumeRoleDuration validates a string can be parsed as a valid time.Duration | ||
// and is within a minimum of 15 minutes and maximum of 12 hours | ||
func ValidAssumeRoleDuration(v interface{}, k string) (ws []string, errors []error) { | ||
duration, err := time.ParseDuration(v.(string)) | ||
|
||
if err != nil { | ||
errors = append(errors, fmt.Errorf("%q cannot be parsed as a duration: %w", k, err)) | ||
return | ||
} | ||
|
||
if duration.Minutes() < 15 || duration.Hours() > 12 { | ||
errors = append(errors, fmt.Errorf("duration %q must be between 15 minutes (15m) and 12 hours (12h), inclusive", k)) | ||
} | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package provider | ||
|
||
import ( | ||
"regexp" | ||
"testing" | ||
) | ||
|
||
func TestValidAssumeRoleDuration(t *testing.T) { | ||
testCases := []struct { | ||
val interface{} | ||
expectedErr *regexp.Regexp | ||
}{ | ||
{ | ||
val: "", | ||
expectedErr: regexp.MustCompile(`cannot be parsed as a duration`), | ||
}, | ||
{ | ||
val: "1", | ||
expectedErr: regexp.MustCompile(`cannot be parsed as a duration`), | ||
}, | ||
{ | ||
val: "10m", | ||
expectedErr: regexp.MustCompile(`must be between 15 minutes \(15m\) and 12 hours \(12h\)`), | ||
}, | ||
{ | ||
val: "12h30m", | ||
expectedErr: regexp.MustCompile(`must be between 15 minutes \(15m\) and 12 hours \(12h\)`), | ||
}, | ||
{ | ||
|
||
val: "15m", | ||
}, | ||
{ | ||
val: "1h10m10s", | ||
}, | ||
{ | ||
|
||
val: "12h", | ||
}, | ||
} | ||
|
||
matchErr := func(errs []error, r *regexp.Regexp) bool { | ||
// err must match one provided | ||
for _, err := range errs { | ||
if r.MatchString(err.Error()) { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
for i, tc := range testCases { | ||
_, errs := ValidAssumeRoleDuration(tc.val, "test_property") | ||
|
||
if len(errs) == 0 && tc.expectedErr == nil { | ||
continue | ||
} | ||
|
||
if len(errs) != 0 && tc.expectedErr == nil { | ||
t.Fatalf("expected test case %d to produce no errors, got %v", i, errs) | ||
} | ||
|
||
if !matchErr(errs, tc.expectedErr) { | ||
t.Fatalf("expected test case %d to produce error matching \"%s\", got %v", i, tc.expectedErr, errs) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters