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 a nomad_job_v2 resource #149

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
f14911d
Add a nomad_job_v2 resource
remilapeyre Aug 31, 2020
309f00a
Fix pronoun
remilapeyre Sep 4, 2020
bf13fd2
Simplify error checking in resourceJobV2Read() by using helper.StateW…
remilapeyre Sep 12, 2020
a4a865a
Rename resource_job_fields.go to resource_job_v2_fields.go
remilapeyre Sep 12, 2020
af5b807
Use the helpers from funcs.go
remilapeyre Sep 12, 2020
693fe1a
Add getListOfString() helper
remilapeyre Sep 12, 2020
2e78053
Don't reuse the duration name
remilapeyre Sep 12, 2020
b4ac4d8
Don't reuse the isSet name
remilapeyre Sep 12, 2020
f48113f
Merge remote-tracking branch 'origin/master' into nomad-job-v2
remilapeyre Sep 12, 2020
58278cc
Don't set consul_token and vault_token in resourceJobV2Read()
remilapeyre Sep 13, 2020
cf4fa68
Move the job definition in a block
remilapeyre Sep 13, 2020
8a6c01a
Add ID attribute
remilapeyre Sep 13, 2020
210f08b
Fix typo
remilapeyre Sep 13, 2020
92b9231
Fix ID handling
remilapeyre Sep 13, 2020
686dd39
Fix handling of ID and name
remilapeyre Sep 13, 2020
9e1c753
Fix type of local_bind_port and native
remilapeyre Sep 13, 2020
f8f5901
Add import support to nomad_job_v2
remilapeyre Sep 13, 2020
3bb1560
Use provider region as default
remilapeyre Sep 14, 2020
3a7e53d
Add a label attribute in the port block
remilapeyre Sep 14, 2020
016b726
Fix handling of the port block
remilapeyre Sep 14, 2020
b6d6930
Read port properly
remilapeyre Sep 14, 2020
57d5a8b
Fix handling of consul_token and vault_token in resourceJobV2Read()
remilapeyre Sep 14, 2020
3bd9fe0
Fix diff for durations and defaults in template block
remilapeyre Sep 14, 2020
4ccac80
Add ForceNew to id, namespace and type
remilapeyre Sep 14, 2020
9218406
Set the default for a few attributes
remilapeyre Sep 14, 2020
e256690
Fix handling of the spread attribute
remilapeyre Sep 14, 2020
843d16a
Add test with constraint block
remilapeyre Sep 14, 2020
ed24173
Move all normalization in a new step
remilapeyre Sep 19, 2020
423984a
Remove the constraint added by Nomad
remilapeyre Sep 19, 2020
06c2a38
Merge remote-tracking branch 'origin/master' into nomad-job-v2
remilapeyre Sep 19, 2020
2b4df89
Use Nomad defaults
remilapeyre Sep 19, 2020
ed2c2c4
Use job.SpecChanged() to suppress diff
remilapeyre Sep 27, 2020
1f33aea
Add note in resource_job_v2_converter.go
remilapeyre Sep 27, 2020
f03bba2
Add test for https://github.com/hashicorp/terraform-provider-nomad/is…
remilapeyre Sep 27, 2020
fee2902
Add some documentation
remilapeyre Sep 27, 2020
b4e20ef
Add migrate and reschedule at job level
remilapeyre Sep 27, 2020
d699aa7
Use /v1/job/:job_id/plan to determine whether the job spec changed
remilapeyre Sep 28, 2020
428e25f
Enforce that the job does not already exist when creating it
remilapeyre Sep 28, 2020
7e6891f
Add the vault stanza at the job and group level
remilapeyre Sep 28, 2020
c2c6815
Add testCheckEnt() in TestResourceJob_vaultMultiNamespace()
remilapeyre Sep 28, 2020
0e422d3
Empty commit to run CI
remilapeyre Sep 28, 2020
b5d0669
Log the diff on read
remilapeyre Sep 28, 2020
9c0c4a1
Add spew in go.mod
remilapeyre Sep 28, 2020
3215165
Try to debug the CI
remilapeyre Sep 28, 2020
51998ba
Ignore the Nomad token for the diff
remilapeyre Sep 28, 2020
60a64ee
Remove logging in CI
remilapeyre Sep 28, 2020
d64fceb
Remove unused resource_job_v2_converter.go
remilapeyre Sep 29, 2020
5f49668
Document the differences between the Nomad job specification and the …
remilapeyre Sep 29, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ exclude (
)

require (
github.com/google/go-cmp v0.3.1
github.com/hashicorp/go-multierror v1.0.0
github.com/hashicorp/go-version v1.2.0
github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f
github.com/hashicorp/nomad/api v0.0.0-20200812181322-71e8a68d9948
github.com/davecgh/go-spew v1.1.1
github.com/google/go-cmp v0.4.0
github.com/hashicorp/go-multierror v1.1.0
github.com/hashicorp/go-version v1.2.1-0.20191009193637-2046c9d0f0b0
github.com/hashicorp/hcl v1.0.1-0.20191016231534-914dc3f8dd7c
github.com/hashicorp/nomad v0.12.5
github.com/hashicorp/nomad/api v0.0.0-20200924154459-261adf0b4d76
github.com/hashicorp/terraform-plugin-sdk v1.15.0
github.com/hashicorp/vault v0.10.4
github.com/mitchellh/mapstructure v1.1.2
github.com/mitchellh/mapstructure v1.3.1
github.com/stretchr/testify v1.5.1
)
1,139 changes: 1,137 additions & 2 deletions go.sum

Large diffs are not rendered by default.

51 changes: 50 additions & 1 deletion nomad/core/helper/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,26 @@ import (

multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/hcl/hcl/ast"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

// boolToPtr returns the pointer to a boolean
// MapStringStringSliceValueSet returns the set of values in a map[string][]string
func MapStringStringSliceValueSet(m map[string][]string) []string {
set := make(map[string]struct{})
for _, slice := range m {
for _, v := range slice {
set[v] = struct{}{}
}
}

flat := make([]string, 0, len(set))
for k := range set {
flat = append(flat, k)
}
return flat
}

// BoolToPtr returns the pointer to a boolean
func BoolToPtr(b bool) *bool {
return &b
}
Expand All @@ -25,6 +42,11 @@ func TimeToPtr(t time.Duration) *time.Duration {
return &t
}

// IntToPtr returns the pointer to an int
func IntToPtr(i int) *int {
return &i
}

func CheckHCLKeys(node ast.Node, valid []string) error {
var list *ast.ObjectList
switch n := node.(type) {
Expand Down Expand Up @@ -108,3 +130,30 @@ func unusedKeysImpl(path []string, val reflect.Value) error {
}
return nil
}

type StateWriter struct {
d *schema.ResourceData
errors []string
}

func NewStateWriter(d *schema.ResourceData) *StateWriter {
return &StateWriter{d: d}
}

func (sw *StateWriter) Set(key string, value interface{}) {
err := sw.d.Set(key, value)
if err != nil {
sw.errors = append(
sw.errors,
fmt.Sprintf(" - failed to set '%s': %v", key, err),
)
}
}

func (sw *StateWriter) Error() error {
if sw.errors == nil {
return nil
}
errors := strings.Join(sw.errors, "\n")
return fmt.Errorf("Failed to write the state:\n%s", errors)
}
3 changes: 3 additions & 0 deletions nomad/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type ProviderConfig struct {
client *api.Client
vaultToken *string
region *string
}

func Provider() terraform.ResourceProvider {
Expand Down Expand Up @@ -83,6 +84,7 @@ func Provider() terraform.ResourceProvider {
"nomad_acl_policy": resourceACLPolicy(),
"nomad_acl_token": resourceACLToken(),
"nomad_job": resourceJob(),
"nomad_job_v2": resourceJobV2(),
"nomad_namespace": resourceNamespace(),
"nomad_quota_specification": resourceQuotaSpecification(),
"nomad_sentinel_policy": resourceSentinelPolicy(),
Expand Down Expand Up @@ -132,6 +134,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
res := ProviderConfig{
client: client,
vaultToken: &vaultToken,
region: &conf.Region,
}

return res, nil
Expand Down
8 changes: 6 additions & 2 deletions nomad/resource_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@ func TestResourceJob_serviceWithoutDeployment(t *testing.T) {
func TestResourceJob_multiregion(t *testing.T) {
r.Test(t, r.TestCase{
Providers: testProviders,
PreCheck: func() { testAccPreCheck(t); testCheckMinVersion(t, "0.12.0-beta1") },
PreCheck: func() {
testAccPreCheck(t)
testCheckMinVersion(t, "0.12.0-beta1")
testCheckEnt(t)
},
Steps: []r.TestStep{
{
Config: testResourceJob_multiregion,
Expand Down Expand Up @@ -1721,7 +1725,7 @@ func TestResourceJob_vault(t *testing.T) {
func TestResourceJob_vaultMultiNamespace(t *testing.T) {
r.Test(t, r.TestCase{
Providers: testProviders,
PreCheck: func() { testAccPreCheck(t); testCheckVaultEnabled(t) },
PreCheck: func() { testAccPreCheck(t); testCheckEnt(t); testCheckVaultEnabled(t) },
Steps: []r.TestStep{
{
Config: testResourceJob_validVaultNamspaceConfig,
Expand Down
Loading