def create_ecs_cluster( creds: AwsCredentials, params: GeneralConfiguration, ecs_conf: ECSConfigs ) -> Any: """Create ecs cluster with asg.""" logger.info("Executing run_id=%s", params.run_id) if not ecs_conf.ssh_key_name: logger.info("Creating new ssh key-pair. run_id=%s", params.run_id) ecs_conf = ecs_conf._replace( ssh_key_name=create_ssh_key( f"{params.project_name}_{params.env_name}_{params.env_slug}", creds ) ) if not ecs_conf.ecs_aws_ami: logger.info("Retrieving aws ami id. run_id=%s", params.run_id) ecs_conf = ecs_conf._replace(ecs_aws_ami=get_ecs_ami_id(creds)) executor = TerraformExecutor( creds=creds, general_configs=params, cmd_configs=ecs_conf, executor_configs=ExecutorConfiguration( name="ecs", action="create", config_dir="ecs", state_key=build_project_state_key(params, "ecs"), variables_file_name="", ), ) return executor.execute_apply()
def get_network_details(creds: AwsCredentials, params: GeneralConfiguration,) -> Any: """Get network details.""" executor = TerraformExecutor( creds, params, cmd_configs=None, executor_configs=ExecutorConfiguration( name="network", action="outputs", config_dir="network", state_key=build_environment_state_key(params, "network"), variables_file_name="network.tfvars", ), ) return executor.get_outputs()
def get_alb_details(creds: AwsCredentials, params: GeneralConfiguration, alb_conf: ALBConfigs) -> Any: executor = TerraformExecutor( creds=creds, general_configs=params, cmd_configs=alb_conf, executor_configs=ExecutorConfiguration( name="alb", action="outputs", config_dir="alb", state_key=build_project_state_key(params, "alb"), variables_file_name="", ), ) return executor.get_outputs()
def destroy_network(creds: AwsCredentials, params: GeneralConfiguration,) -> None: """Destroy vpc that was created with create_network from above.""" executor = TerraformExecutor( creds, params, cmd_configs=None, executor_configs=ExecutorConfiguration( name="network", action="destroy", config_dir="network", state_key=build_environment_state_key(params, "network"), variables_file_name="network.tfvars", ), ) return executor.execute_destroy()
def create_bucket(creds: AwsCredentials, params: GeneralConfiguration, s3_conf: S3Configs) -> Any: """Create a bucket.""" logger.info("Executing run id=%s", params.run_id) executor = TerraformExecutor( creds, params, cmd_configs=s3_conf, executor_configs=ExecutorConfiguration( name="s3_bucket", action="create", config_dir="s3_bucket", state_key=build_resource_state_key(params, "s3_bucket"), ), ) return executor.execute_apply()
def get_cache_details(creds: AwsCredentials, params: GeneralConfiguration, cache_conf: CacheConfigs) -> Any: """Get terraform outputs for elasticache resource.""" logger.info("Executing destroy redis. run_id=%s", params.run_id) executor = TerraformExecutor( creds, params, cmd_configs=cache_conf, executor_configs=ExecutorConfiguration( name="elasticache", action="outputs", config_dir="elasticache", state_key=build_project_state_key(params, "elasticache"), ), ) return executor.get_outputs()
def create_cache(creds: AwsCredentials, params: GeneralConfiguration, cache_conf: CacheConfigs) -> Any: """Create a database.""" logger.info("Executing run id=%s", params.run_id) executor = TerraformExecutor( creds, params, cmd_configs=cache_conf, executor_configs=ExecutorConfiguration( name="elasticache", action="create", config_dir="elasticache", state_key=build_project_state_key(params, "elasticache"), ), ) return executor.execute_apply()
def destroy_ecr(creds: AwsCredentials, params: GeneralConfiguration, ecr_conf: ECRConfigs) -> Any: """Destroy alb.""" logger.info("Executing run_id=%s", params.run_id) executor = TerraformExecutor( creds=creds, general_configs=params, cmd_configs=ecr_conf, executor_configs=ExecutorConfiguration( name="ecr", action="destroy", config_dir="ecr", state_key=build_service_state_key(params, "ecr"), variables_file_name="", ), ) return executor.execute_destroy()
def remove_build_worker_server(creds: AwsCredentials, params: GeneralConfiguration, run_config: BuildWorkerConfigs): logger.info("Executing run_id=%s", params.run_id) executor = TerraformExecutor( creds=creds, general_configs=params, cmd_configs=run_config, executor_configs=ExecutorConfiguration( name="build_worker", action="destroy", config_dir="build_worker", state_key=build_service_state_key(params, "build_worker"), variables_file_name="", ), ) return executor.execute_destroy()
def destroy_bucket(creds: AwsCredentials, params: GeneralConfiguration, s3_conf: S3Configs) -> None: """Destroy a bucket.""" logger.info("Executing destroy postgres. run_id=%s", params.run_id) executor = TerraformExecutor( creds, params, cmd_configs=s3_conf, executor_configs=ExecutorConfiguration( name="s3_bucket", action="destroy", config_dir="s3_bucket", state_key=build_resource_state_key(params, "s3_bucket"), ), ) executor.execute_destroy() logger.info("Bucket removed")
def create_postgresql( creds: AwsCredentials, params: GeneralConfiguration, db_conf: DBConfigs ) -> Any: """Create a database.""" logger.info("Executing run id=%s", params.run_id) executor = TerraformExecutor( creds, params, cmd_configs=db_conf, executor_configs=ExecutorConfiguration( name="postgres", action="create", config_dir="postgres", state_key=build_resource_state_key(params, "postgres"), ), ) return executor.execute_apply()
def destroy_cache(creds: AwsCredentials, params: GeneralConfiguration, cache_conf: CacheConfigs) -> None: """Destroy cache.""" logger.info("Executing destroy redis. run_id=%s", params.run_id) executor = TerraformExecutor( creds, params, cmd_configs=cache_conf, executor_configs=ExecutorConfiguration( name="elasticache", action="destroy", config_dir="elasticache", state_key=build_project_state_key(params, "elasticache"), ), ) executor.execute_destroy() logger.info("Cache destroyed")
def create_alb(creds: AwsCredentials, params: GeneralConfiguration, alb_conf: ALBConfigs) -> Any: """Create and manage alb.""" logger.info("Executing run_id=%s", params.run_id) executor = TerraformExecutor( creds=creds, general_configs=params, cmd_configs=alb_conf, executor_configs=ExecutorConfiguration( name="alb", action="create", config_dir="alb", state_key=build_project_state_key(params, "alb"), variables_file_name="", ), ) return executor.execute_apply()
def destroy_ecs_cluster( creds: AwsCredentials, params: GeneralConfiguration, ecs_conf: ECSConfigs ) -> Any: """Destroy ecs cluster and its resources.""" logger.info("Executing run_id=%s", params.run_id) executor = TerraformExecutor( creds=creds, general_configs=params, cmd_configs=ecs_conf, executor_configs=ExecutorConfiguration( name="ecs", action="destroy", config_dir="ecs", state_key=build_project_state_key(params, "ecs"), variables_file_name="", ), ) return executor.execute_destroy()
def destroy_postgresql( creds: AwsCredentials, params: GeneralConfiguration, db_conf: DBConfigs ) -> None: """Destroy database.""" logger.info("Executing destroy postgres. run_id=%s", params.run_id) executor = TerraformExecutor( creds, params, cmd_configs=db_conf, executor_configs=ExecutorConfiguration( name="postgres", action="destroy", config_dir="postgres", state_key=build_resource_state_key(params, "postgres"), ), ) executor.execute_destroy() logger.info("DB destroyed")
def get_ecs_cluster_details( creds: AwsCredentials, params: GeneralConfiguration, ecs_conf: ECSConfigs ) -> Any: """Utility to run terraform outputs and return infra params.""" logger.info("Executing run_id=%s", params.run_id) executor = TerraformExecutor( creds=creds, general_configs=params, cmd_configs=ecs_conf, executor_configs=ExecutorConfiguration( name="ecs", action="destroy", config_dir="ecs", state_key=build_project_state_key(params, "ecs"), variables_file_name="", ), ) return executor.get_outputs()
def get_r53_details( creds: AwsCredentials, params: GeneralConfiguration, run_config: Route53Configuration, ) -> Any: """Get route 53 details.""" executor = TerraformExecutor( creds=creds, general_configs=params, cmd_configs=run_config, executor_configs=ExecutorConfiguration( name="route53", action="outputs", config_dir="route53", state_key=build_environment_state_key(params, "route53"), variables_file_name="", ), ) return executor.get_outputs()
def destroy_route53( creds: AwsCredentials, params: GeneralConfiguration, run_config: Route53Configuration, ) -> Any: """Create and apply changes in route 53.""" logger.info("Executing run_id=%s", params.run_id) executor = TerraformExecutor( creds=creds, general_configs=params, cmd_configs=run_config, executor_configs=ExecutorConfiguration( name="route53", action="destroy", config_dir="route53", state_key=build_environment_state_key(params, "route53"), variables_file_name="", ), ) return executor.execute_destroy()
def get_acm_details( creds: AwsCredentials, params: GeneralConfiguration, run_config: SSLConfigs, ) -> Any: """Get ACM details.""" logger.info("Executing run_id=%s", params.run_id) executor = TerraformExecutor( creds=creds, general_configs=params, cmd_configs=run_config, executor_configs=ExecutorConfiguration( name="acm", action="outputs", config_dir="acm", state_key=build_service_state_key(params, "acm"), variables_file_name="", ), ) return executor.get_outputs()
def destroy_acm( creds: AwsCredentials, params: GeneralConfiguration, run_config: SSLConfigs, ) -> Any: """Create and apply changes in ACM.""" logger.info("Executing run_id=%s", params.run_id) executor = TerraformExecutor( creds=creds, general_configs=params, cmd_configs=run_config, executor_configs=ExecutorConfiguration( name="acm", action="destroy", config_dir="acm", state_key=build_service_state_key(params, "acm"), variables_file_name="", ), ) return executor.execute_destroy()
def create_network(creds: AwsCredentials, params: GeneralConfiguration,) -> Any: """Create vpc with private and subnet network, with internet access.""" executor = TerraformExecutor( creds, params, cmd_configs=None, executor_configs=ExecutorConfiguration( name="network", action="create", config_dir="network", state_key=build_environment_state_key(params, "network"), variables_file_name="network.tfvars", ), ) network_details = executor.get_outputs() if network_details: logger.info( "Network already exists. project_name=%s env_name=%s", params.project_name, params.env_name, ) return network_details return executor.execute_apply()