runbooks 0.2.5__py3-none-any.whl → 0.7.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- conftest.py +26 -0
- jupyter-agent/.env +2 -0
- jupyter-agent/.env.template +2 -0
- jupyter-agent/.gitattributes +35 -0
- jupyter-agent/.gradio/certificate.pem +31 -0
- jupyter-agent/README.md +16 -0
- jupyter-agent/__main__.log +8 -0
- jupyter-agent/app.py +256 -0
- jupyter-agent/cloudops-agent.png +0 -0
- jupyter-agent/ds-system-prompt.txt +154 -0
- jupyter-agent/jupyter-agent.png +0 -0
- jupyter-agent/llama3_template.jinja +123 -0
- jupyter-agent/requirements.txt +9 -0
- jupyter-agent/tmp/4ojbs8a02ir/jupyter-agent.ipynb +68 -0
- jupyter-agent/tmp/cm5iasgpm3p/jupyter-agent.ipynb +91 -0
- jupyter-agent/tmp/crqbsseag5/jupyter-agent.ipynb +91 -0
- jupyter-agent/tmp/hohanq1u097/jupyter-agent.ipynb +57 -0
- jupyter-agent/tmp/jns1sam29wm/jupyter-agent.ipynb +53 -0
- jupyter-agent/tmp/jupyter-agent.ipynb +27 -0
- jupyter-agent/utils.py +409 -0
- runbooks/__init__.py +71 -3
- runbooks/__main__.py +13 -0
- runbooks/aws/ec2_describe_instances.py +1 -1
- runbooks/aws/ec2_run_instances.py +8 -2
- runbooks/aws/ec2_start_stop_instances.py +17 -4
- runbooks/aws/ec2_unused_volumes.py +5 -1
- runbooks/aws/s3_create_bucket.py +4 -2
- runbooks/aws/s3_list_objects.py +6 -1
- runbooks/aws/tagging_lambda_handler.py +13 -2
- runbooks/aws/tags.json +12 -0
- runbooks/base.py +353 -0
- runbooks/cfat/README.md +49 -0
- runbooks/cfat/__init__.py +74 -0
- runbooks/cfat/app.ts +644 -0
- runbooks/cfat/assessment/__init__.py +40 -0
- runbooks/cfat/assessment/asana-import.csv +39 -0
- runbooks/cfat/assessment/cfat-checks.csv +31 -0
- runbooks/cfat/assessment/cfat.txt +520 -0
- runbooks/cfat/assessment/collectors.py +200 -0
- runbooks/cfat/assessment/jira-import.csv +39 -0
- runbooks/cfat/assessment/runner.py +387 -0
- runbooks/cfat/assessment/validators.py +290 -0
- runbooks/cfat/cli.py +103 -0
- runbooks/cfat/docs/asana-import.csv +24 -0
- runbooks/cfat/docs/cfat-checks.csv +31 -0
- runbooks/cfat/docs/cfat.txt +335 -0
- runbooks/cfat/docs/checks-output.png +0 -0
- runbooks/cfat/docs/cloudshell-console-run.png +0 -0
- runbooks/cfat/docs/cloudshell-download.png +0 -0
- runbooks/cfat/docs/cloudshell-output.png +0 -0
- runbooks/cfat/docs/downloadfile.png +0 -0
- runbooks/cfat/docs/jira-import.csv +24 -0
- runbooks/cfat/docs/open-cloudshell.png +0 -0
- runbooks/cfat/docs/report-header.png +0 -0
- runbooks/cfat/models.py +1026 -0
- runbooks/cfat/package-lock.json +5116 -0
- runbooks/cfat/package.json +38 -0
- runbooks/cfat/report.py +496 -0
- runbooks/cfat/reporting/__init__.py +46 -0
- runbooks/cfat/reporting/exporters.py +337 -0
- runbooks/cfat/reporting/formatters.py +496 -0
- runbooks/cfat/reporting/templates.py +135 -0
- runbooks/cfat/run-assessment.sh +23 -0
- runbooks/cfat/runner.py +69 -0
- runbooks/cfat/src/actions/check-cloudtrail-existence.ts +43 -0
- runbooks/cfat/src/actions/check-config-existence.ts +37 -0
- runbooks/cfat/src/actions/check-control-tower.ts +37 -0
- runbooks/cfat/src/actions/check-ec2-existence.ts +46 -0
- runbooks/cfat/src/actions/check-iam-users.ts +50 -0
- runbooks/cfat/src/actions/check-legacy-cur.ts +30 -0
- runbooks/cfat/src/actions/check-org-cloudformation.ts +30 -0
- runbooks/cfat/src/actions/check-vpc-existence.ts +43 -0
- runbooks/cfat/src/actions/create-asanaimport.ts +14 -0
- runbooks/cfat/src/actions/create-backlog.ts +372 -0
- runbooks/cfat/src/actions/create-jiraimport.ts +15 -0
- runbooks/cfat/src/actions/create-report.ts +616 -0
- runbooks/cfat/src/actions/define-account-type.ts +51 -0
- runbooks/cfat/src/actions/get-enabled-org-policy-types.ts +40 -0
- runbooks/cfat/src/actions/get-enabled-org-services.ts +26 -0
- runbooks/cfat/src/actions/get-idc-info.ts +34 -0
- runbooks/cfat/src/actions/get-org-da-accounts.ts +34 -0
- runbooks/cfat/src/actions/get-org-details.ts +35 -0
- runbooks/cfat/src/actions/get-org-member-accounts.ts +44 -0
- runbooks/cfat/src/actions/get-org-ous.ts +35 -0
- runbooks/cfat/src/actions/get-regions.ts +22 -0
- runbooks/cfat/src/actions/zip-assessment.ts +27 -0
- runbooks/cfat/src/types/index.d.ts +147 -0
- runbooks/cfat/tests/__init__.py +141 -0
- runbooks/cfat/tests/test_cli.py +340 -0
- runbooks/cfat/tests/test_integration.py +290 -0
- runbooks/cfat/tests/test_models.py +505 -0
- runbooks/cfat/tests/test_reporting.py +354 -0
- runbooks/cfat/tsconfig.json +16 -0
- runbooks/cfat/webpack.config.cjs +27 -0
- runbooks/config.py +260 -0
- runbooks/finops/README.md +337 -0
- runbooks/finops/__init__.py +86 -0
- runbooks/finops/aws_client.py +245 -0
- runbooks/finops/cli.py +151 -0
- runbooks/finops/cost_processor.py +410 -0
- runbooks/finops/dashboard_runner.py +448 -0
- runbooks/finops/helpers.py +355 -0
- runbooks/finops/main.py +14 -0
- runbooks/finops/profile_processor.py +174 -0
- runbooks/finops/types.py +66 -0
- runbooks/finops/visualisations.py +80 -0
- runbooks/inventory/.gitignore +354 -0
- runbooks/inventory/ArgumentsClass.py +261 -0
- runbooks/inventory/FAILED_SCRIPTS_TROUBLESHOOTING.md +619 -0
- runbooks/inventory/Inventory_Modules.py +6130 -0
- runbooks/inventory/LandingZone/delete_lz.py +1075 -0
- runbooks/inventory/PASSED_SCRIPTS_GUIDE.md +738 -0
- runbooks/inventory/README.md +1320 -0
- runbooks/inventory/__init__.py +62 -0
- runbooks/inventory/account_class.py +532 -0
- runbooks/inventory/all_my_instances_wrapper.py +123 -0
- runbooks/inventory/aws_decorators.py +201 -0
- runbooks/inventory/aws_organization.png +0 -0
- runbooks/inventory/cfn_move_stack_instances.py +1526 -0
- runbooks/inventory/check_cloudtrail_compliance.py +614 -0
- runbooks/inventory/check_controltower_readiness.py +1107 -0
- runbooks/inventory/check_landingzone_readiness.py +711 -0
- runbooks/inventory/cloudtrail.md +727 -0
- runbooks/inventory/collectors/__init__.py +20 -0
- runbooks/inventory/collectors/aws_compute.py +518 -0
- runbooks/inventory/collectors/aws_networking.py +275 -0
- runbooks/inventory/collectors/base.py +222 -0
- runbooks/inventory/core/__init__.py +19 -0
- runbooks/inventory/core/collector.py +303 -0
- runbooks/inventory/core/formatter.py +296 -0
- runbooks/inventory/delete_s3_buckets_objects.py +169 -0
- runbooks/inventory/discovery.md +81 -0
- runbooks/inventory/draw_org_structure.py +748 -0
- runbooks/inventory/ec2_vpc_utils.py +341 -0
- runbooks/inventory/find_cfn_drift_detection.py +272 -0
- runbooks/inventory/find_cfn_orphaned_stacks.py +719 -0
- runbooks/inventory/find_cfn_stackset_drift.py +733 -0
- runbooks/inventory/find_ec2_security_groups.py +669 -0
- runbooks/inventory/find_landingzone_versions.py +201 -0
- runbooks/inventory/find_vpc_flow_logs.py +1221 -0
- runbooks/inventory/inventory.sh +659 -0
- runbooks/inventory/list_cfn_stacks.py +558 -0
- runbooks/inventory/list_cfn_stackset_operation_results.py +252 -0
- runbooks/inventory/list_cfn_stackset_operations.py +734 -0
- runbooks/inventory/list_cfn_stacksets.py +453 -0
- runbooks/inventory/list_config_recorders_delivery_channels.py +681 -0
- runbooks/inventory/list_ds_directories.py +354 -0
- runbooks/inventory/list_ec2_availability_zones.py +286 -0
- runbooks/inventory/list_ec2_ebs_volumes.py +244 -0
- runbooks/inventory/list_ec2_instances.py +425 -0
- runbooks/inventory/list_ecs_clusters_and_tasks.py +562 -0
- runbooks/inventory/list_elbs_load_balancers.py +411 -0
- runbooks/inventory/list_enis_network_interfaces.py +526 -0
- runbooks/inventory/list_guardduty_detectors.py +568 -0
- runbooks/inventory/list_iam_policies.py +404 -0
- runbooks/inventory/list_iam_roles.py +518 -0
- runbooks/inventory/list_iam_saml_providers.py +359 -0
- runbooks/inventory/list_lambda_functions.py +882 -0
- runbooks/inventory/list_org_accounts.py +446 -0
- runbooks/inventory/list_org_accounts_users.py +354 -0
- runbooks/inventory/list_rds_db_instances.py +406 -0
- runbooks/inventory/list_route53_hosted_zones.py +318 -0
- runbooks/inventory/list_servicecatalog_provisioned_products.py +575 -0
- runbooks/inventory/list_sns_topics.py +360 -0
- runbooks/inventory/list_ssm_parameters.py +402 -0
- runbooks/inventory/list_vpc_subnets.py +433 -0
- runbooks/inventory/list_vpcs.py +422 -0
- runbooks/inventory/lockdown_cfn_stackset_role.py +224 -0
- runbooks/inventory/models/__init__.py +24 -0
- runbooks/inventory/models/account.py +192 -0
- runbooks/inventory/models/inventory.py +309 -0
- runbooks/inventory/models/resource.py +247 -0
- runbooks/inventory/recover_cfn_stack_ids.py +205 -0
- runbooks/inventory/requirements.txt +12 -0
- runbooks/inventory/run_on_multi_accounts.py +211 -0
- runbooks/inventory/tests/common_test_data.py +3661 -0
- runbooks/inventory/tests/common_test_functions.py +204 -0
- runbooks/inventory/tests/setup.py +24 -0
- runbooks/inventory/tests/src.py +18 -0
- runbooks/inventory/tests/test_cfn_describe_stacks.py +208 -0
- runbooks/inventory/tests/test_ec2_describe_instances.py +162 -0
- runbooks/inventory/tests/test_inventory_modules.py +55 -0
- runbooks/inventory/tests/test_lambda_list_functions.py +86 -0
- runbooks/inventory/tests/test_moto_integration_example.py +273 -0
- runbooks/inventory/tests/test_org_list_accounts.py +49 -0
- runbooks/inventory/update_aws_actions.py +173 -0
- runbooks/inventory/update_cfn_stacksets.py +1215 -0
- runbooks/inventory/update_cloudwatch_logs_retention_policy.py +294 -0
- runbooks/inventory/update_iam_roles_cross_accounts.py +478 -0
- runbooks/inventory/update_s3_public_access_block.py +539 -0
- runbooks/inventory/utils/__init__.py +23 -0
- runbooks/inventory/utils/aws_helpers.py +510 -0
- runbooks/inventory/utils/threading_utils.py +493 -0
- runbooks/inventory/utils/validation.py +682 -0
- runbooks/inventory/verify_ec2_security_groups.py +1430 -0
- runbooks/main.py +1004 -0
- runbooks/organizations/__init__.py +12 -0
- runbooks/organizations/manager.py +374 -0
- runbooks/security/README.md +447 -0
- runbooks/security/__init__.py +71 -0
- runbooks/{security_baseline → security}/checklist/alternate_contacts.py +8 -1
- runbooks/{security_baseline → security}/checklist/bucket_public_access.py +4 -1
- runbooks/{security_baseline → security}/checklist/cloudwatch_alarm_configuration.py +9 -2
- runbooks/{security_baseline → security}/checklist/guardduty_enabled.py +9 -2
- runbooks/{security_baseline → security}/checklist/multi_region_instance_usage.py +5 -1
- runbooks/{security_baseline → security}/checklist/root_access_key.py +6 -1
- runbooks/{security_baseline → security}/config-origin.json +1 -1
- runbooks/{security_baseline → security}/config.json +1 -1
- runbooks/{security_baseline → security}/permission.json +1 -1
- runbooks/{security_baseline → security}/report_generator.py +10 -2
- runbooks/{security_baseline → security}/report_template_en.html +7 -7
- runbooks/{security_baseline → security}/report_template_jp.html +7 -7
- runbooks/{security_baseline → security}/report_template_kr.html +12 -12
- runbooks/{security_baseline → security}/report_template_vn.html +7 -7
- runbooks/{security_baseline → security}/run_script.py +8 -2
- runbooks/{security_baseline → security}/security_baseline_tester.py +12 -4
- runbooks/{security_baseline → security}/utils/common.py +5 -1
- runbooks/utils/__init__.py +204 -0
- runbooks-0.7.0.dist-info/METADATA +375 -0
- runbooks-0.7.0.dist-info/RECORD +249 -0
- {runbooks-0.2.5.dist-info → runbooks-0.7.0.dist-info}/WHEEL +1 -1
- runbooks-0.7.0.dist-info/entry_points.txt +7 -0
- runbooks-0.7.0.dist-info/licenses/LICENSE +201 -0
- runbooks-0.7.0.dist-info/top_level.txt +3 -0
- runbooks/python101/calculator.py +0 -34
- runbooks/python101/config.py +0 -1
- runbooks/python101/exceptions.py +0 -16
- runbooks/python101/file_manager.py +0 -218
- runbooks/python101/toolkit.py +0 -153
- runbooks-0.2.5.dist-info/METADATA +0 -439
- runbooks-0.2.5.dist-info/RECORD +0 -61
- runbooks-0.2.5.dist-info/entry_points.txt +0 -3
- runbooks-0.2.5.dist-info/top_level.txt +0 -1
- /runbooks/{security_baseline/__init__.py → inventory/tests/script_test_data.py} +0 -0
- /runbooks/{security_baseline → security}/checklist/__init__.py +0 -0
- /runbooks/{security_baseline → security}/checklist/account_level_bucket_public_access.py +0 -0
- /runbooks/{security_baseline → security}/checklist/direct_attached_policy.py +0 -0
- /runbooks/{security_baseline → security}/checklist/iam_password_policy.py +0 -0
- /runbooks/{security_baseline → security}/checklist/iam_user_mfa.py +0 -0
- /runbooks/{security_baseline → security}/checklist/multi_region_trail.py +0 -0
- /runbooks/{security_baseline → security}/checklist/root_mfa.py +0 -0
- /runbooks/{security_baseline → security}/checklist/root_usage.py +0 -0
- /runbooks/{security_baseline → security}/checklist/trail_enabled.py +0 -0
- /runbooks/{security_baseline → security}/checklist/trusted_advisor.py +0 -0
- /runbooks/{security_baseline → security}/utils/__init__.py +0 -0
- /runbooks/{security_baseline → security}/utils/enums.py +0 -0
- /runbooks/{security_baseline → security}/utils/language.py +0 -0
- /runbooks/{security_baseline → security}/utils/level_const.py +0 -0
- /runbooks/{security_baseline → security}/utils/permission_list.py +0 -0
@@ -0,0 +1,252 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
|
3
|
+
"""
|
4
|
+
AWS CloudFormation StackSet Operation Results Analysis and Correlation Script
|
5
|
+
|
6
|
+
This enterprise-grade analysis and reporting script provides comprehensive correlation and
|
7
|
+
analysis of CloudFormation StackSet deployment results with AWS Organizations account data.
|
8
|
+
Designed for infrastructure teams, DevOps engineers, and cloud architects managing large-scale
|
9
|
+
StackSet deployments across AWS Organizations for operational excellence and governance.
|
10
|
+
|
11
|
+
Key Features:
|
12
|
+
- StackSet deployment correlation with organizational account structure
|
13
|
+
- Missing deployment identification for compliance and coverage analysis
|
14
|
+
- Outdated and inoperable StackSet instance detection for operational maintenance
|
15
|
+
- Account and region deployment histogram analysis for capacity planning
|
16
|
+
- Cross-reference analysis between StackSet deployments and active accounts
|
17
|
+
- Cleanup recommendations for orphaned StackSet instances and resources
|
18
|
+
|
19
|
+
Analysis Capabilities:
|
20
|
+
- File-based input processing for StackSet operation results and Organizations data
|
21
|
+
- Regular expression-based parsing for flexible input format handling
|
22
|
+
- Multi-dimensional analysis including account, region, and status correlations
|
23
|
+
- Deployment gap analysis for organizational compliance tracking
|
24
|
+
- Status categorization for operational health monitoring and maintenance
|
25
|
+
|
26
|
+
Input File Processing:
|
27
|
+
- StackSets results file parsing with deployment status and regional distribution
|
28
|
+
- AWS Organizations account list processing with status and email correlation
|
29
|
+
- Cross-reference validation between deployment data and organizational structure
|
30
|
+
- Flexible parsing supporting various output formats from inventory scripts
|
31
|
+
|
32
|
+
Enterprise Use Cases:
|
33
|
+
- Infrastructure governance and compliance reporting for organizational oversight
|
34
|
+
- Deployment coverage analysis ensuring consistent policy and security baseline deployment
|
35
|
+
- Operational maintenance identification for outdated and problematic StackSet instances
|
36
|
+
- Capacity planning and resource distribution analysis across accounts and regions
|
37
|
+
- Cleanup orchestration for orphaned resources and inactive account deployments
|
38
|
+
|
39
|
+
Reporting and Analysis:
|
40
|
+
- Account-based deployment histogram for organizational visibility
|
41
|
+
- Regional distribution analysis for capacity planning and disaster recovery
|
42
|
+
- Missing deployment identification for coverage gap analysis
|
43
|
+
- Status-based categorization for operational health monitoring
|
44
|
+
- Cleanup recommendations for resource optimization and maintenance
|
45
|
+
|
46
|
+
Security and Compliance:
|
47
|
+
- Read-only analysis operations ensuring no accidental modifications
|
48
|
+
- Comprehensive audit trail through detailed logging and analysis output
|
49
|
+
- Organizational structure validation for security baseline compliance
|
50
|
+
- Gap analysis supporting compliance frameworks and governance requirements
|
51
|
+
|
52
|
+
Future Enhancements:
|
53
|
+
- Visual dashboard integration for operational monitoring and reporting
|
54
|
+
- Enhanced output formatting with charts and graphical representations
|
55
|
+
- Automated remediation recommendations and workflow integration
|
56
|
+
- Real-time monitoring capabilities for continuous compliance tracking
|
57
|
+
|
58
|
+
Dependencies:
|
59
|
+
- re: Regular expression processing for flexible input file parsing
|
60
|
+
- ArgumentsClass: Standardized CLI argument parsing and validation
|
61
|
+
- colorama: Enhanced terminal output with color coding for operational visibility
|
62
|
+
|
63
|
+
Example Usage:
|
64
|
+
# Basic StackSet results analysis
|
65
|
+
python list_cfn_stackset_operation_results.py --stacksets_filename stacksets.out --org_filename orgs.out
|
66
|
+
|
67
|
+
# Verbose analysis with detailed logging
|
68
|
+
python list_cfn_stackset_operation_results.py --ssf stacksets.out --of orgs.out --verbose
|
69
|
+
|
70
|
+
Output:
|
71
|
+
Provides comprehensive analysis of StackSet deployment status, missing deployments,
|
72
|
+
cleanup recommendations, and organizational coverage for infrastructure governance.
|
73
|
+
"""
|
74
|
+
|
75
|
+
import logging
|
76
|
+
import re
|
77
|
+
|
78
|
+
from ArgumentsClass import CommonArguments
|
79
|
+
from colorama import Fore, init
|
80
|
+
|
81
|
+
init()
|
82
|
+
__version__ = "2024.06.20"
|
83
|
+
|
84
|
+
# Configure CLI argument parsing for StackSet results analysis and correlation
|
85
|
+
parser = CommonArguments()
|
86
|
+
parser.singleprofile() # Add profile support for consistency with other scripts
|
87
|
+
parser.verbosity() # Configure logging verbosity for debugging and audit trails
|
88
|
+
parser.version(__version__) # Version information for tooling compatibility tracking
|
89
|
+
|
90
|
+
# Add StackSets results file input argument for deployment analysis
|
91
|
+
parser.my_parser.add_argument(
|
92
|
+
"--stacksets_filename",
|
93
|
+
"--ssf",
|
94
|
+
dest="StackSetsFilename",
|
95
|
+
metavar="Stacksets results from the script",
|
96
|
+
help="Path to StackSets inventory results file containing deployment status and regional distribution data",
|
97
|
+
)
|
98
|
+
|
99
|
+
# Add AWS Organizations file input argument for account correlation
|
100
|
+
parser.my_parser.add_argument(
|
101
|
+
"--org_filename",
|
102
|
+
"--of",
|
103
|
+
dest="OrgsFilename",
|
104
|
+
metavar="Organizations results from the script",
|
105
|
+
help="Path to AWS Organizations account list file containing active accounts with status and email information",
|
106
|
+
)
|
107
|
+
|
108
|
+
# Parse command-line arguments and extract configuration parameters
|
109
|
+
args = parser.my_parser.parse_args()
|
110
|
+
|
111
|
+
pStackSetsFilename = args.StackSetsFilename # StackSets results file path for analysis
|
112
|
+
pOrgsFilename = args.OrgsFilename # Organizations account file path for correlation
|
113
|
+
verbose = args.loglevel # Logging verbosity level for operational visibility
|
114
|
+
|
115
|
+
# Configure comprehensive logging for analysis operations and audit trails
|
116
|
+
logging.basicConfig(level=verbose, format="[%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s")
|
117
|
+
logging.getLogger("boto3").setLevel(logging.CRITICAL) # Suppress AWS SDK noise
|
118
|
+
logging.getLogger("botocore").setLevel(logging.CRITICAL) # Suppress AWS core library noise
|
119
|
+
logging.getLogger("s3transfer").setLevel(logging.CRITICAL) # Suppress S3 transfer noise
|
120
|
+
logging.getLogger("urllib3").setLevel(logging.CRITICAL) # Suppress HTTP client noise
|
121
|
+
|
122
|
+
##########################
|
123
|
+
# Analysis and Data Processing
|
124
|
+
##########################
|
125
|
+
|
126
|
+
ERASE_LINE = "\x1b[2K" # Terminal line clearing for dynamic output updates
|
127
|
+
|
128
|
+
# Initialize StackSets data structure for comprehensive deployment analysis
|
129
|
+
StackSets = {}
|
130
|
+
|
131
|
+
# Parse StackSets inventory results file for deployment status and regional distribution
|
132
|
+
if pStackSetsFilename:
|
133
|
+
with open(pStackSetsFilename, "r") as StackSets_infile:
|
134
|
+
for line in StackSets_infile:
|
135
|
+
line = line.strip("\n") # Clean line endings for processing
|
136
|
+
|
137
|
+
# Identify StackSet name lines using pattern matching for header detection
|
138
|
+
if re.match("^[A-Za-z]", line) and line.find("MANAGED):$"):
|
139
|
+
stackset_name = line.split(" ", 1)[0] # Extract StackSet name identifier
|
140
|
+
StackSets[stackset_name] = {} # Initialize StackSet data structure
|
141
|
+
|
142
|
+
# Identify and parse deployment status categories (CURRENT, OUTDATED, INOPERABLE)
|
143
|
+
elif re.search("CURRENT|OUTDATED|INOPERABLE", line):
|
144
|
+
Status = line.split(":", 1)[0].strip() # Extract status category for instances
|
145
|
+
StackSets[stackset_name][Status] = [] # Initialize status-specific instance list
|
146
|
+
|
147
|
+
# Parse account and region deployment information using account ID pattern
|
148
|
+
elif re.search("[0-9]{12}", line):
|
149
|
+
acctid, regions = line.split(":") # Split account ID from regions list
|
150
|
+
acctid = acctid.strip() # Clean account ID for processing
|
151
|
+
|
152
|
+
# Parse and clean regions list from various bracket and quote formats
|
153
|
+
region_list = regions.replace("[", "").replace("]", "").replace("'", "").replace(" ", "").split(",")
|
154
|
+
|
155
|
+
# Aggregate account and region deployment data for analysis
|
156
|
+
StackSets[stackset_name][Status].append({"AccountId": acctid.lstrip(), "Regions": region_list})
|
157
|
+
else:
|
158
|
+
print("No StackSets filename provided - using empty dataset for testing")
|
159
|
+
|
160
|
+
# Parse AWS Organizations account list file for active account correlation
|
161
|
+
OrgAccounts = []
|
162
|
+
if pOrgsFilename:
|
163
|
+
with open(pOrgsFilename, "r") as Orgs_infile:
|
164
|
+
for line in Orgs_infile:
|
165
|
+
# Filter lines containing account information using pattern matching
|
166
|
+
if not re.match("^\t\t[0-9]{12}", line):
|
167
|
+
continue
|
168
|
+
|
169
|
+
# Extract account information from formatted Organizations output
|
170
|
+
acct_number = line.split()[0] # AWS account number for correlation
|
171
|
+
Status = line.split()[1] # Account status (ACTIVE, SUSPENDED, etc.)
|
172
|
+
Email = line.split()[2] # Account email for contact identification
|
173
|
+
|
174
|
+
# Aggregate Organizations account data for cross-reference analysis
|
175
|
+
OrgAccounts.append({"AcctId": acct_number, "Status": Status, "Email": Email})
|
176
|
+
else:
|
177
|
+
print("No Organizations filename provided - using empty dataset for testing")
|
178
|
+
|
179
|
+
# Create active account list for deployment coverage analysis
|
180
|
+
AccountList = [x["AcctId"] for x in OrgAccounts]
|
181
|
+
|
182
|
+
# Initialize analysis data structures for comprehensive reporting
|
183
|
+
StacksToCleanUp = [] # Orphaned StackSet instances requiring cleanup
|
184
|
+
StackInstancesToCheckOn = [] # Non-current instances requiring operational attention
|
185
|
+
RegionHistogram = {} # Regional deployment distribution for capacity planning
|
186
|
+
AccountHistogram = {} # Account-based deployment analysis for organizational visibility
|
187
|
+
|
188
|
+
# Perform comprehensive StackSet deployment analysis and correlation
|
189
|
+
for stackset_name, stackset_data in StackSets.items():
|
190
|
+
logging.debug(f"stackset_name: {stackset_name} | stackset_data: {stackset_data}")
|
191
|
+
|
192
|
+
# Analyze each deployment status category for operational insights
|
193
|
+
for status, instances in stackset_data.items():
|
194
|
+
logging.debug(f"status: {status} | instances: {instances}")
|
195
|
+
|
196
|
+
# Process each StackSet instance for correlation and analysis
|
197
|
+
for i in range(len(instances)):
|
198
|
+
current_account = StackSets[stackset_name][status][i]["AccountId"]
|
199
|
+
logging.debug(f"AccountId: {current_account}")
|
200
|
+
|
201
|
+
# Initialize account-based histogram for deployment tracking
|
202
|
+
if current_account not in AccountHistogram.keys():
|
203
|
+
AccountHistogram[current_account] = {}
|
204
|
+
|
205
|
+
# Build comprehensive deployment histograms for analysis and reporting
|
206
|
+
for region in StackSets[stackset_name][status][i]["Regions"]:
|
207
|
+
# Initialize regional histogram structures
|
208
|
+
if region not in RegionHistogram.keys():
|
209
|
+
RegionHistogram[region] = {}
|
210
|
+
if region not in AccountHistogram[current_account].keys():
|
211
|
+
AccountHistogram[current_account][region] = list()
|
212
|
+
if current_account not in RegionHistogram[region].keys():
|
213
|
+
RegionHistogram[region][current_account] = list()
|
214
|
+
|
215
|
+
# Aggregate StackSet deployment data for histogram analysis
|
216
|
+
RegionHistogram[region][current_account].append(stackset_name)
|
217
|
+
AccountHistogram[current_account][region].append(stackset_name)
|
218
|
+
|
219
|
+
# Cross-reference StackSet deployments with active Organizations accounts
|
220
|
+
if current_account in AccountList:
|
221
|
+
# Mark as active account with valid organizational membership
|
222
|
+
StackSets[stackset_name][status][i]["Status"] = "ACTIVE"
|
223
|
+
|
224
|
+
# Identify non-current instances requiring operational attention
|
225
|
+
if not status == "CURRENT":
|
226
|
+
StackInstancesToCheckOn.append(
|
227
|
+
{
|
228
|
+
"StackSetName": stackset_name,
|
229
|
+
"Status": status,
|
230
|
+
"Account": current_account,
|
231
|
+
"Regions": StackSets[stackset_name][status][i]["Regions"],
|
232
|
+
}
|
233
|
+
)
|
234
|
+
else:
|
235
|
+
# Mark as orphaned instance requiring cleanup
|
236
|
+
StackSets[stackset_name][status][i]["Status"] = "MISSING"
|
237
|
+
StacksToCleanUp.append({"StackSetName": stackset_name, "Account": current_account})
|
238
|
+
|
239
|
+
# Identify missing deployments for coverage gap analysis
|
240
|
+
Missing_Stuff = {}
|
241
|
+
for stackset_name, stackset_data in StackSets.items():
|
242
|
+
for status, stack_instances in stackset_data.items():
|
243
|
+
# Analyze current deployments to identify coverage gaps
|
244
|
+
if status == "CURRENT":
|
245
|
+
# Extract accounts with current deployments
|
246
|
+
account_list = [x["AccountId"] for x in stack_instances] if len(stack_instances) > 1 else []
|
247
|
+
# Calculate missing deployments using set difference analysis
|
248
|
+
Missing_Stuff[stackset_name] = list(set(AccountList) - set(account_list))
|
249
|
+
|
250
|
+
print()
|
251
|
+
print("Thanks for using this script...")
|
252
|
+
print()
|