def _get_resource_arn(self, resource, base_resource): resource_type = resource.__class__.__name__.split(".")[-1] properties = resource.meta.data keys = properties.keys() label = self._get_resource_type_label(resource_type) arn = None if "Arn" in keys: arn = properties["Arn"] elif f"{resource_type}Arn" in keys: arn = properties[f"{resource_type}Arn"] elif f"{resource_type}Id" in keys and properties[ f"{resource_type}Id"].startswith("arn:aws"): arn = properties[f"{resource_type}Id"] elif label in RESOURCES.keys(): parent = base_resource.meta.data if base_resource.meta.data is not None else {} combined = {**parent, **properties} arn = RESOURCES.definition(label).format( Region=self.session.region_name, Account=self.account_id, **combined) if isinstance(arn, str) \ and re.compile("arn:aws:([a-zA-Z0-9]+):([a-z0-9-]*):(\d{12}|aws)?:(.*)" ).match(arn) is not None: return arn return None
def validate_types(types): """ Check types against known resources & print invalid ones. """ invalid = set(types) - set(RESOURCES.keys()) if invalid != set(): print(f"Invalid resource type(s): {list(invalid)}.") sys.exit()