Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit c0ef514

Browse files
Merge pull request #3330 from hashicorp/backport/f-nomad-jobspec-hcl1/openly-ruling-bullfrog
This pull request was automerged via backport-assistant
2 parents 82c99a8 + d1b4bad commit c0ef514

File tree

6 files changed

+52
-18
lines changed

6 files changed

+52
-18
lines changed

.changelog/3287.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:improvement
2+
plugin/nomad-jobspec: Add configuration option to parse jobspec as HCL1 instead of HCL2
3+
```

builtin/nomad/jobspec/platform.go

+19-6
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (p *Platform) resourceJobCreate(
102102

103103
// Parse the HCL
104104
st.Update("Parsing the job specification...")
105-
job, err := p.jobspec(client.NomadClient, p.config.Jobspec)
105+
job, err := p.jobspec(client.NomadClient, p.config.Jobspec, p.config.Hcl1)
106106
if err != nil {
107107
return err
108108
}
@@ -179,7 +179,7 @@ func (p *Platform) resourceJobStatus(
179179
jobClient := client.NomadClient.Jobs()
180180

181181
s.Update("Parsing the job specification...")
182-
jobspec, err := p.jobspec(client.NomadClient, p.config.Jobspec)
182+
jobspec, err := p.jobspec(client.NomadClient, p.config.Jobspec, p.config.Hcl1)
183183
if err != nil {
184184
return err
185185
}
@@ -329,7 +329,7 @@ func (p *Platform) Deploy(
329329
return nil, err
330330
}
331331
// Parse the HCL
332-
job, err := p.jobspec(client, p.config.Jobspec)
332+
job, err := p.jobspec(client, p.config.Jobspec, p.config.Hcl1)
333333
if err != nil {
334334
return nil, err
335335
}
@@ -398,7 +398,7 @@ func (p *Platform) Generation(
398398
}
399399

400400
// Parse the HCL
401-
job, err := p.jobspec(client, p.config.Jobspec)
401+
job, err := p.jobspec(client, p.config.Jobspec, p.config.Hcl1)
402402
if err != nil {
403403
return nil, err
404404
}
@@ -419,12 +419,16 @@ func (p *Platform) Generation(
419419

420420
}
421421

422-
func (p *Platform) jobspec(client *api.Client, path string) (*api.Job, error) {
422+
func (p *Platform) jobspec(client *api.Client, path string, hcl1 bool) (*api.Job, error) {
423423
jobspec, err := ioutil.ReadFile(p.config.Jobspec)
424424
if err != nil {
425425
return nil, err
426426
}
427-
job, err := client.Jobs().ParseHCL(string(jobspec), true)
427+
job, err := client.Jobs().ParseHCLOpts(&api.JobsParseRequest{
428+
JobHCL: string(jobspec),
429+
HCLv1: hcl1,
430+
Canonicalize: true,
431+
})
428432
if err != nil {
429433
return nil, err
430434
}
@@ -520,6 +524,9 @@ func (p *Platform) Status(
520524
type Config struct {
521525
// The path to the job specification to load.
522526
Jobspec string `hcl:"jobspec,attr"`
527+
528+
// Signifies whether the jobspec should be parsed as HCL1 or not
529+
Hcl1 bool `hcl:"hcl1,optional"`
523530
}
524531

525532
func (p *Platform) Documentation() (*docs.Documentation, error) {
@@ -624,6 +631,12 @@ job "web" {
624631
"Path to a Nomad job specification file.",
625632
)
626633

634+
doc.SetField(
635+
"hcl1",
636+
"Parses jobspec as HCL1 instead of HCL2.",
637+
docs.Default("false"),
638+
)
639+
627640
doc.SetField(
628641
"consul_token",
629642
"The Consul ACL token used to register services with the Nomad job.",

go.mod

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ require (
6060
github.com/hashicorp/go-version v1.2.0
6161
github.com/hashicorp/hcl/v2 v2.10.1-0.20210621220818-327f3ce2570e
6262
github.com/hashicorp/horizon v0.0.0-20210317214650-d2053943be04
63-
github.com/hashicorp/nomad/api v0.0.0-20210907162733-cf7675a376b9
63+
github.com/hashicorp/nomad/api v0.0.0-20220426182820-059c89dff073
6464
github.com/hashicorp/vault/api v1.0.5-0.20200519221902-385fac77e20f
6565
github.com/hashicorp/vault/sdk v0.1.14-0.20201202172114-ee5ebeb30fef
6666
github.com/hashicorp/waypoint-hzn v0.0.0-20201008221232-97cd4d9120b9
@@ -75,7 +75,7 @@ require (
7575
github.com/mitchellh/go-testing-interface v1.14.1
7676
github.com/mitchellh/go-wordwrap v1.0.1
7777
github.com/mitchellh/hashstructure/v2 v2.0.1
78-
github.com/mitchellh/mapstructure v1.4.1
78+
github.com/mitchellh/mapstructure v1.4.3
7979
github.com/mitchellh/pointerstructure v1.2.0
8080
github.com/mitchellh/protoc-gen-go-json v1.1.1-0.20211009224639-45822525aa9c
8181
github.com/mitchellh/reflectwalk v1.0.1
@@ -93,7 +93,7 @@ require (
9393
github.com/sebdah/goldie/v2 v2.5.3
9494
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
9595
github.com/slack-go/slack v0.6.5
96-
github.com/stretchr/testify v1.7.0
96+
github.com/stretchr/testify v1.7.1
9797
github.com/vektra/mockery v1.1.2
9898
github.com/zclconf/go-cty v1.8.4
9999
github.com/zclconf/go-cty-yaml v1.0.2
@@ -204,7 +204,7 @@ require (
204204
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
205205
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 // indirect
206206
github.com/hashicorp/consul/api v1.7.0 // indirect
207-
github.com/hashicorp/cronexpr v1.1.0 // indirect
207+
github.com/hashicorp/cronexpr v1.1.1 // indirect
208208
github.com/hashicorp/errwrap v1.1.0 // indirect
209209
github.com/hashicorp/go-immutable-radix v1.3.0 // indirect
210210
github.com/hashicorp/go-retryablehttp v0.6.6 // indirect

go.sum

+8-6
Original file line numberDiff line numberDiff line change
@@ -1026,8 +1026,8 @@ github.com/hashicorp/consul/api v1.7.0/go.mod h1:1NSuaUUkFaJzMasbfq/11wKYWSR67Xn
10261026
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
10271027
github.com/hashicorp/consul/sdk v0.6.0 h1:FfhMEkwvQl57CildXJyGHnwGGM4HMODGyfjGwNM1Vdw=
10281028
github.com/hashicorp/consul/sdk v0.6.0/go.mod h1:fY08Y9z5SvJqevyZNy6WWPXiG3KwBPAvlcdx16zZ0fM=
1029-
github.com/hashicorp/cronexpr v1.1.0 h1:dnNsWtH0V2ReN7JccYe8m//Bj14+PjJDntR1dz0Cixk=
1030-
github.com/hashicorp/cronexpr v1.1.0/go.mod h1:P4wA0KBl9C5q2hABiMO7cp6jcIg96CDh1Efb3g1PWA4=
1029+
github.com/hashicorp/cronexpr v1.1.1 h1:NJZDd87hGXjoZBdvyCF9mX4DCq5Wy7+A/w+A7q0wn6c=
1030+
github.com/hashicorp/cronexpr v1.1.1/go.mod h1:P4wA0KBl9C5q2hABiMO7cp6jcIg96CDh1Efb3g1PWA4=
10311031
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
10321032
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
10331033
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
@@ -1116,8 +1116,8 @@ github.com/hashicorp/mdns v1.0.1/go.mod h1:4gW7WsVCke5TE7EPeYliwHlRUyBtfCwuFwuMg
11161116
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
11171117
github.com/hashicorp/memberlist v0.2.2 h1:5+RffWKwqJ71YPu9mWsF7ZOscZmwfasdA8kbdC7AO2g=
11181118
github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE=
1119-
github.com/hashicorp/nomad/api v0.0.0-20210907162733-cf7675a376b9 h1:MJohpDqE60LZmJXdhTdnUz3n4dW/0C5OQWkpqbQSETM=
1120-
github.com/hashicorp/nomad/api v0.0.0-20210907162733-cf7675a376b9/go.mod h1:vYHP9jMXk4/T2qNUbWlQ1OHCA1hHLil3nvqSmz8mtgc=
1119+
github.com/hashicorp/nomad/api v0.0.0-20220426182820-059c89dff073 h1:Rvw2TS44h5hrKXWxIf6wd5EeFoo3+tCsDY9plo5X7DY=
1120+
github.com/hashicorp/nomad/api v0.0.0-20220426182820-059c89dff073/go.mod h1:b/AoT79m3PEpb6tKCFKva/M+q1rKJNUk5mdu1S8DymM=
11211121
github.com/hashicorp/opaqueany v0.0.0-20220321170339-a5c6ff5bb0ec h1:WfdoyL0vJ+mQWaUdzNMkk+o1ACVa6aO2i9AzGPboF5k=
11221122
github.com/hashicorp/opaqueany v0.0.0-20220321170339-a5c6ff5bb0ec/go.mod h1:adXen43rUDlxaaEpSsu3lcG4bfteZNptunpxPvx0sW8=
11231123
github.com/hashicorp/protostructure v0.0.0-20220321173139-813f7b927cb7 h1:jTrmnIPP65IvMLaFr05QzwGGHpK2rMpwFxqh9n3nv3o=
@@ -1414,8 +1414,9 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh
14141414
github.com/mitchellh/mapstructure v1.3.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
14151415
github.com/mitchellh/mapstructure v1.3.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
14161416
github.com/mitchellh/mapstructure v1.3.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
1417-
github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
14181417
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
1418+
github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs=
1419+
github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
14191420
github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f/go.mod h1:OkQIRizQZAeMln+1tSwduZz7+Af5oFlKirV/MSYes2A=
14201421
github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A=
14211422
github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4=
@@ -1791,8 +1792,9 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
17911792
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
17921793
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
17931794
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
1794-
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
17951795
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
1796+
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
1797+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
17961798
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
17971799
github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
17981800
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=

website/content/partials/components/platform-nomad-jobspec-canary.mdx

+9-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,15 @@ Uses the runner config environment variable VAULT_TOKEN.
108108

109109
### Optional Parameters
110110

111-
This plugin has no optional parameters.
111+
These parameters are used in the [`use` stanza](/docs/waypoint-hcl/use) for this plugin.
112+
113+
#### hcl1
114+
115+
Parses jobspec as HCL1 instead of HCL2.
116+
117+
- Type: **bool**
118+
- **Optional**
119+
- Default: false
112120

113121
### Output Attributes
114122

website/content/partials/components/platform-nomad-jobspec.mdx

+9-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,15 @@ Uses the runner config environment variable VAULT_TOKEN.
108108

109109
### Optional Parameters
110110

111-
This plugin has no optional parameters.
111+
These parameters are used in the [`use` stanza](/docs/waypoint-hcl/use) for this plugin.
112+
113+
#### hcl1
114+
115+
Parses jobspec as HCL1 instead of HCL2.
116+
117+
- Type: **bool**
118+
- **Optional**
119+
- Default: false
112120

113121
### Output Attributes
114122

0 commit comments

Comments
 (0)