Terraform初始状态文件创建

Sha*_*han 9 amazon-web-services terraform

有没有办法从现有的基础架构创建terraform状态文件.例如,AWS账户附带了一些服务(例如:默认VPC).

但是terraform,似乎只知道它创造的资源.所以,

  1. 将现有AWS Infrastructure迁移到Terraform代码的最佳方法是什么
  2. 是否可以手动添加资源并手动修改状态文件(不良影响?)

更新

Terraform 0.7.0支持导入单个资源.

yda*_*coR 5

对于相对较小的事情,我在手动处理状态文件以添加存根资源方面取得了一些成功,然后我在顶部继续使用Terraform(尤其是使用预先存在的VPC和子网,然后使用Terraform来应用安全组等)。

对于更复杂的事情,有一个非官方的工具terraforming,我听说它非常擅长生成Terraform状态文件,而且可以与预先存在的状态文件合并。我没有试过,但可能值得研究。

更新资料

Since Terraform 0.7, Terraform now has first class support for importing pre-existing resources using the import command line tool.

As of 0.7.4 this will import the pre-existing resource into the state file but not generate any configuration for the resource. Of course if then attempt a plan (or an apply) Terraform will show that it wants to destroy this orphaned resource. Before running the apply you would then need to create the configuration to match the resource and then any future plans (and applys) should show no changes to the resource and happily keep the imported resource.