简体   繁体   English

将 AWS CloudFormation S3 资源转换为 Terraform 资源

[英]Convert AWS CloudFormation S3 resources to Terraform resources

I want to convert AWS S3 resources form cloudformation template to terraform template.我想将 AWS S3 资源从 cloudformation 模板转换为 terraform 模板。 But No existing data loss/data changes should be there to the S3 storage result from the transition.但是,转换后的 S3 存储结果不应存在现有的数据丢失/数据更改。 Please suggest some idea, how we can avoid S3 bucket data loss or data change issue.请提出一些想法,我们如何避免 S3 存储桶数据丢失或数据更改问题。

You can use terraform import to achieve this.您可以使用terraform import来实现这一点。 Here's a short example of importing an S3 bucket:这是导入 S3 存储桶的简短示例:

  1. Create your terraform definition for the bucket.为存储桶创建地形定义。 You can leave all attributes empty.您可以将所有属性留空。
resource "aws_s3_bucket" "my-bucket" {
}
  1. run terraform init to enable providers运行terraform init以启用提供程序
  2. run terraform import aws_s3_bucket.my-bucket <name-of-existing-bucket>运行terraform import aws_s3_bucket.my-bucket <name-of-existing-bucket>

Now the bucket will be in the Terraform state file and can be managed with Terraform.现在存储桶将位于 Terraform 状态文件中,并且可以使用 Terraform 进行管理。 Any changes to the Terraform file can now be applied to the existing bucket.对 Terraform 文件的任何更改现在都可以应用于现有存储桶。

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

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