-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
33f858c
commit 0168f55
Showing
3 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import boto3 | ||
|
||
from azul import ( | ||
config, | ||
logging, | ||
) | ||
from azul.logging import ( | ||
configure_script_logging, | ||
) | ||
from azul.terraform import ( | ||
terraform, | ||
) | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def main(): | ||
|
||
log_groups = {} # Mapping of TF resource name to AWS Cloudwatch log group | ||
|
||
log_client = boto3.client('logs') | ||
paginator = log_client.get_paginator('describe_log_groups') | ||
for page in paginator.paginate(): | ||
for log_group in page['logGroups']: | ||
group_name = log_group['logGroupName'] | ||
# Chatbot | ||
if config.slack_integration and group_name.startswith('/aws/chatbot'): | ||
name = group_name.rpartition('/')[2] | ||
name, stage = config.unqualified_resource_name(name) | ||
if stage == config.deployment_stage: | ||
log_groups['chatbot'] = group_name | ||
|
||
resources = terraform.run('state', 'list').splitlines() | ||
for name, log_group in log_groups.items(): | ||
resource_name = f'aws_cloudwatch_log_group.{name}' | ||
if resource_name in resources: | ||
log.info('Skipping import of %r.', resource_name) | ||
else: | ||
log.info('Importing resource %r.', resource_name) | ||
terraform.run('import', resource_name, log_group) | ||
|
||
|
||
if __name__ == '__main__': | ||
configure_script_logging() | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters