News for hackers. Stuff that matters.
Re:Terraform should have remained stateless by pharmakom on Saturday May 28, 2022 @03:03AM (#31538222)
The article misses a key bit of information TF needs when making a plan:

   4. The previous Terraform configuration
This is effectively stored by state.

We need this because if a resource is removed from the new config then Terraform needs to be able to delete the existing resource from the world. If we don’t have the state then Terraform must either:

    1. Not delete it from the world

    2. Or risk deleting something not managed by Terraform
If everything were managed by Terraform then perhaps we would not need state, but this is not realistic in my view.
Re:Terraform should have remained stateless by stingraycharles on Saturday May 28, 2022 @05:12AM (#31538832)
The whole idea of the article is that “previous state” is something that can be derived from tags / metadata in the provider’s resources, rather than a standalone file. In other words, this metadata then is the state.

Could you give an example of a situation / transition that cannot be captured correctly by managing the state using these types of tags?

Re:Terraform should have remained stateless by enobrev on Saturday May 28, 2022 @10:35AM (#31540656)
That's still storing state, except instead of keeping it within a single file which you have full control over, you're instead sprinkling that state all over your infrastructure and then hoping it doesn't get mangled in between invocations.

And also hoping that service's API has all the tools needed to find your scattered state within a reasonable amount of time in order to diff any changes you make in your declarations

Re:Terraform should have remained stateless by mountainriver on Saturday May 28, 2022 @11:44AM (#31541212)
Yeah but then you don’t have to worry about the state getting out of sync which is one of the biggest problems. Also versioning is a pain
Re:Terraform should have remained stateless by ImPostingOnHN on Saturday May 28, 2022 @12:14PM (#31541469)
yeah, but then you DO have to worry about scanning every single resource you control, every time you plan and run
Re:Terraform should have remained stateless by hellcow on Saturday May 28, 2022 @12:20PM (#31541526)
I built pretty much the system you’re describing for my company (a stateless terraform alternative) and this scan that you cite as a negative happens in… 100ms in parallel? Roughly the same amount of time it would take to download a state file? Dunno about you but ensuring state is always accurate and in-sync is well worth the trade-off to me.
Re:Terraform should have remained stateless by enobrev on Saturday May 28, 2022 @01:13PM (#31541986)
I'm curious, and not antagonistically, about the size and variability of the infrastructure you're working with, on how many platforms it's running, and how many people are in charge of it.

Is this tool private or available for us to try out?

Re:Terraform should have remained stateless by hellcow on Saturday May 28, 2022 @02:34PM (#31542589)
It’s small, under 50 servers running OpenBSD and Linux under a wide variety of configurations (including gpu), 6 databases, and Redis. Though the system is easily extensible to other clouds and resource types, it only needs to work on GCP right now. Been running it in prod for the past 3 or 4 years—no outages, no downtime, no surprises. Doubled infra over the holidays then scaled everything back with no issue.

The stateless approach has worked really well for us.

Re:Terraform should have remained stateless by shyn3 on Saturday May 28, 2022 @06:28PM (#31544419)
This is the reason we didn't get Terraform. In a windows shop the state is never the same because most people will fix it via the UI and then the state file becomes useless
Re:Terraform should have remained stateless by ImPostingOnHN on Wednesday June 01, 2022 @08:15PM (#31589788)
sounds like a totally reasonable decision
Re:Terraform should have remained stateless by bradknowles on Sunday May 29, 2022 @02:18PM (#31551410)
At small sizes, this probably works reasonably well. However, as you scale, the performance will get worse and worse, and you run the risk of hitting rate limits and/or missing stuff.

So, fine for you in your personal small environment, but maybe not something suitable for Terraform in general.

Re:Terraform should have remained stateless by mountainriver on Saturday May 28, 2022 @01:28PM (#31542093)
That does not seem problematic with modern APIs and concurrency. Two sources of truth is highly problematic
Re:Terraform should have remained stateless by rad_gruchalski on Saturday May 28, 2022 @02:47PM (#31542678)
But it is problematic when you deal with larger infrastructures due to rate limits.
Re:Terraform should have remained stateless by mountainriver on Tuesday May 31, 2022 @08:41AM (#31568832)
I can’t imagine you would ever hit a rate limit, how often are you deploying large sums of infrastructure? For me it’s maybe a couple times a day and the surface area is small
Re:Terraform should have remained stateless by tedivm on Tuesday May 31, 2022 @09:45AM (#31569410)
AWS API Rate limits are very surprising. I've hit them on new accounts when trying to deploy terraform based code, and that's without having to literally scan the entire account.

If I have 3k machines running in an autoscaling group I think it would be ridiculous to have to hit each one of those with API calls to try and infer which were or weren't part of my state. Building a simple high availability VPC is about 72 resources just by itself.

I don't think people advocating for "the cloud is the state" realize how big even trivial environments can get- let alone complex ones.

Re:Terraform should have remained stateless by mountainriver on Tuesday May 31, 2022 @12:36PM (#31571606)
Huh I've never hit rate limiting on GET with AWS, could just be my luck. This also might not be the answer for every problem, but could be nice for some
Re:Terraform should have remained stateless by rad_gruchalski on Wednesday June 01, 2022 @12:42PM (#31584517)
“I have never” doesn’t equal “it doesn’t happen”.
Re:Terraform should have remained stateless by pharmakom on Saturday May 28, 2022 @02:08PM (#31542409)
You do because the metadata on the resource might get changed.
Re:Terraform should have remained stateless by pharmakom on Saturday May 28, 2022 @06:40AM (#31539198)
So the position is Terraform should have state, but rather than keep it in one place such as an S3 object, it should be spread across the metadata of many resources?

Some issues with that:

- Fetching the whole state would be hugely impractical due to the number of API calls

- The risk of losing state information by a resource being deleted outside of Terraform is greater

- Again, not all resources have metadata that could be used to store state

Re:Terraform should have remained stateless by usrn on Saturday May 28, 2022 @06:50AM (#31539247)
>- The risk of losing state information by a resource being deleted outside of Terraform is greater

This isn't losing state information though! That is the state. If state information were kept outside this it would now be wrong which means terraform *would do the wrong thing.

Re:Terraform should have remained stateless by kkdaemas on Saturday May 28, 2022 @08:10AM (#31539681)
No because the metadata on the deleted resource is now lost.

With the information being stored outside the resource, we know that it was deleted and the metadata about it.

Re:Terraform should have remained stateless by usrn on Saturday May 28, 2022 @08:59AM (#31539991)
That's not state information though, that's metadata.
Re:Terraform should have remained stateless by pharmakom on Saturday May 28, 2022 @09:31AM (#31540195)
If some state information is stored using metadata then we need that metadata to know the total state. The contents of TF state is more than what can be read from the provider APIs often.
Re:Terraform should have remained stateless by mountainriver on Saturday May 28, 2022 @01:32PM (#31542138)
Yeah but the extra stuff they add is a trade off and lots of people would rather not have two sources of truth to have it
Re:Terraform should have remained stateless by rad_gruchalski on Saturday May 28, 2022 @02:50PM (#31542697)
Most of the people I know who use Terraform use Terraform as the source of truth.
Re:Terraform should have remained stateless by usrn on Saturday May 28, 2022 @03:31PM (#31543026)
You can wish things are a certain way but that doesn't change reality no matter how nice that would be.
Re:Terraform should have remained stateless by rad_gruchalski on Saturday May 28, 2022 @04:16PM (#31543404)
Seen this many times. People using a tool in an unintended manner and then bashing the tool.
Re:Terraform should have remained stateless by mountainriver on Tuesday May 31, 2022 @08:39AM (#31568822)
Huh so you access your infra through terraform?
Re:Terraform should have remained stateless by tedivm on Tuesday May 31, 2022 @09:46AM (#31569423)
This conversation is embarrassing for both of you.
Re:Terraform should have remained stateless by rad_gruchalski on Wednesday June 01, 2022 @12:39PM (#31584472)
Tell me more please. There’s always something new to learn.
Re:Terraform should have remained stateless by mountainriver on Tuesday May 31, 2022 @12:31PM (#31571547)
its super embarrassing if you thing TF is the source of truth when the cloud provider clearly is
Re:Terraform should have remained stateless by rad_gruchalski on Wednesday June 01, 2022 @12:48PM (#31584596)
My infrastructure drifts from my source of truth.
Re:Terraform should have remained stateless by rad_gruchalski on Wednesday June 01, 2022 @12:41PM (#31584492)
Through an API, really.
Re:Terraform should have remained stateless by EwanToo on Saturday May 28, 2022 @05:51AM (#31539001)
This is the fundamental misconception of the article as far as I understand it.

Cloud providers do not provide enough metadata to enable that mapping across all resources.

Re:Terraform should have remained stateless by Jasp3r on Saturday May 28, 2022 @06:24AM (#31539119)
That cloud providers provide such muddy/inadequate APIs that it is impossible to view the state they are in is a very bold claim to make.

Do you have an example to back this up?

Re:Terraform should have remained stateless by noirbot on Saturday May 28, 2022 @08:35AM (#31539834)
I'm amused that you think "cloud providers have bad APIs" is a bold claim instead of the default state of things. Things as basic as IAM Groups in AWS aren't taggable: https://registry.terraform.io/providers/hashicorp/aws/latest...

IAM Users are taggable, but to get the tags on a given user, you must request them one user at a time from a known list of users. The "List all users" call doesn't return their tags. Obviously this is less of an issue for the TF state use case, but does add to the API call overhead for any tag-based approach.

Re:Terraform should have remained stateless by tedivm on Tuesday May 31, 2022 @09:49AM (#31569443)
My favorite is that you can look up some resources by tag directly, but other resources have to use the special resource tagging api. The AWS API also silently fails, on purpose, for some things- try looking up quotas for Organizations as an example and you'll end up with an empty array instead of the actual quotas.

Cloud providers having bad APIs is definitely the default state.

Re:Terraform should have remained stateless by moondev on Saturday May 28, 2022 @08:07AM (#31539659)
Re:Terraform should have remained stateless by ntoskrnl on Saturday May 28, 2022 @06:43AM (#31539214)
No DNS provider I've ever used has a way to store metadata alongside a DNS record (like an individual A record)
Re:Terraform should have remained stateless by paulgb on Saturday May 28, 2022 @06:45AM (#31539227)
I was just about to give the same example. I’m more familiar with GCP’s DNS, but I don’t see a place for structured metadata in Route 53 either. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGui...
Re:Terraform should have remained stateless by rwmcfa1 on Saturday May 28, 2022 @10:55PM (#31545891)
If you look through the octoDNS providers there's a number of cases where extra info is stored for "dynamic" records. The metadata is often things like the pool name or rule number. In other cases it's details about the health check config/version. The extra info is sometimes stored into a "notes" field, other times it's encoded into the ID or similar.

It's true that nothing extra is needed for simple/standard records, but once you start doing GeoDNS, failover, health check, etc. it's required.

In all cases thus far we've been able to find a way to store/indicate whatever we need.

(maintainer of octoDNS)

Re:Terraform should have remained stateless by georgyo on Saturday May 28, 2022 @07:28AM (#31539468)
Why do I need metadata along with my A record? It either exists or it doesn't. That is the state required for Terraform.

The article explicitly mentions OctoDNS as a stateless configuration management system for DNS as a good solution.

Re:Terraform should have remained stateless by KyeRussell on Saturday May 28, 2022 @07:39AM (#31539514)
To know if it’s managed by TF or not, to know whether or not to delete it. Exactly what’s being described.
Re:Terraform should have remained stateless by NateEag on Saturday May 28, 2022 @08:09AM (#31539678)
That's what TXT records are for:

https://en.m.wikipedia.org/wiki/TXT_record

Re:Terraform should have remained stateless by ntoskrnl on Saturday May 28, 2022 @08:18AM (#31539737)
Terraform can be used to manage TXT records too. Where does it store metadata for them? Or is it TXT all the way down?
Re:Terraform should have remained stateless by NateEag on Saturday May 28, 2022 @11:09AM (#31540904)
You can have multiple TXT records for a given domain name, so it would be possible to store an arbitrary amount of metadata for whatever systems you desire, and just loop through the TXT records to figure out which ones are for the current system's purpose.
Re:Terraform should have remained stateless by gtirloni on Saturday May 28, 2022 @08:14AM (#31539713)
Exposed to the world?
Re:Terraform should have remained stateless by NateEag on Saturday May 28, 2022 @11:12AM (#31540918)
I guess that's not ideal, though I'm not clear what attack surface area is increased by storing creation/ deletion metadata in public.

I guess it lets an attacker know that you're using Terraform, which might help them target their attacks.

Re:Terraform should have remained stateless by bpicolo on Saturday May 28, 2022 @11:25AM (#31541010)
Terraform stores secrets in state. Generated database password, etc.
Re:Terraform should have remained stateless by NateEag on Saturday May 28, 2022 @03:03PM (#31542783)
Oh, gotcha. I've not used Terraform yet.

Yes, if that's the case, then TXT records could easily be unsuitable. Depends exactly what metadata needs to be attached to your DNS records.

Re:Terraform should have remained stateless by orf on Saturday May 28, 2022 @06:53AM (#31539269)
You can create an s3 object in a bucket with terraform. There isn’t a way to go from “tag -> key”.
Re:Terraform should have remained stateless by aequitas on Saturday May 28, 2022 @07:46AM (#31539547)
> The whole idea of the article is that “previous state” is something that can be derived from tags / metadata in the provider’s resources

Except for the Cloud's and API's that don't provide them but we stil need configuration managed. This is the world we live in, and in that world Terraform is the solution to the problems that we seek. In an ideal world Terraform would not be needed, but we don't live in that world.

Re:Terraform should have remained stateless by rorychatt on Saturday May 28, 2022 @06:39PM (#31544489)
We use Terraform extensively at our organisation. Some examples come to mind that make this impractical: - For services that do support tags, we are already reaching limits on the number of tags that can be associated with a single resource. For example, in Azure, some resources still only support 10 unique key/values - Drift detection against write, but no read secrets mean that you cannot do drift detection over certificates, and secrets. Depending on your organisation and how they manage things like PKI, this may be impractical to track validity of the endpoint. - Many services we manage don't have tags. For example, we use Terraform to manage Github Repositories, Actions, AzDo Pipelines, and Permissions - Some object types simply don't have primary keys that are easily searchable by the provider, and requires some sort of composite key to be compiled and tracked.

State gives us a common schema and playing field to significantly simply the generation of dependency graphs and show drift. I imagine that even without a 'statefile', you would end up having to generate a similar graph in memory anyway.

Re:Terraform should have remained stateless by hamandcheese on Saturday May 28, 2022 @10:31AM (#31540619)
So state, but probably way slower and varies from cloud to cloud.
Re:Terraform should have remained stateless by grumple on Saturday May 28, 2022 @08:46AM (#31539905)
> Could you give an example of a situation / transition that cannot be captured correctly by managing the state using these types of tags?

Tags do not solve the deletion issue. It would require two step deployments, for example by adding delete = true to the config, applying, then removing the resource from the config entirely and applying again. But I don't think that's too bad tbh.

Re:Terraform should have remained stateless by tomgouder on Saturday May 28, 2022 @05:57AM (#31539024)
I agree that state can be removed in Terraform.

But I do not believe leveraging tags and/or metadata is the right approach - configuration for these resources could potentially be large (e.g. GKE resources) and most providers will have a size constraint on their metadata and tag values. Creating a metadata/tag key for each configuration key would also get messy, but solves the value size problem.

Why wouldn’t it be possible to not store the previous state at all? Terraform’s job is to reconcile what exists with what is declared - we should be able to rely on the provider’s APIs to understand what exists, perform the diff, and reconcile the changes.

Re:Terraform should have remained stateless by ntoskrnl on Saturday May 28, 2022 @06:45AM (#31539225)
How would TF work without state and without tags?

Let's say your TF config declares a database Foo. Your AWS account has databases Foo and Bar. How does TF know whether it's responsible for database Bar and whether to delete it?

Re:Terraform should have remained stateless by Aeolun on Saturday May 28, 2022 @07:03AM (#31539330)
Resource is tagged with “terraform stack x created this”?
Re:Terraform should have remained stateless by cassianoleal on Saturday May 28, 2022 @07:18AM (#31539405)
Interesting. Disregarding for a moment that not all cloud resources supporting tags on all cloud providers (and let's not get started with all the non-cloud stuff Terraform is capable to manage), how does tf know that `stack x` is the thing that's currently running?
Re:Terraform should have remained stateless by gtirloni on Saturday May 28, 2022 @08:22AM (#31539762)
By the time the tag has enough information to be useful, you are storing a TF state file in a tag. Anyway, I don't think people complaining about a s3 bucket for tf state actually has experience creating tools like tf.
Re:Terraform should have remained stateless by ntoskrnl on Saturday May 28, 2022 @08:20AM (#31539753)
The parent said he thinks tags aren't the right approach. I wanted to know what he proposes instead.
Re:Terraform should have remained stateless by chrisweekly on Saturday May 28, 2022 @09:33AM (#31540206)
"should be able to rely on the provider’s APIs to understand what exists" is the crux of it. Provider APIs, in praxis, are insufficient / impractical.
Re:Terraform should have remained stateless by sockpuppet_12 on Saturday May 28, 2022 @04:55PM (#31543762)
If you deleted a resource block from a previously applied terraform declaration and reapplied it, how would the provider know that the resource in the environment needed to be deleted verses accepting it as an object not managed by terraform?

Where would it store it's history to make the diff against it?

Re:Terraform should have remained stateless by ElectricalUnion on Saturday May 28, 2022 @10:17PM (#31545669)
Well, you can just delete/remove/clean everything visible and create only the things based on the configuration. Then you can't store any state in your Terraform-managed infrastructure, but for people that don't want state anyways, that is a blessing I guess?
Re:Terraform should have remained stateless by baobob on Saturday May 28, 2022 @06:53AM (#31539266)
Where would the metadata for the local_file resource be stored? How would Terraform find files it once created and must now delete?
Re:Terraform should have remained stateless by Too on Sunday May 29, 2022 @02:53AM (#31547029)
Same famous problem for any kind of make-based build system, removing targets usually leave old files in your build directory. IIRC Bazel can avoid it but don’t know how, either it must keep a list of old files or compare the entirety of build directory to the build-graph.
Re:Terraform should have remained stateless by wernerb on Saturday May 28, 2022 @05:40AM (#31538955)
There are plenty of providers/resources that have no such metadata
Re:Terraform should have remained stateless by nanis on Saturday May 28, 2022 @08:51AM (#31539934)
How does that work when terraforming Artifactory?
Re:Terraform should have remained stateless by Faaak on Saturday May 28, 2022 @03:45AM (#31538407)
TF noob here: is it not possible to store a "managed by terraform" annotation on the resources ? Or are not all resources able to store labels (extreme example: terraform-spotify plugin)
Re:Terraform should have remained stateless by pharmakom on Saturday May 28, 2022 @03:48AM (#31538425)
It is possible for resources that support tags, but not everything supports tags.
Re:Terraform should have remained stateless by FooBarWidget on Saturday May 28, 2022 @04:38AM (#31538668)
Many resources don't support abitrary metadata.
Re:Terraform should have remained stateless by runlevel1 on Saturday May 28, 2022 @11:19AM (#31540961)
In Chef, you have to change the resource to `action :remove` if you want it deleted.

Couldn't you do something like that?

Re:Terraform should have remained stateless by zoul on Sunday May 29, 2022 @03:16AM (#31547131)
You could, but then you are losing what I think is the main point of TF – describing what the infra should look like and letting the tool figure out what the necessary steps are for reaching that state.
Re:Terraform should have remained stateless by runlevel1 on Sunday May 29, 2022 @12:52PM (#31550594)
It can still be declarative for the things that it manages.

Perhaps Puppet would have been the better analogy (i.e. `ensure => absent`).

While Terraform providers can be built to do a lot of implicit work, in practice they don't. In my experience, you still have to specify all the pieces.

The only place I can think of where auto-deletion came in handy was for infrastructure CI. However, that CI pipeline doesn't catch many critical issues, and it's very expensive to operate. So I can't say it's been a total win.

Re:Terraform should have remained stateless by jon_adler on Sunday May 29, 2022 @03:48AM (#31547280)
One of terraforms key design principles is that it is declarative whereas this instruction is imperative.
Re:Terraform should have remained stateless by devit on Saturday May 28, 2022 @08:48AM (#31539916)
Or, you know, put an UUID in the configuration and tag everything with it so that it knows what it created by just querying the tag (or similarly, using a namespace if supported, or putting the information in the resource name itself if possible).
Re:Terraform should have remained stateless by vlunkr on Saturday May 28, 2022 @10:27AM (#31540578)
These arguments are just going in circles but here's why: You can't store metadata on every object in every provider, and often, resource names are restrictive in length and allowed characters. And what if something needs deleted? Now every time you run terraform you need to list every type of object the provider offers and check tags, that's a huge waste of time and bandwidth.
Re:Terraform should have remained stateless by ElectricalUnion on Saturday May 28, 2022 @10:19PM (#31545679)
> UUID in the configuration

If you turn the configuration into state, you don't need state anymore I guess?

Re:Terraform should have remained stateless by mountainriver on Saturday May 28, 2022 @11:45AM (#31541218)
I think the trade offs of a stateless terraform would be favored by many
Re:Terraform should have remained stateless by funcDropShadow on Monday May 30, 2022 @09:41AM (#31558848)
Then use ansible, or some other stateless tool in the same space.
Re:Terraform should have remained stateless by barefeg on Saturday May 28, 2022 @12:59PM (#31541863)
You can still store state but delegate it to a different system. One that is more robust and homogeneous like a kubernetes API. This is what crossplane does
Re:Terraform should have remained stateless by mountainriver on Saturday May 28, 2022 @01:36PM (#31542172)
Terraform can use k8s as a state store. The issue is two sources of truth and everything that causes