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

配置 Terraform

最近更新时间2024.01.22 17:52:36

首次发布时间2023.04.18 19:06:03

本文介绍配置 Terraform 的操作步骤。

前提条件

使用 Terraform 管理云数据库 MySQL 版的云资源前,您需要先获取 AK/SK。更多关于如何获取 AK/SK 的信息,请参见访问密钥

操作步骤

  1. 在任意目录下创建一个文本文件,命名为 main.tf

  2. 编辑 main.tf 文件,添加以下内容,设置 Provider 信息。

    terraform {
      required_providers {
        volcengine = {
          source = "volcengine/volcengine"
          version = "0.0.137"
        }
      }
    }
    
    provider "volcengine" {
      access_key = "Your Access Key"
      secret_key = "Your Secret Key"
      region = "cn-beijing"
    }
    

    Provider 中各字段的说明如下:

    • 最新的 version 信息请从 Terraform 获取。
    • access_key必填,密钥 ID,即 AK。
    • secret_key必填,访问密钥,即 SK。
    • region必填,地域。即需要创建管理的资源所属的地域。您可以在这里查询云数据库 MySQL 版支持的地域。
    • session_token选填,角色扮演的安全令牌,如果使用角色扮演,授权后可以通过这里获取。
  3. 进入 main.tf 所在目录,在终端执行 terraform init 进行 terraform 的初始化。有如下响应表示配置成功。

    $ terraform init
    
    Initializing the backend...
    
    Initializing provider plugins...
    - Reusing previous version of volcengine/volcengine from the dependency lock file
    - Using previously-installed volcengine/volcengine v0.0.67
    
    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.