Terraform: 0.6.7 illegal char escape

Created on 24 Nov 2015  ·  19Comments  ·  Source: hashicorp/terraform

Just went from 0.6.6 to 0.6.7 and now on plan I get:

Error loading config: Error parsing foo.tf: At 199:34: illegal char escape

The line it's complaining about (which worked just fine before) is from an inline remote-exec provisioner:

  provisioner "remote-exec" {
    inline = [
            "sed -i s/^search.*/search\ foo.com/ /etc/resolv.conf",
    ]
  }

It would seem that it doesn't like the escaped space anymore.

bug core

All 19 comments

Thanks for the report. This is likely from the new HCL parser we pulled in for 0.6.7 - we'll get this fixed up for the 0.6.8 bugfix release.

Hi @br0ch0n, digging in a bit further on this, it looks like the prior behavior you got out of the \ was undocumented and just happened to work based on a quirk of the old parser. The correct syntax to get a backslash into a string is to use a \\, so if you just update your provisioner to use that it should work just fine:

  provisioner "remote-exec" {
    inline = [
            "sed -i s/^search.*/search\\ foo.com/ /etc/resolv.conf",
    ]
  }

Sorry for the backwards incompatible behavior here, but if you move to this documented syntax it is guaranteed to be supported going forward. :+1:

Thanks @phinze tested and works good with 0.6.6 and 0.6.7

Hello guys , when I try to execute these comand to start vault server I 'm getting the following errors,
Error loading configuration from example.hcl: At 2.27 illegal char escape

backend "file" {
path = "C:\MyKeyManager\Consul"
}

listener "tcp" {
address = "127.0.0.1:8200"
tls_disable = 1
}
Error loading configuration from example.hcl: At 2.27 illegal char escape
Please help me out.Thanks in advance.

@waliul-cse yeah it's definitely a problem right now - i'm actively working on #6359 today which should solve your problem -> \\ should result in \ once that is fixed!

Thanks for your quick reply.I'm trying to configure vault server in production mode and got this error to configure the vault server from example.hcl file.I 'm using vault v0.5.3 version.Please resolve my problem I 'd be very grateful to you.@phinze

@waliul-cse actually in that context I'd expect the \\ to work - if you change your config to include this:

backend "file" {
  path = "C:\\MyKeyManager\\Consul"
}

Does that work?

Alternatively most Windows contexts now handle / as a path separator so you can try this as well:

backend "file" {
  path = "C:/MyKeyManager/Consul"
}

Thanks @phinze that problem has solved.But got another warning: mlock supported on this system

The 'mlock' syscall to prevent memory being swaped to disk is not supported on this system.Enable mlock or running vault on a system with mlock is much more secure.

Then show configuration Log.Is it create any problem to that warning to run vault server ?can you help me about this issue ?I 'm novice to vault server so don't mind.Thanks again.@phinze

Hi @waliul-cse - glad to hear the escaping issue is solved!

I don't think a closed Terraform issue is the right venue for that next question though. 😀 I recommend heading over to the Vault community for further support. I _believe_ the relevant docs on mlock can be found on this page: https://www.vaultproject.io/docs/config/ but beyond that I'd heading over to one of the many spots listed here https://www.vaultproject.io/community.html

Thanks @phinze I 'll do so.

Hi @phinze , I was trying to assign a string to the argument user_data when creating aws_launch_configuration, I did as you suggested to use \ than \ to escape characters, it throws error:
Error loading config: Error parsing .\main.tf: At 217:188: expected: IDENT | STRING | ASSIGN | LBRACE got: NUMBER
This is the string I assigned to user_data as follow, could you please advise?
user_data = "#!/bin/bash -v\nID=\$(curl http://169.254.169.254/latest/meta-data/instance-id)\nhostname \$ID\nsed -i.bak \'/127.0.0.1/d\' /etc/hosts\nsed -i.bak \"1 a 127.0.0.1 \$ID.${var.project_name} \$ID localhost\" /etc/hosts"

Hi @bexie! Sorry for the issue there.

The parsing of configs has changed a bit since this old issue, so probably best to open a fresh issue for this question so it's more visible rather than being buried in here.

Thanks @apparentlymart , I opened a new issue : Error parsing : expected: IDENT | STRING | ASSIGN | LBRACE got: NUMBER #10355

Is this normal in 2017? I still need to add second backslack in order sed to work.

Same question as @holms on this?

Hi @holms, @sudeep1801.

The parsing of configs has changed a bit since this old issue, so if there is any misbehavior it is almost definitely requires a different fix than what was done in this issue. If one of you has the time, it'd be great to have a new top-level issue that describes the apparent problem in more detail, including example configs and the various other things the issue template asks for.

@apparentlymart how would I insert a #?

I still see this issue with 0.11.0 as well. Examples to reproduce.

Sample regex with grep

echo "VyOS (HVM) 1.1.8-66e10eda-0acd-4301-9012-3113b2cfa4f5-ami-220db358.4"| grep -e "^VyOS\s(HVM)\s1\.1\.8-.*ami.*"
VyOS (HVM) 1.1.8-66e10eda-0acd-4301-9012-3113b2cfa4f5-ami-220db358.4

Configuration:

data "aws_ami" "vyos_ami" {
  most_recent      = true
  executable_users = ["self"]

  name_regex = "^VyOS\s(HVM)\s1\.1\.8-.*ami.*"

  owners = ["${module.global_variables.ami_account_id["sentrium"]}"]
}

Error:

Error: Failed to load root config module: Error parsing <my-path>/peer-routers.tf: At 12:36: illegal char escape

When trying with double \\, the syntax passes, but returns no results.

When doing the regex in an alternate way (without \s at all) it works. This of course is not explicit and it seems like somehow the regex is not properly escaped and passed from the config to the Go code on the backend.

In order for this to work, I needed to use the standard filters.

data "aws_ami" "vyos_ami" {
  most_recent      = true
  executable_users = ["self"]

  filter {
    name = "name"

    # The following looks really bad, but "VyOS*1.1.8*" does not work
    values = ["VyOS*1*1*8*"] # Fix to 1.1.8
  }

  owners = ["${module.global_variables.ami_account_id["sentrium"]}"]
}

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

carl-youngblood picture carl-youngblood  ·  3Comments

zeninfinity picture zeninfinity  ·  3Comments

pawelsawicz picture pawelsawicz  ·  3Comments

rjinski picture rjinski  ·  3Comments

ketzacoatl picture ketzacoatl  ·  3Comments