Jenkins and Terraform

238 views
Skip to first unread message

Patria Lukman

unread,
Jun 13, 2019, 12:14:10 AM6/13/19
to Terraform
I'm building a pipeline with Terraform docker container and I'm getting error message: "Terraform initialized in an empty directory!"

In my Jenkinsfile I'm executing something like this:

Terraform 0.12.1


docker run -w /app -v /jenkins_dir:/app my-repo/hashicorp-terraform:0.12.1 init 


When I execute a ls -all on the /jenkins_dir directory, I see the configurations files. I also ran a similar instruction locally and it works without issues. Seems to me this is a Jenkins issue but I can't see why?

⁞ Fernando Miguel

unread,
Jun 13, 2019, 1:45:41 AM6/13/19
to terrafo...@googlegroups.com
You say you executed ls in that directory... Did you change there first from inside the Docker? 
Does it have a WORKING directory set in the Dockerfile? 

--
Fernando Miguel

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/bd1e2436-e790-4fda-b815-43290046d873%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Patria Lukman

unread,
Jun 13, 2019, 2:32:07 AM6/13/19
to Terraform
thanks Miguel for your quick reply. I fixed the issue, I had to use the docker agent facility instead of spinning the Docker container from within the node.

Here is the fix. Using the official Hashicorp image, the important detail is to disable the entrypoint. The definition of the Working directory along with the Volume was already defined.


pipeline {
agent {
docker {
image 'my-repo/hashicorp-terraform:0.12.1'
args '--entrypoint="" -w /app -v /var/jenkins_home/jobs/devopsmigration/jobs/NexusIQ/branches/master/workspace:/app'
}
}

stages {
stage('checkout') {
steps {
checkout scm
}
}

stage('init') {
steps {
sh 'terraform version && terraform init -input=false'
}
}

On Thursday, June 13, 2019 at 1:45:41 AM UTC-4, Fernando wrote:
You say you executed ls in that directory... Did you change there first from inside the Docker? 
Does it have a WORKING directory set in the Dockerfile? 

--
Fernando Miguel

On Thu, 13 Jun 2019, 05:14 Patria Lukman, <phlu...@lukzen.com> wrote:
I'm building a pipeline with Terraform docker container and I'm getting error message: "Terraform initialized in an empty directory!"

In my Jenkinsfile I'm executing something like this:

Terraform 0.12.1


docker run -w /app -v /jenkins_dir:/app my-repo/hashicorp-terraform:0.12.1 init 


When I execute a ls -all on the /jenkins_dir directory, I see the configurations files. I also ran a similar instruction locally and it works without issues. Seems to me this is a Jenkins issue but I can't see why?

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terrafo...@googlegroups.com.

laxman Singh Rathore

unread,
Jun 20, 2019, 3:17:29 PM6/20/19
to terrafo...@googlegroups.com
Hi, 

You need to explore  auto approv option with cli.

Regards 
Laxman singh 

To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/6f93c425-77db-4441-8b7d-9f196b0a1614%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages