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

Hcl2 input variables, local variables and functions #8588

Merged
merged 63 commits into from
Feb 6, 2020
Merged

Conversation

azr
Copy link
Contributor

@azr azr commented Jan 9, 2020

This draft PR introduces basic variables handling; similarly to what currently works in Packer, for example:

variables {
    foo = "value ${1 + 2}"
    my_secret = "bar"
    image_name = "foo-image"
}

variable "image_id" {
  type = string
  default = lower("image-id-DEFAULT")
}

variable "availability_zone_names" {
  type    = list(string)
  default = ["a", "b", "c"]
}

locals {
  feefoo = "${var.foo}_${var.image_id}"
}

// var.foo == "value 3"
// var.feefoo == "value 3_image-id-default"
  • Adding numbers just worked out of the box.
  • open a PR to move functions from terraform (docs), over to go-cty: Import functions from Terraform zclconf/go-cty#37 and Import functions from Terraform go-cty-funcs#4
  • parse sensitive vars
  • setting vars from varfiles
  • setting vars from the command line
  • setting vars from the env ?
  • local vars ?
  • introduce vars that aren't just strings ? link
  • bring test coverage up to 70% ( + making sure variables are well tested )
  • add docs for variables/locals
  • updated index of docs
  • pass sensible vars to core
  • make file functions work with directory
  • document the hcl2template package better

Closes #6988
Closes #8681

EDIT: The following functions have been added:
abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.

@azr azr force-pushed the hcl2_input_variables branch from a5d4178 to e2161c6 Compare January 10, 2020 15:06
@azr azr force-pushed the hcl2_input_variables branch from 841897e to f05e118 Compare January 10, 2020 15:54
@azr azr force-pushed the hcl2_input_variables branch 2 times, most recently from 5af3938 to e8e58f4 Compare January 14, 2020 10:37
@azr azr force-pushed the hcl2_input_variables branch from e8e58f4 to 886d61f Compare January 14, 2020 10:43
hcl2template/functions.go Outdated Show resolved Hide resolved
hcl2template/parser.go Show resolved Hide resolved
@azr azr changed the title Hcl2 input variables Hcl2 input variables, local variables and functions Feb 5, 2020
avoid terraform specificities and remove unused docs
@azr
Copy link
Contributor Author

azr commented Feb 6, 2020

Okay we decided to go on with that one ! The sensible var obfuscating is going to come up in another PR ! 🙂

@ghost
Copy link

ghost commented Apr 1, 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 Apr 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
core Core components of Packer hcl2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Variables not recognized Feature Request: required variables settable through environment
4 participants