terraform-provider-nomad
terraform-provider-nomad copied to clipboard
Add nomad_job_v2 resource using terraform-plugin-go
This is a very interesting and important work. This would mean that the TF PLAN could show only the differences but not a huge string with "+" and "-" in some lines... Any chance to get this PR reviewed? Thanks for this good work @remilapeyre !
Despite @remilapeyre brave efforts, this approach turned out to be impossible to manage over time as it requires keeping the Terraform spec for jobs in sync with Nomad.
We should investigate the advancements in the Terraform plugin development ecosystem to come up with a better solution to #1.
Thank you again @remilapeyre for all the hard work on this!
Hi @lgfa29 just came here to comment, something we did, (needs improvement, but maybe it's a good starting point for this).
We made a nomadpack provider, an example resource is something like this:
resource "nomadpack_pack" "autoscaler_cluster" {
name = "autoscaler_cluster"
pack_name = "autoscaler"
revision = "v0.3.7"
namespace = var.namespace
preserve_counts = true
vars = {
job_name = var.job_name
target = "aws-asg"
region = var.region
namespace = var.namespace
target_creds_path = module.role.creds_path
config_path = var.config_path
}
Under the hood currently this calls the nomad-pack binary to deploy the pack. Having this allows us to chain resources (create a policy and then deploy the job) in the same terraform configuration.
We detect changes by having a shasum of the rendered job and seeing if it changes with the value stored for the previous resource version.
Also if, the nomad-pack plan has changes, we output them in the terraform diagnostics. It's a bit hacky solution but I didn't find another way of getting the plan output displayed nicely.
planOutput, changes, err := np.Plan(ctx)
tflog.Info(ctx, planOutput, map[string]interface{}{"changes": changes})
if err != nil {
resp.Diagnostics.AddError("Error while plannig", err.Error())
return
}
fullName := np.FullName()
if planHasChanges(planOutput, changes) {
resp.Diagnostics.AddWarning(fmt.Sprintf("Changes planned to %s", fullName), planOutput)
return
}
What do you thing about an approximation like this? Using a nomadpack resource we wouldn't need to keep track of the changes in the nomad job spec. Also having nomadpack integrated in terraform will allow to create dependencies and handle everything inside terraform.
Hi @jorgemarey 👋
Thanks for the input. We have received questions about a Nomad Pack + Terraform integration, but we haven't nailed down a design for that quite yet.
Would you mind moving this comment to a new issue so we can track it and discussed it more broadly?
Thank you!
Created in https://github.com/hashicorp/terraform-provider-nomad/issues/409