1
  • what value secret_id variable is referring in below main.tf and terraform.tfstate code
  • There is no variable called "id" in my secrets.tf file

main.tf

    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}"
]
  }
}

terraform.tfstate

                "docker_secret.mysql_db_password": {
                "type": "docker_secret",
                "depends_on": [],
                "primary": {
                    "id": "jqeg2xqzdeeddk12fnfcu7flr",
                    "attributes": {
                        "data": "cDRzU1dvUmQwIQo=",
                        "id": "jqeg2xqzdeeddk12fnfcu7flr",
                        "name": "db_password"
                    },
                    "meta": {
                        "schema_version": "1"
                    },
                    "tainted": false
                },
                "deposed": [],
                "provider": "provider.docker"
            },
            "docker_secret.mysql_root_password": {
                "type": "docker_secret",
                "depends_on": [],
                "primary": {
                    "id": "4xkaouiljotr72urmh9gvhx66",
                    "attributes": {
                        "data": "cDRzU1dvUmQwIQo=",
                        "id": "4xkaouiljotr72urmh9gvhx66",
                        "name": "root_password"
                    },
                    "meta": {
                        "schema_version": "1"
                    },
                    "tainted": false
                },
                "deposed": [],
                "provider": "provider.docker"
            },

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"
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.