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 support for datacenter field on connect upstreams stanza #193

Closed
yaroslav-007 opened this issue Jan 19, 2021 · 6 comments
Closed

Comments

@yaroslav-007
Copy link

Hi there,

I am working on a learning project. I am at step where I have to use consul connect between two datacenters. The setting in a nomad job file should be as follows:

        connect {
          sidecar_service {
            proxy {
              upstreams {
                  destination_name = "mariadb-server"
                  local_bind_port  = 5000
                  datacenter = "dc2"
              }

            }
          }
        }

Nomad has added support for datacenter field on connect upstreams recently: hashicorp/nomad#8964

The nomad job run wordpress.nomad with the above setting is successful , but nomad provider fails to deploy this file with error invalid key: datacenter. I am using latest nomad (Nomad v1.0.2 ) and nomad provider (nomad v1.4.11)

Terraform Version

terraform -v
Terraform v0.14.4
+ provider registry.terraform.io/hashicorp/consul v2.11.0
+ provider registry.terraform.io/hashicorp/google v3.52.0
+ provider registry.terraform.io/hashicorp/nomad v1.4.11

Nomad Version

nomad server members
Name Address Port Status Leader Protocol Build Datacenter Region
dc1-nomad-server-0.global 10.2.0.7 4648 alive false 2 1.0.2 dc1 global
dc1-nomad-server-1.global 10.2.0.9 4648 alive false 2 1.0.2 dc1 global
dc1-nomad-server-2.global 10.2.0.10 4648 alive true 2 1.0.2 dc1 global

Provider Configuration

provider "nomad" {
  alias     = "dc1"
  address   = "https://dc1-nomad.example.com:4646"
  ca_file   = "../certs/${var.dc1.datacenter}-nomad-certs/nomad-ca.pem"
  cert_file = "./certs//uploads/${var.dc1.datacenter}-nomad-certs/server.pem"
  key_file  = "../certs//uploads/${var.dc1.datacenter}-nomad-certs/server-key.pem"
}

Environment Variables

Do you have any Nomad specific environment variable set in the machine running Terraform? -> NO

NOMAD_CACERT=~/nomad-ca.pem
NOMAD_CLIENT_CERT=~/cli.pem
NOMAD_CLIENT_KEY=~/cli-key.pem
NOMAD_ADDR=https://localhost:4646

Affected Resource(s)

Please list the resources as a list, for example:

  • nomad_job

Terraform Configuration Files

resource "nomad_job" "wordpress" {
  depends_on = [nomad_volume.wordpress_volume]
  provider   = nomad.dc1
  jobspec    = file("./nomad-jobs/wordpress.nomad")

}

Debug Output

N/A

Panic Output

N/A

Expected Behavior

terraform apply should be successful

Actual Behavior

Error: error parsing jobspec: error parsing 'job': group: 'wordpress', task: 'wordpress-task', service (0): 'wordpress', sidecar_service, proxy, 1 error occurred:
        * upstream -> invalid key: datacenter
@lgfa29
Copy link
Contributor

lgfa29 commented Jan 19, 2021

Thank you for the report @yaroslav-007.

We updated our Nomad dependency in #166, so this won't be a problem anymore.

I will leave this open until the new version is out and you can confirm that the problem is fixed.

@lgfa29
Copy link
Contributor

lgfa29 commented Jan 20, 2021

Hi @yaroslav-007,

v0.14.12 is out now, could you update the provider and check if this problem is fixed?

@yaroslav-007
Copy link
Author

Hello,
Still the same:

nomad_job.mariadb: Refreshing state... [id=mariadb]

Error: error parsing jobspec: error parsing 'job': group: 'wordpress', task: 'wordpress-task', service (0): 'wordpress', sidecar_service, proxy, 1 error occurred:
        * upstream -> invalid key: datacenter



  on wordpress.tf line 66, in resource "nomad_job" "wordpress":
  66: resource "nomad_job" "wordpress" {


terraform providers -version
Terraform v0.14.4
+ provider registry.terraform.io/hashicorp/consul v2.11.0
+ provider registry.terraform.io/hashicorp/google v3.53.0
+ provider registry.terraform.io/hashicorp/nomad v1.4.12

@lgfa29
Copy link
Contributor

lgfa29 commented Jan 20, 2021

Oh, this field was added after HCL2 support, so only the HCL2 parser recognizes it.

Could you update your Terraform config file to use HCL2 parsing and try again?

@yaroslav-007
Copy link
Author

Hello,

I can confirm that it works now

@lgfa29
Copy link
Contributor

lgfa29 commented Jan 21, 2021

Awesome, glad to hear that 😄

I will go ahead and close this issue.

@lgfa29 lgfa29 closed this as completed Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants