local-exec 中的相对路径 [英] Relative path in local-exec

查看:22
本文介绍了local-exec 中的相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 local-exec 配置程序中引用本地脚本.该脚本位于模块目录上方的几个级别.使用 ${path.module}/../../scripts/somescript.ps1 会产生 path not found 错误.

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.

将脚本目录移动到模块目录下可以解决问题,但不幸的是,在我的情况下这不是一个有效的选项.工作场景:${path.module}/scripts/somescript.ps1

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

我在任何地方都没有看到这是 TF 限制或错误,因此非常感谢任何帮助.

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

提前谢谢你.

这是我的本地执行块:

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}"
 }

推荐答案

尝试使用working_dir

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. 


这篇关于local-exec 中的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆