问题
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