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 data sources for scaling policies #162

Merged
merged 4 commits into from Oct 30, 2020
Merged

Conversation

lgfa29
Copy link
Contributor

@lgfa29 lgfa29 commented Oct 30, 2020

Add two new data sources to load scaling policies from Nomad.

Changelog update will come in a separate PR.

Usage example:

resource "nomad_job" "job" {
  jobspec = <<EOF
job "foo-scaling-policy" {
  datacenters = ["dc1"]
  group "foo" {

    scaling {
      enabled = false
      min     = 1
      max     = 20
          type    = "horizontal"

      policy {
        cooldown = "20s"
      }
    }

    task "foo" {
      driver = "raw_exec"
      config {
        command = "/bin/sleep"
        args    = ["10"]
      }
    }
  }
}
EOF
}

data "nomad_scaling_policies" "policies" {
  job_id = nomad_job.job.name
}

data "nomad_scaling_policy" "policy" {
  id = data.nomad_scaling_policies.policies.policies[0].id
}

This PR also includes a new helper used to check for errors when calling d.Set in a less verbose way:

sw := helper.NewStateWriter(d)

sw.Set("enabled", p.Enabled)
sw.Set("type", p.Type)
sw.Set("min", p.Min)
sw.Set("max", p.Max)
sw.Set("target", p.Target)
                                                                        
if sw.Error() != nil {
	return sw.Error()
}

cgbaker
cgbaker previously approved these changes Oct 30, 2020
Copy link
Contributor

@cgbaker cgbaker left a comment

Choose a reason for hiding this comment

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

LGTM

@lgfa29 lgfa29 merged commit 6ff367b into master Oct 30, 2020
@lgfa29 lgfa29 deleted the f-scaling-policy-data-source branch October 30, 2020 22:27
@lgfa29 lgfa29 mentioned this pull request Oct 30, 2020
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.

None yet

2 participants