Last active
April 4, 2019 16:57
-
-
Save dreverri/d3b705aabc2964c7b675444e331f5d70 to your computer and use it in GitHub Desktop.
tf.libsonnet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
local tf = self, | |
attribute:: function(name) function(r) std.format("${%s.%s.%s}", [r.type, r.name, name]), | |
argument:: function(name) function(value) { args+:: { [name]: value } }, | |
id:: tf.attribute("id"), | |
new:: function(type) function(name) { | |
local resource = self, | |
type:: type, | |
name:: name, | |
args:: {}, | |
resource+: { | |
[resource.type]+: { | |
[resource.name]: resource.args | |
}, | |
}, | |
}, | |
graph:: { | |
resources:: function(nodes) std.foldr(function(n, o) o + n.resource, nodes, {}), | |
}, | |
resource:: { | |
aws:: { | |
attribute:: { | |
arn:: tf.attribute("arn") | |
}, | |
}, | |
aws_instance:: { | |
new:: tf.new("aws_instance"), | |
}, | |
aws_lb:: { | |
new:: tf.new("aws_lb"), | |
attribute:: { | |
arn_suffix:: tf.attribute("arn_suffix"), | |
dns_name:: tf.attribute("dns_name"), | |
zone_id:: tf.attribute("zone_id"), | |
}, | |
mixin:: { | |
name:: tf.argument("name"), | |
subnet_ids:: tf.argument("subnets"), | |
subnets:: function(subnets) self.subnet_ids(std.map(tf.id, subnets)), | |
}, | |
}, | |
aws_lb_listener:: { | |
new:: tf.new("aws_lb_listener"), | |
}, | |
aws_lb_listener_rule:: { | |
new:: tf.new("aws_lb_listener_rule"), | |
}, | |
aws_lb_target_group:: { | |
new:: tf.new("aws_lb_target_group") | |
}, | |
aws_lb_target_group_attachment:: { | |
new:: tf.new("aws_lb_target_group_attachment"), | |
}, | |
aws_security_group:: { | |
new:: tf.new("aws_security_group"), | |
mixin:: { | |
vpc_id:: tf.argument("vpc_id"), | |
vpc:: function(vpc) self.vpc_id(tf.id(vpc)), | |
}, | |
}, | |
aws_security_group_rule:: { | |
new:: tf.new("aws_security_group_rule"), | |
mixin:: { | |
type:: tf.argument("type"), | |
cidr_blocks:: tf.argument("cidr_blocks"), | |
protocol:: tf.argument("protocol"), | |
from_port:: tf.argument("from_port"), | |
to_port:: tf.argument("to_port"), | |
security_group_id:: tf.argument("security_group_id"), | |
security_group:: function(sg) self.security_group_id(tf.id(sg)), | |
egress:: self.type("egress"), | |
ingress:: self.type("ingress"), | |
port_range:: function(from_port, to_port) self.from_port(from_port) + self.to_port(to_port), | |
tcp:: self.protocol("tcp"), | |
allEgress:: self.egress + self.cidr_blocks(["0.0.0.0/0"]) + self.port_range(0, 0) + self.protocol("-1") , | |
vpcIngress:: function(vpc) self.ingress + self.cidr_blocks([tf.resource.aws_vpc.attribute.cidr_block(vpc)]) + self.port_range(0, 0) + self.protocol("-1") , | |
}, | |
}, | |
aws_subnet:: { | |
new:: tf.new("aws_subnet"), | |
}, | |
aws_vpc:: { | |
new:: tf.new("aws_vpc"), | |
attribute:: { | |
cidr_block:: tf.attribute("cidr_block"), | |
}, | |
}, | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment