From ad368e33440f1496e74a2d4748a6ca707ebd5120 Mon Sep 17 00:00:00 2001 From: Alberto Donato Date: Thu, 14 Nov 2024 12:11:48 +0100 Subject: [PATCH] extend tests --- tests/terraform/references/main.tf | 22 ++++++++++++++++------ tests/test_tfparse.py | 20 +++++++++++++++++--- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/tests/terraform/references/main.tf b/tests/terraform/references/main.tf index e0a4113..71b5b3e 100644 --- a/tests/terraform/references/main.tf +++ b/tests/terraform/references/main.tf @@ -14,16 +14,12 @@ provider "aws" { } } -resource "aws_s3_bucket" "unencrypted-bucket" { - bucket = "my-unencrypted-bucket" -} - resource "aws_s3_bucket" "aes-encrypted-bucket" { bucket = "my-aes-encrypted-bucket" } resource "aws_s3_bucket_server_side_encryption_configuration" "aes-encrypted-configuration" { - bucket_ref = aws_s3_bucket.aes-encrypted-bucket.bucket + bucket = aws_s3_bucket.aes-encrypted-bucket.bucket rule { apply_server_side_encryption_by_default { @@ -37,7 +33,7 @@ resource "aws_s3_bucket" "kms-encrypted-bucket" { } resource "aws_s3_bucket_server_side_encryption_configuration" "kms-encrypted-configuration" { - bucket_ref = aws_s3_bucket.kms-encrypted-bucket.bucket + bucket = aws_s3_bucket.kms-encrypted-bucket.bucket rule { apply_server_side_encryption_by_default { @@ -45,3 +41,17 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "kms-encrypted-con } } } + +resource "aws_s3_bucket" "sample-bucket" { + bucket = "sample-bucket" +} + +resource "aws_s3_bucket" "log-bucket" { + bucket = "log-bucket" +} + +resource "aws_s3_bucket_logging" "example" { + bucket = aws_s3_bucket.sample-bucket.id + target_bucket = aws_s3_bucket.log-bucket.id + target_prefix = "log/" +} diff --git a/tests/test_tfparse.py b/tests/test_tfparse.py index 6c12677..d332f6e 100644 --- a/tests/test_tfparse.py +++ b/tests/test_tfparse.py @@ -423,9 +423,9 @@ def test_references(tmp_path): mod_path = init_module("references", tmp_path) parsed = load_from_path(mod_path) - aes_bucket, kms_bucket, _ = parsed["aws_s3_bucket"] + aes_bucket, kms_bucket, log_bucket, sample_bucket = parsed["aws_s3_bucket"] config1, config2 = parsed["aws_s3_bucket_server_side_encryption_configuration"] - assert config1["bucket_ref"] == "my-aes-encrypted-bucket" + assert config1["bucket"] == "my-aes-encrypted-bucket" assert config1["__tfmeta"]["references"] == [ { "id": aes_bucket["id"], @@ -433,7 +433,7 @@ def test_references(tmp_path): "name": "aes-encrypted-bucket", }, ] - assert config2["bucket_ref"] == "my-kms-encrypted-bucket" + assert config2["bucket"] == "my-kms-encrypted-bucket" assert config2["__tfmeta"]["references"] == [ { "id": kms_bucket["id"], @@ -441,6 +441,20 @@ def test_references(tmp_path): "name": "kms-encrypted-bucket", }, ] + # all reference to other blocks are reported + [bucket_logging] = parsed["aws_s3_bucket_logging"] + assert bucket_logging["__tfmeta"]["references"] == [ + { + "id": sample_bucket["id"], + "label": "aws_s3_bucket", + "name": "sample-bucket", + }, + { + "id": log_bucket["id"], + "label": "aws_s3_bucket", + "name": "log-bucket", + }, + ] def test_modules_located_above_root(tmp_path):