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

Adding datasource for nomad_job resource #32

Merged
merged 20 commits into from
Dec 20, 2018

Conversation

slapula
Copy link
Contributor

@slapula slapula commented Mar 23, 2018

This is the first of a couple PRs I'd like to submit. This one introduces a nomad_job datasource which allows a user to act or respond to the resource's various attributes. I've tested this in my limited environments and it works well for me, but further testing and feedback would be greatly appreciated.

Copy link
Contributor

@paddycarver paddycarver left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! Really appreciated. It overall looks good, but some minor comments. The tests need to actually set up the job they're going to read, and should probably check the attributes are at least reasonable values, if we can't predict the exact value.

The descriptions could be a bit better--what information goes in these fields? I think the same holds for the documentation.

Finally, out of curiosity, what use case do you have in mind for this? I mean, I know it's to retrieve details about a job, but why is that a useful thing to do? I just want to understand the intended use here.

Read: dataSourceJobRead,
Schema: map[string]*schema.Schema{

"id": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Naming things id, unfortunately, really messes with our provider framework. job_id may be a better choice here.

Schema: map[string]*schema.Schema{
"placed_canaries": {
Type: schema.TypeString,
Optional: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these should all be Computed, not Optional. I don't know what the behavior of an Optional field in a Computed block is, but the semantics of it don't really make sense. Optional indicates you can supply a value but aren't required to. Computed without Optional or Required prohibits supplying a value.

},
},
"vault_token": {
Description: "Vault Token",
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is doing what I think it's doing--returning the vault token that the job is using--it should be marked Sensitive.

Config: testAccCheckNomadJobConfig_basic(jobId),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.nomad_job.foobar", "id", fmt.Sprintf("%s", jobId)),
Copy link
Contributor

Choose a reason for hiding this comment

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

This could probably be combined with the first TestStep, and ideally would check more of the computed attributes to make sure they're set correctly.


func testAccCheckNomadJobConfig_basic(str string) string {
return fmt.Sprintf(`
data "nomad_job" "foobar" {
Copy link
Contributor

Choose a reason for hiding this comment

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

This test should fail, because it doesn't set up the job but expects it to exist.

* `all_at_once`: All-at-once setting status.
* `contraints`: Job constraints.
* `update_strategy`: Job's update strategy.
* `periodic_config`: Job's periodic configuration.
Copy link
Contributor

Choose a reason for hiding this comment

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

A bit more information (that these are blocks, what's in the blocks, etc.) would be useful here. Also, data types for all of these properties would be useful.

* `contraints`: Job constraints.
* `update_strategy`: Job's update strategy.
* `periodic_config`: Job's periodic configuration.
* `vault_token`: Job Vault token.
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably put a warning up front that using this resource introduces the Job's Vault token into state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. I'm not quite sure of the value in including this data so I'm going to drop it.

@slapula
Copy link
Contributor Author

slapula commented Apr 1, 2018

@paddycarver Thanks for the feedback! I'm not completely satisfied with the documentation too so I've been working on that. I believe I've also fixed the tests so that they actually work and test reasonable values.

I'll admit that this datasource is something that I've only really used in my personal test environment. The data I pull from this resource is used in a couple templated scripts that I've included in my Terraform code. On a broader level, I'm a big fan of Terraform resources pulling in as much data as reasonably possible. I could pull this from the cluster directly but I feel that if I'm managing the job via Terraform I should be pulling the data with Terraform as well. I'm open to other arguments for or against this perspective however.

One of the things I'm thinking about right now is if this datasource needs to pull in every single bit of data from the API call. nomad status <job_id> doesn't display that much information and maybe the most appropriate direction here is to follow that standard. We could then make detailed task group data (for example) accessible through a different datasource. Just an idea, not really sure how practical that would be.

@cgbaker cgbaker merged commit f5c7aef into hashicorp:master Dec 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants