Terraform Escape Single Quotes

terraform

I am trying to escape single quotes in my terraform script and inventory file.

Terraform script line:

list_compute= "${join("\n",formatlist("%s openshift_node_labels="{'region': 'primary', 'zone': 'east'}"", "${module.compute.ops_compute_names}"))}"

How do I preserve/escape the single quote around region, primary, zone and east?

Also my template file which is used for rendering:

openshift_master_identity_providers=[{'name': 'htpasswd_auth', 'login': 'true', 'challenge': 'true', 'kind': 'HTPasswdPasswordIdentityProvider', 'filename': '/etc/origin/master/htpasswd'}]

How do I preserve/escape the single quotes.

Best Answer

This should work

join("\n",formatlist("%s openshift_node_labels={'region': 'primary', 'zone': 'east'}", "${module.compute.ops_compute_names}"))

As long as ops_compute_names is a list