详情页标题前

阿里云RDS数据库在本地安装和配置Terraform-云淘科技

详情页1

在使用%ignore_a_1%的模板语言定义、预览和部署云资源前,您也可以在本地安装预配置Terraform。

操作步骤

  1. 安装程序包。

    1. 前往Terraform官网下载适用于您的操作系统的程序包。

    2. 将程序包解压。

      • Linux或macOS操作系统:将程序包解压到/usr/local/bin目录中,如果将可执行文件解压到其他目录,需要为其设置环境变量。具体方法请参见在Linux系统或macOS系统设置环境变量。

      • Windows操作系统:将程序包解压到任意目录,例如D: erraform\目录,然后将该目录添加到环境变量path中。具体方法请参见在Windows系统设置环境变量。

    3. 运行terraform验证路径配置。

      将显示可用的Terraform选项的列表,类似如下所示,表示安装完成。

      Usage: terraform [global options]  [args]
      
      The available commands for execution are listed below.
      The primary workflow commands are given first, followed by
      less common or more advanced commands.
      
      Main commands:
        init          Prepare your working directory for other commands
        validate      Check whether the configuration is valid
        plan          Show changes required by the current configuration
        apply         Create or update infrastructure
        destroy       Destroy previously-created infrastructure
      
      All other commands:
        console       Try Terraform expressions at an interactive command prompt
        fmt           Reformat your configuration in the standard style
        force-unlock  Release a stuck lock on the current workspace
        get           Install or upgrade remote Terraform modules
        graph         Generate a Graphviz graph of the steps in an operation
        import        Associate existing infrastructure with a Terraform resource
        login         Obtain and save credentials for a remote host
        logout        Remove locally-stored credentials for a remote host
        output        Show output values from your root module
        providers     Show the providers required for this configuration
        refresh       Update the state to match remote systems
        show          Show the current state or a saved plan
        state         Advanced state management
        taint         Mark a resource instance as not fully functional
        test          Experimental support for module integration testing
        untaint       Remove the 'tainted' state from a resource instance
        version       Show the current Terraform version
        workspace     Workspace management
      
      Global options (use these before the subcommand, if any):
        -chdir=DIR    Switch to a different working directory before executing the
                      given subcommand.
        -help         Show this help output, or the help for a specified subcommand.
        -version      An alias for the "version" subcommand.
  2. 为提高权限管理的灵活性和安全性,建议您创建RAM用户,并为其授权。

    1. 登录RAM控制台。

    2. 创建名为Terraform的RAM用户,并为该用户创建AccessKey。具体步骤请参见创建RAM用户和创建AccessKey。

    3. 为RAM用户授权。在本示例中,给用户Terraform授予AliyunRDSFullAccess、AliyunVPCFullAccess和AliyunRAMFullAccess权限,具体步骤请参见为RAM用户授权。

  3. 创建环境变量,用于存放身份认证信息。

    • Linux或macOS:

      export ALICLOUD_ACCESS_KEY="*****"
      export ALICLOUD_SECRET_KEY="*****"
      export ALICLOUD_REGION="cn-hangzhou"

      说明

      ALICLOUD_REGION表示待操作的地域,该配置需与后续创建实例的地域保持一致,请根据实际情况修改。

    • Windows:在系统环境变量中分别添加ALICLOUD_ACCESS_KEY、ALICLOUD_SECRET_KEY和ALICLOUD_REGION。阿里云RDS数据库在本地安装和配置Terraform-云淘科技

  4. 创建执行目录及Terraform模板(terraform.tf)文件。

    1. 创建执行目录并进入。

      说明

      需要为每个Terraform项目创建一个独立的执行目录。

      • Linux或macOS:

        sudo mkdir /usr/local/terraform
        cd /usr/local/terraform

        重要

        如果您使用的非root权限用户,则还需要为terraform目录授权,使用sudo chown -R : /usr/local/terraform命令,将terraform文件夹的owner修改为当前用户。

      • Windows:以D盘下创建rdspg文件夹为例,进入rdspg文件夹。

    2. 在执行目录下,创建Terraform模板(terraform.tf)文件。

      • Linux或macOS:

        touch terraform.tf
      • Windows:手动创建terraform.tf文件。

  5. 以查询可用区信息为例,编辑terraform.tf文件,补充如下信息。

    • Linux或macOS:

      vim terraform.tf
    • Windows:编辑terraform.tf文件。

    模板内容如下:

    data "alicloud_db_zones" "queryzones" {
      instance_charge_type= "PostPaid"
      engine = "PostgreSQL"
      db_instance_storage_type = "cloud_essd"
    }

    说明

    vim命令配置完成后,需按Esc后输入:wq保存并退出。

  6. 在执行目录中使用terraform init命令初始化配置。

    以Windows客户端为例,执行结果示例如下:

    PS D:\rdspg> terraform init
    
    Initializing the backend...
    
    Initializing provider plugins...
    - Reusing previous version of hashicorp/alicloud from the dependency lock file
    - Using previously-installed hashicorp/alicloud v1.186.0
    
    ╷
    │ Warning: Additional provider information from registry
    │
    │ The remote registry returned warnings for registry.terraform.io/hashicorp/alicloud:
    │ - For users on Terraform 0.13 or greater, this provider has moved to aliyun/alicloud. Please update your source in
    │ required_providers.
    ╵
    
    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.
  7. 执行terraform plan命令预览配置。

    以Windows客户端为例,执行结果示例如下:

    PS D:\rdspg> terraform plan
    data.alicloud_db_zones.queryzones: Reading...
    data.alicloud_db_zones.queryzones: Read complete after 4s [id=491248936]
    
    No changes. Your infrastructure matches the configuration.
    
    Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are
    needed.
  8. 执行terraform apply应用配置。

    以Windows客户端为例,执行结果示例如下:

    PS D:\rdspg> terraform apply
    data.alicloud_db_zones.queryzones: Reading...
    data.alicloud_db_zones.queryzones: Read complete after 0s [id=491248936]
    
    No changes. Your infrastructure matches the configuration.
    
    Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are
    needed.
    
    Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
  9. 执行terraform show查看查询结果。

    以Windows客户端为例,执行结果示例如下:

    PS D:\rdspg> terraform show
    # data.alicloud_db_zones.queryzones:
    data "alicloud_db_zones" "queryzones" {
        db_instance_storage_type = "cloud_essd"
        engine                   = "PostgreSQL"
        id                       = "491248936"
        ids                      = [
            "cn-hangzhou-g",
            "cn-hangzhou-h",
            "cn-hangzhou-i",
            "cn-hangzhou-j",
            "cn-hangzhou-k",
        ]
        instance_charge_type     = "PostPaid"
        multi                    = false
        multi_zone               = false
        zones                    = [
            {
                id             = "cn-hangzhou-g"
                multi_zone_ids = []
            },
            {
                id             = "cn-hangzhou-h"
                multi_zone_ids = []
            },
            {
                id             = "cn-hangzhou-i"
                multi_zone_ids = []
            },
            {
                id             = "cn-hangzhou-j"
                multi_zone_ids = []
            },
            {
                id             = "cn-hangzhou-k"
                multi_zone_ids = []
            },
        ]
    }

内容没看懂? 不太想学习?想快速解决? 有偿解决: 联系专家

阿里云企业补贴进行中: 马上申请

腾讯云限时活动1折起,即将结束: 马上收藏

同尘科技为腾讯云授权服务中心。

购买腾讯云产品享受折上折,更有现金返利:同意关联,立享优惠

转转请注明出处:https://www.yunxiaoer.com/167540.html

(0)
上一篇 2023年12月10日 上午10:17
下一篇 2023年12月10日
详情页2

相关推荐

  • 阿里云ECS云服务器CreateLaunchTemplate-云淘科技

    调用CreateLaunchTemplate创建一个ECS实例启动模板,简称模板。实例启动模板能免除每次创建实例时都需要填入大量配置参数。 接口说明 实例启动模板中包含用于创建实例的相关配置,例如实例所属地域、镜像ID、实例规格、安全组ID和公网带宽等。如果模板中没有指定某一实例配置,您需要在创建实例时为实例指定该配置。 创建模板(CreateLaunchT…

    阿里云服务器 2023年12月9日
  • 阿里云RDS数据库逻辑复制(pglogical)-云淘科技

    pglogical是一个完全作为PostgreSQL扩展实现的逻辑复制系统,为PostgreSQL数据库提供了逻辑流复制发布和订阅的功能。 前提条件 RDS PostgreSQL实例大版本为10或以上。 实例内核小版本为20230830或以上。 重要 20230830内核小版本之前已支持此插件,但为了规范插件管理,提升RDS PostgreSQL在插件侧的安…

    阿里云数据库 2023年12月9日
  • 信息流广告,信息流部分建议宽度830px,只针对默认列表样式,顺序随机
  • 阿里云日志服务SLS创建可信实体为阿里云服务的RAM角色及授权-云淘科技

    本文介绍如何创建可信实体为阿里云服务的RAM角色及授权。该RAM角色主要用于解决跨云服务授权访问的问题。 步骤一:创建RAM角色 登录RAM控制台。 在左侧导航栏中,选择身份管理 > 角色。 在角色页面,单击创建角色。 在选择类型配置向导中,选择可信实体类型为阿里云服务,然后单击下一步。 在配置角色配置向导中,配置如下内容,然后单击完成。 参数 说明 …

    阿里云日志服务SLS 2023年12月10日
  • 阿里云日志服务SLS创建流日志-云淘科技

    本文介绍在VPC控制台上创建流日志的操作步骤及其相关的操作。 前提条件 已创建资源实例。具体操作,请参见创建弹性网卡、创建和管理专有网络和创建和管理交换机。 已在资源实例所在地域创建日志服务Project和Logstore。具体操作,请参见创建Project和创建Logstore。 操作步骤 重要 如果您使用RAM用户开通流日志功能,则需先为RAM用户授权。…

    2023年12月10日
  • 阿里云容器服务ACK使用ImageCache加速创建Pod-云淘科技

    阿里云以ImageCache CRD的方式将ECI的镜像缓存功能提供给Kubernetes用户,以便Kubernetes用户也可以使用该功能来加速创建Pod。本文介绍如何使用ImageCache加速创建Pod。 配置说明 ImageCache资源是Cluster级别,因此在不同的Namespace下创建Pod时均可以使用ImageCache来实现加速创建Po…

    阿里云容器服务 2023年12月10日

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
本站为广大会员提供阿里云、腾讯云、华为云、百度云等一线大厂的购买,续费优惠,保证底价,买贵退差。