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 import for CSI volumes and job #359

Merged
merged 4 commits into from
Jul 26, 2023
Merged

add import for CSI volumes and job #359

merged 4 commits into from
Jul 26, 2023

Conversation

lgfa29
Copy link
Contributor

@lgfa29 lgfa29 commented Jul 26, 2023

No changelog since this is a new resource.

Highjacking the PR to also add import support for jobs since I noticed that these are the last resources missing import.

Closes #137

@lgfa29 lgfa29 requested review from schmichael and tgross July 26, 2023 19:52
@lgfa29 lgfa29 changed the title csi: add support to import volume and volume registrations add import for CSI volumes and job Jul 26, 2023
@lgfa29 lgfa29 mentioned this pull request Jul 26, 2023
7 tasks
Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running the terraform import command seems to work fine for me here:

$ terraform import nomad_job.httpd httpd
nomad_job.httpd: Importing from ID "httpd"...
nomad_job.httpd: Import prepared!
  Prepared nomad_job for import
nomad_job.httpd: Refreshing state... [id=httpd]

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

But using an import does not, and I'm not sure if there's something extra we need to implement to make it work. Using the following Terraform config:

provider "nomad" {
  address = "http://localhost:4646"
}

import {
  to = nomad_job.httpd
  id = "httpd"
}

resource "nomad_job" "httpd" {
}

I get the following error:

$ terraform plan
╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│  - hashicorp/nomad in /home/tim/go/bin
│
│ The behavior may therefore not match any released version of the provider and applying
│ changes may cause the state to become incompatible with published releases.
╵
╷
│ Error: Missing required argument
│
│   on main.tf line 10, in resource "nomad_job" "httpd":
│   10: resource "nomad_job" "httpd" {
│
│ The argument "jobspec" is required, but no definition was found.
╵

CHANGELOG.md Show resolved Hide resolved
@lgfa29
Copy link
Contributor Author

lgfa29 commented Jul 26, 2023

Ah yes, you need to add the jobspec attribute pointing to your jobfile. Something like this should work (assuming the job filename is correct and it lives in the same path as your .tf file):

provider "nomad" {
  address = "http://localhost:4646"
}

import {
  to = nomad_job.httpd
  id = "httpd"
}

resource "nomad_job" "httpd" {
  jobspec = file("${path.module}/httpd.nomad.hcl")
}

Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@tgross
Copy link
Member

tgross commented Jul 26, 2023

Ah yes, you need to add the jobspec attribute pointing to your jobfile.

Oh... I guess that makes sense because the jobspec is external to the Terraform module, rather than being a set of attributes on the resource.

@lgfa29
Copy link
Contributor Author

lgfa29 commented Jul 26, 2023

Yeah, after importing your config needs to match your state to prevent values from being lost in the next apply. There is experimental work on auto-generating configuration on import (https://developer.hashicorp.com/terraform/language/import/generating-configuration) but I doubt it would work for nomad_job since it's a weird resource with just a big string as input 😅

@lgfa29 lgfa29 merged commit 78ec344 into main Jul 26, 2023
2 of 3 checks passed
@lgfa29 lgfa29 deleted the f-import-volumes branch July 26, 2023 21:07
@lgfa29 lgfa29 added this to the 2.0.0 milestone Aug 15, 2023
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.

Add importer to resources
2 participants