Can we writenomad job file using terraform?

can we write nomad job file using terraform?

I’m not sure if this is what you mean, but you can create Nomad jobs using the Nomad provider:

https://registry.terraform.io/providers/hashicorp/nomad/latest/docs/resources/job

This requires the Nomad job spec and creates the job in a Nomad cluster. However, if you’re referring to using Terraform to write the job spec itself, I believe the “right” way is to use Levant.

An example is available on the Hashicorp Learn platform:

Can you elaborate a bit more on what you’re trying to achieve?

Thanks for the information.

Want to write nomad multitask job like server configuration nginx php mysql.
but i am new in the town that’s reason i asked this question.
Like want to run any application in docker we are using docker-compose file.
But in nomad using HCL format so i don’t have idea. how to write multiple task job.

No worries :slight_smile: everyone starts at the start!

If HCL is your sticking point, you’re going to experience the same friction whether you create the jobs using the nomad client directly, or using Terraform, since both of them expect HCL. You can write your jobspec in JSON…

From the Nomad docs:

For machine-friendliness, Nomad can also read JSON-equivalent configurations. In general, we recommend using the HCL syntax.

… but it is discouraged.

My understanding is that there is some correspondence between the Docker Compose specification and the Nomad job specification, but it is not 1:1

For example, a Nomad task can be thought of as a Docker compose service. Nomad and Docker diverge in functionality at various points, but perhaps to get comfortable with the ideas, it helps to use this analogy.

Nevertheless, coming back to your original question, there are two issues:

  1. Writing the jobspec correctly.
  2. Creating the job

If you are just getting started, I would suggest using the nomad client first so that you can plan and validate them.

Once you’re confident that the jobs are correct, you can terraform your cluster.

1 Like

Thanks for the information.

1 Like