Giter Club home page Giter Club logo

sato's Introduction

Sato

Maintenance Build Status Latest Release GitHub tag (latest SemVer) Terraform Version pre-commit checkov Github All Releases codecov

Converts CloudFormation (and now also ARM) into Terraform. In Go, but quickerly.

Install

Download the latest releases https://github.com/JamesWoolfenden/sato/releases/tag/v0.1.19 or:

Compile locally:

git clone https://github.com/JamesWoolfenden/sato
cd sato
go install

Windows

I'm now using Scoop to distribute releases, it's much quicker to update and easier to manage than previous methods, you can install scoop from https://scoop.sh/.

Add my scoop bucket:

scoop bucket add iac https://github.com/JamesWoolfenden/scoop.git

Then you can install a tool:

scoop install sato

Usage

Get yourself some valid CloudFormation*

 git clone https://github.com/JamesWoolfenden/aws-cloudformation-templates
 >cd aws-cloudformation-templates/community/codestar/custom-ci-cd-pipeline
 ❯ ls
 README.md    template.yml
 >sato parse -f template.yml
 9:17PM INF Created .sato\variables.tf
 9:17PM INF Created .sato\data.tf
 9:17PM INF Created .sato\aws_codebuild_project.productionbuild.tf
 9:17PM INF Created .sato\aws_codebuild_project.productiondeploy.tf
 9:17PM INF Created .sato\aws_codebuild_project.stagingbuild.tf
 9:17PM INF Created .sato\aws_codebuild_project.stagingdeploy.tf
 9:17PM INF Created .sato\aws_iam_role.codebuildrole.tf
 9:17PM INF Created .sato\aws_codepipeline_pipeline.pipeline.tf
 9:17PM INF Created .sato\aws_iam_role.pipelinerole.tf
 9:17PM INF Created .sato\aws_s3_bucket.pipelines3bucket.tf

That's it. So by default (overridable) the parsed CloudFormation (now Terraform) will be in a .sato subdirectory. So let's have a look see:

> ls .sato
aws_codebuild_project.productionbuild.tf  aws_codebuild_project.stagingbuild.tf     aws_codepipeline_pipeline.pipeline.tf     aws_iam_role.pipelinerole.tf              variables.tf
aws_codebuild_project.productiondeploy.tf aws_codebuild_project.stagingdeploy.tf    aws_iam_role.codebuildrole.tf             aws_s3_bucket.pipelines3bucket.tf

So there are some files that could be Terraform.

The Cats Pyjamas

Testing...

>terraform init
...
Terraform has been successfully initialized!
....
>terraform plan
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create
...
Plan: 12 to add, 0 to change, 0 to destroy.
...

See - finds the terraform resource

This tells you the equivalent resource required, given a CF ..... or an ARM resource;

$ sato see -r Microsoft.Storage/storageAccounts
azurerm_storage_account

or

$sato see -r AWS::EC2::Instance
aws_instance%

Bisect - ARM to terraform

What? You've got these legacy ARM templates, and you'd dearly love to drop them, but you really don't fancy Bicep and the rework. I got you covered. Sato now bisects ARM into Terraform - Take one of the Azure quickstart examples from here https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.compute/vm-simple-windows:

Clone it:

git clone https://github.com/Azure/azure-quickstart-templates.git

Then bisect it!

$ sato bisect -f /Users/jwoolfenden/code/azure-quickstart-templates/quickstarts/microsoft.compute/vm-simple-windows/azuredeploy.json
1:56PM INF Created /Users/jwoolfenden/code/sato/.sato/variables.tf
1:56PM INF Created /Users/jwoolfenden/code/sato/.sato/locals.tf
1:56PM INF Created /Users/jwoolfenden/code/sato/.sato/azurerm_storage_account.sato0.tf
1:56PM INF Created /Users/jwoolfenden/code/sato/.sato/azurerm_public_ip.sato1.tf
1:56PM INF Created /Users/jwoolfenden/code/sato/.sato/azurerm_network_security_group.sato2.tf
1:56PM INF Created /Users/jwoolfenden/code/sato/.sato/azurerm_virtual_network.sato3.tf
1:56PM INF Created /Users/jwoolfenden/code/sato/.sato/azurerm_network_interface.sato4.tf
1:56PM INF Created /Users/jwoolfenden/code/sato/.sato/azurerm_virtual_machine.sato5.tf
1:56PM INF Created /Users/jwoolfenden/code/sato/.sato/azurerm_virtual_machine_extension.sato6.tf
1:56PM INF Created /Users/jwoolfenden/code/sato/.sato/outputs.tf
1:56PM INF Created /Users/jwoolfenden/code/sato/.sato/data.tf

I make an opinionated translation, in Terraform there are no parameters, resources and dependencies are very different, there's no one for one - ARM to Terraform, so the aim is to get you close to 100%.

There needs to be a lot of work supporting resources and built-in functions/template as yet. If you want to use this, let me know so, then I'll know to do so, or even better send me a PR.

Extra credit - Pike

If you use my other tool, Pike you can now apply that and get the policy requirements:

pike scan -d .sato -o json

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "VisualEditor0",
      "Effect": "Allow",
      "Action": [
        "codebuild:BatchGetProjects",
        "codebuild:CreateProject",
        "codebuild:DeleteProject",
        "codebuild:UpdateProject"
      ],
      "Resource": [
        "*"
      ]
    },
    {
      "Sid": "VisualEditor1",
      "Effect": "Allow",
      "Action": [
        "codepipeline:CreatePipeline",
        "codepipeline:DeletePipeline",
        "codepipeline:GetPipeline",
        "codepipeline:ListTagsForResource"
      ],
      "Resource": [
        "*"
      ]
    },
    {
      "Sid": "VisualEditor2",
      "Effect": "Allow",
      "Action": [
        "iam:CreateRole",
        "iam:DeleteRole",
        "iam:DeleteRolePolicy",
        "iam:GetRole",
        "iam:GetRolePolicy",
        "iam:ListAttachedRolePolicies",
        "iam:ListInstanceProfilesForRole",
        "iam:ListRolePolicies",
        "iam:PassRole",
        "iam:PutRolePolicy"
      ],
      "Resource": [
        "*"
      ]
    },
    {
      "Sid": "VisualEditor3",
      "Effect": "Allow",
      "Action": [
        "s3:CreateBucket",
        "s3:DeleteBucket",
        "s3:GetAccelerateConfiguration",
        "s3:GetBucketAcl",
        "s3:GetBucketCORS",
        "s3:GetBucketLogging",
        "s3:GetBucketObjectLockConfiguration",
        "s3:GetBucketPolicy",
        "s3:GetBucketRequestPayment",
        "s3:GetBucketTagging",
        "s3:GetBucketVersioning",
        "s3:GetBucketWebsite",
        "s3:GetEncryptionConfiguration",
        "s3:GetLifecycleConfiguration",
        "s3:GetObject",
        "s3:GetObjectAcl",
        "s3:GetReplicationConfiguration",
        "s3:ListBucket"
      ],
      "Resource": [
        "*"
      ]
    }
  ]
}

Valid CloudFormation

Ditch it all, OK, OK but some older samples can play fast and lose with the CloudFormation schema and data types. The Go-formation parser is less accommodating, you may need to be stricter on your typing.

  • Booleans are true or false and not "false"
  • Ints are 1,2,3 not "1", "2", "3"

sato's People

Contributors

dependabot[bot] avatar it-praktyk avatar jameswoolfenden avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sato's Issues

Parse failure json cloud formation

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
  1. 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.

Add support for converting ARM into terraform

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is.
Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

panic - interface conversion

Describe the bug
Tried to convert an ARM Template and received the following stack trace.

panic: interface conversion: interface {} is map[string]interface {}, not string goroutine 1 [running]: sato/src/arm.preprocess(0x10506d8e0?) /home/runner/work/sato/sato/src/arm/parse.go:570 +0x500 sato/src/arm.Parse({0x16b59b7b9?, 0x104f8db20?}, {0x16b59b7ca, 0x21}) /home/runner/work/sato/sato/src/arm/parse.go:79 +0x970 main.main.func3(0x14000178420) /home/runner/work/sato/sato/main.go:66 +0x34 github.com/urfave/cli/v2.(*Command).Run(0x14000178420, 0x14000130640, {0x1400015c320, 0x5, 0x5}) /home/runner/go/pkg/mod/github.com/urfave/cli/[email protected]/command.go:274 +0x78c github.com/urfave/cli/v2.(*Command).Run(0x14000178840, 0x14000130500, {0x1400012e120, 0x6, 0x6}) /home/runner/go/pkg/mod/github.com/urfave/cli/[email protected]/command.go:267 +0x9ac github.com/urfave/cli/v2.(*App).RunContext(0x140001cc000, {0x105463ab8?, 0x1400011c588}, {0x1400012e120, 0x6, 0x6}) /home/runner/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:332 +0x604 github.com/urfave/cli/v2.(*App).Run(...) /home/runner/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:309 main.main() /home/runner/work/sato/sato/main.go:116 +0xe38

To Reproduce
Steps to reproduce the behavior:

wget https://github.com/JamesWoolfenden/sato/releases/download/v0.1.1/sato_0.1.1_darwin_arm64.tar.gz
tar xzf sato_0.1.1_darwin_arm64.tar.gz
./sato bisect -f template.json -d /Users/xx/AK/GIT/tf1

Expected behavior
Converting the ARM Template into TF.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [MacOS 13.4.1 (22F82)]
  • Version [0.1.1]
  • M2 ARM

AWS::Athena::WorkGroup and AWS::Athena::NamedQuery -> Not found

Describe the bug
When I run the command sato parse -f athena.yaml, the following warnings appear in the log:

10:07AM WRN AWS::Athena::WorkGroup not found
10:07AM WRN AWS::Athena::NamedQuery not found

As a result, the Terraform configuration generation fails.

To Reproduce
Steps to reproduce the behavior:

  1. Create a file named athena.yaml with the following configuration:
Resources:

  athenworkgroup:
    Type: AWS::Athena::WorkGroup
    Properties:
      Name: "my-workgroup"
      State: "ENABLED"

  securityhubAthenaView:
    Type: AWS::Athena::NamedQuery
    Properties:
      Name: AWS-athena
      Database: !Ref database
      WorkGroup: !Ref athenworkgroup
      QueryString: >
          SELECT * FROM "my_table" WHERE "severity" = 'CRITICAL'
  1. Execute the command: sato parse -f athena.yaml.
  2. Observe the warnings in the log.

Expected behavior
The configuration should be parsed without warnings, and the Terraform configuration should be generated successfully.

Screenshots
N/A

Additional context
Any guidance or fixes for this issue would be greatly appreciated. Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.