You need to enable JavaScript to run this app.
导航

快速安装Terraform Provider volcengine

最近更新时间2024.01.22 16:51:51

首次发布时间2023.07.27 16:30:57

Terraform安装时,需要安装Provider volcengine,但由于Provider Release版本存放在海外服务器,安装可能会失败,本文为您介绍安装Provider volcengine的三种方式,您可以选择以下任意方式完成安装。

方式一:自动安装

您可以通过火山镜像源加速下载或更新Provider。

步骤一:创建CLI配置文件

您需要在环境中创建CLI配置文件,不同操作系统CLI配置文件的存放位置不同:

  • Windows系统:CLI配置文件必须以terraform.rc命名并放置在%APPDATA% 目录,具体目录位置由Windows版本和系统配置决定;也可以在PowerShell中使用$env:APPDATA命令确定位置。

  • 其他系统:需要在home目录下创建.terraformrc文件

CLI配置文件具体内容如下:

provider_installation {
  network_mirror {
    url     = "https://mirrors.volces.com/terraform/"
    include = ["registry.terraform.io/volcengine/*"]
  }
  direct {
    exclude = ["registry.terraform.io/volcengine/*"]
  }
}

步骤二:执行terraform init命令

执行terraform init命令,回显如下,表示安装成功。

$ terraform  init

Initializing the backend...

Initializing provider plugins...
- Finding latest version of volcengine/volcengine...
- Installing volcengine/volcengine v0.0.90...
- Installed volcengine/volcengine v0.0.90 (unauthenticated)

Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.

╷
│ Warning: Incomplete lock file information for providers
│
│ Due to your customized provider installation methods, Terraform was forced to calculate lock file checksums locally for the following providers:
│   - volcengine/volcengine
│
│ The current .terraform.lock.hcl file only includes checksums for linux_amd64, so Terraform running on another platform will fail to install these
│ providers.
│
│ To calculate additional checksums for another platform, run:
│   terraform providers lock -platform=linux_amd64
│ (where linux_amd64 is the platform to generate)
╵

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.

方式二:手动安装

  1. 访问Provider volcengine的下载页面,下载所需版本的压缩包,并将其解压得到执行程序。

  2. 执行xattr -l FileName命令,查看 provider 执行程序的文件权限。
    在执行结果中,如果最后出现 "@",说明该执行程序包含某些扩展属性,最后可能导致 Terraform 调用失败。您需要执行 xattr -d AttributeName FileName 命令清除这些额外属性。

    通常在使用浏览器下载安装包时会出现这种情况。

  3. 执行 terraform version 命令查看 Terraform 版本,并根据版本信息执行以下操作。

    • version < 0.13 :创建目录 ~/.terraform.d/plugins,将解压后得到的 provider 执行程序文件移动至该路径。
    • version >= 0.13 :根据下载的 Provider 版本号,以及环境的 OS 和 Architecture 信息,创建目录 ~/.terraform.d/plugins/registry.terraform.io/volcengine/volcengine/ProviderVersion/OS_ARCH,将解压后得到的 provider 执行程序文件移动至该路径。
  4. 执行 terraform init 命令,Terraform 会自动加载手动安装好的Provider volcengine。

方式三:自动化脚本安装

您也可以使用火山引擎为您提供的脚本自动安装Provider volcengine。

使用前提

请您提前安装如下组件:

  • Terraform:请参考快速入门安装Terraform。

  • wget:用于自动下载Provider volcengine安装包。

    如果您选择手动将安装包下载到本地,则无需安装wget组件,安装包下载地址

  • xattr:安装包可能包含某些扩展属性,导致Terraform调用失败,xattr命令用于清除安装包的扩展属性。

  • unzip:用于解压Provider volcengine安装包。

使用说明

  1. 执行以下命令,下载脚本
    wget https://raw.githubusercontent.com/volcengine/terraform-provider-volcengine/master/manual_install_tf.sh

  2. 运行脚本,安装Provider volcengine。

    请确保脚本具有可执行权限:您可以执行chmod +x manual_install_tf.sh命令授予权限,或者使用 sh 执行脚本。

    • 授予权限后,执行以下命令。
      ./manual_install_tf.sh --version 0.0.89 --arch arm64 --provider /YourPath/terraform-provider-volcengine_0.0.89_darwin_arm64.zip
      
    • 未授予权限,执行以下命令。
      sh manual_install_tf.sh --version 0.0.89 --arch arm64 --provider /YourPath/terraform-provider-volcengine_0.0.89_darwin_arm64.zip
      
    参数是否必填参数说明
    --versionProvider volcengine的版本信息,例如0.0.89,您可以通过安装包下载地址查看版本信息。
    --providerProvider volcengine的本地安装包路径。
    如果不填写,脚本则会使用 wget 命令自动下载对应版本的安装包。

    --arch

    您环境的architecture架构信息,取值:

    • 默认为amd64。
    • 对于Mac M1 / M2 芯片,取值应为--arch arm64