forked from hakimel/reveal.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
426 lines (369 loc) · 13 KB
/
demo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="dist/reset.css">
<link rel="stylesheet" href="dist/reveal.css">
<link rel="stylesheet" href="dist/theme/black.css">
<!--link rel="stylesheet" href="plugin/highlight/monokai.css"-->
<link rel="stylesheet" href="css/terraform.css">
<link rel="stylesheet" href="css/slides.css">
<!--link rel="stylesheet" href="terraform.css"-->
<title>Terraform - Lessons Learned</title>
</head>
<body>
<div class="reveal">
<div class="slides">
<!-- Title Slide -->
<section>
<h2>Terraform - Lessons Learned</h2>
<small>
<p>By Robin Schwendele</p>
<a href="https://github.com/R0bes/Terraform-Presentation">
<p>Github</p>
</a>
</small>
</section>
<section>
<h3 class="headline">About Myself</h3>
<div style="position: absolute;
top: 50px;
left: 0px;
width: 250px;
height: 250px;">
<img id="me" data-src="images/me.jpg">
</div>
<ul>
<li>Robin Schwendele</li>
<li>Working student since 10/2020</li>
<li>Bachelor Computer Science Mannheim</li>
<li>Student of Master Software-Engineering Mannheim</li>
</ul-->
</section>
<section id="iot-project">
<h3 class="headline">A practical IoT cloud journey</h3>
<div>
<img width="70%" data-src="http://www.plantuml.com/plantuml/proxy?cache=no&src=https%3A%2F%2Fdev.azure.com%2FGFTDemos%2FGFT.IoT%2F_apis%2Fgit%2Frepositories%2FGFT.IoT%2FItems%3Fpath%3D%252FDocs%252FDiagrams%252Fenvironment.puml%26recursionLevel%3D0%26versionDescriptor.version%3Dmaster%26versionDescriptor.versionOptions%3D0%26versionDescriptor.versionType%3D0%26includeContent%3Dtrue%26resolveLfs%3Dtrue"/>
</div>
<div>
<small><a href="https://dev.azure.com/GFTDemos/GFT.IoT">Repository</a></small>
</div>
</section>
<section>
<div id="tflogo" style="position: absolute;
top: 0px;
right: 0px;
width: 250px;
height: 250px;">
<img data-src="images/terraform_logo.png">
</div>
<h3 class="headline">Terraform</u></h3>
<ul>
<li class="fragment">By HashiCorp</li>
<li class="fragment">Provisioning Tool</li>
<li class="fragment">Infrastructure as Code</li>
<li class="fragment">Declarative</li>
<li class="fragment">Plugin-based architecture model</li>
<li class="fragment">HCL (Hashicorp Configuration Language) </li>
<li class="fragment">Written in Golang</li>
<li class="fragment"><a href="https://github.com/hashicorp/terraform">Open Source</a></li>
</ul>
<aside class="notes">
<p>Tasks:</p>
<ul>
<li>Creation and Standup</li>
<li>Patch or reconfigure</li>
<li>Scale up/down</li>
<li>Decomission</li>
</ul>
</aside>
</section>
<section>
<h3 class="headline">Commands</h3>
<img data-src="images/diagrams/commands.svg" width="1000">
</section>
<section>
<h3 class="headline">Workflow</h3>
<img data-src="images/diagrams/workflow.svg" width="1000">
</section>
<!-- ! DEMO 1 -- Basics -->
<section>
<h3 class="headline">1. Demo - Terraform Basics</h3>
<p><strong>What we will see</strong></p>
<ul>
<li>Example Terraform File (.tf)</li>
<li>Syntax Basics</li>
<li>Terraform Execution</li>
<li>Resource in the Cloud</li>
</ul>
</section>
<section>
<h3 class="headline">1. Demo - Terraform Basics</h3>
<pre><code class="terraform" data-trim data-line-numbers="1-14|1-3|4|5-8|9-14">
provider "azurerm" {
features {}
}
variable "name" {}
resource "azurerm_resource_group" "example" {
name = var.name
location = "westeurope"
}
resource "azurerm_public_ip" "example" {
name = "${var.name}-ip"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
allocation_method = "Static"
}
</code></pre>
</section>
<section>
<h3 class="headline">1. Demo - Terraform Basics</h3>
<aside class="notes">
<ul>
<li>$ cd demos/1/</li>
<li>$ ls</li>
<li>$ type basic.tf</li>
<li>$ terraform init</li>
<li>$ ls</li>
<li>$ terraform plan -out="demo1.tfplan"</li>
<li>$ terraform apply demo1.tfplan</li>
<li>check <a href="https://portal.azure.com/#home">Azure</a></li>
<li>$ terraform plan -destroy -out="demo1.destroy.tfplan"</li>
<li>$ terraform apply demo1.destroy.tfplan</li>
<li>$ terraform apply -var "name=demo12" --auto-approve</li>
<li>$ terraform destroy -var "name=demo12" --auto-approve</li>
<li>$ ls</li>
</ul>
</aside>
</section>
<section>
<h3 class="headline">1. Demo - Terraform Basics</h3>
<p><strong>What we saw</strong></p>
<ul>
<li>Terraform File</li>
<li>State File</li>
<li>Terraform Workflow via command line</li>
<li>Resources in the Cloud</li>
</ul>
</section>
<!-- ! Demo 2 -- External Code -->
<section data-auto-animate>
<h3 class="headline">2. Demo - Digital Twin</h3>
<a href="#iot-project">Practical IoT-Cloud-Joruney</a>
<div style="position: absolute;
top: 0px;
left: 0px;
height: 400px;">
<img data-src="images/digital_twin_turbine2.jpg">
</div>
<div style="position: absolute;
top: 150px;
left: 250px;
width: 450px;">
<img data-src="images/digital_twin_car1.jpg">
</div>
<div style="position: absolute;
top: 130px;
right: 300px;
width: 450px;">
<img data-src="images/digital_twin_turbine1.jpg">
</div>
<div style="position: absolute;
top: 0px;
right: 0px;
width: 400px;">
<img data-src="images/digital_twin_car2.jpg">
</div>
</section>
<section data-auto-animate>
<h3 class="headline">2. Demo - Digital Twin</h3>
<ul>
<li class="fragment">After terraform apply via <a href="https://docs.microsoft.com/de-de/cli/azure/">Azure CLI</a></li>
<li class="fragment">IoT Hub: my-hub</li>
</ul>
<pre class="fragment" data-id="code-animation"><code class="shell" data-trim data-line-numbers="1">
$ az iot hub device-identity create --hub-name 'my-hub' --device-id 'my-device'
</code></pre>
</section>
<section data-auto-animate>
<h3 class="headline">2. Demo - Digital Twin</h3>
<ul>
<li>Local execution Provisioner via Terraform</li>
<li>Interpreter must be installed</li>
<li><b>az login</b> must be executed before <b>terraform apply</b></li>
</ul>
<pre data-id="code-animation"><code class="tf" data-trim data-line-numbers="1|3|5-6">
resource "null_resource" "device_twin" {
provisioner "local-exec" {
when = create
interpreter = ["pwsh" , "-Command"]
command = az iot hub device-identity create -n 'my-hub' -d 'my-device'
}
}
</code></pre>
</section>
<section data-auto-animate>
<h3 class="headline">2. Demo - Digital Twin</h3>
<p>Same thing for destroy</p>
<pre data-id="code-animation"><code class="tf" data-trim data-line-numbers>
resource "null_resource" "device_twin" {
provisioner "local-exec" {
when = destroy
interpreter = ["pwsh" , "-Command"]
command = az iot hub device-identity delete -n 'my-hub' -d 'my-device'
}
}
</code></pre>
</section>
<section data-auto-animate>
<h3 class="headline">2. Demo - Digital Twin</h3>
<p>And together</p>
<pre data-id="code-animation"><code class="hljs" data-trim data-line-numbers>
resource "null_resource" "device_twin" {
provisioner "local-exec" {
when = create
interpreter = ["pwsh" , "-Command"]
command = az iot hub device-identity create -n 'my-hub' -d 'my-device'
}
provisioner "local-exec" {
when = destroy
interpreter = ["pwsh" , "-Command"]
command = az iot hub device-identity delete -n 'my-hub' -d 'my-device'
}
}
</code></pre>
</section>
<section data-auto-animate>
<h3 class="headline">2. Demo - Digital Twin</h3>
<p>Problem: Destroy time provisioner cannot access variables</p>
<pre data-id="code-animation"><code class="hljs" data-trim data-line-numbers>
variable "device_name" {}
resource "null_resource" "device_twin" {
provisioner "local-exec" {
when = create
interpreter = ["pwsh" , "-Command"]
command = az iot hub device-identity create -n 'my-hub' -d '${var.device_name}'
}
provisioner "local-exec" {
when = destroy
interpreter = ["pwsh" , "-Command"]
command = az iot hub device-identity delete -n 'my-hub' -d '${var.device_name}'
}
}
</code></pre>
</section>
<section data-auto-animate>
<h3 class="headline">2. Demo - Digital Twin</h3>
<p>Solution: Triggers can retain data you need at destroy time</p>
<pre data-id="code-animation"><code class="hljs" data-trim data-line-numbers>
variable "device_name" {}
resource "null_resource" "device_twin" {
triggers = { device_name = var.device_name }
provisioner "local-exec" {
when = create
interpreter = ["pwsh" , "-Command"]
command = az iot hub device-identity create -n 'my-hub' -d self.triggers.name
}
provisioner "local-exec" {
when = destroy
interpreter = ["pwsh" , "-Command"]
command = az iot hub device-identity delete -n 'my-hub' -d self.triggers.name
}
}
</code></pre>
</section>
<section data-auto-animate>
<h3 class="headline">2. Demo - Digital Twin</h3>
<pre data-id="code-animation"><code class="hljs" data-trim data-line-numbers>
variable "device_name" {}
resource "null_resource" "device_twin" {
triggers = {
hub_name = azurerm.iothub.my_hub
device_name = var.name
}
provisioner "local-exec" {
...
command = az iot hub device-identity create -n self.triggers.hub -d self.triggers.name
}
provisioner "local-exec" {
...
command = az iot hub device-identity delete -n self.triggers.hub -d self.triggers.name
}
}
</code></pre>
</section>
<section data-auto-animate>
<h3 class="headline">2. Demo - Digital Twin</h3>
<p>Script with error handling/retires</p>
<pre data-id="code-animation"><code class="hljs" data-trim data-line-numbers><script type="text/template">
locals {
create = "create"
destroy = "delete"
commands = toset( [ local.create, local.destroy ] )
}
resource "local_file" "script_template" {
filename = "device_script.ps1.tmpl"
content = <<SCRIPT
$success=$False
$inc=0
while(!$success -and $inc -lt 25) {
$inc = $inc+1
try {
$res = az iot hub device-identity $${command} -n '${var.iot_hub}' -d '${var.name}' 2>$1
if ($res -And !($res -Match "ERROR")) {
$success=$True
}
}
catch [Exception]
{
echo $_.Exception.GetType().FullName, $_.Exception.Message
}
}
echo "Output: $res"
SCRIPT
}
data "template_file" "command_scripts" {
for_each = local.commands
template = local_file.script_template.content
vars = {
command = each.key
}
}
</script></code></pre>
</section>
<section>
<h3 class="headline">Modules</h3>
<ul>
<li class="fragment">Container to group multiple resources</li>
<li class="fragment">
<ul>
<li>Input variables</li>
<li>Output values</li>
<li>Resources to define infrastructure objects</li>
</ul>
</li>
<li class="fragment">Placed in its own directory</li>
</ul>
</section>
</div>
</div>
<script src="dist/reveal.js"></script>
<script src="plugin/zoom/zoom.js"></script>
<script src="plugin/notes/notes.js"></script>
<script src="plugin/search/search.js"></script>
<script src="plugin/markdown/markdown.js"></script>
<script src="plugin/highlight/highlight.js"></script>
<script src="plugin/highlight/highlightjs-terraform/terraform.js"></script>
<script>
Reveal.initialize({
fragments: true,
controls: true,
progress: true,
center: true,
hash: true,
plugins: [ RevealZoom, RevealNotes, RevealSearch, RevealMarkdown, RevealHighlight ]
});
</script>
</body>
</html>