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

时间:2020-09-24 14:07:23

标签: terraform amazon-cloudformation

我有这样的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

我想将其转换为Terraform代码。 是的,我可以手动完成,但是有很多:) 我不想使用resource aws_cloudformation_stack,因为我们正在将所有内容从cloudformation迁移到terraform。 另外,我还发现了该工具https://github.com/humanmade/cf-to-tf,但是当我有现有CloudFormation Stack时,它可以工作。 有什么方法可以通过脚本或其他方式来实现? 预先感谢

1 个答案:

答案 0 :(得分:-1)

CloudFormation到Terraform 一个简单的cli工具,用于为现有CloudFormation模板生成Terraform配置。 https://github.com/humanmade/cf-to-tf