Terraform(二)

Terraform实践

    • 1. Terraform Docker Example
      • 1.1 Install Terraform
      • 1.2 Verify the installation
      • 1.3 Enable tab completion
      • 1.4 Quick start tutorial

在这里插入图片描述
To deploy infrastructure with Terraform:

  • Scope - Identify the infrastructure for your project.
  • Author - Write the configuration for your infrastructure.
  • Initialize - Install the plugins Terraform needs to manage the infrastructure.
  • Plan - Preview the changes Terraform will make to match your configuration.
  • Apply - Make the planned changes.

1. Terraform Docker Example

https://developer.hashicorp.com/terraform/tutorials/docker-get-started

1.1 Install Terraform

yum install -y yum-utils
yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
yum -y install terraform

Tip
Now that you have added the HashiCorp repository, you can install Vault, Consul, Nomad and Packer with the same command.

1.2 Verify the installation

[root@node-252 ~]# terraform -help
Usage: terraform [global options] <subcommand> [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
...
[root@node-252 ~]# terraform -help plan
Usage: terraform [global options] plan [options]

  Generates a speculative execution plan, showing what actions Terraform
  would take to apply the current configuration. This command will not
  actually perform the planned actions.

  You can optionally save the plan to a file, which you can then pass to
  the "apply" command to perform exactly the actions described in the plan.
...

Troubleshoot
If you get an error that terraform could not be found, your PATH environment variable was not set up properly. Please go back and ensure that your PATH variable contains the directory where Terraform was installed.

1.3 Enable tab completion

If you use either Bash or Zsh, you can enable tab completion for Terraform commands. To enable autocomplete, first ensure that a config file exists for your chosen shell.

touch ~/.bashrc

Then install the autocomplete package.

[root@node-252 ~]# terraform -install-autocomplete

1.4 Quick start tutorial

Now that you’ve installed Terraform, you can provision an NGINX server in less than a minute using Docker on Mac, Windows, or Linux. You can also follow the rest of this tutorial in your web browser.

  1. Create a directory named learn-terraform-docker-container.
mkdir learn-terraform-docker-container
  1. Navigate into the working directory.
cd learn-terraform-docker-container
  1. In the working directory, create a file called main.tf and paste the following Terraform configuration into it.
terraform {
  required_providers {
    docker = {
      source  = "kreuzwerker/docker"
      version = "~> 3.0.1"
    }
  }
}

provider "docker" {}

resource "docker_image" "nginx" {
  name         = "nginx"
  keep_locally = false
}

resource "docker_container" "nginx" {
  image = docker_image.nginx.image_id
  name  = "tutorial"

  ports {
    internal = 80
    external = 8000
  }
}
  1. Initialize the project, which downloads a plugin called a provider that lets Terraform interact with Docker.
terraform init
  1. Provision the NGINX server container with apply. When Terraform asks you to confirm type yes and press ENTER.
terraform apply
[root@node-135 learn-terraform-docker-container]# terraform apply

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
symbols:
  + create

Terraform will perform the following actions:

  # docker_container.nginx will be created
  + resource "docker_container" "nginx" {
      + attach                                      = false
      + bridge                                      = (known after apply)
      + command                                     = (known after apply)
      + container_logs                              = (known after apply)
      + container_read_refresh_timeout_milliseconds = 15000
      + entrypoint                                  = (known after apply)
      + env                                         = (known after apply)
      + exit_code                                   = (known after apply)
      + hostname                                    = (known after apply)
      + id                                          = (known after apply)
      + image                                       = (known after apply)
      + init                                        = (known after apply)
      + ipc_mode                                    = (known after apply)
      + log_driver                                  = (known after apply)
      + logs                                        = false
      + must_run                                    = true
      + name                                        = "tutorial"
      + network_data                                = (known after apply)
      + read_only                                   = false
      + remove_volumes                              = true
      + restart                                     = "no"
      + rm                                          = false
      + runtime                                     = (known after apply)
      + security_opts                               = (known after apply)
      + shm_size                                    = (known after apply)
      + start                                       = true
      + stdin_open                                  = false
      + stop_signal                                 = (known after apply)
      + stop_timeout                                = (known after apply)
      + tty                                         = false
      + wait                                        = false
      + wait_timeout                                = 60

      + ports {
          + external = 8000
          + internal = 80
          + ip       = "0.0.0.0"
          + protocol = "tcp"
        }
    }

  # docker_image.nginx will be created
  + resource "docker_image" "nginx" {
      + id           = (known after apply)
      + image_id     = (known after apply)
      + keep_locally = false
      + name         = "nginx"
      + repo_digest  = (known after apply)
    }

Plan: 2 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: yes

docker_image.nginx: Creating...
docker_image.nginx: Still creating... [10s elapsed]
docker_image.nginx: Still creating... [20s elapsed]
docker_image.nginx: Still creating... [30s elapsed]
docker_image.nginx: Still creating... [42s elapsed]
docker_image.nginx: Still creating... [52s elapsed]
docker_image.nginx: Creation complete after 54s [id=sha256:eea7b3dcba7ee47c0d16a60cc85d2b977d166be3960541991f3e6294d795ed24nginx]
docker_container.nginx: Creating...
docker_container.nginx: Still creating... [10s elapsed]
docker_container.nginx: Still creating... [21s elapsed]
docker_container.nginx: Creation complete after 22s [id=109baf53333c9a9b71695a1d639eedd29e6cb8afd0ef259b88cd5c998efe6983]

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
  1. Verify the existence of the NGINX container by visiting localhost:8000 in your web browser or running docker ps to see the container.
docker ps
[root@node-135 learn-terraform-docker-container]# docker ps
CONTAINER ID   IMAGE              COMMAND                  CREATED          STATUS          PORTS                    NAMES
109baf53333c   eea7b3dcba7e       "/docker-entrypoint.…"   59 seconds ago   Up 39 seconds   0.0.0.0:8000->80/tcp     tutorial
  1. To stop the container, run terraform destroy.
terraform destroy

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/88106.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【Rust】Rust学习 第十九章高级特征

现在我们已经学习了 Rust 编程语言中最常用的部分。在第二十章开始另一个新项目之前&#xff0c;让我们聊聊一些总有一天你会遇上的部分内容。你可以将本章作为不经意间遇到未知的内容时的参考。本章将要学习的功能在一些非常特定的场景下很有用处。虽然很少会碰到它们&#xf…

Mysql简短又易懂

MySql 连接池:的两个参数 最大连接数&#xff1a;可以同时发起的最大连接数 单次最大数据报文&#xff1a;接受数据报文的最大长度 数据库如何存储数据 存储引擎&#xff1a; InnoDB:通过执行器对内存和磁盘的数据进行写入和读出 优化SQL语句innoDB会把需要写入或者更新的数…

FPGA原理与结构——RAM IP核的使用与测试

目录 一、前言 二、RAM IP核定制 1、RAM IP核 step1 打开vivado工程&#xff0c;点击左侧栏中的IP Catalog step2 在搜索栏搜索RAM&#xff0c;找到Block Memory Generator IP核&#xff1a; 2、IP核定制 step3 Baisc界面定制 step4 端口定制 step5 Other Options st…

[JavaWeb]【十三】web后端开发-原理篇

目录 一、SpringBoot配置优先级 1.1 配置优先级比较 1.2 java系统属性和命令行参数 1.3 打包运行jar 1.4 综合优先级​编辑 二、Bean管理 2.1 获取bean 2.2 bean作用域 2.2.1 五种作用域 2.2.2 配置作用域 2.3 第三方bean 2.3.1 编写公共配置类 三、SpringBoot原理 …

19万字智慧城市总体规划与设计方案WORD

导读&#xff1a;原文《19万字智慧城市总体规划与设计方案WORD》&#xff08;获取来源见文尾&#xff09;&#xff0c;本文精选其中精华及架构部分&#xff0c;逻辑清晰、内容完整&#xff0c;为快速形成售前方案提供参考。 感知基础设施 感知基础设施架构由感知范围、感知手…

SpringBoot 微人事 职称管理模块(十三)

职称管理前端页面设计 在职称管理页面添加输入框 export default {name: "JobLevelMarna",data(){return{Jl:{name:""}}}}效果图 添加一个下拉框 v-model的值为当前被选中的el-option的 value 属性值 <el-select v-model"Jl.titlelevel" …

Linux 打开U盘硬盘等报错 file type exfat not configured in kernel

目录 原因&#xff1a; 查看系统文件系统和当前系统版本 回归正题&#xff0c;如何解决报错 在centons 7中打开U盘&#xff0c;报错file type exfat not configured in kernel。 原因&#xff1a; 这是因为Linux采用的文件系统和我U盘的文件系统不一致引起。如下图&#xf…

Maven介绍与配置+IDEA集成Maven+使用Maven命令

目录 一、Maven简介 二、配置环境变量 三、IDEA集成Maven 1.配置本地仓库地址 2.集成Maven 3. pom.xml文件介绍 四、Maven命令 jar包太多、jar包相互依赖、不方便管理、项目编译还需要jar包&#xff0c;Maven工具来帮你&#xff01; 一、Maven简介 Maven 是 Apache 软…

解决生僻字,中兴新支点操作系统通过GB 18030-2022《中文编码字符集》认证

您认识上图中的这个字吗&#xff1f; 上面一个“鸟”&#xff0c;下面一个“甲”&#xff0c;这个字读“nia&#xff08;四声&#xff09;”。它是云南丽江傈僳族中一支氏族的姓氏。这个氏族以鸟为图腾。因信息系统中无法输入显示“nia”字&#xff0c;氏族里近700人不得不妥协…

【第七讲---视觉里程计1】

视觉里程计就是通过对图像进行特征提取与匹配得到两帧之间的位姿&#xff0c;并进行估计相机运动。 经典SLAM中以相机位姿-路标来描述SLAM过程 特征提取与匹配 路标是三维空间中固定不变的点&#xff0c;可以在特定位姿下观测到在视觉SLAM中&#xff0c;可利用图像特征点作为…

优化时间流:区间调度问题的探索与解决

在浩如烟海的信息时代&#xff0c;时间的有效管理成为了一门不可或缺的艺术。无论是生活中的琐事&#xff0c;还是工作中的任务&#xff0c;时间都在无声地流逝&#xff0c;挑战着我们的智慧。正如时间在日常生活中具有的宝贵价值一样&#xff0c;在计算机科学领域&#xff0c;…

20.图的遍历

目录 一. 深度优先遍历 二. 广度优先遍历 图的遍历算法和二叉树不同的是&#xff0c;图中可能存在回路&#xff0c;且图的任一顶点都可能与其它顶点相通&#xff0c;在访问完某个顶点之后可能会沿着某些边又回到了曾经访问过的顶点。为了避免重复访问&#xff0c;我们的解决思…

Python 密码破解指南:15~19

协议&#xff1a;CC BY-NC-SA 4.0 译者&#xff1a;飞龙 本文来自【OpenDocCN 饱和式翻译计划】&#xff0c;采用译后编辑&#xff08;MTPE&#xff09;流程来尽可能提升效率。 收割 SB 的人会被 SB 们封神&#xff0c;试图唤醒 SB 的人是 SB 眼中的 SB。——SB 第三定律 十五、…

知网G4期刊《高考》简介及投稿要求

知网G4期刊《高考》简介及投稿要求 一、《高考》期刊简介&#xff1a; 主管单位&#xff1a;长春市委宣传部 主办单位&#xff1a;长春出版社 国内刊号22-1372/G4 国际刊号1673-6265 代号12-240 编辑单位&#xff1a;《高考》杂志社 出版周期&#xff1a;旬刊 类 …

使用Termux在安卓手机上搭建Hexo博客网站,并发布到公网访问

文章目录 1. 安装 Hexo2. 安装cpolar内网穿透3. 公网远程访问4. 固定公网地址 Hexo 是一个用 Nodejs 编写的快速、简洁且高效的博客框架。Hexo 使用 Markdown 解析文章&#xff0c;在几秒内&#xff0c;即可利用靓丽的主题生成静态网页。 下面介绍在Termux中安装个人hexo博客并…

湘潭大学 湘大 XTU OJ 1271 Color 题解(非常详细)

链接 1271 题面 题目描述 Alice在玩一个游戏&#xff0c;她在一个mn的格子里&#xff0c;随机涂黑k个格子。然后她每次可以把一行或者一列的格子染成红色&#xff0c;但是这一行中不能有黑色的格子。 请问她最多能把多少个格子涂成红色&#xff1f; 输入 第一行是一个整数…

geacon_pro配合catcs4.5上线Mac、Linux

我的个人博客: xzajyjs.cn 一些链接 Try师傅的catcs4.5项目: https://github.com/TryGOTry/CobaltStrike_Cat_4.5&#xff0c;最新版解压密码见&#xff1a;https://www.nctry.com/2708.html geacon_pro: https://github.com/testxxxzzz/geacon_pro BeaconTool.jar: https:/…

多线程与高并发——并发编程(1)

文章目录 并发编程一、线程的基本概念1 基础概念1.1 进程和线程1.2 多线程1.3 串行、并行、并发1.4 同步异步、阻塞非阻塞 2 线程的创建2.1 继承Thread类&#xff0c;重写run方法2.2 实现Runnable接口&#xff0c;实现run方法2.3 实现Callable接口&#xff0c;实现call方法&…

30分钟Python自动化从入门到实战(一)

第一章:自动化测试基础 第一节 软件测试分类 关于软件测试领域名词颇多&#xff0c;发现有许多测试新手混淆概念&#xff0c;从不同的角度可以将软件测试有不同的分类的方法&#xff1b;所以&#xff0c;这里汇总常见软件测试的相关名词&#xff0c;对软件测试领域有个概括的…

为什么需要单元测试?

为什么需要单元测试&#xff1f; 从产品角度而言&#xff0c;常规的功能测试、系统测试都是站在产品局部或全局功能进行测试&#xff0c;能够很好地与用户的需要相结合&#xff0c;但是缺乏了对产品研发细节&#xff08;特别是代码细节的理解&#xff09;。 从测试人员角度而言…