一. 官网下载安装包
二. 解压到 /usr/local/bin目录
三. 检查terraform是否安装成功
四. 测试百度云-对象存储
    4.1 创建目录
    4.2 进入 terraform-test 目录。
    4.3 创建配置文件。
    4.4 初始化工作目录
    4.5 Terraform 管理 BOS 
    4.6 Terraform 创建 BOS 
    4.7 Terraform 删除 BOS


一. 官网下载安装包

安装文档 hashicorp给出的安装文档

文档中包含下载地址,选择CentOS 的安装包点击下载,格式为.zip

下载地址:https://www.terraform.io/downloads.html

安装包链接:https://releases.hashicorp.com/terraform/0.12.28/terraform_0.12.28_linux_amd64.zip

二. 解压到 /usr/local/bin目录

下载完成后将 .zip解压到 /usr/local/bin 目录下,方便下一步配置PATH变量。解压后的 terraform是一个 binary 可执行文件,如图所示

解压命令:

~$ unzip terraform_0.12.28_linux_amd64.zip -d /usr/local/bin/
~$ cd /usr/bin
~$ sudo ln -s /usr/local/bin/terraform
~$ source ~/.bash_profile

三. 检查terraform是否安装成功

直接在terminal中输入terraform,如果上一步的PATH配置成功,terminal会提示以下信息

四. 测试百度云-对象存储

因为每个 Terraform 项目都需要创建 1 个独立的工作目录,所以先创建一个测试目录 terraform-test。

4.1 创建目录

[root@test bin]#mkdir terraform-test

4.2 进入 terraform-test 目录。

[root@test bin]#cd terraform-test
[root@test terraform-test]#

4.3 创建配置文件。

Terraform 在运行时,会读取该目录空间下所有 *.tf 和 *.tfvars 文件。因此,您可以按照实际用途将配置信息写入到不同的文件中。下面列出几个常用的配置文件:

provider.tf           -- provider 配置
terraform.tfvars      -- 配置 provider 要用到的变量
varable.tf            -- 通用变量
resource.tf           -- 资源定义
data.tf               -- 包文件定义
output.tf             -- 输出

例如:创建 provider.tf 文件时,您可按以下格式配置您的身份认证信息:

[root@test terraform-test]# vim main.tf
provider "baiducloud" {access_key  = "LTA*****************NO2"secret_key  = "MOk8x0*************wwff"region           = "bj"
}

4.4 初始化工作目录

[root@test terraform-test]#terraform initInitializing provider plugins...
- Checking for available provider plugins on https://releases.hashicorp.com...
- Downloading plugin for provider "alicloud" (1.25.0)...

4.5 Terraform 管理 BOS

terraform plan:预览功能,允许在正式执行配置文件之前,查看将要执行哪些操作。

例如,您添加了创建 Bucket 的配置文件 test.tf :

[root@test terraform-test]#vim main.tf
provider "baiducloud" {access_key  = "LTA*****************NO2"secret_key  = "MOk8x0*************wwff"region           = "bj"
}# 创建源 bucket
resource "baiducloud_bos_bucket" "source" {bucket = "charlietang"acl    = "public-read-write"
}

使用 terraform plan 可查看到将会执行的操作。

[root@test terraform-test]# 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.------------------------------------------------------------------------An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:+ createTerraform will perform the following actions:# baiducloud_bos_bucket.tangdd will be created+ resource "baiducloud_bos_bucket" "tangdd" {+ acl                         = "public-read-write"+ bucket                      = "charlietang1"+ creation_date               = (known after apply)+ force_destroy               = false+ id                          = (known after apply)+ location                    = (known after apply)+ owner_id                    = (known after apply)+ owner_name                  = (known after apply)+ server_side_encryption_rule = (known after apply)+ storage_class               = "STANDARD"}Plan: 1 to add, 0 to change, 0 to destroy.------------------------------------------------------------------------Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.

4.6 Terraform 创建 BOS

terraform apply:执行工作目录中的配置文件。

例如您想创建名为 charlietang 的 Bucket,您需要先添加创建 Bucket 的配置文件 main.tf。

[root@localhost baidu-cloud]# terraform applyAn execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:+ createTerraform will perform the following actions:# baiducloud_bos_bucket.tangdd will be created+ resource "baiducloud_bos_bucket" "tangdd" {+ acl                         = "public-read-write"+ bucket                      = "charlietang1"+ creation_date               = (known after apply)+ force_destroy               = false+ id                          = (known after apply)+ location                    = (known after apply)+ owner_id                    = (known after apply)+ owner_name                  = (known after apply)+ server_side_encryption_rule = (known after apply)+ storage_class               = "STANDARD"}Plan: 1 to add, 0 to change, 0 to destroy.Do you want to perform these actions?Terraform will perform the actions described above.Only 'yes' will be accepted to approve.Enter a value: yesbaiducloud_bos_bucket.tangdd: Creating...
baiducloud_bos_bucket.tangdd: Creation complete after 2s [id=charlietang1]Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

4.7 Terraform 删除 BOS

terraform destroy:可删除通过 Terraform 创建的空 Bucket。

[root@localhost baidu-cloud]# terraform destroy
baiducloud_bos_bucket.tangdd: Refreshing state... [id=charlietang1]An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:- destroyTerraform will perform the following actions:# baiducloud_bos_bucket.tangdd will be destroyed- resource "baiducloud_bos_bucket" "tangdd" {- acl                         = "public-read-write" -> null- bucket                      = "charlietang1" -> null- creation_date               = "2020-07-08T06:47:52Z" -> null- force_destroy               = false -> null- id                          = "charlietang1" -> null- location                    = "bj" -> null- owner_id                    = "3b4c0907265d49daa7fbf103bb2cba4a" -> null- owner_name                  = "UC:29883996" -> null- server_side_encryption_rule = "none" -> null- storage_class               = "STANDARD" -> null}Plan: 0 to add, 0 to change, 1 to destroy.Do you really want to destroy all resources?Terraform will destroy all your managed infrastructure, as shown above.There is no undo. Only 'yes' will be accepted to confirm.Enter a value: yesbaiducloud_bos_bucket.tangdd: Destroying... [id=charlietang1]
baiducloud_bos_bucket.tangdd: Destruction complete after 1sDestroy complete! Resources: 1 destroyed.

CentOS 安装及使用 terraform 最新教程相关推荐

  1. CentOS安装Oracle数据库12C图文教程

    CentOS安装Oracle数据库12C 前言说明 准备工具 虚拟机安装CentOS系统步骤-不弄任何文字,全程图片步骤,会安装请直接跳过 卸载自带的openjava安装SUN java 开始安装Or ...

  2. linux安装ssl证书步骤,centos安装SSL证书的图文教程

    centos安装SSL证书之前首先要去申请一张SSL证书,证书颁发下来之后就可以进行安装,具体的安装教程如下: 一.安装Nginx Web服务器 如图所示,新建文件:/etc/yum.repos.d/ ...

  3. Linux/Centos安装oracle11超详细图文教程

    安装oracle11g,顺便做个记录方便后续查看 目录 数据库安装包下载 安装包上传解压 系统参数及环境初始化 安装数据库服务 设置本地图形显示 设置临时语言环境 取消邮件通知 跳过更新 安装内容 数 ...

  4. CentOS安装使用.netcore极简教程(免费提供学习服务器)

    本文目标是指引从未使用过Linux的.Neter,如何在CentOS7上安装.Net Core环境,以及部署.Net Core应用. 仅针对CentOS,其它Linux系统类似,命令环节稍加调整: 需 ...

  5. Centos安装NFS服务器配置及挂载教程

    为什么80%的码农都做不了架构师?>>>    一.环境介绍: 服务器:centos 192.168.1.225 客户端:centos 192.168.1.226 二.安装: NFS ...

  6. 最新Golang安装教程(Linux环境 Ubuntu + Go) 附centos安装视频链接

    文章目录 下载 小提示: 安装 centos安装视频链接 下载 首先进入网址: https://golang.google.cn/dl/ 然后找到linux版本,右键,复制链接地址. 如图: 然后进入 ...

  7. Ubuntu和Centos安装Tensorflow教程PyTorch

    更多请关注: https://github.com/chanhal https://www.zhihu.com/people/chanhal https://github.com/chanhal/co ...

  8. centos llvm安装_在CentOS上编译安装llvm-3.8.1详细教程

    在CentOS上编译安装llvm-3.8.1详细教程 2020/1/11  18:12 1682次 注:CentOS版本是6.8,6.x版本的操作类似 安装需求: [list] [*]Cmake: 3 ...

  9. centos mysql php tomcat_Linux 安装JDK Tomcat MySQL的教程(使用Mac远程访问)

    一 环境 阿里云服务器: CentOS 7.4 64位(基于RedHat) 本机: macOS High Sierra 二 压缩包 三 文件传输 输入SFTP命令连接 -> 输入实例登录密码 s ...

最新文章

  1. 今天终于把ati集成显卡的linux驱动装好了,看我的3D桌面!哈哈!(博客搬家 2007-07-28 15:56)
  2. linux转mysql_转linux下mysql命令
  3. springboot 启动分析【难点】——如何自动扫描 @SpringBootApplication||如何加载自动配置类 @EnableAutoConfiguration||如何加载前端控制器
  4. wcf 远程终结点已终止该序列 可靠会话出错
  5. 开源!100 页机器学习教程全面开放,附完整代码
  6. Debian 8.2 64位 安装MongoDB
  7. dim private public static_PHP中const,static,public,private,protected的区别
  8. 干货收藏!一文看懂8个常用Python库从安装到应用
  9. C#设计模式之1-工厂方法模式
  10. 唏嘘!又一家手机工厂关闭,一代机皇彻底退出中国制造
  11. 解决eclipse/myeclipse导入项目时出现红色叹号的方法
  12. awk --- 常用技巧
  13. MyBatis(九)------MyBatis的优缺点知多少
  14. 噪声调相干扰matlab程序,噪声调相干扰信号的性能仿真
  15. LayaBox2D使用自定义Shader的方法
  16. 用Java实现N*N的标准数独及对角线数独解题
  17. es拼音分词 大帅哥_Elasticsearch中文分词加拼音
  18. 8. python str( )函数
  19. 图解在EXCEL中,通过身份证自动获得出生日期和性别。
  20. 小程序生成二维码海报

热门文章

  1. 【android】【转】class android.media.MediaPlayer
  2. CodeForces - 468C Hack it!(构造+数位dp)
  3. CodeForces - 1307B Cow and Friend(数学+思维)
  4. 牛客 - 配对(贪心+数学)
  5. HDU - 4612 Warm up(边双缩点+树的直径)
  6. CodeForces - 353E Antichain(贪心+思维)
  7. Photo.scr病毒
  8. 基于 ida 的反汇编转换 Obj 的可行性 笔记(1)
  9. 读取SSDT表和原函数地址
  10. C++ POD(Plain Old Data)类型