hashicorp / terraform-provider-nomad

Terraform Nomad provider
https://registry.terraform.io/providers/hashicorp/nomad/latest
Mozilla Public License 2.0
144 stars 101 forks source link

could not use argument "parameters" inside resource "nomad_csi_volume" #395

Closed maxadamo closed 10 months ago

maxadamo commented 10 months ago

Terraform Version

Terraform v1.6.5

Nomad Version

$ nomad server members
Name                        Address       Port  Status  Leader  Raft Version  Build  Datacenter  Region
test-nomad-server01.global  83.xx.xx.xx.xxx  4648  alive   false   3             1.6.3  test-xxxx  global
test-nomad-server02.global  83.xx.xx.xx.xxx  4648  alive   false   3             1.6.3  test-xxxx  global
test-nomad-server03.global  83.xx.xx.xx.xxx  4648  alive   true    3             1.6.3  test-xxxx  global

Provider Configuration

Which values are you setting in the provider configuration?

provider "nomad" {
  provider "nomad" {}  # provider parameters supplied through variables
}

Environment Variables

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

env | grep "NOMAD_"
NOMAD_TOKEN=xxxxxxxxxxxxxxxx
NOMAD_SKIP_VERIFY=true
NOMAD_ENV=test
NOMAD_ADDR=https://test-nomad-ui.example.org:4646
NOMAD_CACERT=/tmp/COMODO_OV.crt

Affected Resource(s)

Terraform Configuration Files

terraform {
  required_providers {
    nomad = {
      source  = "hashicorp/nomad"
      version = "~> 2.0"
    }
    consul = {
      source  = "hashicorp/consul"
      version = "2.16.2"
    }
  }

  backend "consul" {
    ca_file = "/tmp/COMODO_OV.crt"
    path    = "nomad/terraform_states/cds/tfstate"
    lock    = "true"
  }
}

provider "nomad" {}  # provider parameters supplied through variables
provider "consul" {} # provider parameters supplied through variables

data "nomad_plugin" "kadalu" {
  plugin_id        = "kadalu-csi"
  wait_for_healthy = true
}

data "consul_keys" "cds" {
  datacenter = "xxxx"

  key {
    name = "nomad_env"
    path = "nomad/${terraform.workspace}/common/nomad_env"
  }
  key {
    name = "url_prefix_env"
    path = "nomad/${terraform.workspace}/common/url_prefix_env"
  }
  key {
    name = "version"
    path = "nomad/${terraform.workspace}/cds/version"
  }
}

locals {
  nomad_env = data.consul_keys.cds.var.nomad_env
}

resource "nomad_csi_volume" "cds_volume" {
  depends_on = [data.nomad_plugin.kadalu]
  lifecycle {
    prevent_destroy = true
  }

  plugin_id    = "kadalu-csi"
  volume_id    = "cds_volume"
  name         = "cds_volume"
  capacity_min = "10GiB"
  capacity_max = "20GiB"

  capability {
    access_mode     = "multi-node-reader-only"
    attachment_mode = "file-system"
  }

  mount_options {
    fs_type = "xfs"
  }

  parameters {
    kadalu_format   = "native"
    storage_name    = "csi-pool"
    gluster_hosts   = "${local.nomad_env}-par-gluster01.example.org,${local.nomad_env}-par-gluster02.example.org,${local.nomad_env}-par-gluster03.example.org"
    gluster_volname = "csi"
  }
}

resource "nomad_job" "cds" {
  depends_on = [resource.nomad_csi_volume.cds_volume]
  hcl2 {
    vars = {
      nomad_env      = data.consul_keys.cds.var.nomad_env,
      url_prefix_env = data.consul_keys.cds.var.url_prefix_env,
      version        = data.consul_keys.cds.var.version
    }
  }

  purge_on_destroy = true
  jobspec          = file("${path.module}/cds.nomad")

  provisioner "local-exec" {
    when    = destroy
    command = "nomad system gc"
  }
}

Debug Output

if necessary I can add the debug output.

Panic Output

If Terraform produced a panic, please provide a link to a GitHub Gist containing the output of the crash.log.

Expected Behavior

I should be able to use this parameter: https://registry.terraform.io/providers/hashicorp/nomad/latest/docs/resources/csi_volume#parameters

Actual Behavior

╷
│ Error: Unsupported block type
│
│   on main.tf line 74, in resource "nomad_csi_volume" "cds_volume":
│   74:   parameters {
│
│ Blocks of type "parameters" are not expected here. Did you mean to define argument "parameters"? If so, use the equals sign to assign it a value.
╵

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform plan or terraform apply

Important Factoids

n/a

References

n/a

jrasell commented 10 months ago

Hi @maxadamo and thanks for raising this issue. The parameters configuration is an argument rather than a block and therefore requires an equal sign for assignment as suggested in the Terraform output. If you define your parameters as shown below, I believe the error will be resolved:

  parameters = {
    kadalu_format   = "native"
    storage_name    = "csi-pool"
    gluster_hosts   = "${local.nomad_env}-par-gluster01.example.org,${local.nomad_env}-par-gluster02.example.org,${local.nomad_env}-par-gluster03.example.org"
    gluster_volname = "csi"
  }
maxadamo commented 10 months ago

OMG.... ahahah 😸 I'm closing the issue. Thanks for your quick reply @jrasell !

maxadamo commented 10 months ago

re-opened, just to say, maybe you could add an example in the documentation, to make it clear. Because the parameters is not mentioned in the examples (closing again)