Hey if I repoint my tf config to a new state file ...
# terraform
j
Hey if I repoint my tf config to a new state file and add an import block for every resource will this state be a duplicate of my existing one?
g
hold up
t
Let's back up... what are you trying to do?
j
Satisfy a curiosity
Without actually doing it
I'm being intrpid, Troy - I'm pushing the boundaries of what's possible!
Rhetorically
t
I'm assuming by "repoint" you mean change the location of the state file... TF will then ask you if you want to migrate the state. I'm assuming you don't and you want to create a duplicate statefile... you can always just literally copy the state file. Doing a bunch of import statements seems like a lot of work.
a
If you just want to migrate the state you can simply update the path/configuration of Remote State in the configuration and Terraform should ask you if you want to migrate it
Copying the state would be a strange thing to do, unless you're thinking of a problem that Workspaces or Terragrunt might solve?
t
Yeah, I was thinking this was a second order question. A question you have after the thing you really wanted to do didn't work.
j
Not trying to do anything I'm just curious
a
Ah okay doke. It's almost certainly something you'd never want to do, since you'd create 2 sources of truth for the same infrastructure (1 of which wouldn't be aware of the other) which could cause some accidents
j
I agree it's pointless stupid and reckless but I figured I'd ask since someone here might understand what terraform is actually doing under the hood enough to answer
Like when you lay awake at night and wonder what if nitrogen was the building block of earthly life instead of carbon
t
Keep in mind that there are some things that can't really be imported... like data sources, null resources, stuff like that.
a
Always good to be curious! I've seen some weird use-cases though where people are using the Remote State Data Source to lookup things, so you could potentially create a read-only duplicate of state for that purpose if for some reason you needed to?
j
Yea I'm coming from a place with a very immature terraform deployment and I'm importing stuff that already exists so I guess I'm just thinking about imports
t
It's me... I'm the weird use cases
j
Yea same
Why be normal
I think what spurred my thought process was keeping a state file for each AWS account and what if we wanted to change what goes in which state like if we wanted a file per cloud or per Iam role or some other equally ill advised thing
But to answer the initial question I'm not actually doing anything
t
I use the remote state data source to create an interface module that can be shared to other teams so the source of truth remains with me, but they can get values I "make public" by using the outputs from said module
j
Oh rn we are broken up by env and prod by tenant and each has a state file referenced by remote state in the root of the env tree
t
OpenToFu is actively working on parameterizing backend config, btw... its quite possible that if you want to have workspaces point to completely different instances of a terraform state file (which, honestly makes TONS of sense from a permissions and access perspective) you'll be able to do that in a couple months.
Also, that's a very valid development pattern in TF (making seperate stacks of environments)... and I hate it, lol.
j
We aren't using workspaces cuz I'm the architect and I didn't want the extra overhead. I joined two weeks ago and at that time terraform was a subdir of a monorepo and I'm prioritizing getting everything managed asap
As for tofu as soon as Atlantis supports it I'm on board
t
You can just install it and alias out the command. So have
terraform
point to
tofu
its no big deal
j
Are you a tofu contributor cuz I'd love to help
Yea I know
But I'm deep in time poverty rn
t
I'm not... but they have a slack https://opentofucommunity.slack.com/ssb/redirect
I'm not really sure how workspaces are more overhead... imo, doing work in triplicate (once in dev, once in stg, once in prd) is waaaay more work than just making changes once and letting Atlantis run the plans and applies.
j
Oh you misunderstand me - I haven't used it so I didn't
t
Fair. Make no mistake, though... my ideas have their own problems. Like now I have all these fucking tiny environments like this that I need to orchestrate and then take this whole graph and multiply it by dev, stg, prd, etc... It gets complicated if you don't use some kind of TACOS or something.
j
Oops all problems
Right now if we take on more tenants my life is fucked so I'm trying to get this automation in place asap and accepting some reasonable tech debt
t
One of my friends coined a term for it WDYWYM (where do you want your mess), in my case, I definitely want my TACOS responsible for my mess, so my code stays pretty clean and DRY.
j
I've been saying whenever we hit something nonstandard "when we [are a multinational sensation] this will be our "special snowflake""
None of this will matter when we're famous singers