是否可以在Terraform中执行CloudFormation文件? [英] Is it possible to execute a CloudFormation file in Terraform?

查看:92
本文介绍了是否可以在Terraform中执行CloudFormation文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个团队已经以 .yml 文件的形式编写了cloudformation模板,该模板可提供大量资源.

One team has already written a cloudformation template as a .yml file that provisions a stack of resources.

是否可以通过在Terraform中执行该文件来利用该文件?还是必须重写?

Is it possible to leverage this file by executing it from within Terraform? Or does it have to be rewritten?

我是terraform的新手,刚刚开始.

I'm new to terraform and just getting started.

如果我使用的是AWS CLI,我将执行类似的命令

If I were using the AWS CLI I would execute a command like this,

aws cloudformation create-stack --stack-name my-new-stack --template-body file://mystack.yml --parameters ParameterKey = AmiId

aws cloudformation create-stack --stack-name my-new-stack --template-body file://mystack.yml --parameters ParameterKey=AmiId

我想在我的Terraform配置中包含此命令的等效内容.

I'd like to include the equivalent of this command in my terraform configuration.

如果有可能,您可以举个例子,我将非常感谢.

If it is possible and you can point me to an example, I would really appreciate that.

谢谢!

推荐答案

aws_cloudformation_stack 资源充当从Terraform到CloudFormation的桥梁,既可以用作从CloudFormation迁移到Terraform的辅助工具(如您在此处所做的那样),也可以用于Terraform当前无法处理的某些CloudFormation功能,例如将新实例的部署滚动到 ASG .

resource "aws_cloudformation_stack" "example" {
  name = "example"
  parameters = {
    VpcId = var.vpc_id
  }
  template_body = file("${path.module}/example.yml")
}

parameters 参数允许将数据从Terraform传递到Cloudformation堆栈中.也可以使用 outputs 属性来利用Terraform中其他地方的CloudFormation堆栈的结果,进行双向集成:

The parameters argument allows passing data from Terraform into the Cloudformation stack. It's also possible to use the outputs attribute to make use of the results of the CloudFormation stack elsewhere in Terraform, for a two-way integration:

resource "aws_route_53_record" "example" {
  name = "service.example.com"
  type = "CNAME"
  ttl  = 300

  records = [
    aws_cloudformation_stack.example.outputs["ElbHostname"],
  ]
}


如果您有一个现有的CloudFormation堆栈,不是由Terraform管理的,则仍然可以使用


这些功能一起使您可以有效地将CloudFormation和Terraform以不同的组合组合到单个系统中,无论是在迁移时的临时措施还是在需要混合解决方案的情况下永久使用.


These features together allow you to effectively mix CloudFormation and Terraform in a single system in different combinations, whether it's as a temporary measure while migrating or permanently in situations where a hybrid solution is desired.

这篇关于是否可以在Terraform中执行CloudFormation文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆