Skip to content

Commit

Permalink
extend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
albertodonato committed Nov 14, 2024
1 parent b53d34f commit ad368e3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
22 changes: 16 additions & 6 deletions tests/terraform/references/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -37,11 +33,25 @@ 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 {
sse_algorithm = "aws:kms"
}
}
}

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/"
}
20 changes: 17 additions & 3 deletions tests/test_tfparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,24 +423,38 @@ 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"],
"label": "aws_s3_bucket",
"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"],
"label": "aws_s3_bucket",
"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):
Expand Down

0 comments on commit ad368e3

Please sign in to comment.