Skip to content

Commit 9b710ed

Browse files
author
Vache, Aurelie
committed
feat(tf): add jq
1 parent f674a28 commit 9b710ed

File tree

3 files changed

+105
-6
lines changed

3 files changed

+105
-6
lines changed

terraform-cheat-sheet.adoc

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,19 +210,70 @@ $ terraform workspace list
210210

211211
== Tools
212212

213+
=== jq
214+
215+
jq is a lightweight command-line JSON processor. Combined with terraform output it can be powerful.
216+
217+
==== Installaton
218+
219+
For Linux:
220+
221+
`$ sudo apt-get install jq`
222+
223+
For OS X:
224+
225+
`$ brew install jq`
226+
227+
==== Usage
228+
229+
For example, we defind outputs in a module and when we execute _terraform apply_ outputs are displayed:
230+
231+
....
232+
$ terraform apply
233+
...
234+
235+
Apply complete! Resources: 0 added, 0 changed,
236+
0 destroyed.
237+
238+
Outputs:
239+
240+
elastic_endpoint = vpc-toto-12fgfd4d5f4ds5fngetwe4.
241+
eu-central-1.es.amazonaws.com
242+
....
243+
244+
We can extract the value that we want in order to use it in a script for xample. With jq it's easy:
245+
246+
....
247+
$ terraform output -json
248+
{
249+
"elastic_endpoint": {
250+
"sensitive": false,
251+
"type": "string",
252+
"value": "vpc-toto-12fgfd4d5f4ds5fngetwe4.
253+
eu-central-1.es.amazonaws.com"
254+
}
255+
}
256+
257+
$ terraform output -json | jq '.elastic_endpoint.value'
258+
"vpc-toto-12fgfd4d5f4ds5fngetwe4.eu-central-1.
259+
es.amazonaws.com"
260+
....
261+
213262
=== Terraforming
214263

215264
If you have an existing AWS account for examples with existing components like
216265
S3 buckets, SNS, VPC … You can use terraforming tool, a tool written in Ruby,
217266
which extract existing AWS resources and convert it to Terraform files!
218267

219-
==== Install Terraforming
268+
==== Installation
220269

221270
....
222271
$ sudo apt install ruby
223272
$ gem install terraforming
224273
....
225274

275+
==== Usage
276+
226277
Pre-requisites :
227278

228279
Like for Terraform, you need to set AWS credentials
@@ -311,5 +362,4 @@ If you'd like to update the configuration interactively without storing
311362
the values in your configuration, run "terraform init".
312363
....
313364

314-
It caused in reality by the proxy or a temporary issue between your network
315-
connectivity and AWS.
365+
It caused in reality by a proxy or a temporary issue between your network connectivity and AWS.

terraform-cheat-sheet.pdf

1.4 KB
Binary file not shown.

terraform-cheat-sheet_temp.html

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,68 @@ <h3 id="_list_workspaces">List workspaces</h3>
235235
<h2 id="_tools">Tools</h2>
236236
<div class="sectionbody">
237237
<div class="sect2">
238+
<h3 id="_jq">jq</h3>
239+
<p class="">jq is a lightweight command-line JSON processor. Combined with terraform output it can be powerful.</p>
240+
<div class="sect3">
241+
<h4 id="_installaton">Installaton</h4>
242+
<p class="">For Linux:</p>
243+
<p class=""><code>$ sudo apt-get install jq</code></p>
244+
<p class="">For OS X:</p>
245+
<p class=""><code>$ brew install jq</code></p>
246+
</div>
247+
<div class="sect3">
248+
<h4 id="_usage_2">Usage</h4>
249+
<p class="">For example, we defind outputs in a module and when we execute <em>terraform apply</em> outputs are displayed:</p>
250+
<div class="literalblock">
251+
<div class="content">
252+
<pre>$ terraform apply
253+
...
254+
255+
Apply complete! Resources: 0 added, 0 changed,
256+
0 destroyed.
257+
258+
Outputs:
259+
260+
elastic_endpoint = vpc-toto-12fgfd4d5f4ds5fngetwe4.
261+
eu-central-1.es.amazonaws.com</pre>
262+
</div>
263+
</div>
264+
<p class="">We can extract the value that we want in order to use it in a script for xample. With jq it&#8217;s easy:</p>
265+
<div class="literalblock">
266+
<div class="content">
267+
<pre>$ terraform output -json
268+
{
269+
"elastic_endpoint": {
270+
"sensitive": false,
271+
"type": "string",
272+
"value": "vpc-toto-12fgfd4d5f4ds5fngetwe4.
273+
eu-central-1.es.amazonaws.com"
274+
}
275+
}
276+
277+
$ terraform output -json | jq '.elastic_endpoint.value'
278+
"vpc-toto-12fgfd4d5f4ds5fngetwe4.eu-central-1.
279+
es.amazonaws.com"</pre>
280+
</div>
281+
</div>
282+
</div>
283+
</div>
284+
<div class="sect2">
238285
<h3 id="_terraforming">Terraforming</h3>
239286
<p class="">If you have an existing AWS account for examples with existing components like
240287
S3 buckets, SNS, VPC … You can use terraforming tool, a tool written in Ruby,
241288
which extract existing AWS resources and convert it to Terraform files!</p>
242289
<div class="sect3">
243-
<h4 id="_install_terraforming">Install Terraforming</h4>
290+
<h4 id="_installation_2">Installation</h4>
244291
<div class="literalblock">
245292
<div class="content">
246293
<pre>$ sudo apt install ruby
247294
$ gem install terraforming</pre>
248295
</div>
249296
</div>
297+
</div>
298+
<div class="sect3">
299+
<h4 id="_usage_3">Usage</h4>
250300
<p class="">Pre-requisites :</p>
251301
<p class="">Like for Terraform, you need to set AWS credentials</p>
252302
<div class="literalblock">
@@ -334,8 +384,7 @@ <h3 id="_error_configuring_the_backend_s3_requesterror_send_request_failed">Erro
334384
the values in your configuration, run "terraform init".</pre>
335385
</div>
336386
</div>
337-
<p class="">It caused in reality by the proxy or a temporary issue between your network
338-
connectivity and AWS.</p>
387+
<p class="">It caused in reality by a proxy or a temporary issue between your network connectivity and AWS.</p>
339388
</div>
340389
</div>
341390
</div>

0 commit comments

Comments
 (0)