aws terraform
In the previous tutorial, three AMIs were built. This step will deploy those AMIs with Terraform.
在上一教程中 ,构建了三个AMI。 此步骤将使用Terraform部署这些AMI。
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。
To finish this tutorial, you will need to:
要完成本教程,您将需要:
export ATLAS_TOKEN=<your_token>
生成Atlas令牌并将其另存为环境变量。 export ATLAS_TOKEN=<your_token>
<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_HERE
和YOUR_KEY_HERE
所有实例替换为Atlas用户名,Atlas令牌和AWS密钥。 在文本编辑器中使用“查找并替换”可能是最快的方法。 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文档 。
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。
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帐户中的“环境”选项卡,然后单击新创建的环境。 然后,单击左侧导航栏中的“更改”选项,以查看建议的更改。
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结合在一起,使将应用程序代码转换为已部署应用程序的过程成为可审核,可重复的过程。
To learn more about Atlas, read the getting started guide or experiment with more community examples.
要了解有关Atlas的更多信息,请阅读入门指南或尝试使用更多社区示例 。
aws terraform