-
Notifications
You must be signed in to change notification settings - Fork 428
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
feat: Rework provider configuration fields #3152
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
92ac5c0
wip
sfc-gh-jmichalak 2e641f6
pre push
sfc-gh-jmichalak 075be18
Review
sfc-gh-jmichalak 9f15217
Merge remote-tracking branch 'origin/main' into config-rework
sfc-gh-jmichalak 4c95204
Revert changing case of boolean parser
sfc-gh-jmichalak fdb784e
Move code to internal package
sfc-gh-jmichalak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,14 @@ | ||
package helpers | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func PossibleValuesListed[T ~string | ~int](values []T) string { | ||
valuesWrapped := make([]string, len(values)) | ||
for i, value := range values { | ||
valuesWrapped[i] = fmt.Sprintf("`%v`", value) | ||
} | ||
return strings.Join(valuesWrapped, " | ") | ||
} |
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,60 @@ | ||
package helpers | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/hashicorp/go-cty/cty" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
const ( | ||
BooleanTrue = "true" | ||
BooleanFalse = "false" | ||
BooleanDefault = "default" | ||
|
||
IntDefault = -1 | ||
IntDefaultString = "-1" | ||
) | ||
|
||
// StringInSlice has the same implementation as validation.StringInSlice, but adapted to schema.SchemaValidateDiagFunc | ||
func StringInSlice(valid []string, ignoreCase bool) schema.SchemaValidateDiagFunc { | ||
return func(i interface{}, path cty.Path) diag.Diagnostics { | ||
v, ok := i.(string) | ||
if !ok { | ||
return diag.Errorf("expected type of %v to be string", path) | ||
} | ||
|
||
for _, str := range valid { | ||
if v == str || (ignoreCase && strings.EqualFold(v, str)) { | ||
return nil | ||
} | ||
} | ||
|
||
return diag.Errorf("expected %v to be one of %q, got %s", path, valid, v) | ||
} | ||
} | ||
|
||
var ValidateBooleanString = StringInSlice([]string{BooleanTrue, BooleanFalse}, false) | ||
|
||
var ValidateBooleanStringWithDefault = StringInSlice([]string{BooleanTrue, BooleanFalse, BooleanDefault}, false) | ||
|
||
func booleanStringFromBool(value bool) string { | ||
if value { | ||
return BooleanTrue | ||
} else { | ||
return BooleanFalse | ||
} | ||
} | ||
|
||
func BooleanStringToBool(value string) (bool, error) { | ||
switch value { | ||
case BooleanTrue: | ||
return true, nil | ||
case BooleanFalse: | ||
return false, nil | ||
default: | ||
return false, fmt.Errorf("cannot retrieve boolean value from %s", value) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should move away from this package (use internal/*); we will do with a bigger cleanup but as the general rule, but if we are moving them now, let's place them more correctly, e.g. we have:
maybe we could add internal/provider/validators for validations (then usage is nicer - validators.ValidateXyz and we won't have to move it again), special values may reside it internal/provider and helpers/doc can go to internal/provider/docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.