如何将 CloudFormation 模板转换为 terraform 代码

Mkr*_*yan 4 aws-cloudformation terraform

我有类似这样的 Cloudformation 模板

Resources:

  WafValidHostsCondition:
    Type: AWS::WAF::ByteMatchSet
    Properties:
      Name: !Sub ${AccountCode}-${RegionCode}-${Application}-waf-validhosts
      ByteMatchTuples:
        - FieldToMatch:
            Type: HEADER
            Data: host
          TargetString: !Ref PublicDns
          TextTransformation: NONE
          PositionalConstraint: EXACTLY

  WafValidHostsRule:
    Type: AWS::WAF::Rule
    Properties:
      Name: !Sub ${AccountCode}-${RegionCode}-${Application}-waf-validhosts-rule
      MetricName: WafValidHostsRule
      Predicates:
        - DataId: !Ref WafValidHostsCondition
          Negated: true
          Type: ByteMatch

  WebAcl:
    Type: AWS::WAF::WebACL
    Properties:
      Name: !Sub ${AccountCode}-${RegionCode}-${Application}-globalwebacl
      DefaultAction:
        Type: ALLOW
      MetricName: GlobalWebACL
      Rules:
        - Action:
            Type: BLOCK
          Priority: 1
          RuleId: !Ref WafValidHostsRule
Run Code Online (Sandbox Code Playgroud)

我想将其转换为地形代码。是的,我可以手动完成,但有很多:)我不想使用resource aws_cloudformation_stack,因为我们正在将所有内容从 cloudformation 迁移到 terraform。我还找到了这个工具https://github.com/ humanmade/cf- to-tf ,但是当我有现有的 CloudFormation Stack 时它可以工作。有没有办法通过工具或其他方式通过脚本来做到这一点?提前致谢

Lev*_*evi 5

今天我公开发布了我的副项目cf2tf,它为您完成了大部分工作。

https://github.com/DontShaveTheYak/cf2tf

我尝试转换您的代码,但出现错误

ValueError: Fn::Ref - AccountCode is not a valid Resource or Parameter.
Run Code Online (Sandbox Code Playgroud)

您的示例显然只是 Cloudformation 模板的一部分。