I am trying pass the arguments to python code which will be called from terraform command
. I am looking for the way to solve in terraform code , by passing args which have space
resource "null_resource" "CWS" {
provisioner "local-exec" {
command = "python ..\\ruc.py ${var.com_port} '${var.cmd1}"
}
triggers = {
always_run = "${timestamp()}"
}
}
In my tfvars
com_port="COM12"
cmd1= "n.set_d_cfg w0 p2.5 1678"
My python code have main function as below
def main():
# Parse arguments from command line
parser = argparse.ArgumentParser()
# Set up required arguments this script
parser.add_argument('com_port', type=str, help='comport')
parser.add_argument('uc', type=str, help='cmd')
# Parse the given arguments
args = parser.parse_args()
print(args.com_port)
print(args.uc)
if __name__ == '__main__':
main()
Getting below error
null_resource.CWS (local-exec): Executing: ["cmd" "/C" "python ..\\ruc.py COM12 n.set_d_cfg w0 p2.5 1678"]
null_resource.CWS (local-exec): usage: ruc.py [-h] com_port uc
null_resource.CWS (local-exec): ruc.py: error: unrecognized arguments: w0 p2.5 1678
╷
│ Error: local-exec provisioner error
│
│ with null_resource.CWS,
│ on SPRW.tf line 107, in resource "null_resource" "CWS":
│ 107: provisioner "local-exec" {
│
│ Error running command 'python ..\\ruc.py COM12 n.set_d_cfg w0 p2.5 1678': exit status 2. Output: usage: ruc.py [-h] com_port uc
│ ruc.py: error: unrecognized arguments: w0 p2.5 1678