Skip to content

Commit

Permalink
Use provider region as default
Browse files Browse the repository at this point in the history
  • Loading branch information
remilapeyre committed Sep 14, 2020
1 parent f8f5901 commit 3bb1560
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 2 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 @@ -133,6 +134,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
res := ProviderConfig{
client: client,
vaultToken: &vaultToken,
region: &conf.Region,
}

return res, nil
Expand Down
11 changes: 8 additions & 3 deletions nomad/resource_job_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func resourceJobV2() *schema.Resource {
func resourceJobV2Register(d *schema.ResourceData, meta interface{}) error {
client := meta.(ProviderConfig).client
jobDefinition := d.Get("job").([]interface{})[0].(map[string]interface{})
job, err := getJob(jobDefinition)
job, err := getJob(jobDefinition, meta)
if err != nil {
return fmt.Errorf("Failed to get job definition: %v", err)
}
Expand Down Expand Up @@ -206,7 +206,7 @@ func getDuration(d interface{}) (*time.Duration, error) {
// Those functions should have a 1 to 1 correspondance with the ones in
// resource_job_v2_fields to make it easy to check we did not forget anything

func getJob(d map[string]interface{}) (*api.Job, error) {
func getJob(d map[string]interface{}, meta interface{}) (*api.Job, error) {
datacenters := getListOfString(d["datacenters"])

var parametrizedJob *api.ParameterizedJobConfig
Expand Down Expand Up @@ -246,6 +246,11 @@ func getJob(d map[string]interface{}) (*api.Job, error) {
ID = getString(d, "name")
}

region := getString(d, "region")
if region == nil {
region = meta.(ProviderConfig).region
}

return &api.Job{
ID: ID,
Name: getString(d, "name"),
Expand All @@ -255,7 +260,7 @@ func getJob(d map[string]interface{}) (*api.Job, error) {
Meta: getMapOfString(d["meta"]),
AllAtOnce: getBool(d, "all_at_once"),
Datacenters: datacenters,
Region: getString(d, "region"),
Region: region,
VaultToken: getString(d, "vault_token"),
ConsulToken: getString(d, "consul_token"),

Expand Down
2 changes: 1 addition & 1 deletion nomad/resource_job_v2_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func getJobFields() map[string]*schema.Schema {
},
"region": {
Type: schema.TypeString,
Default: "global",
Computed: true,
Optional: true,
},
"meta": {
Expand Down

0 comments on commit 3bb1560

Please sign in to comment.