Answers: <p>It looks like there are two different problems here, so I'll answer them separately.</p>
  
  <hr>
  
  <p>First, we'll talk about the errors of this type:</p>
  
  <pre><code>Error: Unsupported argument
  
    on main.tf line 8, in resource "docker_service" "mysql-service":
     8:       secrets = {
  
  An argument named "secrets" is not expected here. Did you mean to define a
  block of type "secrets"?
  </code></pre>
  
  <p>This error is talking about the distinction described in the Terraform documentation section <a href="https://www.terraform.io/docs/configuration/syntax.html#arguments-and-blocks" rel="nofollow noreferrer">Arguments and Blocks</a>, and is telling you that <code>secrets</code> is defined in the provider's schema as using nested block syntax rather than argument syntax.</p>
  
  <p>The syntax for nested blocks and the syntax for literal object values are both similar in that they use <code>{</code> <code>}</code> as delimiters, but the meaning of these and what is valid inside the braces in each case is distinct.</p>
  
  <p>To fix this, you can use the block syntax to define these nested objects:</p>
  
  <pre><code>  secrets {
      secret_id   = docker_secret.mysql_root_password.id
      secret_name = docker_secret.mysql_root_password.name
      file_name   = "/run/secrets/${docker_secret.mysql_root_password.name}"
    }
    secrets {
      secret_id   = docker_secret.mysql_db_password.id
      secret_name = docker_secret.mysql_db_password.name
      file_name   = "/run/secrets/${docker_secret.mysql_db_password.name}"
    }
  </code></pre>
  
  <p>The same is true for the <code>mounts</code> block type:</p>
  
  <pre><code>  mounts {
      target = "/var/lib/mysql"
      source = docker_volume.mysql_data_volume.name
      type   = "volume"
    }
  </code></pre>
  
  <hr>
  
  <p>The other error message you saw is an unrelated problem:</p>
  
  <pre><code>Error: Incorrect attribute value type
  
    on main.tf line 34, in resource "docker_service" "mysql-service":
    34:     networks = "docker_network.private_overlay_network.name"
  
  Inappropriate value for attribute "networks": set of string required.
  </code></pre>
  
  <p>This error is saying that the <code>networks</code> argument requires a set of strings, but the value you gave here is a single string. This is happening because you've put the reference expression in quotes, and so Terraform assumes you are intending to give a literal string rather than a reference here. The first step to address this is to remove the quotes so to make this a <a href="https://www.terraform.io/docs/configuration/expressions.html#references-to-named-values" rel="nofollow noreferrer">reference expression</a> rather than a <a href="https://www.terraform.io/docs/configuration/expressions.html#literal-expressions" rel="nofollow noreferrer">literal expression</a>:</p>
  
  <pre><code>  networks = docker_network.private_overlay_network.name
  </code></pre>
  
  <p>That's not sufficient for this particular situation though, because this <code>name</code> attribute is just a single string rather than a set of strings, and so the above change alone will not fully fix the problem. To address this secondary problem we can use brackets <code>[</code> <code>]</code> to construct a single-element sequence:</p>
  
  <pre><code>  networks = [docker_network.private_overlay_network.name]
  </code></pre>
  
  <p>This argument expects a set of strings rather than a sequence of strings, but that's okay here because Terraform will automatically convert the sequence into a set. (A set is an unordered collection of distinct values, whereas a sequence is an ordered collection of values that may contain duplicates.)</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-05-06T17:22:55.240Z
Answers: you nailed it martin!its working..!thanks!
  @arcege fyi
  
  https://github.com/sivatest82/Terraform1/tree/master/secretsv12_martin_changes
Answers: Sivakumarj
Answers: CC BY-SA 4.0
Answers: 2020-05-05T18:21:57.377Z
Answers: 2020-05-05T18:21:57.377Z
Answers: Martin Atkins
Answers: <p>These were made as <a href="https://github.com/hashicorp/terraform/issues/19424" rel="nofollow noreferrer">errors in 0.12</a>.  You need to put these into tfvars file in a <a href="https://www.terraform.io/docs/configuration/locals.html" rel="nofollow noreferrer">locals definition</a>. </p>
  
  <pre><code>locals {
     secret_id = "docker_secret.mysql_db_password.id"
     secret_name = "docker_secret.mysql_db_password.name"
     file_name = "/run/secrets/docker_secret.mysql_db_password.name"
  </code></pre>
  
  <p>}</p>
  
  <p>Update:
  Using a list:</p>
  
  <pre><code>locals {
      secrets = [
          {
              secret_id = "docker_secret.mysql_db_password.id"
              secret_name = "docker_secret.mysql_db_password.name"
              file_name = "/run/secrets/docker_secret.mysql_db_password.name"
          },
          {
              secret_id = "docker_secret.mysql_root_password.id"
              secret_name = "docker_secret.mysql_root_password.name"
              file_name = "/run/secrets/docker_secret.mysql_root_password.name"
          }
      ]
  }
  </code></pre>
  
  <p>Then to access an individual value, use indexing with variable evaluation: <code>${local.secrets[1].file_name}</code>.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-05-03T05:06:08.157Z
Answers: 1)  I already have secrets.tf and variables.tf files for them.. #update2 in the question
  2) If i mention the secret_id,secret_name,file_name in vars.tf, how can i refer them in main.tf
  3) Because the "docker_secret.mysql_db_password.id" and "docker_secret.mysql_db_password.name" are already in secrets.tf file
Answers: Sivakumarj
Answers: CC BY-SA 4.0
Answers: 2020-05-03T16:06:37.333Z
Answers: You access them with variable evaluation, such as `${local.secret_id}`.
Answers: Arcege
Answers: CC BY-SA 4.0
Answers: 2020-05-04T00:16:31.593Z
Answers: ok. but what if , if i have two secrets.. as mentioned in my example
Answers: Sivakumarj
Answers: CC BY-SA 4.0
Answers: 2020-05-04T00:38:40.937Z
Answers: I've updated with the example from the OP
Answers: Arcege
Answers: CC BY-SA 4.0
Answers: 2020-05-05T03:04:35.853Z
Answers: yeap able to compile.. but **scenario** 1)mentioning secrets in main.tf along with tfvars.tf file.. getting error while applying the plan . Error updated in the question **scenario** 2) not mentioning secrets in main.tf but with tfvars.tf file  .. able to apply plan.. but mysql service is not coming up.. it comes up and goes down in seconds..may be it is searching for secrets in the main.tf file?
Answers: Sivakumarj
Answers: CC BY-SA 4.0
Answers: 2020-05-05T03:25:08.820Z
Answers: complete code @ https://github.com/sivatest82/Terraform1/tree/master/secretsv12
Answers: Sivakumarj
Answers: CC BY-SA 4.0
Answers: 2020-05-05T14:08:10.860Z
Answers: After making some adjustments to your code (https://gist.github.com/arcege/c2c17227d7430829b3f5ae8860f8b65f), I can get a successful plan, but when I apply I get `Error: Error response from daemon: rpc error: code = InvalidArgument desc = malformed secret reference` from Docker.  Sounds like Terraform itself isn't the problem.
Answers: Arcege
Answers: CC BY-SA 4.0
Answers: 2020-05-05T17:06:37.533Z
Answers: cool, thanks @arcege . I will try to report this to hashicorp..lets see what they
Answers: Sivakumarj
Answers: CC BY-SA 4.0
Answers: 2020-05-02T20:56:00.190Z
Answers: 2020-05-04T00:38:20.310Z
Answers: 2020-05-04T00:38:20.310Z
Answers: Arcege
Answers: <p>According to the <a href="https://www.terraform.io/docs/providers/docker/r/service.html#advanced" rel="nofollow noreferrer">documentation</a>, you should change your secrets handling to following syntax: </p>
  
  <pre><code>      secrets = [
  
          {
            secret_id   = docker_secret.mysql_db_password.id
            secret_name = docker_secret.mysql_db_password.name
            file_name   = "/run/secrets/${docker_secret.mysql_db_password.name}"
          },
  
          {
            secret_id   = docker_secret.mysql_root_password.id
            secret_name = docker_secret.mysql_root_password.name
            file_name   = "/run/secrets/${docker_secret.mysql_root_password.name}"
          }
        ]
  </code></pre>
  
  <p>So you pass the actual secret ID to the service object and not the Terraform resource reference as a string. The only difference between Terraform 0.11 and 0.12 code is, that in 0.12 you can remove the interpolation syntax (so <code>${}</code>), if you don't actually use it, as you only pass the attribute of other resource, with no additional formatting.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-05-05T03:06:54.427Z
Answers: i have already tried it.. not working in v0.12
Answers: Sivakumarj
Answers: CC BY-SA 4.0
Answers: 2020-05-04T09:43:28.923Z
Answers: 2020-05-04T09:43:28.923Z
Answers: Invidian
Body: <p>I have just upgraded from terraform v0.11 to v0.12
  But i am facing lot of error</p>
  
  <p>complete code @ <a href="https://github.com/sivatest82/Terraform1/tree/master/secretsv12" rel="nofollow noreferrer">https://github.com/sivatest82/Terraform1/tree/master/secretsv12</a></p>
  
  <p>especially in the block</p>
  
  <pre><code> secrets = [
  
      {
        secret_id = "docker_secret.mysql_db_password.id"
        secret_name = "docker_secret.mysql_db_password.name"
        file_name = "/run/secrets/docker_secret.mysql_db_password.name"
      },
  
      {secret_id = "docker_secret.mysql_root_password.id"
        secret_name = "docker_secret.mysql_root_password.name"
        file_name = "/run/secrets/docker_secret.mysql_root_password.name"
      }
    ]
  </code></pre>
  
  <p>v0.11 code which had no issue</p>
  
  <pre><code>   resource "docker_service" "mysql-service" {
    name = "mysql_db"
  
    task_spec {
      container_spec {
        image = "${docker_image.mysql_image.name}"
  
        secrets = [
          {
            secret_id   = "${docker_secret.mysql_root_password.id}"
            secret_name = "${docker_secret.mysql_root_password.name}"
            file_name   = "/run/secrets/${docker_secret.mysql_root_password.name}"
          },
          {
            secret_id   = "${docker_secret.mysql_db_password.id}"
            secret_name = "${docker_secret.mysql_db_password.name}"
            file_name   = "/run/secrets/${docker_secret.mysql_db_password.name}"
          }
        ]
  
        env {
          MYSQL_ROOT_PASSWORD_FILE = "/run/secrets/${docker_secret.mysql_root_password.name}"
          MYSQL_DATABASE           = "mydb"
          MYSQL_PASSWORD_FILE      = "/run/secrets/${docker_secret.mysql_db_password.name}"
        }
  
        mounts = [
          {
            target = "/var/lib/mysql"
            source = "${docker_volume.mysql_data_volume.name}"
            type   = "volume"
          }
        ]
      }
      networks = [
        "${docker_network.private_overlay_network.name}"
      ]
    }
  }
  </code></pre>
  
  <p>v0.12 code </p>
  
  <pre><code>resource "docker_service" "mysql-service" {
    name = "mysql_db"
  
    task_spec {
      container_spec {
        image = "docker_image.mysql_image.name"
  
        secrets = [
  
          {
            secret_id = "docker_secret.mysql_db_password.id"
            secret_name = "docker_secret.mysql_db_password.name"
            file_name = "/run/secrets/docker_secret.mysql_db_password.name"
          },
  
          {secret_id = "docker_secret.mysql_root_password.id"
            secret_name = "docker_secret.mysql_root_password.name"
            file_name = "/run/secrets/docker_secret.mysql_root_password.name"
          }
        ]
  
  
        env = {
          MYSQL_ROOT_PASSWORD_FILE = "/run/secrets/docker_secret.mysql_root_password.name"
          MYSQL_DATABASE           = "mydb"
          MYSQL_PASSWORD_FILE      = "/run/secrets/docker_secret.mysql_db_password.name"
        }
  
        mounts = {
            target = "/var/lib/mysql"
            source = "docker_volume.mysql_data_volume.name"
            type   = "volume"
          }
  
      }
  
      networks = "docker_network.private_overlay_network.name"
  
  
    }
  }
  </code></pre>
  
  <p>Error</p>
  
  <pre><code>[cloud_user@siwgftd9213c secrets]$ terraform validate
  
  Error: Unsupported argument
  
    on main.tf line 8, in resource "docker_service" "mysql-service":
     8:       secrets = {
  
  An argument named "secrets" is not expected here. Did you mean to define a
  block of type "secrets"?
  
  
  Error: Unsupported argument
  
    on main.tf line 26, in resource "docker_service" "mysql-service":
    26:       mounts = {
  
  An argument named "mounts" is not expected here. Did you mean to define a
  block of type "mounts"?
  
  
  Error: Incorrect attribute value type
  
    on main.tf line 34, in resource "docker_service" "mysql-service":
    34:     networks = "docker_network.private_overlay_network.name"
  
  Inappropriate value for attribute "networks": set of string required.
  </code></pre>
  
  <p>I have already have a seperate file for them</p>
  
  <p>Secrets.tf</p>
  
  <pre><code>resource "docker_secret" "mysql_root_password" {
    name = "root_password"
    data = "var.mysql_root_password"
  }
  
  resource "docker_secret" "mysql_db_password" {
    name = "db_password"
    data = "var.mysql_db_password"
  }
  </code></pre>
  
  <p>And variables tf file</p>
  
  <pre><code>variable "mysql_root_password" {
    default     = "cDRzU1dvUmQwIQo="
  }
  
  variable "mysql_db_password" {
    default     = "cDRzU1dvUmQwIQo="
  }
  </code></pre>
  
  <hr>
  
  <p><strong>After tfvars.tf creation</strong> </p>
  
  <ul>
  <li>Able to compile code</li>
  <li>But unable to apply the plan</li>
  </ul>
  
  <blockquote>
    <p>Error: Error response from daemon: rpc error: code = InvalidArgument
    desc = malformed secret reference</p>
    
    <p>on main.tf line 1, in resource "docker_service" "mysql-service":<br>
    1: resource "docker_service" "mysql-service" {</p>
  </blockquote>
  
  <p><strong>main.tf</strong></p>
  
  <pre><code>    resource "docker_service" "mysql-service" {
    name = "mysql_db"
  
    task_spec {
      container_spec {
        image = docker_image.mysql_image.name
  
        secrets {
          file_name = "${local.secrets[0].file_name}"
          secret_id = "${local.secrets[0].secret_id}"
        }
  
        secrets {
          file_name = "${local.secrets[1].file_name}"
          secret_id = "${local.secrets[1].secret_id}"
        }
  
        env = {
          MYSQL_ROOT_PASSWORD_FILE = "/run/secrets/${docker_secret.mysql_root_password.name}"
          MYSQL_DATABASE           = "mydb"
          MYSQL_PASSWORD_FILE      = "/run/secrets/${docker_secret.mysql_db_password.name}"
        }
  
        mounts {
            target = "/var/lib/mysql"
            source = "docker_volume.mysql_data_volume.name"
            type   = "volume"
          }
      }
  
      networks = [docker_network.private_overlay_network.name]
    }
  }
  </code></pre>
  
  <p><strong>tfvars.tf</strong></p>
  
  <pre><code>    locals {
   secrets = [
          {   secret_id   = docker_secret.mysql_root_password.id
              secret_name = docker_secret.mysql_root_password.name
              file_name   = "/run/secrets/${docker_secret.mysql_root_password.name}"
          },
          {
              secret_id   =    docker_secret.mysql_db_password.id
              secret_name =    docker_secret.mysql_db_password.name
              file_name   = "/run/secrets/${docker_secret.mysql_db_password.name}"
         }
      ]
  }
  </code></pre>
  
Comments: CC BY-SA 4.0
Comments: 2020-05-04T20:21:36.490Z
Comments: If you follow [the steps described in the upgrade guide](https://www.terraform.io/upgrade-guides/0-12.html#upgrading-to-terraform-0-12) then the automatic upgrade tool can automatically address these problems. Unfortunately it can only take valid Terraform 0.11 configuration as input, so to use it now would require undoing the manual changes you already made and then running the tool first before making any additional changes.
Comments: Martin Atkins
Comments: CC BY-SA 4.0
Comments: 2020-05-05T03:00:23.870Z
Comments: I am straight away using v0.12.. so i am not upgrading
Comments: Sivakumarj
Comments: CC BY-SA 4.0
Comments: 2020-05-05T06:23:47.177Z
Comments: what i mean is , i installed v0.11 ..written no code, upgraded to v0.12.. written the above code
Comments: Sivakumarj
Comments: CC BY-SA 4.0
Comments: 2020-05-05T18:08:02.110Z
Comments: Ahh, okay! Sorry, I misunderstood your comment that you were upgrading from v0.11 to v0.12.
Comments: Martin Atkins
Tags: <docker><terraform>
Title: Terraform syntax error after V0.12 upgrade
UserDisplayName: Sivakumarj
ThreadText: # Terraform syntax error after V0.12 upgrade
  
  (Asked by: username_0 on 2020-05-02)
  
  I have just upgraded from terraform v0.11 to v0.12
  But i am facing lot of error
  
  complete code @ <https://github.com/sivatest82/Terraform1/tree/master/secretsv12>
  
  especially in the block
  
  ```
   secrets = [
  
      {
        secret_id = "docker_secret.mysql_db_password.id"
        secret_name = "docker_secret.mysql_db_password.name"
        file_name = "/run/secrets/docker_secret.mysql_db_password.name"
      },
  
      {secret_id = "docker_secret.mysql_root_password.id"
        secret_name = "docker_secret.mysql_root_password.name"
        file_name = "/run/secrets/docker_secret.mysql_root_password.name"
      }
    ]
  
  ```
  
  v0.11 code which had no issue
  
  ```
     resource "docker_service" "mysql-service" {
    name = "mysql_db"
  
    task_spec {
      container_spec {
        image = "${docker_image.mysql_image.name}"
  
        secrets = [
          {
            secret_id   = "${docker_secret.mysql_root_password.id}"
            secret_name = "${docker_secret.mysql_root_password.name}"
            file_name   = "/run/secrets/${docker_secret.mysql_root_password.name}"
          },
          {
            secret_id   = "${docker_secret.mysql_db_password.id}"
            secret_name = "${docker_secret.mysql_db_password.name}"
            file_name   = "/run/secrets/${docker_secret.mysql_db_password.name}"
          }
        ]
  
        env {
          MYSQL_ROOT_PASSWORD_FILE = "/run/secrets/${docker_secret.mysql_root_password.name}"
          MYSQL_DATABASE           = "mydb"
          MYSQL_PASSWORD_FILE      = "/run/secrets/${docker_secret.mysql_db_password.name}"
        }
  
        mounts = [
          {
            target = "/var/lib/mysql"
            source = "${docker_volume.mysql_data_volume.name}"
            type   = "volume"
          }
        ]
      }
      networks = [
        "${docker_network.private_overlay_network.name}"
      ]
    }
  }
  
  ```
  
  v0.12 code
  
  ```
  resource "docker_service" "mysql-service" {
    name = "mysql_db"
  
    task_spec {
      container_spec {
        image = "docker_image.mysql_image.name"
  
        secrets = [
  
          {
            secret_id = "docker_secret.mysql_db_password.id"
            secret_name = "docker_secret.mysql_db_password.name"
            file_name = "/run/secrets/docker_secret.mysql_db_password.name"
          },
  
          {secret_id = "docker_secret.mysql_root_password.id"
            secret_name = "docker_secret.mysql_root_password.name"
            file_name = "/run/secrets/docker_secret.mysql_root_password.name"
          }
        ]
  
        env = {
          MYSQL_ROOT_PASSWORD_FILE = "/run/secrets/docker_secret.mysql_root_password.name"
          MYSQL_DATABASE           = "mydb"
          MYSQL_PASSWORD_FILE      = "/run/secrets/docker_secret.mysql_db_password.name"
        }
  
        mounts = {
            target = "/var/lib/mysql"
            source = "docker_volume.mysql_data_volume.name"
            type   = "volume"
          }
  
      }
  
      networks = "docker_network.private_overlay_network.name"
  
    }
  }
  
  ```
  
  Error
  
  ```
  [cloud_user@siwgftd9213c secrets]$ terraform validate
  
  Error: Unsupported argument
  
    on main.tf line 8, in resource "docker_service" "mysql-service":
     8:       secrets = {
  
  An argument named "secrets" is not expected here. Did you mean to define a
  block of type "secrets"?
  
  Error: Unsupported argument
  
    on main.tf line 26, in resource "docker_service" "mysql-service":
    26:       mounts = {
  
  An argument named "mounts" is not expected here. Did you mean to define a
  block of type "mounts"?
  
  Error: Incorrect attribute value type
  
    on main.tf line 34, in resource "docker_service" "mysql-service":
    34:     networks = "docker_network.private_overlay_network.name"
  
  Inappropriate value for attribute "networks": set of string required.
  
  ```
  
  I have already have a seperate file for them
  
  Secrets.tf
  
  ```
  resource "docker_secret" "mysql_root_password" {
    name = "root_password"
    data = "var.mysql_root_password"
  }
  
  resource "docker_secret" "mysql_db_password" {
    name = "db_password"
    data = "var.mysql_db_password"
  }
  
  ```
  
  And variables tf file
  
  ```
  variable "mysql_root_password" {
    default     = "cDRzU1dvUmQwIQo="
  }
  
  variable "mysql_db_password" {
    default     = "cDRzU1dvUmQwIQo="
  }
  
  ```
  
  ---
  
  **After tfvars.tf creation**
  
  * Able to compile code
  * But unable to apply the plan
  
  > Error: Error response from daemon: rpc error: code = InvalidArgument
  > desc = malformed secret reference
  >
  > on main.tf line 1, in resource "docker\_service" "mysql-service":  
  > 1: resource "docker\_service" "mysql-service" {
  
  **main.tf**
  
  ```
      resource "docker_service" "mysql-service" {
    name = "mysql_db"
  
    task_spec {
      container_spec {
        image = docker_image.mysql_image.name
  
        secrets {
          file_name = "${local.secrets[0].file_name}"
          secret_id = "${local.secrets[0].secret_id}"
        }
  
        secrets {
          file_name = "${local.secrets[1].file_name}"
          secret_id = "${local.secrets[1].secret_id}"
        }
  
        env = {
          MYSQL_ROOT_PASSWORD_FILE = "/run/secrets/${docker_secret.mysql_root_password.name}"
          MYSQL_DATABASE           = "mydb"
          MYSQL_PASSWORD_FILE      = "/run/secrets/${docker_secret.mysql_db_password.name}"
        }
  
        mounts {
            target = "/var/lib/mysql"
            source = "docker_volume.mysql_data_volume.name"
            type   = "volume"
          }
      }
  
      networks = [docker_network.private_overlay_network.name]
    }
  }
  
  ```
  
  **tfvars.tf**
  
  ```
      locals {
   secrets = [
          {   secret_id   = docker_secret.mysql_root_password.id
              secret_name = docker_secret.mysql_root_password.name
              file_name   = "/run/secrets/${docker_secret.mysql_root_password.name}"
          },
          {
              secret_id   =    docker_secret.mysql_db_password.id
              secret_name =    docker_secret.mysql_db_password.name
              file_name   = "/run/secrets/${docker_secret.mysql_db_password.name}"
         }
      ]
  }
  
  ```
  
  **Tags:** docker, terraform
  
  > **Comments:**
  > **username_1**: If you follow [the steps described in the upgrade guide](https://www.terraform.io/upgrade-guides/0-12.html#upgrading-to-terraform-0-12) then the automatic upgrade tool can automatically address these problems. Unfortunately it can only take valid Terraform 0.11 configuration as input, so to use it now would require undoing the manual changes you already made and then running the tool first before making any additional changes.  
  > **username_0**: I am straight away using v0.12.. so i am not upgrading  
  > **username_0**: what i mean is , i installed v0.11 ..written no code, upgraded to v0.12.. written the above code  
  > **username_1**: Ahh, okay! Sorry, I misunderstood your comment that you were upgrading from v0.11 to v0.12.  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2020-05-05. Score: 2 | Accepted answer
  
  It looks like there are two different problems here, so I'll answer them separately.
  
  ---
  
  First, we'll talk about the errors of this type:
  
  ```
  Error: Unsupported argument
  
    on main.tf line 8, in resource "docker_service" "mysql-service":
     8:       secrets = {
  
  An argument named "secrets" is not expected here. Did you mean to define a
  block of type "secrets"?
  
  ```
  
  This error is talking about the distinction described in the Terraform documentation section [Arguments and Blocks](https://www.terraform.io/docs/configuration/syntax.html#arguments-and-blocks), and is telling you that `secrets` is defined in the provider's schema as using nested block syntax rather than argument syntax.
  
  The syntax for nested blocks and the syntax for literal object values are both similar in that they use `{` `}` as delimiters, but the meaning of these and what is valid inside the braces in each case is distinct.
  
  To fix this, you can use the block syntax to define these nested objects:
  
  ```
    secrets {
      secret_id   = docker_secret.mysql_root_password.id
      secret_name = docker_secret.mysql_root_password.name
      file_name   = "/run/secrets/${docker_secret.mysql_root_password.name}"
    }
    secrets {
      secret_id   = docker_secret.mysql_db_password.id
      secret_name = docker_secret.mysql_db_password.name
      file_name   = "/run/secrets/${docker_secret.mysql_db_password.name}"
    }
  
  ```
  
  The same is true for the `mounts` block type:
  
  ```
    mounts {
      target = "/var/lib/mysql"
      source = docker_volume.mysql_data_volume.name
      type   = "volume"
    }
  
  ```
  
  ---
  
  The other error message you saw is an unrelated problem:
  
  ```
  Error: Incorrect attribute value type
  
    on main.tf line 34, in resource "docker_service" "mysql-service":
    34:     networks = "docker_network.private_overlay_network.name"
  
  Inappropriate value for attribute "networks": set of string required.
  
  ```
  
  This error is saying that the `networks` argument requires a set of strings, but the value you gave here is a single string. This is happening because you've put the reference expression in quotes, and so Terraform assumes you are intending to give a literal string rather than a reference here. The first step to address this is to remove the quotes so to make this a [reference expression](https://www.terraform.io/docs/configuration/expressions.html#references-to-named-values) rather than a [literal expression](https://www.terraform.io/docs/configuration/expressions.html#literal-expressions):
  
  ```
    networks = docker_network.private_overlay_network.name
  
  ```
  
  That's not sufficient for this particular situation though, because this `name` attribute is just a single string rather than a set of strings, and so the above change alone will not fully fix the problem. To address this secondary problem we can use brackets `[` `]` to construct a single-element sequence:
  
  ```
    networks = [docker_network.private_overlay_network.name]
  
  ```
  
  This argument expects a set of strings rather than a sequence of strings, but that's okay here because Terraform will automatically convert the sequence into a set. (A set is an unordered collection of distinct values, whereas a sequence is an ordered collection of values that may contain duplicates.)
  
  > **Comments:**
  > **username_0**: you nailed it username_1!its working..!thanks! @username_2 fyi  https://github.com/sivatest82/Terraform1/tree/master/secretsv12_martin_changes  
  
  ---
  
  ### Answer by username_2 on 2020-05-02. Score: 1
  
  These were made as [errors in 0.12](https://github.com/hashicorp/terraform/issues/19424). You need to put these into tfvars file in a [locals definition](https://www.terraform.io/docs/configuration/locals.html).
  
  ```
  locals {
     secret_id = "docker_secret.mysql_db_password.id"
     secret_name = "docker_secret.mysql_db_password.name"
     file_name = "/run/secrets/docker_secret.mysql_db_password.name"
  
  ```
  
  }
  
  Update:
  Using a list:
  
  ```
  locals {
      secrets = [
          {
              secret_id = "docker_secret.mysql_db_password.id"
              secret_name = "docker_secret.mysql_db_password.name"
              file_name = "/run/secrets/docker_secret.mysql_db_password.name"
          },
          {
              secret_id = "docker_secret.mysql_root_password.id"
              secret_name = "docker_secret.mysql_root_password.name"
              file_name = "/run/secrets/docker_secret.mysql_root_password.name"
          }
      ]
  }
  
  ```
  
  Then to access an individual value, use indexing with variable evaluation: `${local.secrets[1].file_name}`.
  
  > **Comments:**
  > **username_0**: 1)  I already have secrets.tf and variables.tf files for them.. #update2 in the question 2) If i mention the secret_id,secret_name,file_name in vars.tf, how can i refer them in main.tf 3) Because the "docker_secret.mysql_db_password.id" and "docker_secret.mysql_db_password.name" are already in secrets.tf file  
  > **username_2**: You access them with variable evaluation, such as `${local.secret_id}`.  
  > **username_0**: ok. but what if , if i have two secrets.. as mentioned in my example  
  > **username_2**: I've updated with the example from the OP  
  > **username_0**: yeap able to compile.. but **scenario** 1)mentioning secrets in main.tf along with tfvars.tf file.. getting error while applying the plan . Error updated in the question **scenario** 2) not mentioning secrets in main.tf but with tfvars.tf file  .. able to apply plan.. but mysql service is not coming up.. it comes up and goes down in seconds..may be it is searching for secrets in the main.tf file?  
  > **username_0**: complete code @ https://github.com/sivatest82/Terraform1/tree/master/secretsv12  
  > **username_2**: After making some adjustments to your code (https://gist.github.com/username_2/c2c17227d7430829b3f5ae8860f8b65f), I can get a successful plan, but when I apply I get `Error: Error response from daemon: rpc error: code = InvalidArgument desc = malformed secret reference` from Docker.  Sounds like Terraform itself isn't the problem.  
  > **username_0**: cool, thanks @username_2 . I will try to report this to hashicorp..lets see what they  
  
  ---
  
  ### Answer by username_3 on 2020-05-04. Score: 0
  
  According to the [documentation](https://www.terraform.io/docs/providers/docker/r/service.html#advanced), you should change your secrets handling to following syntax:
  
  ```
        secrets = [
  
          {
            secret_id   = docker_secret.mysql_db_password.id
            secret_name = docker_secret.mysql_db_password.name
            file_name   = "/run/secrets/${docker_secret.mysql_db_password.name}"
          },
  
          {
            secret_id   = docker_secret.mysql_root_password.id
            secret_name = docker_secret.mysql_root_password.name
            file_name   = "/run/secrets/${docker_secret.mysql_root_password.name}"
          }
        ]
  
  ```
  
  So you pass the actual secret ID to the service object and not the Terraform resource reference as a string. The only difference between Terraform 0.11 and 0.12 code is, that in 0.12 you can remove the interpolation syntax (so `${}`), if you don't actually use it, as you only pass the attribute of other resource, with no additional formatting.
  
  > **Comments:**
  > **username_0**: i have already tried it.. not working in v0.12  
  
  ---
  
  