diff --git a/startleft/iac_to_otm.py b/startleft/iac_to_otm.py index 2977d555..f641c0e7 100644 --- a/startleft/iac_to_otm.py +++ b/startleft/iac_to_otm.py @@ -53,7 +53,7 @@ def load_hcl2_source(self, filename): with open(filename, 'r') as f: self.source_model.load(hcl2.load(f)) else: - self.source_model.load(hcl2.load(StringIO(str(filename.read(), 'utf-8')))) + self.source_model.load(hcl2.load(StringIO(initial_value=str(filename.read(), 'utf-8'), newline=None))) def load_source_files(self, loader, filenames): if isinstance(filenames, str): diff --git a/tests/resources/terraform/aws_singleton_components_classic_macos_line_breaks.tf b/tests/resources/terraform/aws_singleton_components_classic_macos_line_breaks.tf new file mode 100644 index 00000000..cc2f1663 --- /dev/null +++ b/tests/resources/terraform/aws_singleton_components_classic_macos_line_breaks.tf @@ -0,0 +1 @@ +resource "aws_cloudwatch_metric_alarm" "cloudwatch_metric_alarm_1" { alarm_name = "terraform-test-foobar5" comparison_operator = "GreaterThanOrEqualToThreshold" evaluation_periods = "2" metric_name = "CPUUtilization" namespace = "AWS/EC2" period = "120" statistic = "Average" threshold = "80" alarm_description = "This metric monitors ec2 cpu utilization" insufficient_data_actions = [] } resource "aws_cloudwatch_metric_alarm" "cloudwatch_metric_alarm_2" { alarm_name = "terraform-test-foobar5" comparison_operator = "GreaterThanOrEqualToThreshold" evaluation_periods = "2" metric_name = "CPUUtilization" namespace = "AWS/EC2" period = "120" statistic = "Average" threshold = "80" alarm_description = "This metric monitors ec2 cpu utilization" insufficient_data_actions = [] } resource "aws_acm_certificate" "acm_certificate_1" { domain_name = "example.com" validation_method = "DNS" tags = { Environment = "test" } lifecycle { create_before_destroy = true } } resource "aws_acm_certificate" "acm_certificate_2" { domain_name = "example.com" validation_method = "DNS" tags = { Environment = "test" } lifecycle { create_before_destroy = true } } resource "aws_kms_key" "kms_key_1" { description = "KMS key 1" deletion_window_in_days = 10 } resource "aws_kms_key" "kms_key_2" { description = "KMS key 1" deletion_window_in_days = 10 } resource "aws_cloudwatch_log_group" "cloudwatch_log_group_1" { name = "Yada" tags = { Environment = "production" Application = "serviceA" } } resource "aws_cloudwatch_log_group" "cloudwatch_log_group_2" { name = "Yada" tags = { Environment = "production" Application = "serviceA" } } resource "aws_secretsmanager_secret" "secretsmanager_secret_1" { name = "example" } resource "aws_secretsmanager_secret" "secretsmanager_secret_2" { name = "example" } resource "aws_ssm_parameter" "ssm_parameter" { name = "foo" type = "String" value = "bar" } resource "aws_ssm_document" "ssm_document" { name = "test_document" document_type = "Command" content = < DATA } resource "aws_cloudfront_origin_access_identity" "cloudfront_origin_access_identity" { comment = "Some comment" } resource "aws_cloudfront_public_key" "cloudfront_public_key" { comment = "test public key" encoded_key = file("public_key.pem") name = "test_key" } resource "aws_config_config_rule" "config_config_rule" { name = "example" source { owner = "AWS" source_identifier = "S3_BUCKET_VERSIONING_ENABLED" } depends_on = [aws_config_configuration_recorder.foo] } resource "aws_config_configuration_recorder" "config_configuration_recorder" { name = "example" role_arn = aws_iam_role.r.arn } resource "aws_ecr_repository" "ecr_repository" { name = "bar" } resource "aws_ecr_lifecycle_policy" "ecr_lifecycle_policy" { repository = aws_ecr_repository.foo.name policy = < + + + + + + + +DATA +} + +resource "aws_cloudfront_origin_access_identity" "cloudfront_origin_access_identity" { + comment = "Some comment" +} + +resource "aws_cloudfront_public_key" "cloudfront_public_key" { + comment = "test public key" + encoded_key = file("public_key.pem") + name = "test_key" +} + +resource "aws_config_config_rule" "config_config_rule" { + name = "example" + + source { + owner = "AWS" + source_identifier = "S3_BUCKET_VERSIONING_ENABLED" + } + + depends_on = [aws_config_configuration_recorder.foo] +} + +resource "aws_config_configuration_recorder" "config_configuration_recorder" { + name = "example" + role_arn = aws_iam_role.r.arn +} + +resource "aws_ecr_repository" "ecr_repository" { + name = "bar" +} + +resource "aws_ecr_lifecycle_policy" "ecr_lifecycle_policy" { + repository = aws_ecr_repository.foo.name + + policy = <