cloud-custodian / cloud-custodian/tfparse
References to data sources aren't fully tracked
- Dominant language
- Go
- Stars
- 57
- Forks
- 19
- Avg merge
- 2h 1m
- Merged PRs (30d)
- 1
Description
We don't currently track references from `resource` blocks to `data` blocks, because upstream we don't really know what we're going to get back. For static analysis those references can still be useful though, for instance...
```hcl
data "aws_rds_reserved_instance_offering" "example" {
db_instance_class = "db.m7g.large"
}
resource "aws_rds_reserved_instance" "example" {
offering_id = data.aws_rds_reserved_instance_offering.example.offering_id
instance_count = 1
}
resource "aws_db_instance" "example" {
instance_class = aws_rds_reserved_instance.example.db_instance_class
}
```
Produces the dump below. We can see traces of references in two different spots:
## Attribute Level
`aws_db_instance` includes this reference to `aws_rds_reserved_instance` for its `instance_class` attribute:
```json
"instance_class": {
"__attribute__": "aws_rds_reserved_instance.example.db_instance_class",
"__name__": "example"
}
```
In turn, that `aws_rds_reserved_instance` references an offering:
```json
"offering_id": {
"__attribute__": "data.aws_rds_reserved_instance_offering.example.offering_id",
"__name__": "example",
"__ref__": "aws_rds_reserved_instance_offering.example",
"__type__": "aws_rds_reserved_instance_offering"
}
```
## Resource Level
The `aws_db_instance` resource's `__tfmeta` attribute captures its `aws_rds_reserved_instance` reference:
```json
"references": [
{
"id": "0c547493-9654-447a-959b-31ae3dd2cacc",
"label": "aws_rds_reserved_instance",
"name": "example"
}
]
```
...but the `aws_rds_reserved_instance` resources does _not_ have any references listed in its `__tfmeta` attribute, so the chain from `aws_db_instance` --> `aws_rds_reserved_instance` --> `data.aws_rds_reserved_instance_offering` is broken.
Full `tfparse.load_from_path()` output
```json
{
"aws_db_instance": [
{
"__tfmeta": {
"filename": "rds.tf",
"label": "aws_db_instance",
"line_end": 12,
"line_start": 10,
"path": "aws_db_instance.example",
"references": [
{
"id": "db6030c1-fad0-4d0a-a6d5-708d9e34c83a",
"label": "aws_rds_reserved_instance",
"name": "example"
}
],
"type": "resource"
},
"id": "822d10d1-08f4-4886-85b4-8740bb9ea4c4",
"instance_class": {
"__attribute__": "aws_rds_reserved_instance.example.db_instance_class",
"__name__": "example"
}
}
],
"aws_rds_reserved_instance": [
{
"__tfmeta": {
"filename": "rds.tf",
"label": "aws_rds_reserved_instance",
"line_end": 8,
"line_start": 5,
"path": "aws_rds_reserved_instance.example",
"type": "resource"
},
"id": "db6030c1-fad0-4d0a-a6d5-708d9e34c83a",
"instance_count": 1,
"offering_id": {
"__attribute__": "data.aws_rds_reserved_instance_offering.example.offering_id",
"__name__": "example",
"__ref__": "aws_rds_reserved_instance_offering.example",
"__type__": "aws_rds_reserved_instance_offering"
}
}
],
"aws_rds_reserved_instance_offering": [
{
"__tfmeta": {
"filename": "rds.tf",
"label": "aws_rds_reserved_instance_offering",
"line_end": 3,
"line_start": 1,
"path": "data.aws_rds_reserved_instance_offering.example",
"type": "data"
},
"db_instance_class": "db.m7g.large",
"id": "9251a42c-9126-413c-9350-d6fc390ce42d"
}
]
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.