Terraform cloud cli driven and terraform apply in CI/CD ends in error EOF

Hi there,

I have difficulties at applying with terraform cloud using a cli driven approach.

My ci cd script step, running on ubuntu :

terraform fmt -check
terraform init 
terraform validate -no-color

terraform apply

From a terraform cloud UI perspective, everything is ok I can see the following message :

Apply pending

Needs Confirmation: Check the plan and confirm to apply it, or discard the run.

Confirm & Apply Discard Run Add Comment

but on my cicd log, I have an error :

[09:00:49] Do you want to perform these actions in workspace “myWorkspace”?
[09:00:49] Terraform will perform the actions described above.
[09:00:49] Only ‘yes’ will be accepted to approve.
[09:00:49]│ Error: Error asking approve: EOF
[09:00:49]│
[09:00:49]│
[09:00:50] Enter a value:
[09:00:50] Process exited with code 1
[09:00:50] Process exited with code 1 (Step: terraform via remote (Command Line))
[09:00:50] Step terraform via remote (Command Line) failed

I have looked upon adding -input=false, but it did not do the trick. I would have loved to see a kind of terraform apply -cloud-automation=true so that the terraform apply does not end in error but rather ends gracefully knowing the end of the process will be assured by the terraform cloud webapp.

As a side note, I have tried with both backend , and it is the same issue :

terraform {
backend “remote” {
organization = “myOrganization”
workspaces {
name = “myWS”
}
}
}

and

terraform {
cloud {
organization = “myOrganization”
workspaces {
name = “myWS”
}
}
}

1 Like

I’m was having a similar problem with GitLab. The root cause for me was that GitLab runs the shell in non-interactive mode. Here is an article describing the canonical way of running Terraform in CI: Running Terraform in Automation | Terraform - HashiCorp Learn