Can before_hook execute process in background?

I have a need to run the Google CloudSQL Proxy as a background process whenever I run a plan or apply. Otherwise I cannot connect to my CloudSQL Postgres instance, and the plan/apply will fail. However, I cannot get the command to execute in the background and have terragunt continue running. Is this expected to work?

before_hook "run_cloudsql_proxy" {
    commands = ["apply", "plan"]
    execute  = ["./cloud_sql_proxy", "-instances=myProject:us-central1:myInstance=tcp:5432", "&" ]
}

also tried nohup, but it did not help

before_hook "run_cloudsql_proxy" {
    commands = ["apply", "plan"]
    execute  = ["nohup", "./cloud_sql_proxy", "-instances=myProject:us-central1:myInstance=tcp:5432", "&" ]
}

I was able to resolve this using “screen”

before_hook "run_cloudsql_proxy" {
    commands = ["apply", "plan"]
    execute  = ["screen", "-d", "-m", "./cloud_sql_proxy", "-instances=myProject:us-central1:myInstance=tcp:5432"]
}
2 Likes