TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Using Terraform Workspace for AWS multi account architectures

30 pointsby maurobaraldi3 months ago

6 comments

sausagefeet3 months ago
I work on Terrateam[0], an open source IaC orchesterator. In our opinion, workspaces in Terraform&#x2F;Tofu kind of suck. The problem is: multiple environments are never actually the same. Workspaces are built under the premise that the differences are small enough to encode in some conditionals, but that just doesn&#x27;t scale well.<p>What we recommend people do is use modules to encapsulate the shape of your infrastructure and parameterize it. Then have each environment be a directory which instantiates the module (or modules).<p>This is more robust for a few reasons:<p>1. In most cases, as you scale, differences between environments will grow, with this approach you don&#x27;t have to make a single root module act like a bunch of root modules via variables and conditionals, instead each environment is its own root module and if you need to do something unique in a particular environment, you can just implement that in the appropriate root module.<p>2. It&#x27;s easier to see what environments are under management by inspecting the layout of the repository. With workspaces, you need to understand how whatever tooling you are using is executed because that is where the environments will be expressed.<p>Last weekend I also implemented what I call &quot;Terralith&quot; which is a proof-of-concept for how to treat a single root module as multiple environments in a principled way. I wrote a blog about the experience if anyone is interested: <a href="https:&#x2F;&#x2F;pid1.dev&#x2F;posts&#x2F;terralith&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pid1.dev&#x2F;posts&#x2F;terralith&#x2F;</a><p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;terrateamio&#x2F;terrateam">https:&#x2F;&#x2F;github.com&#x2F;terrateamio&#x2F;terrateam</a>
评论 #42947160 未加载
jitl3 months ago
The terraform documentation explicitly advises you NOT to do this (<a href="https:&#x2F;&#x2F;developer.hashicorp.com&#x2F;terraform&#x2F;cli&#x2F;workspaces#when-not-to-use-multiple-workspaces" rel="nofollow">https:&#x2F;&#x2F;developer.hashicorp.com&#x2F;terraform&#x2F;cli&#x2F;workspaces#whe...</a>)<p>&gt; In particular, organizations commonly want to create a strong separation between multiple deployments of the same infrastructure serving different development stages or different internal teams. In this case, the backend for each deployment often has different credentials and access controls. CLI workspaces within a working directory use the same backend, so they are not a suitable isolation mechanism for this scenario.<p>For a practical scenario, you will often need different environments to roll out changes at different times, or to have other slight variance. If you rely solely on variables to be the only difference between environments, you will need a lot of tricky shenanigans to say, create a new dynamodb for a proof of concept only in “dev” but not in prod. Sure, you can use `count = var.env == “dev” ? 1 : 0` but this gets old fast.<p>Much better to make modules for common stuff, and then compose them in your different environments. Depending on the complexity of your needs, keeping good organization &amp; practice around using modules can be a bit challenging, but it will definitely scale through composition.<p>Modules also important to make multiple copies of things within an environment, for example to have a cluster in us-west-2 and a cluster in eu-central-1, both are in production environment. I would assume if I started with workspaces I would rapidly hit a point where I want to use it as a module and then need to re-organize things. If you chose workspaces as soon as you want a second region you need a big refactoring, but if you are using modules, you just instantiate the module a second time in your second region.
评论 #42948815 未加载
评论 #42951187 未加载
jayceedenton3 months ago
Is there any benefit to using workspaces over just introducing some variables and having an &#x27;environment&#x27; variable?<p>You can have a directory per environment and a directory of shared resources that are used by all environments.<p>It seems like workspaces add a new construct to be learned and another thing to add to all commands without much benefit. Could we just stick with the simple way of doing this?
评论 #42946020 未加载
评论 #42946241 未加载
评论 #42952160 未加载
评论 #42947239 未加载
评论 #42945894 未加载
hoofhearted3 months ago
The Terraformer tool was the biggest blessing when I had to reverse engineer our AWS stack into .tf modules.<p>Shoutout to the Waze team for creating it!<p><a href="https:&#x2F;&#x2F;github.com&#x2F;GoogleCloudPlatform&#x2F;terraformer">https:&#x2F;&#x2F;github.com&#x2F;GoogleCloudPlatform&#x2F;terraformer</a><p>We built out a large serverless stack on AWS, and we got a request from higher ups to convert it all into Terraform modules for portability and transparency purposes.<p>The Terraformer tool pulled in the entire stack and spit out the whole thing into tf files in less than 30 seconds.<p>Everyone was super impressed on the team lol.
tbrb3 months ago
I generally consider the AWS CLI configuration to be something that&#x27;s unique to a developer&#x27;s workstation, and shouldn&#x27;t be referenced in terraform code (in the form of tying the workspace name to your AWS profile name).<p>This would only work if all developers on a team have synchronised the same AWS CLI config (which to me is like asking people to synchronise dotfiles, not something I&#x27;d be willing to do).<p>My go-to architecture for multi-environment tends to be this, as it lends itself relatively well to Git Flow (or GitHub Flow): <a href="https:&#x2F;&#x2F;github.com&#x2F;antonbabenko&#x2F;terraform-best-practices&#x2F;tree&#x2F;master&#x2F;examples&#x2F;medium-terraform">https:&#x2F;&#x2F;github.com&#x2F;antonbabenko&#x2F;terraform-best-practices&#x2F;tre...</a>
评论 #42948507 未加载
评论 #42946493 未加载
评论 #42946410 未加载
new_user_final3 months ago
There is a typo in the submission title. Isn&#x27;t it easier to copy than type the whole title?
评论 #42945660 未加载