Skip to content

Head First Iac - Terraform

什么是Terraform

Terraform是一个开源工具,帮助您在多种云(AWS/GCP/Azure/Aliyun等)环境下安全高效地预配和管理云基础结构。

HashiCorp Terraform是一个IT基础架构自动化编排工具,可以用代码来管理维护IT资源。它编写了描述云资源拓扑的配置文件中的基础结构,例如虚拟机、存储账户和网络接口。Terraform的命令行接口(Command Line Interface,CLI)提供一种简单机制,用于将配置文件部署到阿里云或其他任意支持的云上,并对其进行版本控制。更多信息,请参见HashiCorp Terraform

使用步骤

配置token访问

初始化

terraform init

在初始化项目的时候,Terraform会解析目录下的*.tf文件并加载相关的provider插件

Initializing the backend...

Initializing provider plugins...
- Reusing previous version of hashicorp/azurerm from the dependency lock file

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

查看执行计划

terraform plan

执行变更

terraform apply

销毁

terraform destroy

Reference