1
1
Fork 0
mirror of https://github.com/mcuadros/ascode synced 2024-05-09 09:06:32 +02:00
AsCode - Terraform Alternative Syntax https://ascode.run
Go to file
Máximo Cuadros b5d48116cc
cmd: version command
2020-03-27 18:33:10 +01:00
.github/workflows ci: docker build based on github actions, tag latest 2020-03-17 18:52:12 +01:00
_documentation/runtime starlark/types: Resource documentation 2020-03-26 21:26:03 +01:00
_examples *: removed provider global in favor of tf 2020-03-21 00:10:22 +01:00
_scripts cmd: version command 2020-03-27 18:33:10 +01:00
cmd cmd: version command 2020-03-27 18:33:10 +01:00
starlark starlark/types: move documentation of ProviderCollection.__call__ 2020-03-27 18:32:13 +01:00
terraform starlark/types: Computed renamed to Attribute, added documentation 2020-03-26 07:13:24 +01:00
.gitignore gitignore 2020-03-16 18:13:54 +01:00
Dockerfile cmd: version command 2020-03-27 18:33:10 +01:00
LICENSE LICENSE 2019-07-05 08:00:41 +02:00
Makefile cmd: version command 2020-03-27 18:33:10 +01:00
README.md README.md: add logo and update text 2020-03-27 01:32:04 +01:00
go.mod starlark/types: standarization of Type and String methods 2020-03-23 21:18:06 +01:00
go.sum go.mod: revert go-plugin update 2020-03-17 15:23:26 +01:00
main.go cmd: version command 2020-03-27 18:33:10 +01:00

alt text

AsCode is a tool to define infrastructure as code using the Starlark language on top of Terraform. It allows to describe your infrastructure using an expressive language in Terraform without writing a single line of HCL, meanwhile, you have the complete ecosystem of providers

Why?

Terraform is a great tool, with support for almost everything you can imagine, making it the industry leader. Terraform is based on HCL, a JSON-alike declarative language, with minimal control flow functionality. IMHO, to unleash the power of the IaC, a powerful, expressive language should be used, where basic elements like loops or functions are first-class citizens.

What is Starlark?

Starlark is a dialect of Python intended for use as a configuration language. A Starlark interpreter is typically embedded within a larger application, and this application may define additional domain-specific functions and data types beyond those provided by the core language. For example, Starlark is embedded within (and was originally developed for) the Bazel build tool, and Bazel's build language is based on Starlark.

Examples

Simple

Creating am Amazon EC2 Instance is as easy as:

aws = tf.provider("aws", "2.13.0")
aws.region = "us-west-2"

aws.resource.instance(instance_type ="t2.micro", ami="ami-2757f631")

Using functions

In this example we create 40 instances, 20 using ubuntu and 20 using ECS.

aws = tf.provider("aws")
aws.region = "us-west-2"

# It creates a new instance for the given name, distro and type.
def new_instance(name, distro, type="t2.micro"):
    instance = aws.resource.instance(name)
    instance.instance_type = type
    instance.ami = get_ami_id(distro)

    return instance

amis = {}
ami_names_owners = {
    "ubuntu": ["ubuntu/images/*/ubuntu-xenial-16.04-amd64-server-*", "099720109477"],
    "ecs": ["*amazon-ecs-optimized", "591542846629"],
}

# We create the AMI data-source for the given distro.
def get_ami_id(distro):
    if distro in amis:
        return amis[distro]

    data = ami_names_owners[distro]

    ami = aws.data.ami(distro)
    ami.most_recent = True
    ami.filter(name="name", values=[data[0]])
    ami.filter(name="virtualization-type", values=["hvm"])
    ami.owners = [data[1]]

    amis[distro] = ami.id
    return ami.id

# Creates 20 instances of each distro.
for i in range(20):
    new_instance("ubuntu_%d" % i, "ubuntu")
    new_instance("ecs_%d" % i, "ecs")

Using the runtime

ascode comes with a built-in runtime with functions to work with yaml, json, http, etc. Take a look to the documentation.

load("encoding/base64", "base64")
load("http", "http")

dec = base64.encode("ascode is amazing")

msg = http.get("https://httpbin.org/base64/%s" % dec)
print(msg.body())

Installation

The recommended way to install ascode it's download the binary from the releases section.

License

GPL-3.0, see LICENSE