Relative path in local-exec

巧了我就是萌 提交于 2021-01-28 06:27:07

问题


I'm trying to reference a local script inside a local-exec provisioner. The script is located several levels above the module directory. Using ${path.module}/../../scripts/somescript.ps1 generates a path not found error.

Moving the scripts directory under the modules directory solves the problem but unfortunately is not a valid option in my case. Working scenario: ${path.module}/scripts/somescript.ps1

I didn't see anywhere that it's a TF limitation or a bug so, any help is highly appreciated.

Thank you in advance.

This is my local-exec block:

provisioner "local-exec" { 
interpreter = ["pwsh", "-Command"] 
command = "${path.module}/scripts/Generate-SQLInfo.ps1 -user ${var.az_sql_server_admin_login} -dbname ${var.az_sql_db_name} -resourceGroupName ${module.resource_group.az_resource_group_name} -sqlServerName ${module.sql_server.sql_server_name} -vaultName ${module.keyvault.az_keyvault_name} -azSubscriptionID ${var.az_subscription_id}"
 }

回答1:


Try using working_dir

https://www.terraform.io/docs/provisioners/local-exec.html

provisioner "local-exec" { 
working_dir = "${path.module}/../scripts/" # assuming its this directory
interpreter = ["pwsh", "-Command"] 
command = "Generate-SQLInfo.ps1 ..."
 }

I dont have resources right now to test this but probably this should work for you. 




来源:https://stackoverflow.com/questions/55679852/relative-path-in-local-exec

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!