from pathlib import Path from scripts.plan_output import parse_plan_resources FIXTURE = Path(__file__).parent / "fixtures" / "plan_output_tofu.txt" def test_parses_create_update_destroy_replace(): txt = FIXTURE.read_text() resources = parse_plan_resources(txt) by_addr = {r.address: r for r in resources} assert by_addr["aws_s3_bucket.audit_logs"].action == "create" assert by_addr["aws_s3_bucket.audit_logs"].type == "aws_s3_bucket" assert by_addr["module.app_role.aws_iam_role.this"].action == "update" assert by_addr["module.app_role.aws_iam_role.this"].type == "aws_iam_role" assert by_addr["aws_security_group.legacy"].action == "delete" assert by_addr["aws_iam_user.svc"].action == "replace" def test_empty_when_no_changes(): txt = "No changes. Your infrastructure matches the configuration.\n" assert parse_plan_resources(txt) == [] def test_type_for_data_source(): txt = """\ # data.aws_caller_identity.current will be read during apply <= data "aws_caller_identity" "current" { } """ out = parse_plan_resources(txt) assert len(out) == 1 assert out[0].action == "read" assert out[0].type == "aws_caller_identity" assert out[0].address == "data.aws_caller_identity.current"