terraframe 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -3
- data/lib/terraframe/aws/aws_context.rb +42 -0
- data/lib/terraframe/aws/aws_resources.rb +41 -0
- data/lib/terraframe/processor.rb +2 -2
- data/lib/terraframe/resource.rb +5 -2
- data/lib/terraframe/state.rb +9 -3
- data/lib/terraframe/version.rb +1 -1
- metadata +3 -2
- data/lib/terraframe/contexts/aws_context.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0dcd49ea8fc966a851305a7ba0141c7a1f20010c
|
4
|
+
data.tar.gz: be6ff6375b82ca3a50dda7b258717ca8f5b41064
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75eae91b7b578746992c9c9ec9dcb03e3ce3398a6f69b42b65b146676248bb2101ca2c5941fa60bc120fe982d934650dc3d7ba8b7b6e48e49a5112946026d36a
|
7
|
+
data.tar.gz: 2f80d7729c29a43c714d573e4c8552dae0c3482b48c64ec1d5d2ac6700b76c80ae5a7e428446a7bd1a9de98a38dd8b4d63ea91e1d1c600513e3d5b67d848f38f
|
data/README.md
CHANGED
@@ -3,9 +3,7 @@ Terraframe is a processor for a domain-specific language that outputs to the Ter
|
|
3
3
|
|
4
4
|
[Terraform][1] is a cool infrastructure-as-code system with a boatload of functionality and a really awesome core that makes building out entire clouds on AWS super easy and super fun. I am a fan.
|
5
5
|
|
6
|
-
_But_. But but but. It's not perfect. And personally, ever since HashiCorp went away from Ruby DSLs as configuration, I have been sad. And worse than sad, I have been unproductive as all hell. I'm just not satisfied with the state of the Terraform description language.
|
7
|
-
|
8
|
-
The configuration, while not CloudFormation-bad, is pretty bad, and I came close to ditching Terraform because it was really hard to write. I got halfway through some ERB templating monstrosity before I learned of a better way: Terraform supports JSON as a declaration notation, and that makes it really easy to build an external DSL that can be exported for use in Terraform.
|
6
|
+
_But_. But but but. It's not perfect. And personally, ever since HashiCorp went away from Ruby DSLs as configuration, I have been sad. And worse than sad, I have been unproductive as all hell. I'm just not satisfied with the state of the Terraform description language. The configuration, while not CloudFormation-bad, is static and limited, and I came close to ditching Terraform because it was really hard to write. I got halfway through some ERB templating monstrosity before I learned of a better way: Terraform supports JSON as a declaration notation, and that makes it really easy to build an external DSL that can be exported for use in Terraform. So everybody wins!
|
9
7
|
|
10
8
|
## Installation ##
|
11
9
|
Terraframe is distributed as a RubyGem.
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'terraframe/context'
|
2
|
+
require 'terraframe/provider'
|
3
|
+
|
4
|
+
require 'terraframe/aws/aws_resources'
|
5
|
+
|
6
|
+
module Terraframe
|
7
|
+
module AWS
|
8
|
+
class AWSContext < Context
|
9
|
+
RESOURCES = {
|
10
|
+
:aws_autoscaling_group => Terraframe::AWS::AWSResource,
|
11
|
+
:aws_db_instance => Terraframe::AWS::AWSResource,
|
12
|
+
:aws_db_security_group => Terraframe::AWS::AWSResource,
|
13
|
+
:aws_db_subnet_group => Terraframe::AWS::AWSResource,
|
14
|
+
:aws_db_parameter_group => Terraframe::AWS::AWSResource,
|
15
|
+
:aws_eip => Terraframe::AWS::AWSResource,
|
16
|
+
:aws_elb => Terraframe::AWS::AWSResource,
|
17
|
+
:aws_internet_gateway => Terraframe::AWS::AWSResource,
|
18
|
+
:aws_launch_configuration => Terraframe::AWS::AWSResource,
|
19
|
+
:aws_network_acl => Terraframe::AWS::AWSResource,
|
20
|
+
:aws_key_pair => Terraframe::AWS::AWSResource,
|
21
|
+
:aws_route_table_association => Terraframe::AWS::AWSResource,
|
22
|
+
:aws_route53_record => Terraframe::AWS::AWSResource,
|
23
|
+
:aws_route53_zone => Terraframe::AWS::AWSResource,
|
24
|
+
:aws_s3_bucket => Terraframe::AWS::AWSResource,
|
25
|
+
|
26
|
+
:aws_instance => Terraframe::AWS::AWSTaggedResource,
|
27
|
+
:aws_route_table => Terraframe::AWS::AWSTaggedResource,
|
28
|
+
:aws_security_group => Terraframe::AWS::AWSTaggedResource,
|
29
|
+
:aws_subnet => Terraframe::AWS::AWSTaggedResource,
|
30
|
+
:aws_vpc => Terraframe::AWS::AWSTaggedResource
|
31
|
+
}
|
32
|
+
|
33
|
+
def provider_type
|
34
|
+
Terraframe::Provider
|
35
|
+
end
|
36
|
+
|
37
|
+
def resources
|
38
|
+
RESOURCES
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'hashie/mash'
|
2
|
+
require 'terraframe/resource'
|
3
|
+
require 'pry'
|
4
|
+
|
5
|
+
module Terraframe
|
6
|
+
module AWS
|
7
|
+
class AWSResource < Terraframe::Resource
|
8
|
+
## DSL FUNCTIONS BELOW
|
9
|
+
def method_missing(method_name, *args, &block)
|
10
|
+
if method_name == "tags"
|
11
|
+
raise "This resource does not support tags."
|
12
|
+
end
|
13
|
+
super(method_name, *args, &block)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class AWSTaggedResource < Terraframe::Resource
|
18
|
+
def initialize(name, vars, &block)
|
19
|
+
@fields = {}
|
20
|
+
@vars = Hashie::Mash.new(vars)
|
21
|
+
|
22
|
+
clear_tags!
|
23
|
+
@fields["tags"]["Name"] = name
|
24
|
+
|
25
|
+
instance_eval &block
|
26
|
+
end
|
27
|
+
|
28
|
+
def tags(&block)
|
29
|
+
tag_set = Terraframe::AWS::AWSTagBlock.new(@vars, &block)
|
30
|
+
@fields["tags"].merge!(tag_set.fields)
|
31
|
+
end
|
32
|
+
|
33
|
+
def clear_tags!
|
34
|
+
@fields["tags"] = {}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class AWSTagBlock < Terraframe::ScriptItem
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/terraframe/processor.rb
CHANGED
@@ -6,7 +6,7 @@ require 'active_support/core_ext/hash'
|
|
6
6
|
require 'awesome_print'
|
7
7
|
|
8
8
|
require 'terraframe/state'
|
9
|
-
require 'terraframe/
|
9
|
+
require 'terraframe/aws/aws_context'
|
10
10
|
|
11
11
|
module Terraframe
|
12
12
|
class Processor
|
@@ -21,7 +21,7 @@ module Terraframe
|
|
21
21
|
logger.debug "Logger initialized."
|
22
22
|
|
23
23
|
@contexts = {}
|
24
|
-
register_context(:aws, Terraframe::
|
24
|
+
register_context(:aws, Terraframe::AWS::AWSContext.new)
|
25
25
|
end
|
26
26
|
|
27
27
|
def register_context(name, context)
|
data/lib/terraframe/resource.rb
CHANGED
@@ -2,8 +2,11 @@ require 'terraframe/script_item'
|
|
2
2
|
|
3
3
|
module Terraframe
|
4
4
|
class Resource < Terraframe::ScriptItem
|
5
|
-
|
6
|
-
|
5
|
+
attr_reader :resource_name
|
6
|
+
|
7
|
+
def initialize(resource_name, vars, &block)
|
8
|
+
@resource_name = resource_name
|
9
|
+
super(vars, &block)
|
7
10
|
end
|
8
11
|
end
|
9
12
|
end
|
data/lib/terraframe/state.rb
CHANGED
@@ -70,12 +70,18 @@ module Terraframe
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def resource(resource_type, resource_name, &block)
|
73
|
-
|
74
|
-
|
73
|
+
handling_context_pair = @__contexts.find { |k, v| v.resources.include?(resource_type) }
|
74
|
+
if handling_context_pair == nil
|
75
|
+
msg = "Could not find a context that supports resource type '#{resource_type}'."
|
76
|
+
logger.error msg
|
77
|
+
raise msg
|
75
78
|
end
|
76
79
|
|
80
|
+
handling_context = handling_context_pair[1]
|
81
|
+
resource_class = handling_context.resources[resource_type]
|
82
|
+
|
77
83
|
@__output[:resource][resource_type] ||= {}
|
78
|
-
@__output[:resource][resource_type][resource_name.to_s] =
|
84
|
+
@__output[:resource][resource_type][resource_name.to_s] = resource_class.new(resource_name, vars, &block)
|
79
85
|
end
|
80
86
|
|
81
87
|
# anything that is not a provider or a variable should be interpreted
|
data/lib/terraframe/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: terraframe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ed Ropple
|
@@ -109,8 +109,9 @@ files:
|
|
109
109
|
- Rakefile
|
110
110
|
- bin/terraframe
|
111
111
|
- lib/terraframe.rb
|
112
|
+
- lib/terraframe/aws/aws_context.rb
|
113
|
+
- lib/terraframe/aws/aws_resources.rb
|
112
114
|
- lib/terraframe/context.rb
|
113
|
-
- lib/terraframe/contexts/aws_context.rb
|
114
115
|
- lib/terraframe/processor.rb
|
115
116
|
- lib/terraframe/provider.rb
|
116
117
|
- lib/terraframe/resource.rb
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'terraframe/context'
|
2
|
-
require 'terraframe/provider'
|
3
|
-
|
4
|
-
module Terraframe
|
5
|
-
module Contexts
|
6
|
-
class AWSContext < Context
|
7
|
-
RESOURCES = [
|
8
|
-
:aws_instance
|
9
|
-
]
|
10
|
-
|
11
|
-
def provider_type
|
12
|
-
Terraframe::Provider
|
13
|
-
end
|
14
|
-
|
15
|
-
def resources
|
16
|
-
RESOURCES
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|