如何将 terraform 文件 (main.tf) 拆分为多个文件(无模块)? [英] How to split a terraform file (main.tf) in several files (No Modules)?

查看:21
本文介绍了如何将 terraform 文件 (main.tf) 拆分为多个文件(无模块)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过 Terraform 部署的 GCP 基础设施:存储桶、服务帐户、计算引擎、VPC、云 SQL、BigTable、BigQuery、Composer 等.

Terraform v0.11.10提供程序google"(2.15.0)

最近客户要求我将我们仅有的一个 terraform 文件(例如 main.tf)拆分为多个文件.例如:一个文件用于存储桶,另一个用于服务帐户,另一个用于数据库服务等

我的 GCP 存储桶中只有一个 terraform 状态文件.

我怎样才能以最小的影响做到这一点?地形状态怎么样?(是否也会有多个状态文件?或者是只保留一个 TF 文件的想法,即使我们将代码拆分出来?)

注意:这与 Terraform 模块无关,只是将单个 terraform 文件 (.tf) 分成多个文件 (.tf)

提前致谢!

解决方案

terraform apply 命令可以应用于文件或目录,根据文档.因此,将所有文件放在一个目录中并应用它们.

tfstate 文件与部署相关.你只有一个.

关于最低影响......很难说.一切都取决于您的变量和资源依赖项.如果您必须搜索多个文件以了解资源的创建方式或变量的设置位置,则多个文件不是一个好主意...但是,这是您的客户要求,并且为了可读性而这样做要简单得多.

I have a GCP infrastructure deployed through Terraform: buckets, service accounts, Compute Engines, VPC, cloud SQL, BigTable, BigQuery, Composer, etc.

Terraform v0.11.10 Provider "google" (2.15.0)

Recently the client asked me to split our only one terraform file (e.g. main.tf) in several files. E.g: One files for Buckets, other for Service Accounts, other for Database Services, etc.

I only have one terraform state file located in a GCP bucket.

How could I do it with the lowest impact ? What about with the terraform state ? (Will there also be also multiples state files ? Or Is the idea to keep only one TF file, even if we split the code out ?)

NOTE: This has nothing to do with Terraform modules, it's just about dividing a single terraform file (.tf) into several files (.tf)

Thanks in advance!

解决方案

The command terraform apply can be apply to a file or a directory, according with the documentation. Thus, put all your file in a directory and apply them.

The tfstate file is relative to a deployment. You will have only one.

About the lowest impact... Hard to say. All depends of your variables and your resource dependencies. If you have to search is several file to understand how a resource is created or where a variable is set, multiple file isn't a great idea... However, it's your customer requirement and do it the much simpler for readability.

这篇关于如何将 terraform 文件 (main.tf) 拆分为多个文件(无模块)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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