Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nomad_job_v2 resource using terraform-plugin-go #238

Closed
wants to merge 4 commits into from

Conversation

remilapeyre
Copy link
Contributor

No description provided.

@hashicorp-cla
Copy link

hashicorp-cla commented Mar 12, 2022

CLA assistant check
All committers have signed the CLA.

@meyerbro
Copy link

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 !

@lgfa29
Copy link
Contributor

lgfa29 commented Nov 25, 2023

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!

@lgfa29 lgfa29 closed this Nov 25, 2023
@jorgemarey
Copy link
Contributor

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.

@lgfa29
Copy link
Contributor

lgfa29 commented Dec 16, 2023

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!

@jorgemarey
Copy link
Contributor

Created in #409

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants