"""Creates the database inside a vpc.""" from typing import Any, NamedTuple, List from infra_executors.constants import AwsCredentials, GeneralConfiguration from infra_executors.constructors import build_resource_state_key from infra_executors.logger import get_logger from infra_executors.terraform_executor import ( ExecutorConfiguration, TerraformExecutor, ) logger = get_logger("db") class DBConfigs(NamedTuple): """Configures db executor.""" identifier: str name: str username: str password: str instance_type: str = "db.t2.large" allocated_storage: int = 100 allowed_security_groups_ids: List[str] = [] def create_postgresql( creds: AwsCredentials, params: GeneralConfiguration, db_conf: DBConfigs ) -> Any: """Create a database."""
"""Creates the vpc and it's network.""" from typing import Any from infra_executors.constants import ( AwsCredentials, GeneralConfiguration, ) from infra_executors.constructors import build_environment_state_key from infra_executors.logger import get_logger from infra_executors.terraform_executor import ( ExecutorConfiguration, TerraformExecutor, ) logger = get_logger("network") 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", ),
"""Manages AWS ACM certificate.""" from typing import NamedTuple, Any from infra_executors.constants import AwsCredentials, GeneralConfiguration from infra_executors.constructors import build_service_state_key from infra_executors.logger import get_logger from infra_executors.terraform_executor import ( ExecutorConfiguration, TerraformExecutor, ) logger = get_logger("ssl") class SSLConfigs(NamedTuple): """Configs required for R53.""" zone_id: str domain_name: str def create_acm( creds: AwsCredentials, params: GeneralConfiguration, run_config: SSLConfigs, ) -> Any: """Create ACM certificate.""" logger.info("Executing run_id=%s", params.run_id) executor = TerraformExecutor( creds=creds, general_configs=params,
"""Manages ecr repos.""" from typing import Any, List, NamedTuple from infra_executors.constants import AwsCredentials, GeneralConfiguration from infra_executors.constructors import build_service_state_key from infra_executors.logger import get_logger from infra_executors.terraform_executor import ( ExecutorConfiguration, TerraformExecutor, ) logger = get_logger("ecr") class ECRConfigs(NamedTuple): """List of repositories to create.""" repositories: List[str] def create_ecr(creds: AwsCredentials, params: GeneralConfiguration, ecr_conf: ECRConfigs) -> Any: """Create and manage 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="create",
create_ecs_cluster, destroy_ecs_cluster, get_ecs_cluster_details, ) from infra_executors.logger import get_logger from infra_executors.network import ( create_network, get_network_details, ) from infra_executors.route53 import ( create_route53, Route53Configuration, destroy_route53, ) logger = get_logger("ecs-env") class ESCEnvironmentError(Exception): """Raised to indicate any errors in the process of building/destroying.""" class EnvConfigs(NamedTuple): """Configuration parameters required to create an environment.""" domain: str route53: Route53Configuration def create_global_parts( creds: AwsCredentials,
"""Manages service infra.""" from typing import NamedTuple from infra_executors.acm import create_acm, SSLConfigs, destroy_acm from infra_executors.alb import ALBConfigs, create_alb from infra_executors.constants import AwsCredentials, GeneralConfiguration from infra_executors.ecr import ECRConfigs, create_ecr, destroy_ecr from infra_executors.logger import get_logger from infra_executors.route53 import ( Route53Configuration, create_route53, CnameSubDomain, get_r53_details, ) logger = get_logger("ecs-service") class ServiceConfiguration(NamedTuple): name: str subdomain: str def create_acm_for_service( creds: AwsCredentials, common_conf: GeneralConfiguration, route53_conf: Route53Configuration, subdomain: str, r53_zone_id: str, ): """Creates acm certificate for service subdomain."""
EXEC_LOGS_DIR, PLANS_DIR, TERRAFORM_DIR, TERRAFORM_PLUGIN_DIR, ) from infra_executors.constructors import build_env_vars from infra_executors.logger import get_logger from infra_executors.utils import execute_shell_command if TYPE_CHECKING: from infra_executors.constants import ( AwsCredentials, GeneralConfiguration, ) logger = get_logger(__name__) class ExecutorConfiguration(NamedTuple): """Terraform executor configurations.""" name: str action: str config_dir: str state_key: str variables_file_name: str = "" class TerraformExecutorError(Exception): """Indicates execution error."""
"""Manages ALB component.""" from typing import Any, List, NamedTuple, NewType from infra_executors.constants import AwsCredentials, GeneralConfiguration from infra_executors.constructors import build_project_state_key from infra_executors.logger import get_logger from infra_executors.terraform_executor import ( ExecutorConfiguration, TerraformExecutor, ) logger = get_logger("alb") Protocol = NewType("Protocol", str) TCP = Protocol("TCP") UDP = Protocol("UDP") TLS = Protocol("TLS") TCP_UDP = Protocol("TCP_UDP") HTTP = Protocol("HTTP") HTTPS = Protocol("HTTPS") class OpenPort(NamedTuple): """Describes open ports configuration.""" name: str container_port: int alb_port_http: int alb_port_https: int health_check_endpoint: str