Skip to content

Commit

Permalink
feat(tf): add jq
Browse files Browse the repository at this point in the history
  • Loading branch information
Vache, Aurelie committed Dec 3, 2018
1 parent f674a28 commit 9b710ed
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 6 deletions.
56 changes: 53 additions & 3 deletions terraform-cheat-sheet.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,70 @@ $ terraform workspace list

== Tools

=== jq

jq is a lightweight command-line JSON processor. Combined with terraform output it can be powerful.

==== Installaton

For Linux:

`$ sudo apt-get install jq`

For OS X:

`$ brew install jq`

==== Usage

For example, we defind outputs in a module and when we execute _terraform apply_ outputs are displayed:

....
$ terraform apply
...
Apply complete! Resources: 0 added, 0 changed,
0 destroyed.
Outputs:
elastic_endpoint = vpc-toto-12fgfd4d5f4ds5fngetwe4.
eu-central-1.es.amazonaws.com
....

We can extract the value that we want in order to use it in a script for xample. With jq it's easy:

....
$ terraform output -json
{
"elastic_endpoint": {
"sensitive": false,
"type": "string",
"value": "vpc-toto-12fgfd4d5f4ds5fngetwe4.
eu-central-1.es.amazonaws.com"
}
}
$ terraform output -json | jq '.elastic_endpoint.value'
"vpc-toto-12fgfd4d5f4ds5fngetwe4.eu-central-1.
es.amazonaws.com"
....

=== Terraforming

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

==== Install Terraforming
==== Installation

....
$ sudo apt install ruby
$ gem install terraforming
....

==== Usage

Pre-requisites :

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

It caused in reality by the proxy or a temporary issue between your network
connectivity and AWS.
It caused in reality by a proxy or a temporary issue between your network connectivity and AWS.
Binary file modified terraform-cheat-sheet.pdf
Binary file not shown.
55 changes: 52 additions & 3 deletions terraform-cheat-sheet_temp.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,68 @@ <h3 id="_list_workspaces">List workspaces</h3>
<h2 id="_tools">Tools</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_jq">jq</h3>
<p class="">jq is a lightweight command-line JSON processor. Combined with terraform output it can be powerful.</p>
<div class="sect3">
<h4 id="_installaton">Installaton</h4>
<p class="">For Linux:</p>
<p class=""><code>$ sudo apt-get install jq</code></p>
<p class="">For OS X:</p>
<p class=""><code>$ brew install jq</code></p>
</div>
<div class="sect3">
<h4 id="_usage_2">Usage</h4>
<p class="">For example, we defind outputs in a module and when we execute <em>terraform apply</em> outputs are displayed:</p>
<div class="literalblock">
<div class="content">
<pre>$ terraform apply
...

Apply complete! Resources: 0 added, 0 changed,
0 destroyed.

Outputs:

elastic_endpoint = vpc-toto-12fgfd4d5f4ds5fngetwe4.
eu-central-1.es.amazonaws.com</pre>
</div>
</div>
<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>
<div class="literalblock">
<div class="content">
<pre>$ terraform output -json
{
"elastic_endpoint": {
"sensitive": false,
"type": "string",
"value": "vpc-toto-12fgfd4d5f4ds5fngetwe4.
eu-central-1.es.amazonaws.com"
}
}

$ terraform output -json | jq '.elastic_endpoint.value'
"vpc-toto-12fgfd4d5f4ds5fngetwe4.eu-central-1.
es.amazonaws.com"</pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_terraforming">Terraforming</h3>
<p class="">If you have an existing AWS account for examples with existing components like
S3 buckets, SNS, VPC … You can use terraforming tool, a tool written in Ruby,
which extract existing AWS resources and convert it to Terraform files!</p>
<div class="sect3">
<h4 id="_install_terraforming">Install Terraforming</h4>
<h4 id="_installation_2">Installation</h4>
<div class="literalblock">
<div class="content">
<pre>$ sudo apt install ruby
$ gem install terraforming</pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_usage_3">Usage</h4>
<p class="">Pre-requisites :</p>
<p class="">Like for Terraform, you need to set AWS credentials</p>
<div class="literalblock">
Expand Down Expand Up @@ -334,8 +384,7 @@ <h3 id="_error_configuring_the_backend_s3_requesterror_send_request_failed">Erro
the values in your configuration, run "terraform init".</pre>
</div>
</div>
<p class="">It caused in reality by the proxy or a temporary issue between your network
connectivity and AWS.</p>
<p class="">It caused in reality by a proxy or a temporary issue between your network connectivity and AWS.</p>
</div>
</div>
</div>
Expand Down

0 comments on commit 9b710ed

Please sign in to comment.