diff options
author | Jake Champlin <jake@gnu.space> | 2017-06-09 17:54:32 +0000 |
---|---|---|
committer | Jake Champlin <jake@gnu.space> | 2017-06-09 17:54:32 +0000 |
commit | 9b12e4fe6f3c95986f1f3ec791636c58ca7e7583 (patch) | |
tree | 38f5f12bec0e488a12f0459a7356e6b7de7d8f84 /vendor/github.com/hashicorp/terraform/config | |
parent | cec3de8a3bcaffd21dedd1bf42da4b490cae7e16 (diff) | |
download | terraform-provider-statuscake-9b12e4fe6f3c95986f1f3ec791636c58ca7e7583.tar.gz terraform-provider-statuscake-9b12e4fe6f3c95986f1f3ec791636c58ca7e7583.tar.zst terraform-provider-statuscake-9b12e4fe6f3c95986f1f3ec791636c58ca7e7583.zip |
Transfer of provider code
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/config')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/config/config.go | 64 | ||||
-rw-r--r-- | vendor/github.com/hashicorp/terraform/config/interpolate_funcs.go | 48 |
2 files changed, 49 insertions, 63 deletions
diff --git a/vendor/github.com/hashicorp/terraform/config/config.go b/vendor/github.com/hashicorp/terraform/config/config.go index 9a764ac..a157824 100644 --- a/vendor/github.com/hashicorp/terraform/config/config.go +++ b/vendor/github.com/hashicorp/terraform/config/config.go | |||
@@ -545,7 +545,7 @@ func (c *Config) Validate() error { | |||
545 | 545 | ||
546 | // Verify provisioners | 546 | // Verify provisioners |
547 | for _, p := range r.Provisioners { | 547 | for _, p := range r.Provisioners { |
548 | // This validation checks that there are now splat variables | 548 | // This validation checks that there are no splat variables |
549 | // referencing ourself. This currently is not allowed. | 549 | // referencing ourself. This currently is not allowed. |
550 | 550 | ||
551 | for _, v := range p.ConnInfo.Variables { | 551 | for _, v := range p.ConnInfo.Variables { |
@@ -705,17 +705,6 @@ func (c *Config) Validate() error { | |||
705 | } | 705 | } |
706 | } | 706 | } |
707 | 707 | ||
708 | // Check that all variables are in the proper context | ||
709 | for source, rc := range c.rawConfigs() { | ||
710 | walker := &interpolationWalker{ | ||
711 | ContextF: c.validateVarContextFn(source, &errs), | ||
712 | } | ||
713 | if err := reflectwalk.Walk(rc.Raw, walker); err != nil { | ||
714 | errs = append(errs, fmt.Errorf( | ||
715 | "%s: error reading config: %s", source, err)) | ||
716 | } | ||
717 | } | ||
718 | |||
719 | // Validate the self variable | 708 | // Validate the self variable |
720 | for source, rc := range c.rawConfigs() { | 709 | for source, rc := range c.rawConfigs() { |
721 | // Ignore provisioners. This is a pretty brittle way to do this, | 710 | // Ignore provisioners. This is a pretty brittle way to do this, |
@@ -787,57 +776,6 @@ func (c *Config) rawConfigs() map[string]*RawConfig { | |||
787 | return result | 776 | return result |
788 | } | 777 | } |
789 | 778 | ||
790 | func (c *Config) validateVarContextFn( | ||
791 | source string, errs *[]error) interpolationWalkerContextFunc { | ||
792 | return func(loc reflectwalk.Location, node ast.Node) { | ||
793 | // If we're in a slice element, then its fine, since you can do | ||
794 | // anything in there. | ||
795 | if loc == reflectwalk.SliceElem { | ||
796 | return | ||
797 | } | ||
798 | |||
799 | // Otherwise, let's check if there is a splat resource variable | ||
800 | // at the top level in here. We do this by doing a transform that | ||
801 | // replaces everything with a noop node unless its a variable | ||
802 | // access or concat. This should turn the AST into a flat tree | ||
803 | // of Concat(Noop, ...). If there are any variables left that are | ||
804 | // multi-access, then its still broken. | ||
805 | node = node.Accept(func(n ast.Node) ast.Node { | ||
806 | // If it is a concat or variable access, we allow it. | ||
807 | switch n.(type) { | ||
808 | case *ast.Output: | ||
809 | return n | ||
810 | case *ast.VariableAccess: | ||
811 | return n | ||
812 | } | ||
813 | |||
814 | // Otherwise, noop | ||
815 | return &noopNode{} | ||
816 | }) | ||
817 | |||
818 | vars, err := DetectVariables(node) | ||
819 | if err != nil { | ||
820 | // Ignore it since this will be caught during parse. This | ||
821 | // actually probably should never happen by the time this | ||
822 | // is called, but its okay. | ||
823 | return | ||
824 | } | ||
825 | |||
826 | for _, v := range vars { | ||
827 | rv, ok := v.(*ResourceVariable) | ||
828 | if !ok { | ||
829 | return | ||
830 | } | ||
831 | |||
832 | if rv.Multi && rv.Index == -1 { | ||
833 | *errs = append(*errs, fmt.Errorf( | ||
834 | "%s: use of the splat ('*') operator must be wrapped in a list declaration", | ||
835 | source)) | ||
836 | } | ||
837 | } | ||
838 | } | ||
839 | } | ||
840 | |||
841 | func (c *Config) validateDependsOn( | 779 | func (c *Config) validateDependsOn( |
842 | n string, | 780 | n string, |
843 | v []string, | 781 | v []string, |
diff --git a/vendor/github.com/hashicorp/terraform/config/interpolate_funcs.go b/vendor/github.com/hashicorp/terraform/config/interpolate_funcs.go index f1f97b0..7b7b3f2 100644 --- a/vendor/github.com/hashicorp/terraform/config/interpolate_funcs.go +++ b/vendor/github.com/hashicorp/terraform/config/interpolate_funcs.go | |||
@@ -24,6 +24,7 @@ import ( | |||
24 | "github.com/hashicorp/hil" | 24 | "github.com/hashicorp/hil" |
25 | "github.com/hashicorp/hil/ast" | 25 | "github.com/hashicorp/hil/ast" |
26 | "github.com/mitchellh/go-homedir" | 26 | "github.com/mitchellh/go-homedir" |
27 | "golang.org/x/crypto/bcrypt" | ||
27 | ) | 28 | ) |
28 | 29 | ||
29 | // stringSliceToVariableValue converts a string slice into the value | 30 | // stringSliceToVariableValue converts a string slice into the value |
@@ -59,6 +60,7 @@ func Funcs() map[string]ast.Function { | |||
59 | "base64encode": interpolationFuncBase64Encode(), | 60 | "base64encode": interpolationFuncBase64Encode(), |
60 | "base64sha256": interpolationFuncBase64Sha256(), | 61 | "base64sha256": interpolationFuncBase64Sha256(), |
61 | "base64sha512": interpolationFuncBase64Sha512(), | 62 | "base64sha512": interpolationFuncBase64Sha512(), |
63 | "bcrypt": interpolationFuncBcrypt(), | ||
62 | "ceil": interpolationFuncCeil(), | 64 | "ceil": interpolationFuncCeil(), |
63 | "chomp": interpolationFuncChomp(), | 65 | "chomp": interpolationFuncChomp(), |
64 | "cidrhost": interpolationFuncCidrHost(), | 66 | "cidrhost": interpolationFuncCidrHost(), |
@@ -89,6 +91,7 @@ func Funcs() map[string]ast.Function { | |||
89 | "merge": interpolationFuncMerge(), | 91 | "merge": interpolationFuncMerge(), |
90 | "min": interpolationFuncMin(), | 92 | "min": interpolationFuncMin(), |
91 | "pathexpand": interpolationFuncPathExpand(), | 93 | "pathexpand": interpolationFuncPathExpand(), |
94 | "pow": interpolationFuncPow(), | ||
92 | "uuid": interpolationFuncUUID(), | 95 | "uuid": interpolationFuncUUID(), |
93 | "replace": interpolationFuncReplace(), | 96 | "replace": interpolationFuncReplace(), |
94 | "sha1": interpolationFuncSha1(), | 97 | "sha1": interpolationFuncSha1(), |
@@ -394,6 +397,17 @@ func interpolationFuncConcat() ast.Function { | |||
394 | } | 397 | } |
395 | } | 398 | } |
396 | 399 | ||
400 | // interpolationFuncPow returns base x exponential of y. | ||
401 | func interpolationFuncPow() ast.Function { | ||
402 | return ast.Function{ | ||
403 | ArgTypes: []ast.Type{ast.TypeFloat, ast.TypeFloat}, | ||
404 | ReturnType: ast.TypeFloat, | ||
405 | Callback: func(args []interface{}) (interface{}, error) { | ||
406 | return math.Pow(args[0].(float64), args[1].(float64)), nil | ||
407 | }, | ||
408 | } | ||
409 | } | ||
410 | |||
397 | // interpolationFuncFile implements the "file" function that allows | 411 | // interpolationFuncFile implements the "file" function that allows |
398 | // loading contents from a file. | 412 | // loading contents from a file. |
399 | func interpolationFuncFile() ast.Function { | 413 | func interpolationFuncFile() ast.Function { |
@@ -1310,6 +1324,40 @@ func interpolationFuncBase64Sha512() ast.Function { | |||
1310 | } | 1324 | } |
1311 | } | 1325 | } |
1312 | 1326 | ||
1327 | func interpolationFuncBcrypt() ast.Function { | ||
1328 | return ast.Function{ | ||
1329 | ArgTypes: []ast.Type{ast.TypeString}, | ||
1330 | Variadic: true, | ||
1331 | VariadicType: ast.TypeString, | ||
1332 | ReturnType: ast.TypeString, | ||
1333 | Callback: func(args []interface{}) (interface{}, error) { | ||
1334 | defaultCost := 10 | ||
1335 | |||
1336 | if len(args) > 1 { | ||
1337 | costStr := args[1].(string) | ||
1338 | cost, err := strconv.Atoi(costStr) | ||
1339 | if err != nil { | ||
1340 | return "", err | ||
1341 | } | ||
1342 | |||
1343 | defaultCost = cost | ||
1344 | } | ||
1345 | |||
1346 | if len(args) > 2 { | ||
1347 | return "", fmt.Errorf("bcrypt() takes no more than two arguments") | ||
1348 | } | ||
1349 | |||
1350 | input := args[0].(string) | ||
1351 | out, err := bcrypt.GenerateFromPassword([]byte(input), defaultCost) | ||
1352 | if err != nil { | ||
1353 | return "", fmt.Errorf("error occured generating password %s", err.Error()) | ||
1354 | } | ||
1355 | |||
1356 | return string(out), nil | ||
1357 | }, | ||
1358 | } | ||
1359 | } | ||
1360 | |||
1313 | func interpolationFuncUUID() ast.Function { | 1361 | func interpolationFuncUUID() ast.Function { |
1314 | return ast.Function{ | 1362 | return ast.Function{ |
1315 | ArgTypes: []ast.Type{}, | 1363 | ArgTypes: []ast.Type{}, |