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

Support HCL2 file function in jobspec #191

Closed
lgfa29 opened this issue Jan 16, 2021 · 0 comments · Fixed by #192
Closed

Support HCL2 file function in jobspec #191

lgfa29 opened this issue Jan 16, 2021 · 0 comments · Fixed by #192

Comments

@lgfa29
Copy link
Contributor

lgfa29 commented Jan 16, 2021

Terraform Version

Terraform v0.14.4
+ provider hashicorp.com/dev/nomad v0.14.2

Nomad Version

Name                          Address    Port  Status  Leader  Protocol  Build  Datacenter  Region
laoqui-hc-mbp-6.local.global  127.0.0.1  4648  alive   true    2         1.0.1  dc1         global

Provider Configuration

provider "nomad" {
  address = "http://localhost:4646"
}

Environment Variables

No

Affected Resource(s)

  • nomad_job

Terraform Configuration Files

main.tf

provider "nomad" {
  address = "http://localhost:4646"
}

resource "nomad_job" "nginx" {
  jobspec = file("${path.root}/nginx.nomad")
  hcl2    = true
}

nginx.nomad

job "nginx" {
  datacenters = ["dc1"]

  group "nginx" {
    network {
      port "http" {
        to     = 8080
        static = 8080
      }
    }

    task "nginx" {
      driver = "docker"

      config {
        image = "nginx:1.19"
        ports = ["http"]
        volumes = [
          "local/nginx/hello.conf:/etc/nginx/conf.d/hello.conf",
          "local/www:/www/data"
        ]
      }

      template {
        data        = <<EOF
server {
  root /www/data;
  listen {{ env "NOMAD_PORT_http" }};
}
EOF
        destination = "local/nginx/hello.conf"
      }

      template {
        data        = file("./index.html")
        destination = "local/www/index.html"
      }
    }
  }
}

index.html

<html>
  <head>
    <title>Hello, World!</title>
  </head>
  <body>
    <p>Hello, World!</p>
  </body>
</html>

Expected Behavior

The nginx job is created with the index page content read from index.html.

Actual Behavior

$ terraform plan

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

Error: error parsing jobspec: job "nginx" {
  datacenters = ["dc1"]

  group "nginx" {
    network {
      port "http" {
        to     = 8080
        static = 8080
      }
    }

    task "nginx" {
      driver = "docker"

      config {
        image = "nginx:1.19"
        ports = ["http"]
        volumes = [
          "local/nginx/hello.conf:/etc/nginx/conf.d/hello.conf",
          "local/www:/www/data"
        ]
      }

      template {
        data        = <<EOF
server {
  root /www/data;
  listen {{ env "NOMAD_PORT_http" }};
}
EOF
        destination = "local/nginx/hello.conf"
      }

      template {
        data        = file("./index.html")
        destination = "local/www/index.html"
      }
    }
  }
}
:35,23-28: Error in function call; Call to function "file" failed: filesystem function disabled.
job "nginx" {
  datacenters = ["dc1"]

  group "nginx" {
    network {
      port "http" {
        to     = 8080
        static = 8080
      }
    }

    task "nginx" {
      driver = "docker"

      config {
        image = "nginx:1.19"
        ports = ["http"]
        volumes = [
          "local/nginx/hello.conf:/etc/nginx/conf.d/hello.conf",
          "local/www:/www/data"
        ]
      }

      template {
        data        = <<EOF
server {
  root /www/data;
  listen {{ env "NOMAD_PORT_http" }};
}
EOF
        destination = "local/nginx/hello.conf"
      }

      template {
        data        = file("./index.html")
        destination = "local/www/index.html"
      }
    }
  }
}
:35,23-28: Unsuitable value type; Unsuitable value: value must be known

  on main.tf line 14, in resource "nomad_job" "nginx":
  14: resource "nomad_job" "nginx" {

Steps to Reproduce

  1. terraform plan

References

@lgfa29 lgfa29 changed the title Support HCL2 functions in jobspec Support HCL2 file function in jobspec Jan 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant