Define terraform module using Ruby DSL

Hello team,

I’m new to using Terraspace. I have a case where I’d like to define Terraform resources using Ruby DSL. From the docs, I see that I can define resource, variable and output. I also managed to define a provider and locals (not documented). However, I can’t seem to define a terraform module, is there any way to do this?

What I’m trying is this:

module("my_test_module",
    source: "../../test_module",
    test_var: "${var.test_var}"
)

Error I’m getting is:

syntax error, unexpected ',', expecting ')' (SyntaxError)
...("my_test_module",
...                 ^

Is there any way to achieve this?

Interesting to see someone using the Ruby DSL. :grin:

Yes. You can define a module with the DSL with module!.

module!("my_test_module",
    source: "../../test_module",
    test_var: "${var.test_var}"
)

You need the ! because module is a Ruby keyword. So it cannot be used for the DSL.

It’s a bummer that I couldn’t use module vs module!. I remember at the time that I considered preprocessing the files but figure complexity was not worth it.

Anyway, give module! a try.

Thank you, works great!

As you took interest, I’m using Ruby DSL to dynamically create terraform providers and resources for multiple account, since as you probably know - terraform doesn’t support dynamic provider creation.

1 Like