Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex for amazon-ami data source filter comments out part of the code #5

Open
feyzee opened this issue Apr 21, 2021 · 2 comments
Open

Comments

@feyzee
Copy link

feyzee commented Apr 21, 2021

Plugin is commenting out part of the code when it encounters the string - '/*'.

I'm using filters for data source amazon-ami to get an ubuntu image. Value for name key in the filter is "ubuntu/images/ubuntu-bionic-18.04-amd64-server-".

images/*ubuntu

Above part is the problematic one, as plugin assumes it is a comment. Following code is from Packer docs and valid. Tested using validate and build subcommands in Packer.

data "amazon-ami" "ubuntu" {
	filters = {
		virtualization-type = "hvm"
		name = "ubuntu/images/*ubuntu-bionic-18.04-amd64-server-*"
		root-device-type = "ebs"
	}
	owners = ["099720109477"]
        most_recent = true
	profile = var.aws_profile
	region = var.region
}

Here's a screenshot of the code above code.

image

And without "/*" part

image

@comerford
Copy link

can confirm, have the same issue - HCL allows you to create a comment block with:

/* comment1
comment2
*/
var abc = int 0

The fix would be something like ignoring this pattern inside string quotes (single or double) but I have no idea how to make that the case in the grammar format used here. For now I am putting the data block for the amazon ami at the bottom of the config to limit the impact of the highlighting issue, or put the search string for the name in a variable and reference that instead.

@triti
Copy link

triti commented Jun 24, 2021

put the search string for the name in a variable and reference that instead

Additionally... You have to use a variable (probably with a hardcoded default value) and not a local as datasources cannot currently reference locals in Packer (as of 1.7.3). Reference: hashicorp/packer#11011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants