Resource Types
The Resource Types view shows all Terraform resource types in your infrastructure, with counts and quick access to instances of each type.
Overview
Resource types are the building blocks of Terraform configurations:
aws_instance- EC2 instancesaws_s3_bucket- S3 bucketsgoogle_compute_instance- GCE VMsazurerm_virtual_machine- Azure VMs
Stategraph catalogs every resource type across all your states.
Accessing Resource Types
Via UI
- Navigate to Inventory > Types in the sidebar
- Browse the list of all resource types
- See instance counts for each type
- Click a type to see all instances of that type
Via API
Get a summary of resource types (see instances docs for getting STATE_ID):
curl "http://localhost:8080/api/v1/states/$STATE_ID/resources/summary" \
-H "Authorization: Bearer $STATEGRAPH_API_KEY"
Response:
{
"aws_instance": { "instances": 20 },
"aws_security_group": { "instances": 15 },
"aws_subnet": { "instances": 6 },
"aws_iam_role": { "instances": 12 }
}
Type Analysis
Count All Types
SELECT r.type, count(*) as count
FROM resources r
GROUP BY r.type
ORDER BY count DESC
Types by Provider
-- AWS resources
SELECT r.type, count(*) as count
FROM resources r
WHERE r.provider LIKE '%aws%'
GROUP BY r.type
ORDER BY count DESC
-- Google Cloud resources
SELECT r.type, count(*) as count
FROM resources r
WHERE r.provider LIKE '%google%'
GROUP BY r.type
ORDER BY count DESC
-- Azure resources
SELECT r.type, count(*) as count
FROM resources r
WHERE r.provider LIKE '%azurerm%'
GROUP BY r.type
ORDER BY count DESC
Unique Types per State
SELECT s.name as state, count(DISTINCT r.type) as types
FROM resources r
JOIN states s ON r.state_id = s.id
GROUP BY s.name
ORDER BY types DESC
Common Resource Types
AWS
| Type | Description |
|---|---|
aws_instance |
EC2 instances |
aws_security_group |
Security groups |
aws_iam_role |
IAM roles |
aws_s3_bucket |
S3 buckets |
aws_subnet |
VPC subnets |
aws_vpc |
Virtual private clouds |
aws_lambda_function |
Lambda functions |
aws_db_instance |
RDS instances |
Google Cloud
| Type | Description |
|---|---|
google_compute_instance |
Compute Engine VMs |
google_storage_bucket |
Cloud Storage buckets |
google_container_cluster |
GKE clusters |
google_sql_database_instance |
Cloud SQL instances |
Azure
| Type | Description |
|---|---|
azurerm_virtual_machine |
Virtual machines |
azurerm_storage_account |
Storage accounts |
azurerm_kubernetes_cluster |
AKS clusters |
azurerm_sql_server |
SQL servers |
Type-Specific Queries
EC2 Instances by Type
SELECT i.attributes->>'instance_type' as instance_type, count(*) as count
FROM instances i
JOIN resources r ON i.resource_address = r.address AND i.state_id = r.state_id
WHERE r.type = 'aws_instance'
GROUP BY i.attributes->>'instance_type'
ORDER BY count DESC
S3 Buckets by Region
SELECT i.attributes->>'region' as region, count(*) as count
FROM instances i
JOIN resources r ON i.resource_address = r.address AND i.state_id = r.state_id
WHERE r.type = 'aws_s3_bucket'
GROUP BY i.attributes->>'region'
ORDER BY count DESC
RDS Instances by Engine
SELECT i.attributes->>'engine' as engine, count(*) as count
FROM instances i
JOIN resources r ON i.resource_address = r.address AND i.state_id = r.state_id
WHERE r.type = 'aws_db_instance'
GROUP BY i.attributes->>'engine'
ORDER BY count DESC
Lambda Functions by Runtime
SELECT i.attributes->>'runtime' as runtime, count(*) as count
FROM instances i
JOIN resources r ON i.resource_address = r.address AND i.state_id = r.state_id
WHERE r.type = 'aws_lambda_function'
GROUP BY i.attributes->>'runtime'
ORDER BY count DESC
Resource Categories
Group resource types by category:
Compute Resources
SELECT r.type, count(*) as count
FROM resources r
WHERE r.type IN (
'aws_instance',
'aws_lambda_function',
'aws_ecs_service',
'google_compute_instance',
'azurerm_virtual_machine'
)
GROUP BY r.type
ORDER BY count DESC
Storage Resources
SELECT r.type, count(*) as count
FROM resources r
WHERE r.type IN (
'aws_s3_bucket',
'aws_ebs_volume',
'google_storage_bucket',
'azurerm_storage_account'
)
GROUP BY r.type
ORDER BY count DESC
Network Resources
SELECT r.type, count(*) as count
FROM resources r
WHERE r.type LIKE '%vpc%'
OR r.type LIKE '%subnet%'
OR r.type LIKE '%security_group%'
OR r.type LIKE '%network%'
GROUP BY r.type
ORDER BY count DESC
Security Resources
SELECT r.type, count(*) as count
FROM resources r
WHERE r.type LIKE '%iam%'
OR r.type LIKE '%kms%'
OR r.type LIKE '%secret%'
GROUP BY r.type
ORDER BY count DESC
Type Distribution Analysis
Types per Workspace
SELECT s.workspace, r.type, count(*) as count
FROM resources r
JOIN states s ON r.state_id = s.id
GROUP BY s.workspace, r.type
ORDER BY s.workspace, count DESC
New Resource Types
Find types that only appear in certain states (potentially new additions):
SELECT r.type, count(DISTINCT r.state_id) as states_count
FROM resources r
GROUP BY r.type
HAVING count(DISTINCT r.state_id) = 1
ORDER BY r.type
Most Common Types
SELECT r.type, count(*) as count
FROM resources r
GROUP BY r.type
ORDER BY count DESC
LIMIT 10
Monitoring Type Growth
Track how resource types grow over time by comparing counts periodically:
-- Current counts
SELECT r.type, count(*) as count
FROM resources r
GROUP BY r.type
ORDER BY count DESC
Save these queries to a Dashboard for regular monitoring.
Best Practices
- Monitor growth - Track type counts over time
- Review distribution - Ensure resources are distributed appropriately
- Check for drift - Compare expected vs actual type counts
- Identify outliers - Look for unexpected resource types
Next Steps
- Instances - Browse all instances
- Modules - View by module
- Query - Advanced queries
- Dashboards - Save type queries