/
blockstorage_block_volume_report_unattached.sp
72 lines (62 loc) · 1.83 KB
/
blockstorage_block_volume_report_unattached.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
dashboard "blockstorage_block_volume_unattached_report" {
title = "OCI Block Storage Block Volume Unattached Report"
documentation = file("./dashboards/blockstorage/docs/blockstorage_block_volume_report_unattached.md")
tags = merge(local.blockstorage_common_tags, {
type = "Report"
category = "Unused"
})
container {
card {
query = query.blockstorage_block_volume_unattached_count
width = 3
}
}
table {
column "OCID" {
display = "none"
}
column "Name" {
href = "${dashboard.blockstorage_block_volume_detail.url_path}?input.block_volume_id={{.OCID | @uri}}"
}
query = query.blockstorage_block_volume_unattached_report
}
}
query "blockstorage_block_volume_unattached_count" {
sql = <<-EOQ
select
count(*) as value,
'Unattached' as label,
case count(*) when 0 then 'ok' else 'alert' end as type
from
oci_core_volume
where
id not in (
select
volume_id
from
oci_core_volume_attachment
) and lifecycle_state <> 'TERMINATED';
EOQ
}
query "blockstorage_block_volume_unattached_report" {
sql = <<-EOQ
select
v.display_name as "Name",
a.lifecycle_state as "Attachment Status",
i.display_name as "Instance Name",
t.title as "Tenancy",
coalesce(c.title, 'root') as "Compartment",
v.region as "Region",
v.id as "OCID"
from
oci_core_volume as v
left join oci_core_volume_attachment as a on a.volume_id = v.id
left join oci_core_instance as i on a.instance_id = i.id
left join oci_identity_compartment as c on v.compartment_id = c.id
left join oci_identity_tenancy as t on v.tenant_id = t.id
where
v.lifecycle_state <> 'TERMINATED'
order by
v.display_name;
EOQ
}