rayward / terraform-plex

Terraform Script for Sonarr + CouchPotato + NZBGet + Plex Server
5 stars 3 forks source link

ports and volumes in plex.tf are blocks, not variables #1

Open DavidRedstone opened 2 years ago

DavidRedstone commented 2 years ago

Hi Ray,

I'm also from Sydney. So hey, I want to convert my existing docker-compose HTPC setup to Terraform, just to practise using Terraform with something other than AWS (which is my job). My existing setup has sonarr, radarr, jackett, plex, deluge, and portainer (although I don't really use portainer -- was just curious).

When I tried to fire up your code with Terraform, I got errors -- can't declare ports and volumes variables multiple times.

I'm on: terraform --version Terraform v1.1.9

I have since located the warnings and errors in your plex.tf file -- terraform will not init, fmt, or validate until they are fixed:

'ports' is not a variable. It is a block, so it should be ports { (i.e. no equals)

ports = { internal = 6789 external = 6789 } 'volumes' is also not a variable, so it should be volumes { (i.e. no equals)

volumes = { host_path = "/etc/localtime" container_path = "/etc/localtime" read_only = true }

These need to be changed in multiple places. I had already separated your code into multiple files, which is what we do at work. So I '.disabled' all the files and undisabled one by one, doing fmt and validate and init -- to check everything

You can also add a volume name for each block:

volumes { volume_name = "tv" host_path = var.tv_dir container_path = "/tv" }

This one gets a deprecated warning: networks = ["${docker_network.private_network.id}"]

Warning: Quoted references are deprecated │ │ on couchpotato.tf line 48, in resource "docker_container" "couchpotato": │ 48: depends_on = ["docker_container.nzbget"] │ │ In this context, references are expected literally rather than in quotes. Terraform 0.11 and earlier required quotes, but quoted references are now deprecated and │ will be removed in a future version of Terraform. Remove the quotes surrounding this reference to silence this warning.

The fix is to change it to: networks = [docker_network.private_network.id]

Similarly, remove the double quotes for all depends_on lines to remove those warnings: depends_on = ["docker_container.nzbget"]

There is one more, but I haven't looked into it yet... need to use a 'networks_advanced' block.

https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/container "networks (Set of String, Deprecated) ID of the networks in which the container is. networks_advanced (Block Set) The networks the container is attached to (see below for nested schema)"

terraform validate ╷ │ Warning: Argument is deprecated │ │ with docker_container.couchpotato, │ on couchpotato.tf line 11, in resource "docker_container" "couchpotato": │ 11: networks = [docker_network.private_network.id] │ │ Use networks_advanced instead. Will be removed in v3.0.0 │ │ (and 4 more similar warnings elsewhere) ╵ Success! The configuration is valid, but there were some validation warnings as shown above.

My file structure, fwiw image

Hope this helps :)

DavidRedstone commented 2 years ago

hmmm ... multi line code blocks aren't working as expected in this issue post. Hope it's still readable.