

Terraform 系列-Terraform 项目的典型文件布局 - 东风微鸣
source link: https://www.cnblogs.com/east4ming/p/17278063.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

典型文件布局
- modules/
- services/
- webserver-cluster/
- examples/
- main.tf
- outputs.tf
- vars.tf
- user-data.sh
- README.md
- [ ] versions.tf
- stage/
- vpc/
- services/
- frontend-app/
- backend-app/
- main.tf
- outputs.tf
- vars.tf
- user-data.sh
- README.md
- [ ] provider.tf
- [ ] versions.tf
- [ ] terraform.tfvars(or `*.auto.tfvars`)
- [ ] main.tfvars
- data-storage/
- mysql/
- redis/
- prod/
- vpc/
- services/
- frontend-app/
- backend-app/
- data-storage/
- mysql/
- redis/
- mgmt/
- vpc/
- services/
- bastion-host/
- jenkins/
- global/
- iam/
- s3/
- main.tf
- outputs.tf
- vars.tf
- user-data.sh
- README.md
- [ ] provider.tf
- [ ] versions.tf
🔥 提示:
- [ ]
表示该项为可选内容- 示例如
examples/
表示该项为文件夹
顶层文件夹
用于隔离环境
modules
:Terraform (可复用)模块文件夹stage
:预发布 Envprod
:生产 envmgmt
:管理/DevOps 环境(如:堡垒机、Jenkins 等)global
:用于运行各种环境下都要共享的资源(如:Terraform backend - S3、IAM)
二级文件夹
用于环境中的组件
vpc
:网络拓扑services
:此环境中运行的应用环境或微服务,例如 NGINX 前端或 Java 后端。每个应用程序甚至都应该驻留在单独的文件夹中,与其他应用程序隔离data-storage
:在此环境中运行的数据存储,例如 MySQL 或 Redis。每个数据存储应该驻留在它自己的文件夹中,与其他数据存储隔离。
每一个组件中,都会有相应的 Terraform 的配置文件,其命名规则如下:
vars.tf
: 输入变量outputs.tf
: 输出变量main.tf
: 资源定义user-data.sh
:(可选),用户自定义脚本README.md
:说明文档provider.tf
:(可选),provider 信息,典型如:provider、region。不同环境,甚至同一环境的不同组件的 provider 可能不同。versions.tf
:(可选),Terraform version、provider version、Terraform backend 信息。terraform.tfvars
(or*.auto.tfvars
): (可选),terraform plan 及 apply
默认会传入该文件中的变量值main.tfvars
:(可选),terraform plan 及 apply
可以通过-var-file=filename
来手动指定。
可以通过如下 3 种方式指定变量:
-var 'foo=bar' Set a value for one of the input variables in the root
module of the configuration. Use this option more than
once to set more than one variable.
-var-file=filename Load variable values from the given file, in addition
to the default files terraform.tfvars and *.auto.tfvars.
Use this option more than once to include more than one
variables file.
-
命令行参数:
-var 'foo=bar'
-
参数文件:默认读取 terraform.tfvars(or
*.auto.tfvars
) 或通过命令行-var-file=filename
指定 -
环境变量:可以通过设置名为
TF_VAR_<NAME>
的环境变量为输入变量赋值,例如:$ export TF_VAR_image_id=ami-abc123 $ terraform plan ...
环境变量传值非常适合在自动化流水线中使用,尤其适合用来传递敏感数据,类似密码、访问密钥等
三人行, 必有我师; 知识共享, 天下为公. 本文由东风微鸣技术博客 EWhisper.cn 编写.
Recommend
-
8
二十篇系列:关于签到系统是典型的Birdcage Effect逻辑分析 发布时间:2021-04-19 09:02:02 Tags:Jagex Games,
-
8
黑色5月:典型安全事件超32起,BSC链上项目损失约达3亿美元 链安科技 2021-06-01 12:05 摘要: 多起BSC链上项目在5月集中“...
-
1
信息系统项目典型生命周期模型 精选 原创 微笑涛声 2022-09-19 09:36:56...
-
10
本文是通过 Helm 3 来安装 Velero, 只做最基本的安装。并计划将 YAML (只备份 YAML, 不备份 Volume) 备份到腾讯云的 COS(兼容 S3, 所以可以通过 AWS S3 插件来实现) 需要安装: velero AWS S3 插件 VolumeSnap...
-
5
四 NGINX 高可用实施方案 高可用的实施, 主要步骤概述如下: NGINX 的安装及基础配置 负载均衡层高可用: NGINX + Keepalived配置 应用服务层高可用: NGINX -> 应用服务层 转发配置
-
7
📚️Reference: https://github.com/grafana/intro-to-mlt 这是关于 Grafana 中可观察性的三个支柱的一系列演讲的配套资源库。
-
3
Grafana 系列文章(二):使用 Grafana Agent 和 Grafana Tempo 进行 Tracing ...
-
7
👉️URL: https://grafana.com/docs/tempo/latest/api_docs/pushing-spans-with-http/ 📝Description:
-
5
Terraform 系列-什么是 IaC? 👉
-
6
👉 Terraform 系列文章 最近在使用 Terraform 来置备 OCI 的 Always Free Tier, 发现它非常好用。总结学习下:Terraform 的基础知识。 什么是 Terraform?
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK