Ruby string manipulation

It is possible to apply ruby string manipulation on boot terraspace stage?
if I define following in config/boot/devel.rb

ENV['AWS_REGION'] ||= 'eu-west-1'

It is possible to replace “-” in “_” using ruby on early ENV subst stage ?

It can be probably done using terraform string manipulation functions but it is interesting to know if can be done with ruby.too.

Ruby has many string power manipulation methods.

  1. Lots of them are built into Ruby’s standard core String class.
  2. And a lot more come with activesupport String extensions, which Terraspace includes.

Here are the Ruby String reference docs:

You can test them out quickly win an irb (interactive ruby shell) session. Example:

$ irb
> 'eu-west-1'.gsub('-','_')
 => "eu_west_1" 

Here are the activesupport docs:


$ irb
> require "active_support/core_ext/string"
 => true 
> "some_test".camelize
 => "SomeTest" 
> "some_test".camelize.underscore
 => "some_test" 
> "some_test".dasherize
 => "some-test" 

Thank you tung. I tried gsub in a wrong way (wrong position). Now I found it works fine.
An example below if someone need it:

define in conf/boot/

ENV['AWS_REGION'] ||= 'eu-west-1'

then in configuration something like this:

<%= ENV['AWS_REGION'].gsub("-","_") %>

If you want to set once removing dashes, in config/boot/devel.rb define:

ENV['AWS_REGION'] ||= 'eu-west-1'
ENV['AWS_REGION_FLAT'] ||= ENV['AWS_REGION'].gsub("-","")

then in configuration use:


Thank you again