Skip to content

TF continually wants to update nomad_job resource between plan/apply #290

@kian

Description

@kian

Terraform Version

Terraform v1.0.0
Nomad provider version 1.4.17

Nomad Version

1.1.0

Provider Configuration

Which values are you setting in the provider configuration?

nomad = {
  source = "hashicorp/nomad"
  version = "1.4.17"
}

provider "nomad" {
  address = "https://nomad.service./${var.datacenter}.internal:4646"
  region  = "global"
}

Environment Variables

No

Affected Resource(s)

Please list the resources as a list, for example:

  • nomad_job

Terraform Configuration Files

Terraform:

variable "datacenter" {
  type        = string
  description = "Datacenter ID to deploy the job to"
}

resource "nomad_job" "cassandra_stage" {
  jobspec = templatefile("${path.module}/cassandra-stage.hcl",
            { datacenter = var.datacenter })
}

Job spec template:

job "cassandra_stage" {
  datacenters = ["${datacenter}"]
  type = "service"
  update {
    max_parallel = 1
    stagger      = "1m"
  }
  group "cassandra-1.50" {
    constraint {
      attribute = "$${attr.unique.network.ip-address}"
      value     = "10.10.1.50"
    }
    restart {
      attempts = 10
      delay    = "30s"
      interval = "30m"
      mode     = "delay"
    }
    task "cassandra-1-50" {
      driver = "docker"
      config {
        image = "ecr-proxy.service.xxx.internal/internal/cassandra:master-20220105-39f4ce4a0"
        port_map = {
          rpc    = 9160
          gossip = 7000
        }
        network_mode = "host"
        logging {
          type = "gelf"
          config {
            gelf-address = "udp://$${node.unique.name}:12201"
            tag = "cassandra"
          }
        }
        volumes = [
          "/mnt/ebs/cassandra/:/srv/var/"
        ]
      }
      service {
        name = "cassandra"
        port = "rpc"
      }
      env {
        CLUSTER_NAME                       = "${datacenter}"
        SEEDS                              = "10.10.2.50,10.10.2.51,10.10.3.51,10.10.3.52"
        LISTEN_ADDRESS                     = "$${NOMAD_IP_rpc}"
        HEAP                               = "8G"
        KEY_CACHE_MB                       = "1024"
        COMPACTION_THROUGHPUT_MB           = "8"
        STREAM_THROUGHPUT_MEGABITS_PER_SEC = "400"
        ENABLE_HINTED_HANDOFF              = "true"
      }
      kill_timeout = "300s"
      resources {
        cpu    = 10000
        memory = 18432
        network {
          mbits = 100
          port "rpc" {
            static = 9160
          }
          port "gossip" {
            static = 7000
          }
        }
      }
    }
  }
  group "cassandra-2.50" {
    constraint {
      attribute = "$${attr.unique.network.ip-address}"
      value     = "10.10.2.50"
    }
    restart {
      attempts = 10
      delay    = "30s"
      interval = "30m"
      mode     = "delay"
    }
    task "cassandra-2-50" {
      driver = "docker"
      config {
        image = "ecr-proxy.service.xxx.internal/internal/cassandra:master-20220105-39f4ce4a0"
        port_map = {
          rpc    = 9160
          gossip = 7000
        }
        network_mode = "host"
        logging {
          type = "gelf"
          config {
            gelf-address = "udp://$${node.unique.name}:12201"
            tag = "cassandra"
          }
        }
        volumes = [
          "/mnt/ebs/cassandra/:/srv/var/"
        ]
      }
      service {
        name = "cassandra"
        port = "rpc"
      }
      env {
        CLUSTER_NAME                       = "${datacenter}"
        SEEDS                              = "10.10.1.50,10.10.2.51,10.10.3.51,10.10.3.52"
        LISTEN_ADDRESS                     = "$${NOMAD_IP_rpc}"
        HEAP                               = "8G"
        KEY_CACHE_MB                       = "1024"
        COMPACTION_THROUGHPUT_MB           = "8"
        STREAM_THROUGHPUT_MEGABITS_PER_SEC = "400"
        ENABLE_HINTED_HANDOFF              = "true"
      }
      kill_timeout = "300s"
      resources {
        cpu    = 10000
        memory = 18432
        network {
          mbits = 100
          port "rpc" {
            static = 9160
          }
          port "gossip" {
            static = 7000
          }
        }
      }
    }
  }
  group "cassandra-1.51" {
    constraint {
      attribute = "$${attr.unique.network.ip-address}"
      value     = "10.10.1.51"
    }
    restart {
      attempts = 10
      delay    = "30s"
      interval = "30m"
      mode     = "delay"
    }
    task "cassandra-1-51" {
      driver = "docker"
      config {
        image = "ecr-proxy.service.xxx.internal/internal/cassandra:master-20220105-39f4ce4a0"
        port_map = {
          rpc    = 9160
          gossip = 7000
        }
        network_mode = "host"
        logging {
          type = "gelf"
          config {
            gelf-address = "udp://$${node.unique.name}:12201"
            tag = "cassandra"
          }
        }
        volumes = [
          "/mnt/ebs/cassandra/:/srv/var/"
        ]
      }
      service {
        name = "cassandra"
        port = "rpc"
      }
      env {
        CLUSTER_NAME                       = "${datacenter}"
        SEEDS                              = "10.10.1.50,10.10.2.50,10.10.2.51"
        LISTEN_ADDRESS                     = "$${NOMAD_IP_rpc}"
        HEAP                               = "8G"
        KEY_CACHE_MB                       = "1024"
        COMPACTION_THROUGHPUT_MB           = "8"
        STREAM_THROUGHPUT_MEGABITS_PER_SEC = "400"
        ENABLE_HINTED_HANDOFF              = "true"
      }
      kill_timeout = "300s"
      resources {
        cpu    = 10000
        memory = 18432
        network {
          mbits = 100
          port "rpc" {
            static = 9160
          }
          port "gossip" {
            static = 7000
          }
        }
      }
    }
  }
  group "cassandra-2.51" {
    constraint {
      attribute = "$${attr.unique.network.ip-address}"
      value     = "10.10.2.51"
    }
    restart {
      attempts = 10
      delay    = "30s"
      interval = "30m"
      mode     = "delay"
    }
    task "cassandra-2-51" {
      driver = "docker"
      config {
        image = "ecr-proxy.service.xxx.internal/internal/cassandra:master-20220105-39f4ce4a0"
        port_map = {
          rpc    = 9160
          gossip = 7000
        }
        network_mode = "host"
        logging {
          type = "gelf"
          config {
            gelf-address = "udp://$${node.unique.name}:12201"
            tag = "cassandra"
          }
        }
        volumes = [
          "/mnt/ebs/cassandra/:/srv/var/"
        ]
      }
      service {
        name = "cassandra"
        port = "rpc"
      }
      env {
        CLUSTER_NAME                       = "${datacenter}"
        SEEDS                              = "10.10.1.50,10.10.2.50,10.10.3.51,10.10.3.52"
        LISTEN_ADDRESS                     = "$${NOMAD_IP_rpc}"
        HEAP                               = "8G"
        KEY_CACHE_MB                       = "1024"
        COMPACTION_THROUGHPUT_MB           = "8"
        STREAM_THROUGHPUT_MEGABITS_PER_SEC = "400"
        ENABLE_HINTED_HANDOFF              = "true"
      }
      kill_timeout = "300s"
      resources {
        cpu    = 10000
        memory = 18432
        network {
          mbits = 100
          port "rpc" {
            static = 9160
          }
          port "gossip" {
            static = 7000
          }
        }
      }
    }
  }
  group "cassandra-3.51" {
    constraint {
      attribute = "$${attr.unique.network.ip-address}"
      value     = "10.10.3.51"
    }
    restart {
      attempts = 10
      delay    = "30s"
      interval = "30m"
      mode     = "delay"
    }
    task "cassandra-3-51" {
      driver = "docker"
      config {
        image = "ecr-proxy.service.xxx.internal/internal/cassandra:master-20220105-39f4ce4a0"
        port_map = {
          rpc    = 9160
          gossip = 7000
        }
        network_mode = "host"
        logging {
          type = "gelf"
          config {
            gelf-address = "udp://$${node.unique.name}:12201"
            tag = "cassandra"
          }
        }
        volumes = [
          "/mnt/ebs/cassandra/:/srv/var/"
        ]
      }
      service {
        name = "cassandra"
        port = "rpc"
      }
      env {
        CLUSTER_NAME                       = "${datacenter}"
        SEEDS                              = "10.10.1.50,10.10.2.50,10.10.2.51,10.10.3.52"
        LISTEN_ADDRESS                     = "$${NOMAD_IP_rpc}"
        HEAP                               = "8G"
        KEY_CACHE_MB                       = "1024"
        COMPACTION_THROUGHPUT_MB           = "8"
        STREAM_THROUGHPUT_MEGABITS_PER_SEC = "400"
        ENABLE_HINTED_HANDOFF              = "true"
      }
      kill_timeout = "300s"
      resources {
        cpu    = 10000
        memory = 18432
        network {
          mbits = 100
          port "rpc" {
            static = 9160
          }
          port "gossip" {
            static = 7000
          }
        }
      }
    }
  }
  group "cassandra-3.52" {
    constraint {
      attribute = "$${attr.unique.network.ip-address}"
      value     = "10.10.3.52"
    }
    restart {
      attempts = 10
      delay    = "30s"
      interval = "30m"
      mode     = "delay"
    }
    task "cassandra-3-52" {
      driver = "docker"
      config {
        image = "ecr-proxy.service.xxx.internal/internal/cassandra:master-20220105-39f4ce4a0"
        port_map = {
          rpc    = 9160
          gossip = 7000
        }
        network_mode = "host"
        logging {
          type = "gelf"
          config {
            gelf-address = "udp://$${node.unique.name}:12201"
            tag = "cassandra"
          }
        }
        volumes = [
          "/mnt/ebs/cassandra/:/srv/var/"
        ]
      }
      service {
        name = "cassandra"
        port = "rpc"
      }
      env {
        CLUSTER_NAME                       = "${datacenter}"
        SEEDS                              = "10.10.1.50,10.10.2.50,10.10.2.51,10.10.3.51"
        LISTEN_ADDRESS                     = "$${NOMAD_IP_rpc}"
        HEAP                               = "8G"
        KEY_CACHE_MB                       = "1024"
        COMPACTION_THROUGHPUT_MB           = "8"
        STREAM_THROUGHPUT_MEGABITS_PER_SEC = "400"
        ENABLE_HINTED_HANDOFF              = "true"
      }
      kill_timeout = "300s"
      resources {
        cpu    = 10000
        memory = 18432
        network {
          mbits = 100
          port "rpc" {
            static = 9160
          }
          port "gossip" {
            static = 7000
          }
        }
      }
    }
  }
}

Expected Behavior

terraform plan and terraform apply do not continually report a difference in nomad_job attributes such as allocation_ids and region.

Actual Behavior

terraform plan followed by terraform apply constantly show a change in the nomad job resource.

first plan, followed by apply:

# module.cassandra_stage.nomad_job.cassandra_stage will be updated in-place
  ~ resource "nomad_job" "cassandra_stage" {
      ~ allocation_ids          = [
          - "d7ead8f3-6668-316b-2593-d8e3c02a725d",
          - "01820573-0c0d-0321-9a32-bd8966f6e366",
          - "874ec969-80c1-a344-1f3c-0d174ed9ec02",
          - "0c7e412d-cc7d-832b-e1d9-d4f345104d37",
          - "02d16058-65d5-3a68-502d-051a58c4b6e9",
          - "ad8a8744-f776-3636-bd4c-31ee82db23b4",
        ] -> (known after apply)
        id                      = "cassandra_stage"
      ~ modify_index            = "5289351" -> (known after apply)
        name                    = "cassandra_stage"
      ~ region                  = "global" -> (known after apply)
        # (8 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

after applying, second plan:

# module.cassandra_stage.nomad_job.cassandra_stage will be updated in-place
  ~ resource "nomad_job" "cassandra_stage" {
      ~ allocation_ids          = [
          - "d7ead8f3-6668-316b-2593-d8e3c02a725d",
          - "01820573-0c0d-0321-9a32-bd8966f6e366",
          - "874ec969-80c1-a344-1f3c-0d174ed9ec02",
          - "0c7e412d-cc7d-832b-e1d9-d4f345104d37",
          - "02d16058-65d5-3a68-502d-051a58c4b6e9",
          - "ad8a8744-f776-3636-bd4c-31ee82db23b4",
        ] -> (known after apply)
        id                      = "cassandra_stage"
      ~ modify_index            = "5289351" -> (known after apply)
        name                    = "cassandra_stage"
      ~ region                  = "global" -> (known after apply)
        # (8 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Steps to Reproduce

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

  1. terraform apply && terraform apply

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions