Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 5

How to fork step process and make new process running within the same enviroment?

Solved! Go to Solution.

Hi,

I'm running terraform from my Github Actions workflow. One of my Terraform resources uses a 'post-create' step to run a bash command.

resource "google_endpoints_service" "openapi_service" {
service_name = replace(var.espService.url, "https://", "")
project = var.project_id
openapi_config = var.config
provisioner "local-exec" {
command = "gcloud beta run services update ${var.espService.name} --set-env-vars ENDPOINTS_SERVICE_NAME=${self.service_name} --project ${var.project_id} --platform=managed --region=${var.region}"
interpreter = ["/bin/bash", "-c"]
}
}

 

So this invokes the following bash command 

cloud beta run services update ${var.espService.name} --set-env-vars ENDPOINTS_SERVICE_NAME=${self.service_name} --project ${var.project_id} --platform=managed --region=${var.region}

Please note that the command is initiated by Terraform process (job step) and not by the Github Action runner  (from workflow yaml).

It turns out that my command gets started within a completely different enviroment, perfectly 'clean'. I don't have access to previously installed Google SDK (gcloud). Though if run same command from my workflow yaml it works just fine.

- name Run command
 run: gcloud beta run services update $ESP_NAME --set-env-vars ENDPOINTS_SERVICE_NAME=$ENDPOINT --project $PROJECT --platform=managed 

Is there a way to run bash command from inside the Job Step process so that it runs within the same enviroment and have access to the same 'resources' as command started with run: ... from workflow yaml ?

4 Replies
Highlighted
Solution
GitHub Partner
Message 2 of 5

Re: How to fork step process and make new process running within the same enviroment?

Do you use this Terraform GitHub Actions? As this is a Docker Container action, if you run post-create bash command inside this step, it is executed on docker container not on the github actions runner machine. So when you run scripts in next steps, the environment will change, it will use runner machine environment , not the Terraform docker container.  
If this doesn't match your scenario, could you please enable step debug logging and share your workflow yaml and workflow run logs here? 

Highlighted
Copilot Lvl 2
Message 3 of 5

Re: How to fork step process and make new process running within the same enviroment?

Hi,

Yes I use Terraform GitHub Actions.

Hm ... do you know if there is any alternative to Terraform GitHub Actions which is not a docker based? this is quite an annoying limitattion as having access to local-exec would be userful.

 

Thank you for the reply!

Highlighted
GitHub Partner
Message 4 of 5

Re: How to fork step process and make new process running within the same enviroment?

Sorry to tell you that I don't know an alternative to that docker container Terraform action. What's the insufficient of

running gcloud command from your workflow yaml ? 

Highlighted
Copilot Lvl 2
Message 5 of 5

Re: How to fork step process and make new process running within the same enviroment?

yeah that's what I finally went for! 

Thank you.