hugo-teek is loading...

Terraform使用

最后更新于:

Terraform

默认下载插件目录

当前目录下.terraform

image-20240530192429976

terraform配置文件

1#vim /root/terraformrc

terraformrc 文件是 Terraform 的配置文件,通常命名为 .terraformrcterraform.rc,它位于用户的主目录下。在 Windows 系统上,该文件被命名为 terraform.rc 并且位于用户的“应用数据”文件夹中。这个文件用于配置一些 Terraform 的全局设置,如插件的安装位置和访问 Terraform Registry 的凭证。

以下是 .terraformrc 中可以设置的一些常用参数:

  1. plugin_cache_dir - 指定插件缓存的目录位置,用于加速插件下载和安装。

    1plugin_cache_dir = "$HOME/.terraform.d/plugin-cache"
    
  2. provider_installation - 用于配置自定义的提供程序安装选项,例如直接从文件系统中安装,或者指定镜像地址。

     1provider_installation {
     2  filesystem_mirror {
     3    path    = "/mnt/terraform-plugins"
     4    include = ["registry.terraform.io/*/*"]
     5  }
     6  network_mirror {
     7    url     = "https://mirrors.example.com/terraform/"
     8    include = ["registry.terraform.io/*/*"]
     9  }
    10  direct {
    11    exclude = ["registry.terraform.io/hashicorp/*"]
    12  }
    13}
    
  3. credentials - 用来设置访问私有 Terraform Registry 的凭证。

    1credentials "app.terraform.io" {
    2  token = "xxxxxx.atlasv1.zzzzzzzzzzzzz"
    3}
    
  4. disable_checkpoint - 可以禁用 Terraform 的检查点功能,这通常用于避免自动更新和检查 Terraform 版本。

    1disable_checkpoint = true
    
  5. disable_checkpoint_signature - 关闭检查点签名验证,增加安全风险。

    1disable_checkpoint_signature = true
    

请注意,对于大多数用户来说,.terraformrc 文件是不必要的,因为 Terraform 默认情况下会采用合理的设置。.terraformrc 文件通常用于高级用户或在企业环境中,需要细致地控制 Terraform 的行为时使用。如果你选择使用 .terraformrc 文件,请确保它不被错误地提交到版本控制系统中,因为它可能包含敏感信息。

命令

1terraform init
2
3#install
4terraform apply --auto-approve
5
6# uninstall
7terraform destroy --auto-approve

注意:当使用terraform重新部署一个应用时,之前生成的缓存文件一定要清理干净,否则会各种报错

 1[root@devops8 k8s]#ls -al
 2total 48
 3drwxr-xr-x 3 root root   128 Jun 19 09:06 .
 4drwxr-xr-x 6 root root   115 May 30 21:13 ..
 5-rw-r--r-- 1 root root 15343 May 30 17:37 ingress.yaml
 6-rw-r--r-- 1 root root  2778 May 30 17:37 kind.tf
 7-rw-r--r-- 1 root root  1010 May 30 17:37 README.md
 8drwxr-xr-x 3 root root    23 Jun 19 09:04 .terraform
 9-rw-r--r-- 1 root root   452 Jun 19 09:04 .terraform.lock.hcl
10-rw-r--r-- 1 root root 19207 Jun 19 09:06 terraform.tfstate
11[root@devops8 k8s]#rm -rf .terraform .terraform.lock.hcl terraform.tfstate
推荐使用微信支付
微信支付二维码
推荐使用支付宝
支付宝二维码
最新文章

文档导航