use*_*567 10 amazon-web-services aws-cloudformation terraform
一个团队已经将一个cloudformation模板编写为一个.yml提供一堆资源的文件.
是否可以通过在Terraform中执行来利用此文件?还是必须重写?
我是terraform的新手,刚入门.
如果我使用AWS CLI,我会执行这样的命令,
aws cloudformation create-stack --stack-name my-new-stack --template-body file://mystack.yml --parameters ParameterKey = AmiId
我想在我的terraform配置中包含相当于此命令的内容.
如果有可能,你可以给我一个例子,我真的很感激.
谢谢!
Mar*_*ins 23
该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")}"
}
Run Code Online (Sandbox Code Playgroud)
该parameters参数允许将数据从Terraform传递到Cloudformation堆栈.也可以使用该outputs属性在Terraform的其他地方利用CloudFormation堆栈的结果进行双向集成:
resource "aws_route_53_record" "example" {
name = "service.example.com"
type = "CNAME"
ttl = 300
records = ["${aws_cloudformation_stack.example.outputs["ElbHostname"]}"]
}
Run Code Online (Sandbox Code Playgroud)
如果你有一个预先存在的CloudFormation堆栈没有通过Terraform管理,你仍然可以利用使用其输出的aws_cloudformation_stack 数据源:
data "aws_cloudformation_stack" "example" {
name = "example"
}
resource "aws_route_53_record" "example" {
name = "service.example.com"
type = "CNAME"
ttl = 300
records = ["${data.aws_cloudformation_stack.example.outputs["ElbHostname"]}"]
}
Run Code Online (Sandbox Code Playgroud)
这些功能一起使您可以在单个系统中以不同的组合有效地混合CloudFormation和Terraform,无论是在迁移时作为临时措施还是在需要混合解决方案的情况下永久性地.
我可以通过对 cloudformation 模板的文件引用来确认 template_body 有效。我认为 template_url 也能很好地工作。例子
resource "aws_cloudformation_stack" "my-new-stack" {
name = "my-new-stack"
parameters {
Name="my-new-stack"
Port="22"
VpcId = "${var.vpc_id}"
}
template_body = "${file("${path.module}/mystack.yml")}"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5494 次 |
| 最近记录: |