Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mujx/dhall-terraform
Generate dhall records from terraform resouces, data_sources & providers
https://github.com/mujx/dhall-terraform
aws configuration dhall terraform terraform-aws
Last synced: about 2 months ago
JSON representation
Generate dhall records from terraform resouces, data_sources & providers
- Host: GitHub
- URL: https://github.com/mujx/dhall-terraform
- Owner: mujx
- License: unlicense
- Created: 2019-11-07T15:57:40.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-04-20T18:04:17.000Z (over 4 years ago)
- Last Synced: 2024-08-01T03:42:21.016Z (5 months ago)
- Topics: aws, configuration, dhall, terraform, terraform-aws
- Language: Dhall
- Homepage:
- Size: 804 KB
- Stars: 54
- Watchers: 4
- Forks: 13
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
- awesome-list - dhall-terraform
README
# dhall-terraform
[![CircleCI](https://circleci.com/gh/mujx/dhall-terraform.svg?style=svg)](https://circleci.com/gh/mujx/dhall-terraform)
[![License: Unlicense](https://img.shields.io/badge/license-Unlicense-blue.svg)](http://unlicense.org/)`dhall-terraform` uses terraform's provider schema to generate Dhall types & defaults
for each `resource`, `data_source` & `provider` block.This allows us to use Dhall to create cloud resources instead of HCL & avoid its
limitations.### Installation
You can use one of `cabal-install`, `stack` or `nix` to build and install the
project.### Usage
- Use `dhall-terraform` to generate the types of your provider.
See [here](https://www.terraform.io/docs/commands/providers/schema.html) how
you can generate the provider's schema.
- Write the resources in Dhall. Checkout the [examples](./examples).
- Use `dhall-to-json` to generate terraform's [JSON syntax][terraform_json_syntax]
- Continue with `terraform` operations as normal.### AWS example
Example using the generated resources from the AWS provider.
```dhall
let Prelude =
https://raw.githubusercontent.com/dhall-lang/dhall-lang/master/Prelude/package.dhall-- Get the correct type needed for Terraform's JSON syntax.
let jsonRes = λ(a : Type) → { mapKey : Text, mapValue : a }-- Create a JSON serialized resource given its name and type.
let mkRes =
λ(a : Type)
→ λ(name : Text)
→ λ(body : a)
→ Prelude.JSON.keyValue a name body-- Import the necessary resources.
let AwsProvider =
https://raw.githubusercontent.com/mujx/dhall-terraform/99a96658642aef74f0b01c0da73f2c9a07171f52/lib/aws/provider/provider.dhalllet AwsS3Bucket =
https://raw.githubusercontent.com/mujx/dhall-terraform/99a96658642aef74f0b01c0da73f2c9a07171f52/lib/aws/resources/aws_s3_bucket.dhalllet defaultRegion = "us-east-1"
let Bucket = { region : Text, name : Text }
let buckets =
[ { region = defaultRegion, name = "images" }
, { region = defaultRegion, name = "files" }
]
: List Bucketlet toBucketResource
: Bucket → jsonRes AwsS3Bucket.Type
= λ(bkt : Bucket)
→ mkRes
AwsS3Bucket.Type
bkt.name
AwsS3Bucket::{
, tags = Some [ { mapKey = "content", mapValue = bkt.name } ]
, region = Some defaultRegion
}let awsProvider =
mkRes
AwsProvider.Type
"aws"
AwsProvider::{ region = defaultRegion, version = Some "2.34.0" }in { provider = [ awsProvider ]
, resource =
{ aws_s3_bucket =
Prelude.List.map
Bucket
(jsonRes AwsS3Bucket.Type)
toBucketResource
buckets
}
}
```### Options
```
dhall-terraform :: v0.1.0Usage: dhall-terraform (-f|--schema-file SCHEMA) (-p|--provider-name PROVIDER)
[-o|--output-dir OUT_DIR]
Generate Dhall types from Terraform resourcesAvailable options:
-h,--help Show this help text
-f,--schema-file SCHEMA Terraform provider's schema definitions
-p,--provider-name PROVIDER
Which provider's resources will be generated
-o,--output-dir OUT_DIR The directory to store the generated
files (default: "./lib")
```[terraform_json_syntax]: https://www.terraform.io/docs/configuration/syntax-json.html