sparkle_formation 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/docs/README.md +28 -0
- data/docs/anatomy.md +205 -0
- data/docs/building-blocks.md +360 -0
- data/docs/compile-time-parameters.md +182 -0
- data/docs/helper-methods.md +157 -0
- data/docs/nested-stacks.md +425 -0
- data/docs/overview.md +54 -0
- data/docs/sparkle-packs.md +211 -0
- data/docs/sparkleformation-dsl.md +303 -0
- data/docs/stack-policies.md +90 -0
- data/docs/translation.md +64 -0
- data/docs/v/0.3.2/marked.js +1272 -0
- data/docs/v/bootstrap.min.css +7 -0
- data/docs/v/finalizer.css +6 -0
- data/docs/v/highlight.min.css +1 -0
- data/docs/v/highlight.min.js +2 -0
- data/docs/v/jquery-2.1.3.min.js +4 -0
- data/docs/v/loader.js +34 -0
- data/lib/sparkle_formation/sparkle.rb +4 -0
- data/lib/sparkle_formation/sparkle_formation.rb +75 -14
- data/lib/sparkle_formation/sparkle_struct.rb +17 -0
- data/lib/sparkle_formation/version.rb +1 -1
- data/sparkle_formation.gemspec +1 -1
- metadata +21 -4
@@ -0,0 +1,182 @@
|
|
1
|
+
---
|
2
|
+
title: "Compile Time Parameters"
|
3
|
+
category: "dsl"
|
4
|
+
weight: 10
|
5
|
+
anchors:
|
6
|
+
- title: "Usage"
|
7
|
+
url: "#usage"
|
8
|
+
- title: "Template Nesting"
|
9
|
+
url: "#template-nesting"
|
10
|
+
---
|
11
|
+
|
12
|
+
## Compile Time Parameters
|
13
|
+
|
14
|
+
Compile time parameters are parameters utilized during the compilation
|
15
|
+
of a template. These parameters can _only_ be used via the SparkleFormation
|
16
|
+
library. It is for this reason that compile time parameters are generally
|
17
|
+
discouraged from use. In most situations the structure of the template
|
18
|
+
can be refactored to remove any requirement of compile time parameters. To
|
19
|
+
handle the cases that fall outside of "most situations", SparkleFormation
|
20
|
+
provides support for compile time parameters.
|
21
|
+
|
22
|
+
### Usage
|
23
|
+
|
24
|
+
Compile time parameters are defined during the instantiation of a template:
|
25
|
+
|
26
|
+
~~~ruby
|
27
|
+
SparkleFormation.new(:test,
|
28
|
+
:compile_time_parameters => {
|
29
|
+
:number_of_nodes => {
|
30
|
+
:type => :number,
|
31
|
+
:default => 1
|
32
|
+
}
|
33
|
+
}
|
34
|
+
) do
|
35
|
+
|
36
|
+
state!(:number_of_nodes).times do |i|
|
37
|
+
dynamic!(:ec2_instance, "node_#{i}")
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
~~~
|
42
|
+
|
43
|
+
#### Parameter Declaration
|
44
|
+
|
45
|
+
Declaring compile time parameters is done via the `:compile_time_parameters`
|
46
|
+
option when instantiating a new template. This option expects a `Hash` value
|
47
|
+
in which the keys are parameter names, and their respective values are a `Hash`
|
48
|
+
defining options for the parameter. The available items within the option
|
49
|
+
`Hash` for compile time parameters:
|
50
|
+
|
51
|
+
* `:type` - Data type of parameter
|
52
|
+
* Required: yes
|
53
|
+
* Valid: `:number`, `:string`
|
54
|
+
* Default: none
|
55
|
+
* `:description` - Description of the parameter
|
56
|
+
* Required: no
|
57
|
+
* Valid: `String`
|
58
|
+
* Default: none
|
59
|
+
* `:default` - Default value for parameter
|
60
|
+
* Required: no
|
61
|
+
* Valid: `String`, `Integer`
|
62
|
+
* Default: none
|
63
|
+
* `:multiple` - Accept multiple values
|
64
|
+
* Required: no
|
65
|
+
* Valid: `TrueClass`, `FalseClass`
|
66
|
+
* Default: `false`
|
67
|
+
* `:prompt_when_nested` - Prompt for value when template is nested
|
68
|
+
* Required: no
|
69
|
+
* Valid: `TrueClass`, `FalseClass`
|
70
|
+
* Default: `true`
|
71
|
+
|
72
|
+
##### Multiple value support
|
73
|
+
|
74
|
+
The `:multiple` option for compile time parameters will automatically convert
|
75
|
+
a received comma-delimited list into an `Array` of items. Each item in the list
|
76
|
+
must be the expected type for the parameter. For example, a compile time parameter
|
77
|
+
defined as:
|
78
|
+
|
79
|
+
~~~ruby
|
80
|
+
SparkleFormation.new(:test,
|
81
|
+
:compile_time_parameters => {
|
82
|
+
:network_ids => {
|
83
|
+
:type => :string,
|
84
|
+
:multiple => true
|
85
|
+
}
|
86
|
+
}
|
87
|
+
)
|
88
|
+
~~~
|
89
|
+
|
90
|
+
If the value provided for this parameter is:
|
91
|
+
|
92
|
+
~~~
|
93
|
+
network-a2413, network-cs214, network-as113
|
94
|
+
~~~
|
95
|
+
|
96
|
+
The resulting value when accessed will be:
|
97
|
+
|
98
|
+
~~~ruby
|
99
|
+
[
|
100
|
+
"network-a2413",
|
101
|
+
"network-cs214",
|
102
|
+
"network-as113"
|
103
|
+
]
|
104
|
+
~~~
|
105
|
+
|
106
|
+
##### Prompting when nested
|
107
|
+
|
108
|
+
The `:prompt_when_nested` is used by implementations to suppress parameter prompts
|
109
|
+
when the template is encountered in a nested context. This allows for parent templates
|
110
|
+
to handle compile time parameters for a nested template, but the nested template still
|
111
|
+
retains its ability to be built in a standalone context.
|
112
|
+
|
113
|
+
#### Accessing Parameter Values
|
114
|
+
|
115
|
+
Compile time parameter values can be accessed via the `state!` method. If a compile time
|
116
|
+
parameter has been defined for a template, and no value has been provided when that template
|
117
|
+
is compiled, `state!` will raise an `ArgumentError`. This exception will only be raised on
|
118
|
+
defined compile time parameters, and not other values that may be persisted within the state.
|
119
|
+
|
120
|
+
Example usage:
|
121
|
+
|
122
|
+
~~~ruby
|
123
|
+
SparkleFormation.new(:test,
|
124
|
+
:compile_time_parameters => {
|
125
|
+
:number_of_nodes => {
|
126
|
+
:type => :number,
|
127
|
+
:default => 1
|
128
|
+
}
|
129
|
+
}
|
130
|
+
) do
|
131
|
+
|
132
|
+
state!(:number_of_nodes).times do |i|
|
133
|
+
dynamic!(:ec2_instance, "node_#{i}")
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
~~~
|
138
|
+
|
139
|
+
#### Template Modification
|
140
|
+
|
141
|
+
When compile time parameters are present SparkleFormation will automatically adjust the outputs
|
142
|
+
of the template to include a `CompileState` output. The output will contain a JSON dump of the
|
143
|
+
compile time parameter values used to generate the template. This allows update requests to
|
144
|
+
fetch the previous state and seed the compilation of the updated template. This approach provides
|
145
|
+
consistency and removes any requirement of prior knowledge about how a template was used to build
|
146
|
+
a stack.
|
147
|
+
|
148
|
+
### Template Nesting
|
149
|
+
|
150
|
+
Compile time parameters are local to a given template instance. A parent template can provide
|
151
|
+
compile time parameters when nesting a template. This is done using the `:parameters` option
|
152
|
+
when nesting:
|
153
|
+
|
154
|
+
~~~ruby
|
155
|
+
SparkleFormation.new(:node_generator,
|
156
|
+
:parameters => {
|
157
|
+
:number_of_nodes => {
|
158
|
+
:type => :number,
|
159
|
+
:prompt_when_nested => false
|
160
|
+
}
|
161
|
+
}
|
162
|
+
) do
|
163
|
+
state!(:number_of_nodes).times do |i|
|
164
|
+
dynamic!(:ec2_instance, "node_#{i}")
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
SparkleFormation.new(:root) do
|
170
|
+
nest!(:nested_template,
|
171
|
+
:parameters => {
|
172
|
+
:number_of_nodes => 5
|
173
|
+
}
|
174
|
+
)
|
175
|
+
end
|
176
|
+
~~~
|
177
|
+
|
178
|
+
In this example the `:root` template is providing the compile time parameter `:number_of_nodes`
|
179
|
+
explicitly to the `:node_generator` template. Due to the compile time parameter option
|
180
|
+
`:prompt_when_nested` being set to false, when the `:root` template is compiled, no prompt
|
181
|
+
will be received for the `:number_of_nodes` compile time parameter. However, if the
|
182
|
+
`:node_generator` template is compiled directly, the prompt will be received.
|
@@ -0,0 +1,157 @@
|
|
1
|
+
---
|
2
|
+
title: "Helper Methods"
|
3
|
+
category: "dsl"
|
4
|
+
weight: 5
|
5
|
+
anchors:
|
6
|
+
- title: "Dynamics"
|
7
|
+
url: "#dynamics"
|
8
|
+
- title: "Registries"
|
9
|
+
url: "#registries"
|
10
|
+
- title: "Nests"
|
11
|
+
url: "#nests"
|
12
|
+
- title: "Local System Call"
|
13
|
+
url: "#local-system-call"
|
14
|
+
- title: "AWS Helpers"
|
15
|
+
url: "#aws-helpers"
|
16
|
+
---
|
17
|
+
|
18
|
+
## Helper methods
|
19
|
+
|
20
|
+
SparkleFormation provides a collection of helper methods
|
21
|
+
for facilitating faster development and cleaner code. Some
|
22
|
+
helpers provide easier access to underlying SparkleFormation
|
23
|
+
functionality, while others provide automatic generation of
|
24
|
+
known template data structures.
|
25
|
+
|
26
|
+
### Functionality Helpers
|
27
|
+
|
28
|
+
#### Dynamics
|
29
|
+
|
30
|
+
Inserting a dynamic directly requires calling out to the
|
31
|
+
singleton method and providing the local context, which
|
32
|
+
looks like this:
|
33
|
+
|
34
|
+
~~~ruby
|
35
|
+
SparkleFormation.new(:test) do
|
36
|
+
SparkleFormation.insert(:my_dynamic, self, :some => [:value])
|
37
|
+
end
|
38
|
+
~~~
|
39
|
+
|
40
|
+
The helper compacts this call to:
|
41
|
+
|
42
|
+
~~~ruby
|
43
|
+
SparkleFormation.new(:test) do
|
44
|
+
dynamic!(:my_dynamic, :some => [:value])
|
45
|
+
end
|
46
|
+
~~~
|
47
|
+
|
48
|
+
#### Registries
|
49
|
+
|
50
|
+
Registries are used by calling out the singleton method and
|
51
|
+
providing the local context:
|
52
|
+
|
53
|
+
~~~ruby
|
54
|
+
SparkleFormation.new(:test) do
|
55
|
+
SparkleFormation::Registry.insert(:my_registry, self, :some => [:value])
|
56
|
+
end
|
57
|
+
~~~
|
58
|
+
|
59
|
+
and can be compacted to:
|
60
|
+
|
61
|
+
~~~ruby
|
62
|
+
SparkleFormation.new(:test) do
|
63
|
+
registry!(:my_registry, :some => [:value])
|
64
|
+
end
|
65
|
+
~~~
|
66
|
+
|
67
|
+
#### Nests
|
68
|
+
|
69
|
+
Nests are used by calling out to the singleton method and
|
70
|
+
providing the local context:
|
71
|
+
|
72
|
+
~~~ruby
|
73
|
+
SparkleFormation.new(:test) do
|
74
|
+
SparkleFormation.nest(:my_template, self, :some => [:value])
|
75
|
+
end
|
76
|
+
~~~
|
77
|
+
|
78
|
+
and can be compacted to:
|
79
|
+
|
80
|
+
~~~ruby
|
81
|
+
SparkleFormation.new(:test) do
|
82
|
+
nest!(:my_template, :some => [:value])
|
83
|
+
end
|
84
|
+
~~~
|
85
|
+
|
86
|
+
#### Other
|
87
|
+
|
88
|
+
##### Local system call
|
89
|
+
|
90
|
+
Use the `system!` helper method to shell out to the local system,
|
91
|
+
execute a command, and return the string output:
|
92
|
+
|
93
|
+
~~~ruby
|
94
|
+
SparkleFormation.new(:test) do
|
95
|
+
parameters.creator.default system!('whoami')
|
96
|
+
end
|
97
|
+
~~~
|
98
|
+
|
99
|
+
### Generation Helpers
|
100
|
+
|
101
|
+
#### AWS Helpers
|
102
|
+
|
103
|
+
Data generation helpers are available for all the AWS
|
104
|
+
intrinsic functions and pseudo parameters:
|
105
|
+
|
106
|
+
|
107
|
+
##### Base intrinsic functions
|
108
|
+
|
109
|
+
* `base64!(VAL)`
|
110
|
+
* `find_in_map!(A, B, C)`
|
111
|
+
* `attr!(RESOURCE, ATTRIBUTE)`
|
112
|
+
* `azs!(REGION)`
|
113
|
+
* `join!(VAL1, VAL2, ...)`
|
114
|
+
* `select!(INDEX, ITEM)`
|
115
|
+
* `ref!(NAME)`
|
116
|
+
|
117
|
+
##### Pseudo Parameters
|
118
|
+
|
119
|
+
* `account_id!`
|
120
|
+
* `notification_arns!`
|
121
|
+
* `no_value!`
|
122
|
+
* `region!`
|
123
|
+
* `stack_id!`
|
124
|
+
* `stack_name!`
|
125
|
+
|
126
|
+
##### Conditional functions
|
127
|
+
|
128
|
+
AWS CFN supports runtime conditions. Helpers for building conditions:
|
129
|
+
|
130
|
+
* `and!(VAL1, VAL2, ...)`
|
131
|
+
* `equals!(VAL1, VAL2)`
|
132
|
+
* `not!(VAL)`
|
133
|
+
* `or!(VAL1, VAL2, ...)`
|
134
|
+
* `condition!(CONDITION_NAME)`
|
135
|
+
|
136
|
+
Helpers for using conditions:
|
137
|
+
|
138
|
+
* `if!(CONDITION_NAME)`
|
139
|
+
|
140
|
+
~~~ruby
|
141
|
+
SparkleFormation.new(:test) do
|
142
|
+
...
|
143
|
+
some_value if!(:my_condition, TRUE_VALUE, FALSE_VALUE)
|
144
|
+
...
|
145
|
+
end
|
146
|
+
~~~
|
147
|
+
|
148
|
+
* `on_condition!(CONDITION_NAME)`
|
149
|
+
|
150
|
+
~~~ruby
|
151
|
+
SparkleFormation.new(:test) do
|
152
|
+
...
|
153
|
+
resources.my_cool_resource do
|
154
|
+
on_condition!(:stack_is_cool)
|
155
|
+
...
|
156
|
+
end
|
157
|
+
~~~
|