JamesWoolfenden / sato

Sato converts ARM or CFN into Terraform
Apache License 2.0
98 stars 6 forks source link

Parse failure json cloud formation #14

Closed oijkn closed 1 month ago

oijkn commented 2 months ago

Describe the bug When attempting to convert a CloudFormation template to Terraform using sato, I encountered a parsing error. The command used was: sato parse -f cf.yaml

The error message returned is: parse failure parse failure json: cannot unmarshal number into Go struct field Template.Resources of type string

To Reproduce Steps to reproduce the behavior:

  1. Prepare a CloudFormation template (cf.yaml) with the following content:
    Resources:
    SecHubEventsFirehoseDeliveryStream:
    Type: AWS::KinesisFirehose::DeliveryStream
    Properties:
      DeliveryStreamName: aws-sechub-logs-kinesis-delivery-stream
      DeliveryStreamType: DirectPut
      DeliveryStreamEncryptionConfigurationInput:
        KeyType: AWS_OWNED_CMK
      ExtendedS3DestinationConfiguration:
        BucketARN: !GetAtt S3Bucketsechubyashdatafirehose.Arn
        Prefix: !Sub "sechub_events/managementid=${AWS::AccountId}/!{timestamp:yyyy}/!{timestamp:MM}/!{timestamp:dd}/"
        ErrorOutputPrefix: "aws-sechub-logs-firehose-error/"
        RoleARN: !GetAtt kinesisFirehoseRole.Arn
        CloudWatchLoggingOptions:
          Enabled: true
          LogGroupName: !Ref FirehoseLogGroup
          LogStreamName: !Ref FirehoseLogStream
        BufferingHints:
          IntervalInSeconds: 900
          SizeInMBs: 30
        CompressionFormat: "GZIP"
        ProcessingConfiguration:
          Enabled: true
          Processors:
            - Type: Lambda
              Parameters:
                - ParameterName: LambdaArn
                  ParameterValue: !GetAtt LambdaFunctiontransformationsechub.Arn
                - ParameterName: BufferIntervalInSeconds
                  ParameterValue: 600
                - ParameterName: BufferSizeInMBs
                  ParameterValue: 3
  2. Run the command: sato parse -f cf.yaml

Expected behavior The tool should parse the CloudFormation template and convert it to Terraform without any errors.

Actual behavior The tool fails to parse the template, returning the error: parse failure parse failure json: cannot unmarshal number into Go struct field Template.Resources of type string

Additional context The issue seems to be related to the handling of numeric values in the CloudFormation template.

Please let me know if additional information is required.

JamesWoolfenden commented 1 month ago

ok mea no culpa.

CF sometime define a number as a number but sometimes it does care care about its type and treats it as string. I rely on the go formation library which can be blind to this and so the lines for parameters need to be: ` - ParameterName: BufferIntervalInSeconds ParameterValue: "600"

I think you might also want to AWS::KinesisFirehose::DeliveryStream resource adding?