How To Convert CloudFormation template to terraform code

Viewed 7820

I have Cloudformation template something like this

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

And I wanna convert it to terraform code. Yeah I can do it manually , but there are a lot :) I don't wanna use resource aws_cloudformation_stack, because we are migrating all the stuff from cloudformation to terraform. Also I have found this tool https://github.com/humanmade/cf-to-tf , but it work when I have existing CloudFormation Stack. Is there any way to do it by script by tool or another way? Thanks in advance

2 Answers

Today I publicly released my side project cf2tf that does most of this work for you.

https://github.com/DontShaveTheYak/cf2tf

I tried to convert your code but their was error

ValueError: Fn::Ref - AccountCode is not a valid Resource or Parameter.

Your example is obviously just part of the Cloudformation template.

Related