简体   繁体   English

AWS 中的 Cloudformation/Serverless 与 Terraform

[英]Cloudformation/Serverless vs Terraform in AWS

I would like to understand the need of tools like Terraform.我想了解 Terraform 等工具的需求。 When we do have Cloudformation template available and one can create/update all AWS services with that , What is the point in using a service like Terraform.当我们有可用的 Cloudformation 模板并且可以使用它创建/更新所有 AWS 服务时,使用像 Terraform 这样的服务有什么意义。 Please Suggest.请建议。

There are a couple of reasons why you might choose Terraform over CloudFormation:您可能会选择 Terraform 而不是 CloudFormation 的原因有两个:

  1. Vendor Agnostic: There might be a point in the future where you need to migrate your cloud infrastructure.供应商不可知:未来可能需要迁移云基础架构。 This could be due to several reasons (eg costs, regulatory compliance, etc.).这可能是由于多种原因(例如成本、法规遵从性等)。 With Terraform you are still able to use the same tool to deploy the new infrastructure.使用 Terraform,您仍然可以使用相同的工具来部署新的基础设施。 With smart use of Terraform modules you can even leave large parts of your infrastucture as code repository in tact.通过巧妙地使用 Terraform 模块,您甚至可以将大部分基础设施保留为代码存储库。
  2. Support for other tools: This also builds a bit on the previous point, but Terraform can deploy a lot more then just AWS resources.对其他工具的支持:这也是在前一点的基础上构建的,但 Terraform 可以部署更多的 AWS 资源。 For example, you can use Terraform to orchestrate the deployment of an EC2 machine that is then configured with Ansible.例如,您可以使用 Terraform 来编排 EC2 机器的部署,然后使用 Ansible 进行配置。 Or you could use Terraform to deploy applications on top of your Kubernetes cluster.或者,您可以使用 Terraform 在 Kubernetes 集群之上部署应用程序。 While CloudFormation supports custom resources via the creation of custom Lambdas, it is quite a lot of work to maintain.虽然 CloudFormation 通过创建自定义 Lambda 来支持自定义资源,但维护工作量相当大。
  3. Wider ecosystem: Due to the Open Source nature of Terraform, there is a huge ecosystem of tools that help you solve all kinds of issues, such as testing the infrastructure as code or building in compliance in a continuous fashion.更广泛的生态系统:由于 Terraform 的开源性质,有一个庞大的工具生态系统可以帮助您解决各种问题,例如测试基础设施即代码或以持续的方式构建合规性。
  4. Arguably a better language: Personally I think Terraform is a way more suited for Infrastructure as Code then CloudFormation.可以说是一种更好的语言:我个人认为 Terraform 是一种比 CloudFormation 更适合基础设施即代码的方式。 Terraform has a lot more flexibility build in to the language (HCL) and their module system allows for a lot more composability then what can be achieved in CloudFormation. Terraform 在语言 (HCL) 中内置了更多的灵活性,并且它们的模块系统允许比 CloudFormation 中实现的更多的可组合性。

CloudFormation (CFN) and Terraform (CF) are both Infrastructure as Code (IaC) development tools. CloudFormation (CFN) 和 Terraform (CF) 都是基础设施即代码 (IaC) 开发工具。

However, CFN is only for AWS .但是, CFN 仅适用于 AWS You can't use it with Azure, GCP or anything else outside of AWS ecosystem.您不能将它与 Azure、GCP 或 AWS 生态系统之外的任何其他东西一起使用。 In contrast, TF is cloud agnostic .相比之下, TF 与云无关 You can use it across not only multiple cloud providers, but also to work with non-cloud products, such as docker, various databases and even domino pizza if you want.您不仅可以跨多个云提供商使用它,还可以使用非云产品,例如 docker、各种数据库,如果需要,甚至可以使用多米诺比萨。

So the main advantage of TF is that once you learn it only once , you can apply it to a number of cloud providers.所以 TF 的主要优点是,一旦你只学习一次,你就可以将其应用到多个云提供商。 CFN is only useful in AWS, and once you stop using CFN, you have to learn something new to work with other cloud. CFN 只在 AWS 中有用,一旦你停止使用 CFN,你必须学习一些新的东西才能与其他云一起工作。

There are also difference in how TF and CFN work. TF 和 CFN 的工作方式也有所不同。 Both have their strengths and weekends .两者各有长处和周末 For example:例如:

  • when you deploy using CFN all resources are available to view in one central location in AWS along with template's source code.当您使用 CFN 进行部署时,所有资源都可以在 AWS 的一个中心位置与模板的源代码一起查看。 Whereas with TF there is no such place.而TF则没有这样的地方。 If you login to the AWS console, you have no idea what was created by TF, what was the source code used, etc.如果您登录 AWS 控制台,您不知道 TF 创建了什么,使用的源代码是什么等等。

  • TF has loops and complex data structures and condtions, while CFN does not. TF 有循环和复杂的数据结构和条件,而 CFN 没有。

  • CFN has creation policies and update policies, TF has not. CFN 有创建策略和更新策略,TF 没有。

  • You can control access to CFN using CFN policies and IAM policies.您可以使用 CFN 策略和 IAM 策略控制对 CFN 的访问。 You can't do same with TF as it "lives" outside of AWS.您不能对 TF 做同样的事情,因为它“存在”于 AWS 之外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM