aws terraform_在AWS上部署LAMP堆栈(第3部分):使用Terraform部署基础架构和应用程序...

aws terraform

In the previous tutorial, three AMIs were built. This step will deploy those AMIs with Terraform.

在上一教程中 ,构建了三个AMI。 此步骤将使用Terraform部署这些AMI。

使用Terraform供应基础架构 (Using Terraform to provision infrastructure)

Terraform by HashiCorp is a tool for creating, combining, and modifying infrastructure. In the Atlas workflow Terraform reads from the artifact registry and provisions infrastructure. In this LAMP tutorial we use Terraform to deploy the three AMIs that were created by Packer in the previous step.

HashiCorp的Terraform是用于创建,组合和修改基础结构的工具。 在Atlas工作流程中,Terraform从工件注册表和配置基础结构中读取。 在本LAMP教程中,我们使用Terraform部署Packer在上一步中创建的三个AMI。

常规设置 (General setup)

To finish this tutorial, you will need to:

要完成本教程,您将需要:

  1. Clone this repository

    克隆此存储库
  2. Create an Atlas account

    创建一个Atlas帐户
  3. Generate an Atlas token and save as environment variable. export ATLAS_TOKEN=<your_token>

    生成Atlas令牌并将其另存为环境变量。 export ATLAS_TOKEN=<your_token>
  4. In the Terraform files replace all instances of <username>, YOUR_SECRET_HERE, and YOUR_KEY_HERE with your Atlas username, Atlas token, and AWS keys. Using "find and replace" in your text editor is probably the fastest way to do this.

    在Terraform文件中,将<username>YOUR_SECRET_HEREYOUR_KEY_HERE所有实例替换为Atlas用户名,Atlas令牌和AWS密钥。 在文本编辑器中使用“查找并替换”可能是最快的方法。

Terraform配置概述 (Terraform configuration overview)

There are four key types in this Terraform configuration. The first is the aws provider, which authorizes Terraform to interact with resources on AWS. The second type is atlas_artifact, which is the reference to the AMI created in the previous step. Atlas artifacts are not limited to just AMIs, you can build and store Google Cloud images, OpenStack images, VMware images, and more. The aws_security_group resource type creates a security group on AWS. Finally, the aws_instance type creates instances on AWS. It's important to note the AMI fields on the aws_instances: ami = "${atlas_artifact.php.metadata_full.region-us-east-1}". As you can see, the AMI id is taken from the atlas_artifact defined above. Terraform interpolates those values and calculates resource dependencies. For example, the artifacts and security group must be created before the instances, since the instances rely on those resources.

此Terraform配置中有四种键类型。 第一个是aws提供程序,它授权Terraform与AWS上的资源进行交互。 第二种类型是atlas_artifact ,它是对上一步中创建的AMI的引用。 Atlas工件不仅限于AMI,您还可以构建和存储Google Cloud映像,OpenStack映像,VMware映像等。 aws_security_group资源类型在AWS上创建一个安全组。 最后, aws_instance类型在AWS上创建实例。 重要的是要注意aws_instances上的AMI字段: ami = "${atlas_artifact.php.metadata_full.region-us-east-1}" 。 如您所见,AMI ID来自atlas_artifact定义的atlas_artifact 。 Terraform内插这些值并计算资源依赖性。 例如,由于实例依赖那些资源,因此必须在实例之前创建构件和安全组。

For more information on Terraform and its configurations, read through the Terraform documenation.

有关Terraform及其配置的更多信息,请通读Terraform文档

步骤1:设置Terraform以在Atlas中保存状态 (Step 1: Setup Terraform to save state in Atlas)

Terraform stores the infrastructure state in order to calculate what changes need to be made on the next deploy. It's possible to store that state locally, or you can store that state in Atlas so multiple operators can collaborate on the same infrastructure. To store state in Atlas: 1. Run terraform remote config -backend-config="name=ATLAS_USERNAME/example" in the terraform directory. Of course replace ATLAS_USERNAME with your personal username.

Terraform存储基础结构状态,以便计算在下一次部署中需要进​​行哪些更改。 可以将状态存储在本地,也可以将状态存储在Atlas中,以便多个操作员可以在同一基础结构上进行协作。 要将状态存储在Atlas中:1.在terraform目录中运行terraform remote config -backend-config="name=ATLAS_USERNAME/example" 。 当然,用您的个人用户名替换ATLAS_USERNAME。

步骤2:将Terraform配置推送到Atlas (Step 2: Push the Terraform configuration to Atlas)

Just as we pushed the Packer template to Atlas to be run remotely, we will push the Terraform configuration to Atlas. 1. Run terraform push -name="ATLAS_USERNAME/example" in the terraform directory. Of course replace ATLAS_USERNAME with your personal username. 1. This will create a Terraform plan in Atlas. To view the plan output, go to the Environments tab in your Atlas account and click on the newly created environment. Then click on the "changes" option in the left navigation to view the proposed changes.

正如我们将Packer模板推送到Atlas以便远程运行一样,我们还将Terraform配置推送到Atlas。 1.在terraform目录中运行terraform push -name="ATLAS_USERNAME/example" 。 当然,用您的个人用户名替换ATLAS_USERNAME。 1.这将在Atlas中创建Terraform计划。 要查看计划输出,请转到Atlas帐户中的“环境”选项卡,然后单击新创建的环境。 然后,单击左侧导航栏中的“更改”选项,以查看建议的更改。

步骤3:部署基础架构 (Step 3: Deploy infrastructure)

  1. If the plan looks good in Atlas, click "Confirm & Apply" to deploy the infrastructure!

    如果该计划在Atlas中看起来不错,请单击“确认并应用”以部署基础结构!
  2. Navigate to the public IP of the PHP instance to see your application.

    导航到PHP实例的公共IP以查看您的应用程序。
  3. Click on "Status" in the left navigation to view the real-time status of the newly deployed nodes

    单击左侧导航中的“状态”以查看新部署的节点的实时状态

评论 (Review)

In the Packer step of this tutorial, you built 3 AMIs. Those AMIs were then deployed with Terraform. A Consul agent was configured in the Packer phase on each AMI.The Consul agent reports the service running on each node, as well as the health of the node.

本教程Packer步骤中 ,您构建了3个AMI 。 然后,这些AMI与Terraform一起部署。 一个领事代理在每个AMI.The领事代理的封隔器相配置报告每个节点上运行的服务,以及节点的健康。

Atlas combines Packer, Terraform, and Consul to make the process of turning application code into a deployed application a auditable, repeatable process.

Atlas将Packer,Terraform和Consul结合在一起,使将应用程序代码转换为已部署应用程序的过程成为可审核,可重复的过程。

下一步 (Next Steps)

To learn more about Atlas, read the getting started guide or experiment with more community examples.

要了解有关Atlas的更多信息,请阅读入门指南或尝试使用更多社区示例

翻译自: https://scotch.io/tutorials/deploying-a-lamp-stack-on-aws-part-3-deploy-infrastructure-and-applications-with-terraform

aws terraform

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值