claranet / terraform-aws-lambda

Terraform module for AWS Lambda functions
MIT License
157 stars 126 forks source link

Ensures quoted arguments are handled similarly across platforms #44

Closed lorengordon closed 5 years ago

lorengordon commented 5 years ago

With this patch, the inputs in build.py resolve the same on both linux and windows.

null_resource.archive (local-exec): cd C:\...
null_resource.archive (local-exec): cd /home/...

Fixes #43

raymondbutcher commented 5 years ago

Hi again. Thanks for this.

I wonder if argparse handles it correctly, something like:

import argparse

parser = argparse.ArgumentParser()
parser.add_argument('filename')
parser.add_argument('runtime')
parser.add_argument('source_path')

args = parser.parse_args()

filename = args.filename
runtime = args.runtime
source_path = args.source_path

I'd lean towards using argparse over shlex if it works.

lorengordon commented 5 years ago

Good idea! I'll give that a try also, probably tomorrow.

lorengordon commented 5 years ago

@raymondbutcher Unfortunately, no, argparse preserves the quotes also, and so the error reported in the linked issue still occurs.

I suppose I'm not too sure what the difference is on Windows, that the argument is quoted in *argv, where on Linux it is not. I've tried both double quotes and single quotes in build_command and both fail the same way.

I've also tried no quotes, which changes the behavior and gets further, but then fails in a different way that I understand even less at the moment. It also probably would not work at all when there are spaces in the path.

I eventually fell back to treating the symptom with shlex, which at least gets things working across platforms again.

lorengordon commented 5 years ago

Any other concerns @raymondbutcher?

raymondbutcher commented 5 years ago

Thanks for trying argparse. One last idea, if you wouldn't mind trying it.

The quote is probably coming from here:

variable "build_command" {
  description = "The command that creates the Lambda package zip file"
  type        = "string"
  default     = "python build.py '$filename' '$runtime' '$source'"
}

Could you please try with double quotes instead of single quotes?

variable "build_command" {
  description = "The command that creates the Lambda package zip file"
  type        = "string"
  default     = "python build.py \"$filename\" \"$runtime\" \"source\""
}

Maybe Windows handles double quotes and single quotes differently.

lorengordon commented 5 years ago

Hi @raymondbutcher, that was one of the first things I tried, thinking the same thing. :smile: No luck though. The double quotes are passed through, and then os.path.dirname strips off the closing quote as mentioned in the linked issue, resulting in an invalid path.

raymondbutcher commented 5 years ago

OK, I guess this will have to go in then :smile:

lorengordon commented 5 years ago

Thanks @raymondbutcher! Mind tagging that also?

raymondbutcher commented 5 years ago

@lorengordon sorry for the delay, it's now in v0.11.5

lorengordon commented 5 years ago

Awesome, thanks @raymondbutcher!