code: def terraform_generate_handler(
      config, init=False, check_tf=True, check_creds=True
  ):
      """Generate all Terraform plans for the configured clusters.
  
      Keyword Args:
          config (dict): The loaded config from the 'conf/' directory
          init (bool): Indicates if main.tf.json is generated for `init`
  
      Returns:
          bool: Result of cluster generating
      """
      # Check for valid credentials
      if check_creds and not check_credentials():
          return False
  
      # Verify terraform is installed
      if check_tf and not terraform_check():
          return False
  
      # Setup the main.tf.json file
      LOGGER.debug("Generating cluster file: main.tf.json")
      _create_terraform_module_file(
          generate_main(config, init=init),
          os.path.join(config.build_directory, "main.tf.json"),
      )
  
      # Return early during the init process, clusters are not needed yet
      if init:
          return True
  
      # Setup cluster files
      for cluster in config.clusters():
          if cluster in RESTRICTED_CLUSTER_NAMES:
              raise InvalidClusterName(
                  'Rename cluster "main" or "athena" to something else!'
              )
  
          LOGGER.debug("Generating cluster file: %s.tf.json", cluster)
          cluster_dict = generate_cluster(
              config=config, cluster_name=cluster
          )
          if not cluster_dict:
              LOGGER.error(
                  "An error was generated while creating the %s cluster",
                  cluster,
              )
              return False
  
          file_name = "{}.tf.json".format(cluster)
          _create_terraform_module_file(
              cluster_dict,
              os.path.join(config.build_directory, file_name),
          )
  
      metric_filters = generate_aggregate_cloudwatch_metric_filters(
          config
      )
      if metric_filters:
          _create_terraform_module_file(
              metric_filters,
              os.path.join(
                  config.build_directory, "metric_filters.tf.json"
              ),
          )
  
      metric_alarms = generate_aggregate_cloudwatch_metric_alarms(
          config
      )
      if metric_alarms:
          _create_terraform_module_file(
              metric_alarms,
              os.path.join(
                  config.build_directory, "metric_alarms.tf.json"
              ),
          )
  
      # Setup Threat Intel Downloader Lambda function if it is enabled
      generate_global_lambda_settings(
          config,
          conf_name="threat_intel_downloader_config",
          generate_func=generate_threat_intel_downloader,
          tf_tmp_file_name="ti_downloader",
          required=False,
      )
  
      # Setup Rule Promotion if it is enabled
      generate_global_lambda_settings(
          config,
          conf_name="rule_promotion_config",
          generate_func=generate_rule_promotion,
          tf_tmp_file_name="rule_promotion",
          required=False,
      )
  
      # Setup Athena Partitioner
      generate_global_lambda_settings(
          config,
          conf_name="athena_partitioner_config",
          generate_func=generate_athena,
          tf_tmp_file_name="athena",
      )
  
      # Setup Rules Engine
      generate_global_lambda_settings(
          config,
          conf_name="rules_engine_config",
          generate_func=generate_rules_engine,
          tf_tmp_file_name="rules_engine",
      )
  
      # Setup Alert Processor
      generate_global_lambda_settings(
          config,
          conf_name="alert_processor_config",
          generate_func=generate_alert_processor,
          tf_tmp_file_name="alert_processor",
      )
  
      # Setup Alert Merger
      generate_global_lambda_settings(
          config,
          conf_name="alert_merger_config",
          generate_func=generate_alert_merger,
          tf_tmp_file_name="alert_merger",
      )
  
      # Setup Lookup Tables if applicable
      _generate_lookup_tables_settings(config)
  
      # Setup StreamQuery
      _generate_streamquery_module(config)
  
      # FIXME: make sure test 'python manage.py destroy' artifact_extractor case
      # Setup artifact_extractor
      _generate_artifact_extractor_module(config)
  
      return True
  
imports: import json
  import os
  from streamalert.shared.config import ConfigError, firehose_alerts_bucket
  from streamalert.shared.logger import get_logger
  from streamalert.shared.utils import get_database_name, get_data_file_format
  from streamalert_cli.athena.helpers import generate_alerts_table_schema
  from streamalert_cli.helpers import check_credentials
  from streamalert_cli.terraform.common import InvalidClusterName, infinitedict, monitoring_topic_name, s3_access_logging_bucket, terraform_state_bucket
  from streamalert_cli.terraform.artifact_extractor import generate_artifact_extractor
  from streamalert_cli.terraform.alert_merger import generate_alert_merger
  from streamalert_cli.terraform.alert_processor import generate_alert_processor
  from streamalert_cli.terraform.apps import generate_apps
  from streamalert_cli.terraform.athena import generate_athena
  from streamalert_cli.terraform.cloudtrail import generate_cloudtrail
  from streamalert_cli.terraform.cloudwatch_destinations import generate_cloudwatch_destinations
  from streamalert_cli.terraform.cloudwatch_events import generate_cloudwatch_events
  from streamalert_cli.terraform.firehose import generate_firehose
  from streamalert_cli.terraform.flow_logs import generate_flow_logs
  from streamalert_cli.terraform.helpers import terraform_check
  from streamalert_cli.terraform.kinesis_events import generate_kinesis_events
  from streamalert_cli.terraform.kinesis_streams import generate_kinesis_streams
  from streamalert_cli.terraform.metrics import generate_aggregate_cloudwatch_metric_alarms, generate_aggregate_cloudwatch_metric_filters, generate_cluster_cloudwatch_metric_filters, generate_cluster_cloudwatch_metric_alarms
  from streamalert_cli.terraform.monitoring import generate_monitoring
  from streamalert_cli.terraform.rule_promotion import generate_rule_promotion
  from streamalert_cli.terraform.classifier import generate_classifier
  from streamalert_cli.terraform.rules_engine import generate_rules_engine
  from streamalert_cli.terraform.s3_events import generate_s3_events
  from streamalert_cli.terraform.scheduled_queries import generate_scheduled_queries_module_configuration
  from streamalert_cli.terraform.threat_intel_downloader import generate_threat_intel_downloader
  from streamalert_cli.utils import CLICommand
label_desc: Use image node_id 5 for calling a global function with example usage: terraform_generate_handler(config, init, check_tf, check_creds) and returns: True, False, False, True, False