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

add conditionals to module resource #268

Closed
BrianHicks opened this issue Sep 19, 2016 · 4 comments
Closed

add conditionals to module resource #268

BrianHicks opened this issue Sep 19, 2016 · 4 comments
Assignees
Milestone

Comments

@BrianHicks
Copy link
Contributor

BrianHicks commented Sep 19, 2016

module resource should have conditional evaluation. Something like this:

module "x.hcl" "x" {
  when = [
    "eq {{system.os}} \"darwin\""
  ]
}

If the whens combine (with and) to false, the subtree rooted at the module is dropped from evaluation.

@BrianHicks BrianHicks added this to the 0.3 milestone Sep 19, 2016
@BrianHicks
Copy link
Contributor Author

This still makes sense a couple of days later… mostly. The string syntax for the conditionals is too different from the rest of our configuration. A better syntax could look llike:

module "x.hcl" "x" {
  when equal ["{{system.os}}", "darwin"]
}

To generalize: a when block will have a string for the operator, then the operator's arguments. These arguments could take pretty much any shape, depending on the operator.

@sehqlr this syntax might be useful for your param validation work as well?

@sehqlr
Copy link
Contributor

sehqlr commented Sep 21, 2016

Yes, this would be useful for parameters. I like the basic idea, but I
think the syntax will be tricky.

On Sep 21, 2016 8:36 AM, "Steven Borrelli" [email protected] wrote:

when "{{ system.os == "darwin" }}" ?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#268 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACnp5IOC8dJX_9WGxkRJ6o9COXHIjavsks5qsTLagaJpZM4KA9al
.

@BrianHicks
Copy link
Contributor Author

Right, whiteboard discussion in the office over. We're going to go forward with something like a switch construct that will be expanded like a macro (that is, it will not be evaluated at runtime, but before and pruned.)

select { // or `switch` or `select!` or `switch!`... You get the idea.
  case {
    conditional = "some syntax goes here"
    value = {
      module "x.hcl" "x" {}
    }
  }
}

If the conditional syntax ends up being within a string, we can move that to the path selector of case and get rid of value.

Preferred syntax among the group was something like "platform.os == 'darwin'" (Or so I remember; @stevendborrelli and @rebeccaskinner can you confirm)? At any rate, we want to not use all of text/template here because are "bob" or similar strings true or false?

@rebeccaskinner
Copy link
Contributor

PR #362

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants