opentofu/configs
Martin Atkins 5661ab5991 configs: allow full type constraints for variables
Previously we just ported over the simple "string", "list", and "map" type
hint keywords from the old loader, which exist primarily as hints to the
CLI for whether to treat -var=... arguments and environment variables as
literal strings or as HCL expressions.

However, we've been requested before to allow more specific constraints
here because it's generally better UX for a type error to be detected
within an expression in a calling "module" block rather than at some point
deep inside a third-party module.

To allow for more specific constraints, here we use the type constraint
expression syntax defined as an extension within HCL, which uses the
variable and function call syntaxes to represent types rather than values,
like this:
 - string
 - number
 - bool
 - list(string)
 - list(any)
 - list(map(string))
 - object({id=string,name=string})

In native HCL syntax this looks like:

    variable "foo" {
      type = map(string)
    }

In JSON, this looks like:

    {
      "variable": {
        "foo": {
          "type": "map(string)"
        }
      }
    }

The selection of literal processing or HCL parsing of CLI-set values is
now explicit in the model and separate from the type, though it's still
derived from the type constraint and thus not directly controllable in
configuration.

Since this syntax is more complex than the keywords that replaced it, for
now the simpler keywords are still supported and "list" and "map" are
interpreted as list(any) and map(any) respectively, mimicking how they
were interpreted by Terraform 0.11 and earlier. For the time being our
documentation should continue to recommend these shorthand versions until
we gain more experience with the more-specific type constraints; most
users should just make use of the additional primitive type constraints
this enables: bool and number.

As a result of these more-complete type constraints, we can now type-check
the default value at config load time, which has the nice side-effect of
allowing us to produce a tailored error message if an override file
produces an invalid situation; previously the result was rather confusing
because the error message referred to the original definition of the
variable and not the overridden parts.
2018-03-08 16:23:35 -08:00
..
configload configs/configload: installer tests inspect their result 2018-02-15 15:56:39 -08:00
test-fixtures configs: allow full type constraints for variables 2018-03-08 16:23:35 -08:00
backend.go configs: Parser.LoadConfigFile 2018-02-15 15:56:37 -08:00
compat_shim.go configs: Disable deprecation warning for quoted keywords/references 2018-03-08 15:42:47 -08:00
config_build_test.go configs/configload: package for loading configurations 2018-02-15 15:56:38 -08:00
config_build.go configs: BuildConfig sorts child modules by name 2018-02-15 15:56:38 -08:00
config.go configs/configload: package for loading configurations 2018-02-15 15:56:38 -08:00
depends_on.go configs: quoted keywords/references are warnings, not errors 2018-02-15 15:56:39 -08:00
doc.go configs: Additional guidance in doc.go 2018-02-15 15:56:39 -08:00
module_call.go configs: allow overrides files to omit args that primary files can't 2018-02-15 15:56:38 -08:00
module_merge_body.go configs: Implementation of mergeBody 2018-02-15 15:56:38 -08:00
module_merge_test.go configs: allow full type constraints for variables 2018-03-08 16:23:35 -08:00
module_merge.go configs: allow full type constraints for variables 2018-03-08 16:23:35 -08:00
module.go configs: Parser.LoadConfigDir 2018-02-15 15:56:37 -08:00
named_values.go configs: allow full type constraints for variables 2018-03-08 16:23:35 -08:00
parser_config_dir_test.go configs: quoted keywords/references are warnings, not errors 2018-02-15 15:56:39 -08:00
parser_config_dir.go configs: allow overrides files to omit args that primary files can't 2018-02-15 15:56:38 -08:00
parser_config_test.go configs: allow full type constraints for variables 2018-03-08 16:23:35 -08:00
parser_config.go configs: allow full type constraints for variables 2018-03-08 16:23:35 -08:00
parser_test.go configs: Implementation of mergeBody 2018-02-15 15:56:38 -08:00
parser_values_test.go configs: update values file invalid syntax test for new HCL behavior 2018-03-08 11:17:39 -08:00
parser_values.go configs: Parser.LoadValuesFile 2018-02-15 15:56:37 -08:00
parser.go configs: Parser type 2018-02-15 15:56:36 -08:00
provider.go configs: Parser.LoadConfigDir 2018-02-15 15:56:37 -08:00
provisioner.go configs: quoted keywords/references are warnings, not errors 2018-02-15 15:56:39 -08:00
provisioneronfailure_string.go configs: stub out main configuration structs 2018-02-15 15:56:37 -08:00
provisionerwhen_string.go configs: stub out main configuration structs 2018-02-15 15:56:37 -08:00
resource.go configs: highlight resource name in diags when invalid 2018-03-08 15:41:19 -08:00
util.go configs: allow overrides files to omit args that primary files can't 2018-02-15 15:56:38 -08:00
variable_type_hint.go configs: stub out main configuration structs 2018-02-15 15:56:37 -08:00
variabletypehint_string.go configs: stub out main configuration structs 2018-02-15 15:56:37 -08:00
version_constraint.go configs: Parser.LoadConfigFile 2018-02-15 15:56:37 -08:00