From 5c27d5ad19ba3f00d1218d88e1004ef9938edd53 Mon Sep 17 00:00:00 2001 From: ronsh12 <101520407+ronsh12@users.noreply.github.com> Date: Mon, 18 Dec 2023 13:11:24 +0200 Subject: [PATCH] feat: Added queries for unused resources cost (#348) --- .../unused/aws_cost__unused_acm_certs.sql | 1 + .../unused/aws_cost__unused_backup_vaults.sql | 1 + ..._cost__unused_cloudfront_distributions.sql | 1 + ...ost__unused_directconntect_connections.sql | 1 + .../aws_cost__unused_dynamodb_tables.sql | 1 + .../aws_cost__unused_ec2_ebs_volumes.sql | 1 + .../unused/aws_cost__unused_ec2_eips.sql | 1 + .../unused/aws_cost__unused_ec2_hosts.sql | 1 + .../unused/aws_cost__unused_ec2_images.sql | 1 + ...aws_cost__unused_ec2_internet_gateways.sql | 3 ++ .../aws_cost__unused_ec2_network_acls.sql | 3 ++ .../aws_cost__unused_ec2_transit_gateways.sql | 1 + .../aws_cost__unused_ecr_repositories.sql | 1 + .../aws_cost__unused_efs_filesystems.sql | 1 + ...t__unused_lightsail_container_services.sql | 1 + .../aws_cost__unused_lightsail_disks.sql | 1 + ...s_cost__unused_lightsail_distributions.sql | 1 + ..._cost__unused_lightsail_load_balancers.sql | 1 + .../aws_cost__unused_lightsail_static_ips.sql | 1 + .../aws_cost__unused_load_balancers.sql | 1 + .../aws_cost__unused_route53_histed_zones.sql | 1 + .../unused/aws_cost__unused_sns_topics.sql | 1 + .../aws/macros/unused/unused_acm_certs.sql | 18 +++++++++++ .../macros/unused/unused_backup_vaults.sql | 29 ++++++++++++++++++ .../unused_cloudfront_distributions.sql | 19 ++++++++++++ .../unused_directconntect_connections.sql | 19 ++++++++++++ .../macros/unused/unused_dynamodb_tables.sql | 19 ++++++++++++ .../macros/unused/unused_ec2_ebs_volumes.sql | 19 ++++++++++++ .../aws/macros/unused/unused_ec2_eips.sql | 19 ++++++++++++ .../aws/macros/unused/unused_ec2_hosts.sql | 19 ++++++++++++ .../aws/macros/unused/unused_ec2_images.sql | 19 ++++++++++++ .../unused/unused_ec2_internet_gateways.sql | 19 ++++++++++++ .../macros/unused/unused_ec2_network_acls.sql | 18 +++++++++++ .../unused/unused_ec2_transit_gateways.sql | 26 ++++++++++++++++ .../macros/unused/unused_ecr_repositories.sql | 26 ++++++++++++++++ .../macros/unused/unused_efs_filesystems.sql | 19 ++++++++++++ .../unused_lightsail_container_services.sql | 26 ++++++++++++++++ .../macros/unused/unused_lightsail_disks.sql | 18 +++++++++++ .../unused/unused_lightsail_distributions.sql | 18 +++++++++++ .../unused_lightsail_load_balancers.sql | 18 +++++++++++ .../unused/unused_lightsail_static_ips.sql | 18 +++++++++++ .../macros/unused/unused_load_balancers.sql | 30 +++++++++++++++++++ .../unused/unused_route53_histed_zones.sql | 18 +++++++++++ .../aws/macros/unused/unused_sns_topics.sql | 25 ++++++++++++++++ 44 files changed, 485 insertions(+) create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_acm_certs.sql create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_backup_vaults.sql create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_cloudfront_distributions.sql create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_directconntect_connections.sql create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_dynamodb_tables.sql create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_ec2_ebs_volumes.sql create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_ec2_eips.sql create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_ec2_hosts.sql create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_ec2_images.sql create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_ec2_internet_gateways.sql create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_ec2_network_acls.sql create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_ec2_transit_gateways.sql create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_ecr_repositories.sql create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_efs_filesystems.sql create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_lightsail_container_services.sql create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_lightsail_disks.sql create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_lightsail_distributions.sql create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_lightsail_load_balancers.sql create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_lightsail_static_ips.sql create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_load_balancers.sql create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_route53_histed_zones.sql create mode 100644 transformations/aws/cost/models/unused/aws_cost__unused_sns_topics.sql create mode 100644 transformations/aws/macros/unused/unused_acm_certs.sql create mode 100644 transformations/aws/macros/unused/unused_backup_vaults.sql create mode 100644 transformations/aws/macros/unused/unused_cloudfront_distributions.sql create mode 100644 transformations/aws/macros/unused/unused_directconntect_connections.sql create mode 100644 transformations/aws/macros/unused/unused_dynamodb_tables.sql create mode 100644 transformations/aws/macros/unused/unused_ec2_ebs_volumes.sql create mode 100644 transformations/aws/macros/unused/unused_ec2_eips.sql create mode 100644 transformations/aws/macros/unused/unused_ec2_hosts.sql create mode 100644 transformations/aws/macros/unused/unused_ec2_images.sql create mode 100644 transformations/aws/macros/unused/unused_ec2_internet_gateways.sql create mode 100644 transformations/aws/macros/unused/unused_ec2_network_acls.sql create mode 100644 transformations/aws/macros/unused/unused_ec2_transit_gateways.sql create mode 100644 transformations/aws/macros/unused/unused_ecr_repositories.sql create mode 100644 transformations/aws/macros/unused/unused_efs_filesystems.sql create mode 100644 transformations/aws/macros/unused/unused_lightsail_container_services.sql create mode 100644 transformations/aws/macros/unused/unused_lightsail_disks.sql create mode 100644 transformations/aws/macros/unused/unused_lightsail_distributions.sql create mode 100644 transformations/aws/macros/unused/unused_lightsail_load_balancers.sql create mode 100644 transformations/aws/macros/unused/unused_lightsail_static_ips.sql create mode 100644 transformations/aws/macros/unused/unused_load_balancers.sql create mode 100644 transformations/aws/macros/unused/unused_route53_histed_zones.sql create mode 100644 transformations/aws/macros/unused/unused_sns_topics.sql diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_acm_certs.sql b/transformations/aws/cost/models/unused/aws_cost__unused_acm_certs.sql new file mode 100644 index 000000000..d833c9a3e --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_acm_certs.sql @@ -0,0 +1 @@ +{{unused_route53_histed_zones()}} \ No newline at end of file diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_backup_vaults.sql b/transformations/aws/cost/models/unused/aws_cost__unused_backup_vaults.sql new file mode 100644 index 000000000..f8f2fa334 --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_backup_vaults.sql @@ -0,0 +1 @@ +{{unused_backup_vaults()}} diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_cloudfront_distributions.sql b/transformations/aws/cost/models/unused/aws_cost__unused_cloudfront_distributions.sql new file mode 100644 index 000000000..43b208742 --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_cloudfront_distributions.sql @@ -0,0 +1 @@ +{{unused_cloudfront_distributions()}} diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_directconntect_connections.sql b/transformations/aws/cost/models/unused/aws_cost__unused_directconntect_connections.sql new file mode 100644 index 000000000..fc615f5e9 --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_directconntect_connections.sql @@ -0,0 +1 @@ +{{unused_directconntect_connections()}} diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_dynamodb_tables.sql b/transformations/aws/cost/models/unused/aws_cost__unused_dynamodb_tables.sql new file mode 100644 index 000000000..2bed9c9d4 --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_dynamodb_tables.sql @@ -0,0 +1 @@ +{{unused_dynamodb_tables()}} diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_ec2_ebs_volumes.sql b/transformations/aws/cost/models/unused/aws_cost__unused_ec2_ebs_volumes.sql new file mode 100644 index 000000000..0495c83d7 --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_ec2_ebs_volumes.sql @@ -0,0 +1 @@ +{{unused_ec2_ebs_volumes()}} diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_ec2_eips.sql b/transformations/aws/cost/models/unused/aws_cost__unused_ec2_eips.sql new file mode 100644 index 000000000..604b71373 --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_ec2_eips.sql @@ -0,0 +1 @@ +{{unused_ec2_eips()}} diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_ec2_hosts.sql b/transformations/aws/cost/models/unused/aws_cost__unused_ec2_hosts.sql new file mode 100644 index 000000000..ba13c66c7 --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_ec2_hosts.sql @@ -0,0 +1 @@ +{{unused_ec2_hosts()}} diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_ec2_images.sql b/transformations/aws/cost/models/unused/aws_cost__unused_ec2_images.sql new file mode 100644 index 000000000..b281104a9 --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_ec2_images.sql @@ -0,0 +1 @@ +{{unused_ec2_images()}} diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_ec2_internet_gateways.sql b/transformations/aws/cost/models/unused/aws_cost__unused_ec2_internet_gateways.sql new file mode 100644 index 000000000..5f7c5d6a7 --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_ec2_internet_gateways.sql @@ -0,0 +1,3 @@ +-- depends_on: {{ ref('aws_cost__by_resources') }} + +{{unused_ec2_internet_gateways()}} diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_ec2_network_acls.sql b/transformations/aws/cost/models/unused/aws_cost__unused_ec2_network_acls.sql new file mode 100644 index 000000000..180584bfd --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_ec2_network_acls.sql @@ -0,0 +1,3 @@ +-- depends_on: {{ ref('aws_cost__by_resources') }} + +{{unused_ec2_network_acls()}} diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_ec2_transit_gateways.sql b/transformations/aws/cost/models/unused/aws_cost__unused_ec2_transit_gateways.sql new file mode 100644 index 000000000..dcdbfc879 --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_ec2_transit_gateways.sql @@ -0,0 +1 @@ +{{unused_ec2_transit_gateways()}} diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_ecr_repositories.sql b/transformations/aws/cost/models/unused/aws_cost__unused_ecr_repositories.sql new file mode 100644 index 000000000..6d3f168dd --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_ecr_repositories.sql @@ -0,0 +1 @@ +{{unused_ecr_repositories()}} diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_efs_filesystems.sql b/transformations/aws/cost/models/unused/aws_cost__unused_efs_filesystems.sql new file mode 100644 index 000000000..1a28dad76 --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_efs_filesystems.sql @@ -0,0 +1 @@ +{{unused_efs_filesystems()}} diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_lightsail_container_services.sql b/transformations/aws/cost/models/unused/aws_cost__unused_lightsail_container_services.sql new file mode 100644 index 000000000..816c1f806 --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_lightsail_container_services.sql @@ -0,0 +1 @@ +{{unused_lightsail_container_services()}} diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_lightsail_disks.sql b/transformations/aws/cost/models/unused/aws_cost__unused_lightsail_disks.sql new file mode 100644 index 000000000..4eec813db --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_lightsail_disks.sql @@ -0,0 +1 @@ +{{unused_lightsail_disks()}} diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_lightsail_distributions.sql b/transformations/aws/cost/models/unused/aws_cost__unused_lightsail_distributions.sql new file mode 100644 index 000000000..e013235fd --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_lightsail_distributions.sql @@ -0,0 +1 @@ +{{unused_lightsail_distributions()}} diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_lightsail_load_balancers.sql b/transformations/aws/cost/models/unused/aws_cost__unused_lightsail_load_balancers.sql new file mode 100644 index 000000000..23a9ff51d --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_lightsail_load_balancers.sql @@ -0,0 +1 @@ +{{unused_lightsail_load_balancers()}} diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_lightsail_static_ips.sql b/transformations/aws/cost/models/unused/aws_cost__unused_lightsail_static_ips.sql new file mode 100644 index 000000000..53f067b03 --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_lightsail_static_ips.sql @@ -0,0 +1 @@ +{{unused_lightsail_static_ips()}} \ No newline at end of file diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_load_balancers.sql b/transformations/aws/cost/models/unused/aws_cost__unused_load_balancers.sql new file mode 100644 index 000000000..e027b9f14 --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_load_balancers.sql @@ -0,0 +1 @@ +{{unused_load_balancers()}} diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_route53_histed_zones.sql b/transformations/aws/cost/models/unused/aws_cost__unused_route53_histed_zones.sql new file mode 100644 index 000000000..d833c9a3e --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_route53_histed_zones.sql @@ -0,0 +1 @@ +{{unused_route53_histed_zones()}} \ No newline at end of file diff --git a/transformations/aws/cost/models/unused/aws_cost__unused_sns_topics.sql b/transformations/aws/cost/models/unused/aws_cost__unused_sns_topics.sql new file mode 100644 index 000000000..19a45ab41 --- /dev/null +++ b/transformations/aws/cost/models/unused/aws_cost__unused_sns_topics.sql @@ -0,0 +1 @@ +{{unused_sns_topics()}} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_acm_certs.sql b/transformations/aws/macros/unused/unused_acm_certs.sql new file mode 100644 index 000000000..a6e5ceee4 --- /dev/null +++ b/transformations/aws/macros/unused/unused_acm_certs.sql @@ -0,0 +1,18 @@ +{% macro unused_acm_certs(framework, check_id) %} + {{ return(adapter.dispatch('unused_acm_certs')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_acm_certs(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_acm_certs(framework, check_id) %} +select + c.account_id, + c.arn as resource_id, + rbc.cost +from aws_acm_certificates c +JOIN {{ ref('aws_cost__by_resources') }} rbc ON c.arn = rbc.line_item_resource_id +where array_length(c.in_use_by, 1) = 0 +{% endmacro %} + +{% macro snowflake__unused_acm_certs(framework, check_id) %} +{% endmacro %} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_backup_vaults.sql b/transformations/aws/macros/unused/unused_backup_vaults.sql new file mode 100644 index 000000000..23147f79f --- /dev/null +++ b/transformations/aws/macros/unused/unused_backup_vaults.sql @@ -0,0 +1,29 @@ +{% macro unused_backup_vaults(framework, check_id) %} + {{ return(adapter.dispatch('unused_backup_vaults')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_backup_vaults(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_backup_vaults(framework, check_id) %} +with point as ( + select distinct vault_arn + from aws_backup_vault_recovery_points + ), + unused_vaults as ( +select + vault.account_id, + vault.arn as resource_id +from aws_backup_vaults vault + left join point on point.vault_arn = vault.arn +where point.vault_arn is null) +SELECT + uv.account_id, + uv.resource_id, + rbc.cost +FROM unused_vaults uv +JOIN {{ ref('aws_cost__by_resources') }} rbc ON uv.resource_id = rbc.line_item_resource_id +{% endmacro %} + +{% macro snowflake__unused_backup_vaults(framework, check_id) %} + +{% endmacro %} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_cloudfront_distributions.sql b/transformations/aws/macros/unused/unused_cloudfront_distributions.sql new file mode 100644 index 000000000..41e0f23c3 --- /dev/null +++ b/transformations/aws/macros/unused/unused_cloudfront_distributions.sql @@ -0,0 +1,19 @@ +{% macro unused_cloudfront_distributions(framework, check_id) %} + {{ return(adapter.dispatch('unused_cloudfront_distributions')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_cloudfront_distributions(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_cloudfront_distributions(framework, check_id) %} +select + d.account_id, + d.arn as resource_id, + rbc.cost +from aws_cloudfront_distributions d +JOIN {{ ref('aws_cost__by_resources') }} rbc ON d.arn = rbc.line_item_resource_id +where (d.distribution_config->>'Enabled')::boolean is distinct from true +{% endmacro %} + +{% macro snowflake__unused_cloudfront_distributions(framework, check_id) %} + +{% endmacro %} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_directconntect_connections.sql b/transformations/aws/macros/unused/unused_directconntect_connections.sql new file mode 100644 index 000000000..110c1b65a --- /dev/null +++ b/transformations/aws/macros/unused/unused_directconntect_connections.sql @@ -0,0 +1,19 @@ +{% macro unused_directconntect_connections(framework, check_id) %} + {{ return(adapter.dispatch('unused_directconntect_connections')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_directconntect_connections(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_directconntect_connections(framework, check_id) %} +select + dc.account_id, + dc.arn as resource_id, + rbc.cost +from aws_directconnect_connections dc +JOIN {{ ref('aws_cost__by_resources') }} rbc ON dc.arn = rbc.line_item_resource_id +where dc.connection_state = 'down' +{% endmacro %} + +{% macro snowflake__unused_directconntect_connections(framework, check_id) %} + +{% endmacro %} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_dynamodb_tables.sql b/transformations/aws/macros/unused/unused_dynamodb_tables.sql new file mode 100644 index 000000000..9f9467786 --- /dev/null +++ b/transformations/aws/macros/unused/unused_dynamodb_tables.sql @@ -0,0 +1,19 @@ +{% macro unused_dynamodb_tables(framework, check_id) %} + {{ return(adapter.dispatch('unused_dynamodb_tables')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_dynamodb_tables(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_dynamodb_tables(framework, check_id) %} +select + ddb.account_id, + ddb.arn as resource_id, + rbc.cost +from aws_dynamodb_tables ddb +JOIN {{ ref('aws_cost__by_resources') }} rbc ON ddb.arn = rbc.line_item_resource_id +where ddb.item_count = 0 +{% endmacro %} + +{% macro snowflake__unused_dynamodb_tables(framework, check_id) %} + +{% endmacro %} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_ec2_ebs_volumes.sql b/transformations/aws/macros/unused/unused_ec2_ebs_volumes.sql new file mode 100644 index 000000000..4b6a7ba5b --- /dev/null +++ b/transformations/aws/macros/unused/unused_ec2_ebs_volumes.sql @@ -0,0 +1,19 @@ +{% macro unused_ec2_ebs_volumes(framework, check_id) %} + {{ return(adapter.dispatch('unused_ec2_ebs_volumes')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_ec2_ebs_volumes(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_ec2_ebs_volumes(framework, check_id) %} +select + ev.account_id, + ev.arn as resource_id, + rbc.cost +from aws_ec2_ebs_volumes ev +JOIN {{ ref('aws_cost__by_resources') }} rbc ON ev.arn = rbc.line_item_resource_id +where coalesce(jsonb_array_length(ev.attachments), 0) = 0 +{% endmacro %} + +{% macro snowflake__unused_ec2_ebs_volumes(framework, check_id) %} + +{% endmacro %} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_ec2_eips.sql b/transformations/aws/macros/unused/unused_ec2_eips.sql new file mode 100644 index 000000000..e350573ee --- /dev/null +++ b/transformations/aws/macros/unused/unused_ec2_eips.sql @@ -0,0 +1,19 @@ +{% macro unused_ec2_eips(framework, check_id) %} + {{ return(adapter.dispatch('unused_ec2_eips')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_ec2_eips(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_ec2_eips(framework, check_id) %} +select + eips.account_id, + eips.allocation_id as resource_id, + rbc.cost +from aws_ec2_eips eips +JOIN {{ ref('aws_cost__by_resources') }} rbc ON eips.allocation_id = rbc.line_item_resource_id +where eips.association_id is null +{% endmacro %} + +{% macro snowflake__unused_ec2_eips(framework, check_id) %} + +{% endmacro %} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_ec2_hosts.sql b/transformations/aws/macros/unused/unused_ec2_hosts.sql new file mode 100644 index 000000000..30b80e5db --- /dev/null +++ b/transformations/aws/macros/unused/unused_ec2_hosts.sql @@ -0,0 +1,19 @@ +{% macro unused_ec2_hosts(framework, check_id) %} + {{ return(adapter.dispatch('unused_ec2_hosts')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_ec2_hosts(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_ec2_hosts(framework, check_id) %} +select + h.account_id, + h.arn as resource_id, + rbc.cost +from aws_ec2_hosts h +JOIN {{ ref('aws_cost__by_resources') }} rbc ON h.arn = rbc.line_item_resource_id +where coalesce(jsonb_array_length(h.instances), 0) = 0 +{% endmacro %} + +{% macro snowflake__unused_ec2_hosts(framework, check_id) %} + +{% endmacro %} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_ec2_images.sql b/transformations/aws/macros/unused/unused_ec2_images.sql new file mode 100644 index 000000000..3bb3080f5 --- /dev/null +++ b/transformations/aws/macros/unused/unused_ec2_images.sql @@ -0,0 +1,19 @@ +{% macro unused_ec2_images(framework, check_id) %} + {{ return(adapter.dispatch('unused_ec2_images')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_ec2_images(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_ec2_images(framework, check_id) %} +select + i.account_id, + i.arn as resource_id, + rbc.cost +from aws_ec2_images i +JOIN {{ ref('aws_cost__by_resources') }} rbc ON i.arn = rbc.line_item_resource_id +where coalesce(jsonb_array_length(i.block_device_mappings), 0) = 0 +{% endmacro %} + +{% macro snowflake__unused_ec2_images(framework, check_id) %} + +{% endmacro %} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_ec2_internet_gateways.sql b/transformations/aws/macros/unused/unused_ec2_internet_gateways.sql new file mode 100644 index 000000000..ed557fa01 --- /dev/null +++ b/transformations/aws/macros/unused/unused_ec2_internet_gateways.sql @@ -0,0 +1,19 @@ +{% macro unused_ec2_internet_gateways(framework, check_id) %} + {{ return(adapter.dispatch('unused_ec2_internet_gateways')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_ec2_internet_gateways(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_ec2_internet_gateways(framework, check_id) %} +select + ig.account_id, + ig.arn as resource_id, + rbc.cost +from aws_ec2_internet_gateways ig +JOIN {{ ref('aws_cost__by_resources') }} rbc ON ig.arn = rbc.line_item_resource_id +where coalesce(jsonb_array_length(ig.attachments), 0) = 0 +{% endmacro %} + +{% macro snowflake__unused_ec2_internet_gateways(framework, check_id) %} + +{% endmacro %} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_ec2_network_acls.sql b/transformations/aws/macros/unused/unused_ec2_network_acls.sql new file mode 100644 index 000000000..464a1186e --- /dev/null +++ b/transformations/aws/macros/unused/unused_ec2_network_acls.sql @@ -0,0 +1,18 @@ +{% macro unused_ec2_network_acls(framework, check_id) %} + {{ return(adapter.dispatch('unused_ec2_network_acls')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_ec2_network_acls(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_ec2_network_acls(framework, check_id) %} +select + a.account_id, + a.arn as resource_id, + rbc.cost +from aws_ec2_network_acls a +JOIN {{ ref('aws_cost__by_resources') }} rbc ON a.arn = rbc.line_item_resource_id +where coalesce(jsonb_array_length(a.associations), 0) = 0 +{% endmacro %} + +{% macro snowflake__unused_ec2_network_acls(framework, check_id) %} +{% endmacro %} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_ec2_transit_gateways.sql b/transformations/aws/macros/unused/unused_ec2_transit_gateways.sql new file mode 100644 index 000000000..b7326eb7f --- /dev/null +++ b/transformations/aws/macros/unused/unused_ec2_transit_gateways.sql @@ -0,0 +1,26 @@ +{% macro unused_ec2_transit_gateways(framework, check_id) %} + {{ return(adapter.dispatch('unused_ec2_transit_gateways')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_ec2_transit_gateways(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_ec2_transit_gateways(framework, check_id) %} +with attachment as (select distinct transit_gateway_arn from aws_ec2_transit_gateway_attachments), +unused_transit_gateways as ( +select + gateway.account_id, + gateway.arn as resource_id +from aws_ec2_transit_gateways gateway + left join attachment on attachment.transit_gateway_arn = gateway.arn +where attachment.transit_gateway_arn is null) +SELECT + ug.account_id, + ug.resource_id, + rbc.cost +FROM unused_transit_gateways ug +JOIN {{ ref('aws_cost__by_resources') }} rbc ON ug.resource_id = rbc.line_item_resource_id +{% endmacro %} + +{% macro snowflake__unused_ec2_transit_gateways(framework, check_id) %} + +{% endmacro %} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_ecr_repositories.sql b/transformations/aws/macros/unused/unused_ecr_repositories.sql new file mode 100644 index 000000000..622f0a6b5 --- /dev/null +++ b/transformations/aws/macros/unused/unused_ecr_repositories.sql @@ -0,0 +1,26 @@ +{% macro unused_ecr_repositories(framework, check_id) %} + {{ return(adapter.dispatch('unused_ecr_repositories')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_ecr_repositories(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_ecr_repositories(framework, check_id) %} +with image as (select distinct account_id, repository_name from aws_ecr_repository_images), +unused_repo as ( +select + repository.account_id, + repository.arn as resource_id +from aws_ecr_repositories repository + left join image on image.account_id = repository.account_id and image.repository_name = repository.repository_name +where image.repository_name is null) +SELECT + ur.account_id, + ur.resource_id, + rbc.cost +FROM unused_repo ur +JOIN {{ ref('aws_cost__by_resources') }} rbc ON ur.resource_id = rbc.line_item_resource_id +{% endmacro %} + +{% macro snowflake__unused_ecr_repositories(framework, check_id) %} + +{% endmacro %} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_efs_filesystems.sql b/transformations/aws/macros/unused/unused_efs_filesystems.sql new file mode 100644 index 000000000..615ca9cf5 --- /dev/null +++ b/transformations/aws/macros/unused/unused_efs_filesystems.sql @@ -0,0 +1,19 @@ +{% macro unused_efs_filesystems(framework, check_id) %} + {{ return(adapter.dispatch('unused_efs_filesystems')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_efs_filesystems(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_efs_filesystems(framework, check_id) %} +select + fs.account_id, + fs.arn as resource_id, + rbc.cost +from aws_efs_filesystems fs +JOIN {{ ref('aws_cost__by_resources') }} rbc ON fs.arn = rbc.line_item_resource_id +where fs.number_of_mount_targets = 0 +{% endmacro %} + +{% macro snowflake__unused_efs_filesystems(framework, check_id) %} + +{% endmacro %} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_lightsail_container_services.sql b/transformations/aws/macros/unused/unused_lightsail_container_services.sql new file mode 100644 index 000000000..790b7d4fb --- /dev/null +++ b/transformations/aws/macros/unused/unused_lightsail_container_services.sql @@ -0,0 +1,26 @@ +{% macro unused_lightsail_container_services(framework, check_id) %} + {{ return(adapter.dispatch('unused_lightsail_container_services')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_lightsail_container_services(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_lightsail_container_services(framework, check_id) %} +with deployment as (select distinct container_service_arn from aws_lightsail_container_service_deployments), +unused_cs AS ( +select + cs.account_id, + cs.arn as resource_id +from aws_lightsail_container_services cs + left join deployment on deployment.container_service_arn = cs.arn +where deployment.container_service_arn is null) +SELECT + cs.account_id, + cs.resource_id, + rbc.cost +FROM unused_cs cs +JOIN {{ ref('aws_cost__by_resources') }} rbc ON cs.resource_id = rbc.line_item_resource_id +{% endmacro %} + +{% macro snowflake__unused_lightsail_container_services(framework, check_id) %} + +{% endmacro %} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_lightsail_disks.sql b/transformations/aws/macros/unused/unused_lightsail_disks.sql new file mode 100644 index 000000000..10bcca835 --- /dev/null +++ b/transformations/aws/macros/unused/unused_lightsail_disks.sql @@ -0,0 +1,18 @@ +{% macro unused_lightsail_disks(framework, check_id) %} + {{ return(adapter.dispatch('unused_lightsail_disks')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_lightsail_disks(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_lightsail_disks(framework, check_id) %} +select + d.account_id, + d.arn as resource_id, + rbc.cost +from aws_lightsail_disks d +JOIN {{ ref('aws_cost__by_resources') }} rbc ON d.arn = rbc.line_item_resource_id +where d.is_attached = false +{% endmacro %} + +{% macro snowflake__unused_lightsail_disks(framework, check_id) %} +{% endmacro %} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_lightsail_distributions.sql b/transformations/aws/macros/unused/unused_lightsail_distributions.sql new file mode 100644 index 000000000..2a704b9ec --- /dev/null +++ b/transformations/aws/macros/unused/unused_lightsail_distributions.sql @@ -0,0 +1,18 @@ +{% macro unused_lightsail_distributions(framework, check_id) %} + {{ return(adapter.dispatch('unused_lightsail_distributions')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_lightsail_distributions(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_lightsail_distributions(framework, check_id) %} +select + d.account_id, + d.arn as resource_id, + rbc.cost +from aws_lightsail_distributions d +JOIN {{ ref('aws_cost__by_resources') }} rbc ON d.arn = rbc.line_item_resource_id +where d.is_enabled = false +{% endmacro %} + +{% macro snowflake__unused_lightsail_distributions(framework, check_id) %} +{% endmacro %} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_lightsail_load_balancers.sql b/transformations/aws/macros/unused/unused_lightsail_load_balancers.sql new file mode 100644 index 000000000..c142bdcec --- /dev/null +++ b/transformations/aws/macros/unused/unused_lightsail_load_balancers.sql @@ -0,0 +1,18 @@ +{% macro unused_lightsail_load_balancers(framework, check_id) %} + {{ return(adapter.dispatch('unused_lightsail_load_balancers')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_lightsail_load_balancers(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_lightsail_load_balancers(framework, check_id) %} +select + lb.account_id, + lb.arn as resource_id, + rbc.cost +from aws_lightsail_load_balancers lb +JOIN {{ ref('aws_cost__by_resources') }} rbc ON lb.arn = rbc.line_item_resource_id +where coalesce(jsonb_array_length(lb.instance_health_summary), 0) = 0 +{% endmacro %} + +{% macro snowflake__unused_lightsail_load_balancers(framework, check_id) %} +{% endmacro %} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_lightsail_static_ips.sql b/transformations/aws/macros/unused/unused_lightsail_static_ips.sql new file mode 100644 index 000000000..53acd3c80 --- /dev/null +++ b/transformations/aws/macros/unused/unused_lightsail_static_ips.sql @@ -0,0 +1,18 @@ +{% macro unused_lightsail_static_ips(framework, check_id) %} + {{ return(adapter.dispatch('unused_lightsail_static_ips')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_lightsail_static_ips(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_lightsail_static_ips(framework, check_id) %} +select + si.account_id, + si.arn as resource_id, + rbc.cost +from aws_lightsail_static_ips si +JOIN {{ ref('aws_cost__by_resources') }} rbc ON si.arn = rbc.line_item_resource_id +where si.is_attached = false +{% endmacro %} + +{% macro snowflake__unused_lightsail_static_ips(framework, check_id) %} +{% endmacro %} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_load_balancers.sql b/transformations/aws/macros/unused/unused_load_balancers.sql new file mode 100644 index 000000000..1981d28a0 --- /dev/null +++ b/transformations/aws/macros/unused/unused_load_balancers.sql @@ -0,0 +1,30 @@ +{% macro unused_load_balancers(framework, check_id) %} + {{ return(adapter.dispatch('unused_load_balancers')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_load_balancers(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_load_balancers(framework, check_id) %} +with listener as (select distinct load_balancer_arn from aws_elbv2_listeners), + target_group as (select distinct unnest(load_balancer_arns) as load_balancer_arn + from aws_elbv2_target_groups), +lb_unused AS ( +select + lb.account_id, + lb.arn as resource_id + from aws_elbv2_load_balancers lb + left join listener on listener.load_balancer_arn = lb.arn + left join target_group on target_group.load_balancer_arn = lb.arn +where listener.load_balancer_arn is null + or target_group.load_balancer_arn is null) +SELECT + lb.account_id, + lb.resource_id, + rbc.cost +FROM lb_unused lb +JOIN {{ ref('aws_cost__by_resources') }} rbc ON lb.resource_id = rbc.line_item_resource_id +{% endmacro %} + +{% macro snowflake__unused_load_balancers(framework, check_id) %} + +{% endmacro %} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_route53_histed_zones.sql b/transformations/aws/macros/unused/unused_route53_histed_zones.sql new file mode 100644 index 000000000..1318a1580 --- /dev/null +++ b/transformations/aws/macros/unused/unused_route53_histed_zones.sql @@ -0,0 +1,18 @@ +{% macro unused_route53_histed_zones(framework, check_id) %} + {{ return(adapter.dispatch('unused_route53_histed_zones')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_route53_histed_zones(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_route53_histed_zones(framework, check_id) %} +select + hz.account_id, + hz.arn as resource_id, + rbc.cost +from aws_route53_hosted_zones hz +JOIN {{ ref('aws_cost__by_resources') }} rbc ON hz.arn = rbc.line_item_resource_id +where hz.resource_record_set_count = 0 +{% endmacro %} + +{% macro snowflake__unused_route53_histed_zones(framework, check_id) %} +{% endmacro %} \ No newline at end of file diff --git a/transformations/aws/macros/unused/unused_sns_topics.sql b/transformations/aws/macros/unused/unused_sns_topics.sql new file mode 100644 index 000000000..d4c363c33 --- /dev/null +++ b/transformations/aws/macros/unused/unused_sns_topics.sql @@ -0,0 +1,25 @@ +{% macro unused_sns_topics(framework, check_id) %} + {{ return(adapter.dispatch('unused_sns_topics')(framework, check_id)) }} +{% endmacro %} + +{% macro default__unused_sns_topics(framework, check_id) %}{% endmacro %} + +{% macro postgres__unused_sns_topics(framework, check_id) %} +with subscription as (select distinct topic_arn from aws_sns_subscriptions), +unused_topics as ( +select + topic.account_id, + topic.arn as resource_id +from aws_sns_topics topic + left join subscription on subscription.topic_arn = topic.arn +where subscription.topic_arn is null) +SELECT + ut.account_id, + ut.resource_id, + rbc.cost +FROM unused_topics ut +JOIN {{ ref('aws_cost__by_resources') }} rbc ON ut.resource_id = rbc.line_item_resource_id +{% endmacro %} + +{% macro snowflake__unused_sns_topics(framework, check_id) %} +{% endmacro %} \ No newline at end of file