Skip to content
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

Input validation block for local variables needed #25422

Closed
plaformsre opened this issue Jun 28, 2020 · 2 comments
Closed

Input validation block for local variables needed #25422

plaformsre opened this issue Jun 28, 2020 · 2 comments

Comments

@plaformsre
Copy link

plaformsre commented Jun 28, 2020

Current Terraform Version

0.12.28

Use-cases

Attempted Solutions

  • we need to sanitise input from data or any other internal calculations using local variables, using only 'input variables' was not sufficient

Proposal

  • introduce same logic for local variables as for input variables

References

@apparentlymart
Copy link
Contributor

Hi @mapdegree! Thanks for this proposal.

I think this is covering the same use-case as #15469, and there's already some commentary there about some different ways to represent assertions about "internal" values, rather than input variables. It's likely that something will come for this in a future release, but I'm going to close this issue just to consolidate discussion in #15469.

Thanks again!


In the meantime, one (admittedly awkward) way you can use the variable validation feature to validate something within a module is to write a child module that consists only of a validation rule:

variable "to_validate" {
  type = string

  validation {
    # (whatever rule you need)
  }
}

output "validated" {
  value = var.to_validate
}

You can instantiate this module setting to_validate to whatever local value you want to validate:

module "validate_foo" {
  to_validate = local.foo
}

...and then elsewhere in the module you can use module.validate_foo.validated instead of local.foo to get a result that is guaranteed to have passed your validation rules.

It's too cumbersome for everyday use, but if you have a module that is particularly in need of an internal assertion for some reason then this is a way to get that done with the features as they currently exist.

@ghost
Copy link

ghost commented Jul 30, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Jul 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants