https://github.com/skorfmann/cfn2tf
https://github.com/skorfmann/cfn2tf
Last synced: 10 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/skorfmann/cfn2tf
- Owner: skorfmann
- License: apache-2.0
- Created: 2020-07-21T12:34:22.000Z (about 5 years ago)
- Default Branch: benisrae
- Last Pushed: 2023-01-07T20:21:52.000Z (almost 3 years ago)
- Last Synced: 2025-02-28T19:06:49.195Z (8 months ago)
- Language: TypeScript
- Size: 1.58 MB
- Stars: 10
- Watchers: 3
- Forks: 0
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cfn2tf
Converts CloudFormation resources to Terraform resources.
> THIS IS A PROTOTYPE.
## Usage
```ts
import { TerraformMapper } from 'cfn2tf';const bucketMapper = new TerraformMapper('AWS::S3::Bucket');
equal(
bucketMapper.terraformResourceType,
'aws_s3_bucket'
);const tfprops = bucketMapper.toTerraformProps({
BucketName: 'my-bucket',
VersioningConfiguration: { Status: 'Enabled' },
WebsiteConfiguration: {
IndexDocument: 'index.html',
}
});equal(tfprops, {
bucket: 'foo',
versioning: [ { enabled: true } ],
website: [ { indexDocument: 'index.html' } ],
});equal(
bucketMapper.toTerraformAttribute('RegionalDomainName'),
'bucket_regional_domain_name'
);
```## API
### `new TerraformMapper(cfnResourceType)`
Returns the a mapper associated with the specified CFN resource type (e.g. `AWS::S3::Bucket`).
### `mapper.terraformResourceType => string`
Returns the Terraform resource type name (in the AWS provider) (e.g. `aws_s3_bucket`).
### `mapper.toTerraformProps(cfnProps) => tfProps`
Converts an object with CloudFormation resource properties to Terraform semantics.
Throws an error if one of the properties could not be mapped.
### `mapper.toTerraformAttribute(cfnAttr) => string`
Returns the name of the corresponding Terraform resource attribute (e.g. `RegionalDomainName` => `bucket_regional_domain_name`).
## Contributions
This project heavily relies on contributions to succeed. See the
[src/mapping](./src/mapping) directory to add mappings.## TODO
- [ ] Add "fuzz" testing to ensure property handlers are only picking up their own properties.
- [ ] Allow adding mapping if mapping is missing.
- [ ] Generate types to make it safer to write mappers
- [ ] Generate input property types from CloudFormation spec (steal from awscdk)
- [ ] Generate output property types from Terraform specs (steal from cdktf)
- [ ] Generate input attribute types
- [ ] Generate output attribute types
- [ ] Generate scaffolding for all CFN resource types with "not implemented"
- [ ] See if we can use heuristics to deduce mapping in certain cases
- [ ] Take a complex CDK L2 example (e.g. ECS) and implement all the mappers for it
- [ ] Create some helpers like `pick(obj, jsonpath)` which return the value at `jsonpath` and
delete it from the object.## License
Distributed under the Apache 2.0 License.