-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
108 additions
and
0 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
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,56 @@ | ||
package random | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
const numChars = "0123456789" | ||
const lowerChars = "abcdefghijklmnopqrstuvwxyz" | ||
const upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
const specialChars = "!@#$%&*()-_=+[]{}<>:?" | ||
|
||
func updateStringResourceAttributes(d *schema.ResourceData, charSet string, charClass string, charClassMin string) *schema.ResourceData { | ||
count := 0 | ||
val := d.Id() | ||
for i := range val { | ||
if strings.Contains(charSet, string(val[i])) { | ||
count = count + 1 | ||
} | ||
} | ||
//Check for character set | ||
if count > 0 { | ||
d.Set(charClass, true) | ||
} else { | ||
d.Set(charClass, false) | ||
} | ||
|
||
//Check for minimum number of required chars from a character set | ||
_, newMinClass := d.GetChange(charClassMin) | ||
|
||
if count >= newMinClass.(int) { | ||
d.Set(charClassMin, newMinClass.(int)) | ||
} else { | ||
d.Set(charClassMin, count) | ||
} | ||
return d | ||
|
||
} | ||
|
||
func UpperCharsInValue(d *schema.ResourceData) *schema.ResourceData { | ||
|
||
return updateStringResourceAttributes(d, upperChars, "upper", "min_upper") | ||
} | ||
|
||
func LowerCharsInValue(d *schema.ResourceData) *schema.ResourceData { | ||
return updateStringResourceAttributes(d, lowerChars, "lower", "min_lower") | ||
} | ||
|
||
func SpecialCharsInValue(d *schema.ResourceData) *schema.ResourceData { | ||
return updateStringResourceAttributes(d, specialChars, "special", "min_special") | ||
} | ||
|
||
func NumbersInValue(d *schema.ResourceData) *schema.ResourceData { | ||
return updateStringResourceAttributes(d, numChars, "number", "min_numeric") | ||
} |
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