初始文件准备
获取 terraform bin文件
先准备一台可联网的Centos/RHEL,安装terraform 或者把terraform的安装文件下载下来
官方文档:支持 MAC,Win,Linux
https://developer.hashicorp.com/terraform/tutorials/azure-get-started/install-cli
Centos/RHEL
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo yum -y install terraform
检查版本
[root@centos8 azure-terraform]# terraform version
Terraform v1.3.9
on linux_amd64
+ provider registry.terraform.io/hashicorp/azurerm v3.44.1
[root@centos8 test]# whereis terraform
terraform: /usr/bin/terraform
把 /usr/bin/terraform 文件上传到离线环境
获取 terraform 插件
新建一个目录,创建要用的 providers.tf 文件,文件中定义好要使用的插件,比如此处是 azurerm 不低于3.0版本
执行 terraform init 则会依照版本要求下载最新的插件,存放路径为当前目录的 .terraform
将来要使用其他插件,也是在此文件定义插件版本,执行 init 命令自动下载插件
mkdir test
cd test/
# 新建 providers.tf 文件
[root@centos8 test]# cat providers.tf
terraform {
required_version = ">=1.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>3.0"
}
}
}
provider "azurerm"