Can't make Machine Env variables work with fly deploy in platform V2

Hello there!

I’m deploying my environment using Terraform.
I use this resource: Terraform Registry

to create a machine with env variables that are stored in Terraform Cloud.

Then when I want to upgrade the docker container to a new version, if I try to do fly deploy, I get:

Error: found 1 machines that are unmanaged. `fly deploy` only updates machines with fly_platform_version=v2 in their metadata. Use `fly machine list` to list machines and `fly machine update --metadata fly_platform_version=v2 <machine id>` to update individual machines with the metadata. Once done, `fly deploy` will update machines with the metadata based on your fly.toml app configuration

I tried to do so, but when I do a fly deploy after that, the env variables values are the initial values (i.e. no env variable I added since then exists and my container fails).
I guess this is what you mean with fly deploy will update machines with the metadata based on your fly.toml but I don’t even have a fly.toml, so where does Fly get this old variable values?

How can I make a Terraform infrastructure work with the fly deploy method and on V2 (I would like to avoid manually pushing to a repository then updating the image tag in the terraform, I love the simplicity of fly deploy and would like terraform to only manage infra and env variables)

Thanks a lot for your help!

I think I managed to make it work, rather than using fly deploy I’m using fly deploy --build-only --push to push the image to the repository then fly image update to update the machine.

That way I don’t need to have the metadata setup for v2 and my env variables stay the same between updates.

Do you confirm it’s the way to go for my setup?

That resource manages a Fly Machine directly. This is a low-level compute primitive, similar to a virtual private server. You can think of it as an equivalent to EC2 from AWS or a Droplet from DigitalOcean. It’s most useful when you either want more control or to build your own platform on top of our infrastructure.

fly deploy works with our Fly Apps platform. The Apps platform is built on Fly Machines and manages the underlying Fly Machines for you for the most part. We don’t have a way to manage this using Terraform. Fly Apps are managed through flyctl, our CLI.

If you’d like to keep using Fly Machines, you will need to build/manage them yourself. A new deployment of an updated machine would require you to push the new Docker image, create a set of new machines and then subsequently destroy the current set of machines.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.