yle_tf 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b756a2e77feec940d0faac15ac402b1b624e0cbc
4
- data.tar.gz: 6202a1cbe6e3aba3337b908bbb0c72cbd56eaef2
3
+ metadata.gz: e7b1c7b056ec918749df48648c4648f2c48f1ea1
4
+ data.tar.gz: a914bf80887e137d875a462ff6fa41e0d90719e7
5
5
  SHA512:
6
- metadata.gz: 3d417c9827c142b9d38d08e82f2574771edd50f664c4a4d4e8a5dec0edf7c3d9facca02efad74a56a2813e1b168b71c202743f961b13d27c42b3807f5e10ddc2
7
- data.tar.gz: '09842437220a7b72909c19b951219b798b30def5c41fa59e06502ccac760740f75f9e90a0c03951babd5db7b2c9598fa14fa00a94672e7877bf716c2c08657b2'
6
+ metadata.gz: '097b3721ffacb30739b37cd9eacfa583a582f8e210778869a47d5f47c18269f98df41b68387e996199abd879855d9bddcf9100d2dd278793cb837ac9abdcbc83'
7
+ data.tar.gz: 353f0124461ff8cfd6c742f0a4eeae635793c9dabc39cce25b3aac64b76325aedfb1d62118b831d79a73b98cd15696dc4be7b659812b48fc06e0ab8999f05725
data/bin/tf CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'bundler/setup' if File.exist? File.expand_path('../../Gemfile', __FILE__)
3
+ require 'bundler/setup' if File.exist?(File.expand_path('../../Gemfile', __FILE__))
4
4
  require 'yle_tf/cli'
5
5
 
6
6
  cli = YleTf::CLI.new(ARGV)
@@ -19,10 +19,10 @@ class YleTf
19
19
  end
20
20
 
21
21
  def self.load_bundler_plugins
22
- if defined?(Bundler)
23
- print_bundler_plugin_list if Logger.debug?
24
- Bundler.require(BUNDLER_PLUGIN_GROUP)
25
- end
22
+ return if !bundler_set_up?
23
+
24
+ Logger.debug { print_bundler_plugin_list }
25
+ Bundler.require(BUNDLER_PLUGIN_GROUP)
26
26
  end
27
27
 
28
28
  def self.load_user_plugins
@@ -47,6 +47,10 @@ class YleTf
47
47
  ENV.fetch('TF_PLUGINS', '').split(/[ ,]+/)
48
48
  end
49
49
 
50
+ def self.bundler_set_up?
51
+ defined?(Bundler) && Bundler.respond_to?(:require)
52
+ end
53
+
50
54
  def self.print_bundler_plugin_list
51
55
  plugins = bundler_plugins
52
56
  if !plugins.empty?
@@ -1,3 +1,3 @@
1
1
  class YleTf
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yle_tf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yleisradio
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-08-29 00:00:00.000000000 Z
13
+ date: 2017-08-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -64,23 +64,7 @@ executables:
64
64
  extensions: []
65
65
  extra_rdoc_files: []
66
66
  files:
67
- - ".gitignore"
68
- - ".rspec"
69
- - ".rubocop.yml"
70
- - ".travis.yml"
71
- - CHANGELOG.md
72
- - CODE_OF_CONDUCT.md
73
- - Gemfile
74
- - LICENSE.txt
75
- - README.md
76
- - Rakefile
77
67
  - bin/tf
78
- - examples/envs/prod.tfvars
79
- - examples/envs/test.tfvars
80
- - examples/main.tf
81
- - examples/tf.yaml
82
- - examples/tf_hooks/pre/get_current_hash.sh
83
- - examples/variables.tf
84
68
  - lib/yle_tf.rb
85
69
  - lib/yle_tf/action.rb
86
70
  - lib/yle_tf/action/builder.rb
@@ -132,7 +116,6 @@ files:
132
116
  - vendor/middleware/LICENSE
133
117
  - vendor/middleware/builder.rb
134
118
  - vendor/middleware/runner.rb
135
- - yle_tf.gemspec
136
119
  homepage: https://github.com/Yleisradio/yle_tf
137
120
  licenses:
138
121
  - MIT
@@ -145,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
128
  requirements:
146
129
  - - ">="
147
130
  - !ruby/object:Gem::Version
148
- version: '0'
131
+ version: '2.2'
149
132
  required_rubygems_version: !ruby/object:Gem::Requirement
150
133
  requirements:
151
134
  - - ">="
@@ -153,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
136
  version: '0'
154
137
  requirements: []
155
138
  rubyforge_project:
156
- rubygems_version: 2.6.11
139
+ rubygems_version: 2.6.13
157
140
  signing_key:
158
141
  specification_version: 4
159
142
  summary: Tooling for Terraform
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
data/.rubocop.yml DELETED
@@ -1,26 +0,0 @@
1
- Metrics/BlockLength:
2
- Exclude:
3
- - 'spec/**/*'
4
-
5
- Metrics/ClassLength:
6
- Severity: warning
7
-
8
- Metrics/LineLength:
9
- Max: 100
10
- Severity: warning
11
-
12
- Metrics/MethodLength:
13
- Max: 12
14
- Severity: warning
15
-
16
- Style/Documentation:
17
- Enabled: false
18
-
19
- Style/GuardClause:
20
- MinBodyLength: 3
21
-
22
- Style/NegatedIf:
23
- Enabled: false
24
-
25
- Style/TrailingCommaInLiteral:
26
- Enabled: false
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
-
4
- rvm:
5
- - 2.4.1
6
- - 2.3.4
7
- - 2.2.7
data/CHANGELOG.md DELETED
@@ -1,3 +0,0 @@
1
- ## 0.1.0 / 2017-08-29
2
-
3
- - Initial public release
data/CODE_OF_CONDUCT.md DELETED
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at teemu.matilainen@reaktor.fi. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in yle_tf.gemspec
4
- gemspec
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2016-2017 Yleisradio Oy
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
data/README.md DELETED
@@ -1,442 +0,0 @@
1
- # YleTf
2
-
3
- A wrapper for [Terraform](https://www.terraform.io/) with support for hooks and environments.
4
-
5
- Offers a command-line helper tool, `tf`
6
-
7
- ## Getting started
8
-
9
- YleTf requires Terraform which can be installed according to their [instructions](https://www.terraform.io/intro/getting-started/install.html). On MacOS (and OSX) you can use [Homebrew](https://brew.sh/). You can also easily install and manage multiple versions of Terraform with [homebrew-terraforms](https://github.com/Yleisradio/homebrew-terraforms).
10
-
11
- ## Installation
12
-
13
- YleTf can be installed as a gem:
14
-
15
- ```sh
16
- $ gem install yle_tf
17
- ```
18
-
19
- ## Usage
20
-
21
- The syntax to run YleTf is much like vanilla [Terraform](https://terraform.io). The main difference is that you must include desired environment as the first argument:
22
-
23
- ```
24
- tf <environment> <command> [<args>]
25
- ```
26
-
27
- For example:
28
-
29
- ```
30
- $ tf test plan
31
-
32
- $ tf prod apply
33
-
34
- $ tf stage destroy
35
- ```
36
-
37
- For a full list of available options, run `tf --help`.
38
-
39
- When `tf` is executed, it creates a temporary directory where your project is copied and initialized.
40
-
41
- ### Example project
42
-
43
- The following is a really basic example on what you need in order to use YleTf. The project is pretty much the same as the [example project](https://www.terraform.io/intro/getting-started/build.html) in Terraform documentation but with the added support for environments. Introduction to [hooks](#hooks) is in it's own section.
44
-
45
- #### Project Config
46
-
47
- The root of your project directory will look like this:
48
-
49
- ```
50
- .
51
- ├── envs
52
- │   ├── prod.tfvars
53
- │   └── test.tfvars
54
- ├── main.tf
55
- ├── tf.yaml
56
- └── variables.tf
57
- ```
58
-
59
- And here are the contents of the files:
60
-
61
- ##### main.tf
62
-
63
- ```hcl
64
- provider "aws" {
65
- access_key = "${var.aws_access_key}"
66
- secret_key = "${var.aws_secret_key}"
67
- region = "${var.region}"
68
- }
69
-
70
- resource "aws_instance" "example" {
71
- ami = "ami-2757f631"
72
- instance_type = "t2.micro"
73
- }
74
- ```
75
-
76
- _Please note that the AMI identifier changes based on your desired OS and region. For more information see [AWS documentation](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html)._
77
-
78
- ##### variables.tf
79
-
80
- ```hcl
81
- variable "region" {
82
- description = "The AWS region for the resources"
83
- default = "eu-west-1"
84
- }
85
-
86
- variable "env" {
87
- # passed by `tf`
88
- description = "The environment"
89
- }
90
-
91
- variable "aws_access_key" {
92
- description = "Your AWS access key id"
93
- }
94
-
95
- variable "aws_secret_key" {
96
- description = "Your AWS secret key"
97
- }
98
-
99
- variable "instance_type" {
100
- description = "Instance type to use"
101
- default = "t2.micro"
102
- }
103
- ```
104
-
105
- ##### envs/test.tfvars
106
-
107
- ```ini
108
- aws_access_key = "TEST_ACCOUNT_ACCESS_KEY_HERE"
109
- aws_secret_key = "TEST_ACCOUNT_SECRET_KEY_HERE"
110
- ```
111
-
112
- ##### tf.yaml
113
-
114
- ```yaml
115
- backend:
116
- type: file
117
- terraform:
118
- version_requirement: "~> 0.9.11"
119
- ```
120
-
121
- #### Execution
122
-
123
- With all the above in order, there's nothing more to do than to try and run the commands:
124
-
125
- First plan:
126
-
127
- ```
128
- $ tf test plan
129
- INFO: Symlinking state to '/usr/local/src/yle_tf/examples/examples_test.tfstate'
130
-
131
- Terraform has been successfully initialized!
132
-
133
- You may now begin working with Terraform. Try running "terraform plan" to see
134
- any changes that are required for your infrastructure. All Terraform commands
135
- should now work.
136
-
137
- If you ever set or change modules or backend configuration for Terraform,
138
- rerun this command to reinitialize your environment. If you forget, other
139
- commands will detect it and remind you to do so if necessary.
140
- Refreshing Terraform state in-memory prior to plan...
141
- The refreshed state will be used to calculate this plan, but will not be
142
- persisted to local or remote state storage.
143
-
144
- The Terraform execution plan has been generated and is shown below.
145
- Resources are shown in alphabetical order for quick scanning. Green resources
146
- will be created (or destroyed and then created if an existing resource
147
- exists), yellow resources are being changed in-place, and red resources
148
- will be destroyed. Cyan entries are data sources to be read.
149
-
150
- Note: You didn't specify an "-out" parameter to save this plan, so when
151
- "apply" is called, Terraform can't guarantee this is what will execute.
152
-
153
- + aws_instance.example
154
- ami: "ami-d7b9a2b1"
155
- associate_public_ip_address: "<computed>"
156
- availability_zone: "<computed>"
157
- ebs_block_device.#: "<computed>"
158
- ephemeral_block_device.#: "<computed>"
159
- instance_state: "<computed>"
160
- instance_type: "t2.micro"
161
- ipv6_address_count: "<computed>"
162
- ipv6_addresses.#: "<computed>"
163
- key_name: "<computed>"
164
- network_interface.#: "<computed>"
165
- network_interface_id: "<computed>"
166
- placement_group: "<computed>"
167
- primary_network_interface_id: "<computed>"
168
- private_dns: "<computed>"
169
- private_ip: "<computed>"
170
- public_dns: "<computed>"
171
- public_ip: "<computed>"
172
- root_block_device.#: "<computed>"
173
- security_groups.#: "<computed>"
174
- source_dest_check: "true"
175
- subnet_id: "<computed>"
176
- tenancy: "<computed>"
177
- volume_tags.%: "<computed>"
178
- vpc_security_group_ids.#: "<computed>"
179
-
180
-
181
- Plan: 1 to add, 0 to change, 0 to destroy.
182
- ```
183
-
184
- Then apply:
185
-
186
- ```
187
- $ tf test apply
188
-
189
- < SNIP >
190
-
191
- aws_instance.example: Creating...
192
- ami: "" => "ami-d7b9a2b1"
193
- associate_public_ip_address: "" => "<computed>"
194
- availability_zone: "" => "<computed>"
195
- ebs_block_device.#: "" => "<computed>"
196
- ephemeral_block_device.#: "" => "<computed>"
197
- instance_state: "" => "<computed>"
198
- instance_type: "" => "t2.micro"
199
- ipv6_address_count: "" => "<computed>"
200
- ipv6_addresses.#: "" => "<computed>"
201
- key_name: "" => "<computed>"
202
- network_interface.#: "" => "<computed>"
203
- network_interface_id: "" => "<computed>"
204
- placement_group: "" => "<computed>"
205
- primary_network_interface_id: "" => "<computed>"
206
- private_dns: "" => "<computed>"
207
- private_ip: "" => "<computed>"
208
- public_dns: "" => "<computed>"
209
- public_ip: "" => "<computed>"
210
- root_block_device.#: "" => "<computed>"
211
- security_groups.#: "" => "<computed>"
212
- source_dest_check: "" => "true"
213
- subnet_id: "" => "<computed>"
214
- tenancy: "" => "<computed>"
215
- volume_tags.%: "" => "<computed>"
216
- vpc_security_group_ids.#: "" => "<computed>"
217
- aws_instance.example: Still creating... (10s elapsed)
218
- aws_instance.example: Still creating... (20s elapsed)
219
- aws_instance.example: Creation complete (ID: i-0f1327bbc53fd6bab)
220
-
221
- Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
222
-
223
- < SNIP >
224
- ```
225
-
226
- And when you're done using the infrastructure, destroy:
227
-
228
- ```
229
- $ tf test destroy
230
-
231
- < SNIP >
232
-
233
- Do you really want to destroy?
234
- Terraform will delete all your managed infrastructure.
235
- There is no undo. Only 'yes' will be accepted to confirm.
236
-
237
- Enter a value: yes
238
-
239
- aws_instance.example: Refreshing state... (ID: i-0f1327bbc53fd6bab)
240
- aws_instance.example: Destroying... (ID: i-0f1327bbc53fd6bab)
241
- aws_instance.example: Still destroying... (ID: i-0f1327bbc53fd6bab, 10s elapsed)
242
- aws_instance.example: Still destroying... (ID: i-0f1327bbc53fd6bab, 20s elapsed)
243
- aws_instance.example: Still destroying... (ID: i-0f1327bbc53fd6bab, 30s elapsed)
244
- aws_instance.example: Still destroying... (ID: i-0f1327bbc53fd6bab, 40s elapsed)
245
- aws_instance.example: Still destroying... (ID: i-0f1327bbc53fd6bab, 50s elapsed)
246
- aws_instance.example: Still destroying... (ID: i-0f1327bbc53fd6bab, 1m0s elapsed)
247
- aws_instance.example: Still destroying... (ID: i-0f1327bbc53fd6bab, 1m10s elapsed)
248
- aws_instance.example: Destruction complete
249
-
250
- Destroy complete! Resources: 1 destroyed.
251
- ```
252
-
253
- #### Production environment
254
-
255
- Now that we've tried that everything works in the test environment, let's do the same in production. Note that you can override variables if needed:
256
-
257
- ##### envs/prod.tfvars
258
-
259
- ```ini
260
- aws_access_key = "PRODUCTION_ACCOUNT_ACCESS_KEY_HERE"
261
- aws_secret_key = "PRODUCTION_ACCOUNT_SECRET_KEY_HERE"
262
-
263
- # let's use a bigger instance type in prod
264
- instance_type = "t2.medium"
265
- ```
266
-
267
- And run the commands just like with _test_:
268
-
269
- ```
270
- $ tf prod plan
271
-
272
- < SNIP >
273
-
274
- $ tf prod apply
275
-
276
- < SNIP >
277
-
278
- $ tf prod destroy
279
-
280
- < SNIP >
281
- ```
282
-
283
- _Note that the instance type is now t2.medium_
284
-
285
- ## Default components
286
-
287
- ### tf.yaml
288
-
289
- Here be dragons that configure your project. The tools serches for `tf.yaml`'s up your path all the way to root `/`. Configs made in subdirectories override those made upper in the path. This makes it easy to define common settings without having to edit `tf.yaml` in every project.
290
-
291
- By defalt the following configuration options are supported:
292
- * [`hooks`](#hooks) - Pre and Post hooks.
293
- * [`backend`](#backend) - Configuration of remote state location.
294
- * [`terraform`](#terraform) - Terraform specific configuration.
295
-
296
- #### Hooks
297
-
298
- There are cases when it would be beneficial to run a task at the same time as terrafrom, but building native support for that would be quite cumbersome. The support for hooks was build into YleTf having those cases in mind.
299
-
300
- Essentially hooks are just scripts and small applications to extend the functionality of Terraform. Hooks can be either
301
- * [local](#local-hooks) or
302
- * [remote](#remote-hooks) i.e. stored into git.
303
-
304
- Real world usecases for hooks include at least the following:
305
- * Automatically register ACM certificates and link them to desired resources
306
- * Automatically generate dns record resources that are managed by separate configuration
307
- * Package lambda applications for deployment via Terraform
308
- * Manage SES authorisations and rules
309
- * Modify parameters not yet supported by Terraform
310
-
311
- Currently two kinds of hooks are supported:
312
- * `pre` - Hooks that run before terraform execution.
313
- * `post` - Hooks that run after terraform execution.
314
-
315
- #### Local hooks
316
-
317
- For local hooks, add a directory called `tf_hooks` to your tf project root. You also need a folder to determine wether the hook is run before or after the execution of terraform. The folders are `pre` and/or `post`:
318
-
319
- ```
320
- .
321
- ├── envs
322
- │   ├── prod.tfvars
323
- │   └── test.tfvars
324
- ├── main.tf
325
- ├── tf.yaml
326
- ├── tf_hooks
327
- │   ├── pre
328
- │   │ └── pre-hook.sh
329
- │   └── post
330
- │   │ └── post-hook.rb
331
- └── variables.tf
332
- ```
333
-
334
- For example, let's say you wish to have a variable `current_git_hash` and you want to populate it with a value of the latest git commit hash. The hook could be something like this:
335
-
336
- ##### tf_hooks/pre/get_current_hash.sh
337
-
338
- ```bash
339
- #!/bin/bash
340
-
341
- set -eu
342
-
343
- current_hash() {
344
- CURRENT_GIT_HASH="$(git rev-parse HEAD)"
345
-
346
- cat <<EOF > current_git_hash.tf.json
347
- {
348
- "variable": {
349
- "current_git_hash": {
350
- "value": "$CURRENT_GIT_HASH"
351
- }
352
- }
353
- }
354
- EOF
355
- }
356
-
357
- # Execute only for commands `plan` and `apply`
358
- case "$TF_COMMAND" in
359
- plan|apply)
360
- current_hash
361
- ;;
362
- *)
363
- ;;
364
- esac
365
- ```
366
-
367
- _Please note that the script in the [examples](examples/) directory is intentionnally without the execute bit._
368
-
369
- Once you set the hook script executable (`chmod +x tf_hooks/pre/get_current_hash.sh`) and run `tf` with either `plan` or `apply`, you'll have the following file during runtime:
370
-
371
- ##### current_git_hash.tf.json
372
-
373
- ```json
374
- {
375
- "variable": {
376
- "current_git_hash": {
377
- "value": "c6a02baf0597e55d7698f78d70299ca4a65776cd"
378
- }
379
- }
380
- }
381
- ```
382
-
383
- _Naturraly the actual value varies according to your repository._
384
-
385
- _**Please note that files generated into the temporary working directory while running hooks are removed once the execution has ended.**_
386
-
387
- #### Remote hooks
388
-
389
- Hooks can also be stored in common git repositories. This is a handy way to avoid duplication in codebase.
390
- To use a hook from git just add your script to a suitable repository (making sure it's still executable) and add following config to your `tf.yaml`:
391
-
392
- ##### tf.yaml
393
-
394
- ```yaml
395
- hooks:
396
- pre:
397
- - description: "Get your current git commit hash"
398
- source: "git@github.com:your-org/tf-hooks.git//git-hash/get_current_hash.sh"
399
- vars:
400
- defaults:
401
- MESSAGE: "You can also define environment variables to your hooks"
402
- test:
403
- MESSAGE: "And the variables can also be environment spesific"
404
- ```
405
-
406
- #### Backend
407
-
408
- Configure where Terraform [remote state](https://www.terraform.io/docs/state/remote.html) is stored
409
-
410
- * `type` - Backend type where the Terraform state is stored.
411
- * `bucket` - The name of the S3 bucket.
412
- * `file` - The name of the state file.
413
- * `region` - The region of the S3 bucket.
414
- * `encrypt` - Whether to enable server side encryption of the state file.
415
-
416
- ```yaml
417
- backend:
418
- type: s3
419
- ```
420
-
421
- #### Terraform
422
-
423
- * `version_requirement` - The version requirement of Terraform in ruby gem syntax.
424
-
425
- ```yaml
426
- terraform:
427
- version_requirement: "~> 0.9.11"
428
- ```
429
-
430
- ## Development
431
-
432
- After checking out the repo, run `bundle update` to install and update the dependencies. Then, run `bundle exec rake spec` to run the tests.
433
-
434
- To install this gem onto your local machine, run `bundle exec rake install`.
435
-
436
- ## Contributing
437
-
438
- Bug reports and pull requests are welcome on GitHub at https://github.com/Yleisradio/yle_tf. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
439
-
440
- ## License
441
-
442
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task default: :spec
@@ -1,5 +0,0 @@
1
- aws_access_key = "PRODUCTION_ACCOUNT_ACCESS_KEY_HERE"
2
- aws_secret_key = "PRODUCTION_ACCOUNT_SECRET_KEY_HERE"
3
-
4
- # let's use a bigger instance type in prod
5
- instance_type = "t2.medium"
@@ -1,2 +0,0 @@
1
- aws_access_key = "TEST_ACCOUNT_ACCESS_KEY_HERE"
2
- aws_secret_key = "TEST_ACCOUNT_SECRET_KEY_HERE"
data/examples/main.tf DELETED
@@ -1,10 +0,0 @@
1
- provider "aws" {
2
- access_key = "${var.aws_access_key}"
3
- secret_key = "${var.aws_secret_key}"
4
- region = "${var.region}"
5
- }
6
-
7
- resource "aws_instance" "example" {
8
- ami = "ami-d7b9a2b1"
9
- instance_type = "${var.instance_type}"
10
- }
data/examples/tf.yaml DELETED
@@ -1,4 +0,0 @@
1
- backend:
2
- type: file
3
- terraform:
4
- version_requirement: "~> 0.9.11"
@@ -1,26 +0,0 @@
1
- #!/bin/bash
2
-
3
- set -eu
4
-
5
- current_hash() {
6
- CURRENT_GIT_HASH="$(git rev-parse HEAD)"
7
-
8
- cat <<EOF > current_git_hash.tf.json
9
- {
10
- "variable": {
11
- "current_git_hash": {
12
- "value": "$CURRENT_GIT_HASH"
13
- }
14
- }
15
- }
16
- EOF
17
- }
18
-
19
- # Execute only for commands `plan` and `apply`
20
- case "$TF_COMMAND" in
21
- plan|apply)
22
- current_hash
23
- ;;
24
- *)
25
- ;;
26
- esac
@@ -1,22 +0,0 @@
1
- variable "region" {
2
- description = "The AWS region for the resources"
3
- default = "eu-west-1"
4
- }
5
-
6
- variable "env" {
7
- # passed by `tf`
8
- description = "The environment"
9
- }
10
-
11
- variable "aws_access_key" {
12
- description = "Your AWS access key id"
13
- }
14
-
15
- variable "aws_secret_key" {
16
- description = "Your AWS secret key"
17
- }
18
-
19
- variable "instance_type" {
20
- description = "Instance type to use"
21
- default = "t2.micro"
22
- }
data/yle_tf.gemspec DELETED
@@ -1,37 +0,0 @@
1
- # coding: utf-8
2
-
3
- lib = File.expand_path('../lib', __FILE__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'yle_tf/version'
6
-
7
- Gem::Specification.new do |spec|
8
- spec.name = 'yle_tf'
9
- spec.version = YleTf::VERSION
10
- spec.summary = 'Tooling for Terraform'
11
- spec.description = 'Tooling for Terraform to support environments, hooks, etc.'
12
- spec.homepage = 'https://github.com/Yleisradio/yle_tf'
13
- spec.license = 'MIT'
14
-
15
- spec.authors = [
16
- 'Yleisradio',
17
- 'Teemu Matilainen',
18
- 'Antti Forsell',
19
- ]
20
- spec.email = [
21
- 'devops@yle.fi',
22
- 'teemu.matilainen@iki.fi',
23
- 'antti.forsell@iki.fi',
24
- ]
25
-
26
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
- f.match(%r{^(test|spec|features)/})
28
- end
29
-
30
- spec.bindir = 'bin'
31
- spec.executables = ['tf']
32
- spec.require_paths = ['lib']
33
-
34
- spec.add_development_dependency 'bundler', '~> 1.13'
35
- spec.add_development_dependency 'rake', '~> 12.0'
36
- spec.add_development_dependency 'rspec', '~> 3.5'
37
- end