理想的 terraform 工作空间项目结构 [英] Ideal terraform workspace project structure

查看:32
本文介绍了理想的 terraform 工作空间项目结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置 Terraform 来管理 dev/stage/prod 环境.基础设施在所有环境中都是相同的,但每个环境中的变量存在差异.

I'd like to setup Terraform to manage dev/stage/prod environments. The infrastructure is the same in all environments, but there are differences in the variables in every environment.

在 Terraform 0.10 中引入了工作空间后,理想的 Terraform 项目结构是什么样的?在命名/标记基础架构时如何引用工作区?

What does an ideal Terraform project structure look like now that workspaces have been introduced in Terraform 0.10? How do I reference the workspace when naming/tagging infrastructure?

推荐答案

我不建议在静态环境中使用工作区(以前的环境"),因为它们增加了相当多的复杂性并且更难跟踪.

I wouldn't recommend using workspaces (previously 'environments') for static environments because they add a fair bit of complexity and are harder to keep track of.

您可以对所有环境使用单个文件夹结构,使用工作区分隔环境,然后使用基于工作区的条件值来设置差异.在实践中(尤其是在超过 2 个环境导致嵌套三元语句的情况下)您可能会发现这很难管理.

You could get away with using a single folder structure for all environments, use workspaces to separate the environments and then use conditional values based on the workspace to set the differences. In practice (and especially with more than 2 environments leading to nested ternary statements) you'll probably find this difficult to manage.

相反,我仍然提倡为每个静态环境使用单独的文件夹,并使用符号链接来保存所有 .tf 文件在所有环境中都相同,并使用 terraform.tfvars 文件来提供每个环境的差异.

Instead I'd still advocate for separate folders for every static environment and using symlinks to keep all your .tf files the same across all environments and a terraform.tfvars file to provide any differences at each environment.

我会推荐用于动态环境的工作区,例如短期审查/实验室环境,因为这样可以提供很大的灵活性.我目前正在使用它们在 Gitlab CI 中创建审查环境,因此每个分支都可以有一个可选部署的审查环境,可用于手动集成或探索性测试.

I would recommend workspaces for dynamic environments such as short lived review/lab environments as this allows for a lot of flexibility. I'm currently using them to create review environments in Gitlab CI so every branch can have an optionally deployed review environment that can be used for manual integration or exploratory testing.

这篇关于理想的 terraform 工作空间项目结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆