详情页标题前

阿里云RDS数据库在Cloud Shell中使用Terraform-云淘科技

详情页1

阿里云Cloud Shell是一款帮助您运维的免费产品,预装了Terraform的组件,并配置好身份凭证(credentials)。因此您可直接在Cloud Shell中运行Terraform的命令。

操作步骤

  1. 打开浏览器,访问Cloud Shell。

    说明

    更多Cloud Shell入口及使用请参见使用云命令行。

    阿里云RDS数据库在Cloud Shell中使用Terraform-云淘科技

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

    说明

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

    mkdir /usr/local/terraform
    cd /usr/local/terraform
  3. 使用vim编写Terraform模板(terraform.tf)。

    以查询可用区信息为例:

    vim terraform.tf

    模板内容如下:

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

    说明

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

  4. 执行terraform init命令初始化配置。

    执行结果示例:

    shell@Alicloud:/usr/local/terraform$ terraform init
    
    Initializing the backend...
    
    Initializing provider plugins...
    - Checking for available provider plugins...
    - Downloading plugin for provider "alicloud" (hashicorp/alicloud) 1.186.0...
    
    The following providers do not have any version constraints in configuration,
    so the latest version was installed.
    
    To prevent automatic upgrades to new major versions that may contain breaking
    changes, it is recommended to add version = "..." constraints to the
    corresponding provider blocks in configuration, with the constraint strings
    suggested below.
    
    * provider.alicloud: version = "~> 1.186"
    
    
    Warning: registry.terraform.io: 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.
  5. 执行terraform plan命令预览配置。

    执行结果示例:

    shell@Alicloud:/usr/local/terraform$ terraform plan
    Refreshing Terraform state in-memory prior to plan...
    The refreshed state will be used to calculate this plan, but will not be
    persisted to local or remote state storage.
    
    data.alicloud_db_zones.queryzones: Refreshing state...
    
    ------------------------------------------------------------------------
    
    No changes. Infrastructure is up-to-date.
    
    This means that Terraform did not detect any differences between your
    configuration and real physical resources that exist. As a result, no
    actions need to be performed.
  6. 执行terraform apply应用配置。

    执行结果示例:

    shell@Alicloud:/usr/local/terraform$ terraform apply
    data.alicloud_db_zones.queryzones: Refreshing state...
    
    Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
  7. 执行terraform show查看查询结果。

    执行结果示例:

    shell@Alicloud:/usr/local/terraform$ 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/167521.html

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

相关推荐

  • 阿里云大数据开发治理平台 DataWorksGBase8a数据源-云淘科技

    GBase8a数据源为您提供读取和写入GBase8a双向通道的功能,本文为您介绍DataWorks的GBase8a数据同步的能力支持情况。 使用限制 目前Gbase8a Reader和Gbase8a Writer仅支持使用新增和使用独享数据集成资源组。 insert into…:当主键或唯一性索引冲突时,无法写入冲突的行。 目的表所在数据库必须是主库才能…

  • 阿里云RDS数据库修改pg_hba.conf文件配置-云淘科技

    本文介绍如何使用Terraform修改pg_hba.conf文件配置。 前提条件 已创建RDS PostgreSQL实例,详情请参见创建RDS PostgreSQL实例。 实例状态为运行中,您可以通过如下两种方式查看: 参见查询实例详情查看参数status,如果取值为Runing则表示实例状态为运行中。 前往RDS管理控制台,切换到目标地域,找到指定实例后,…

    2023年12月9日
  • 阿里云日志服务SLS简介-云淘科技

    机器组是包含多台服务器的虚拟分组,日志服务通过机器组的方式管理所有需要通过Logtail采集日志的服务器。 日志服务支持通过一个Logtail采集配置来采集多台服务器上的日志,您可以将这些服务器加入到同一个机器组,并将Logtail采集配置应用到该机器组。 您可以通过如下两种方法定义一个机器组。 IP地址:在机器组中添加服务器的IP地址,通过IP地址识别服务…

    阿里云日志服务SLS 2023年12月10日
  • 信息流广告,信息流部分建议宽度830px,只针对默认列表样式,顺序随机
  • 阿里云日志服务SLSLogtail限制说明-云淘科技

    本文简介Logtail采集数据时在运行环境、文件采集、容器采集、CheckPoint管理、Logtail采集配置、机器组、性能、错误处理等方面的限制。 运行环境 限制项 限制说明 体系结构 Linux Logtail版本支持x86_64和arm64。 Windows Logtail版本支持x86_32和x86_64。 内存 负载为空时,不开启插件最少需要20…

    阿里云日志服务SLS 2023年12月10日
  • 阿里云大数据开发治理平台 DataWorks对接使用CDH与CDP-云淘科技

    DataWorks 提供了与CDH(Cloudera’s Distribution Including Apache Hadoop,以下简称CDH) 与CDP(Cloudera Data Platform,以下简称CDP)集群对接的能力,在保留CDH集群或CDP集群作为存储和计算引擎的前提下,您可以使用DataWorks的任务开发、调度、数据地图(元数据管理…

    2023年12月10日

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

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