Fork me on GitHub
#clojure-uk
<
2018-08-08
>
dominicm06:08:53

["${var.vpc_security_group_ids}"] who knows what this does? πŸ˜„ What does it look like when expanded?

otfrom07:08:32

@dominicm looks like a vector containing a string that will be expanded by something that isn't clojure

dominicm07:08:20

@otfrom this is 100% terraform

agile_geek07:08:45

Bore da pawb welsh_flag

firthh07:08:57

@dominicm does it find a variable called vpc_security_group_ids?

dominicm07:08:51

@firthh it does. I've expanded the question, to make it a little clearer what the gotcha might be πŸ˜‰

firthh07:08:05

well the [] I would assume is an array of things, and then based on the name I would assume would contain an array as well, so something like - [ [ "group-1", "group-2" ] ]?

firthh07:08:49

Or does it do the variable substitution inside a string...?

alexlynham08:08:50

I vaguely remember sometimes terraform folk make a string like "sg-gbgbg, sg-dfhfhfd, sg-hfhfhf"

alexlynham08:08:58

and then drop it into a vector

alexlynham08:08:12

I've seen something like that before, no idea if it's idiomatic

dominicm08:08:32

Terraform treats [ as special from the inside out. And despite being in a string, interpolation doesn't have to return a string. The logical thing of course would be what @firthh says. Terraform does magic and turns it into ["group-1", "group-2"]

firthh08:08:41

@dominicm does "${var.vpc_security_group_ids}" alone also give you ["group-1", "group-2"]?

dominicm08:08:56

Good question, I don't actually know!

dominicm08:08:31

I imagine it would automagically figure it out, but I'm not sure.

firthh08:08:56

None of their documentation shows them using lists anywhere

firthh08:08:05

Only how to create variables that are lists

dominicm08:08:26

if you look at examples, that's where you see it, and then it's prevalent in the community https://github.com/coryodaniel/terraform-aws-cloudwatch_widget/blob/master/main.tf#L13

dominicm08:08:35

(I happened to have that open right now)

firthh08:08:19

Which suggests "${var.LIST}" alone will return a list like I would have expected

dominicm08:08:39

to make it all a bit weirder, [] doesn't mean anything inside of "${}"

firthh08:08:30

When I was at uSwitch someone wrote a ruby wrapper around terraform so that you had a proper programming language to do all of this - https://github.com/uswitch/terrafying

jasonbell08:08:40

Why do it in Ruby when you can do it in Clojure πŸ™‚

firthh08:08:45

I wonder how many other languages you can find basically the same thing πŸ˜›

jasonbell08:08:01

I'm sure there'll be plenty of them @firthh

dominicm08:08:41

we were generating terraform via clojurescript, but discovered that their json syntax does not allow you to express everything you can in hcl

guy08:08:26

morning!

Aleksander14:08:50

There is HCL 0.12 comming with some exciting new features like … for loops!

Aleksander14:08:16

HCL being an acronym for Hashicorp Configuration Language - the language used in Terraform

dominicm14:08:54

I've seen πŸ™‚

dominicm14:08:07

I like that conditionals can return strings AND lists

Aleksander14:08:59

yes, I don’t know how can anyone hold their excitement hearing about those features

firthh14:08:16

But is another language still the best solution? I quite like a DSL in a language I know

dominicm14:08:28

you can already encode json, but now you can decode json!

dominicm14:08:47

this update resolves a lot of quirks of terraform's crappy language.

danm14:08:16

I didn't realise Terraform was its own thing... I thought it was just JSON...

danm14:08:26

I mean, with specific keys to do specific things, but...

firthh14:08:55

It's fully compatible with JSON

firthh14:08:13

> JSON can be used as completely valid input to a system expecting HCL

dominicm14:08:51

But HCL can represent things you can't in JSON, e.g. duplicate keys (this bit us hard)