diff --git a/terragrunt/org_account/billing_extract_tags/lambdas/billing_extract_tags/main.py b/terragrunt/org_account/billing_extract_tags/lambdas/billing_extract_tags/main.py index e5c1f1a5..381070ec 100644 --- a/terragrunt/org_account/billing_extract_tags/lambdas/billing_extract_tags/main.py +++ b/terragrunt/org_account/billing_extract_tags/lambdas/billing_extract_tags/main.py @@ -15,7 +15,7 @@ TARGET_BUCKET = os.getenv("TARGET_BUCKET") -def lambda_handler(event, context): +def handler(event, context): """ Get the tags for all accounts in the organization and save them to an s3 bucket """ @@ -62,8 +62,8 @@ def lambda_handler(event, context): # .write json to string and add a newline between each record logging.info("Writing account tags to json") accounts = json.dumps(accounts, default=str) - # accounts = accounts.replace('},', '},\n') - # accounts = accounts.replace('[{', '[\n{') + accounts = accounts.replace("}, ", "},\n") + accounts = accounts.replace("[{", "[\n{") logging.info(f"Accounts: {accounts}") # save accounts to an s3 bucket diff --git a/terragrunt/org_account/billing_extract_tags/lambdas/billing_extract_tags/test_main.py b/terragrunt/org_account/billing_extract_tags/lambdas/billing_extract_tags/test_main.py index bd6aa60e..dd98c31d 100644 --- a/terragrunt/org_account/billing_extract_tags/lambdas/billing_extract_tags/test_main.py +++ b/terragrunt/org_account/billing_extract_tags/lambdas/billing_extract_tags/test_main.py @@ -1,7 +1,6 @@ import unittest -import os -from unittest.mock import call, patch, MagicMock -from main import lambda_handler +from unittest.mock import patch, MagicMock +from main import handler TARGET_BUCKET = "TARGET_BUCKET" ACCOUNT_TAGS_KEY = "account_tags.json" @@ -24,14 +23,15 @@ def test_lambda_handler( } mock_orgs_list_tags.return_value = {"Tags": [{"Key": "Name", "Value": "Dev"}]} - response = lambda_handler(self.event, self.context) + response = handler(self.event, self.context) mock_orgs_list_accounts.assert_called() mock_orgs_list_tags.assert_called_with(ResourceId="123") mock_s3_put.assert_called_with( Bucket=TARGET_BUCKET, Key=ACCOUNT_TAGS_KEY, - Body='[{"Id": "123", "tag_Name": "Dev"}]', + Body="""[ +{"Id": "123", "tag_Name": "Dev"}]""", ) self.assertEqual(response, {"statusCode": 200}) @@ -52,7 +52,7 @@ def test_lambda_handler_pagination( {"Tags": [{"Key": "Name", "Value": "Prod"}]}, ] - lambda_handler(self.event, self.context) + handler(self.event, self.context) mock_orgs_list_accounts.assert_any_call(NextToken="token") mock_orgs_list_tags.assert_any_call(ResourceId="123") @@ -60,5 +60,7 @@ def test_lambda_handler_pagination( mock_s3_put.assert_called_with( Bucket=TARGET_BUCKET, Key=ACCOUNT_TAGS_KEY, - Body='[{"Id": "123", "tag_Name": "Dev"}, {"Id": "456", "tag_Name": "Prod"}]', + Body="""[ +{"Id": "123", "tag_Name": "Dev"}, +{"Id": "456", "tag_Name": "Prod"}]""", ) diff --git a/terragrunt/org_account/billing_extract_tags/s3.tf b/terragrunt/org_account/billing_extract_tags/s3.tf index 9bd203a0..ceeec561 100644 --- a/terragrunt/org_account/billing_extract_tags/s3.tf +++ b/terragrunt/org_account/billing_extract_tags/s3.tf @@ -1,18 +1,3 @@ -import { - to = module.billing_extract_tags.aws_s3_bucket.this - id = "5bf89a78-1503-4e02-9621-3ac658f558fb" -} - -import { - to = module.billing_extract_tags.aws_s3_bucket_public_access_block.this - id = "5bf89a78-1503-4e02-9621-3ac658f558fb" -} - -import { - to = aws_s3_bucket_policy.billing_extract_tags - id = "5bf89a78-1503-4e02-9621-3ac658f558fb" -} - module "billing_extract_tags" { source = "github.com/cds-snc/terraform-modules//S3?ref=v9.2.5" bucket_name = "5bf89a78-1503-4e02-9621-3ac658f558fb"