forked from turbot/steampipe-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhcl_with_block.sp
104 lines (88 loc) · 1.66 KB
/
hcl_with_block.sp
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
dashboard "using_hcl_with" {
tags = {
service = "v18 examples"
}
text {
value = <<EOQ
EOQ
}
with "data" {
query = query.data
}
container {
width = 4
text {
value = <<EOQ
```
query "data" {
value = <<EOQ
with data(person, server) as (
values
('jon', 'mastodon.social'),
('chris', 'infosec.exchange')
)
select
*
from
data
```
EOQ
}
text {
value = <<EOQ
```
with "data" {
query = query.data
}
```
EOQ
}
}
container {
width = 6
table {
title = "use query.data directly"
query = query.data
}
table {
title = "use query.data via with.data, pass a single row"
args = [ with.data.rows[0].person, with.data.rows[0].server ]
sql = <<EOQ
select
$1 as person,
$2 as server
EOQ
}
table {
title = "use query.data via with.data, pass all rows, display as arrays of text"
args = [ with.data.rows[*].person, with.data.rows[*].server ]
sql = <<EOQ
select
$1::text[] as person,
$2::text[] as server
EOQ
}
table {
title = "use query.data via with.data, pass all rows, unnest the arrays to display rows"
args = [ with.data.rows[*].person, with.data.rows[*].server ]
sql = <<EOQ
select
unnest($1::text[]) as person,
unnest($2::text[]) as server
EOQ
}
}
}
query "data" {
sql = <<EOQ
with data(person, server) as (
values
('jon', 'mastodon.social'),
('chris', 'infosec.exchange')
)
select
*
from
data
EOQ
}