Advertisement
pulidovpe

Untitled

Nov 8th, 2019
276
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.71 KB | None
  1. ## Variables
  2. variable "database_name" {
  3.    description = "The database name"
  4.    default     = "DB_Name"
  5. }
  6.  
  7. variable "database_username" {
  8.    description = "The username of the database"
  9.    default     = "postgres"
  10. }
  11.  
  12. variable "database_password" {
  13.    description = "The password of the database"
  14.    default     = "1234567890"
  15. }
  16.  
  17. ...
  18.  
  19. ## RDS
  20. resource "aws_db_instance" "rds" {
  21.   name                        = var.database_name
  22.   identifier                  = "${var.environment}-database"
  23.   username                    = var.database_username
  24.   password                    = var.database_password
  25.   port                        = "5432"
  26.   engine                      = "postgres"
  27.   engine_version              = "11"
  28.   ...
  29. }
  30.  
  31. ## the task definition for the app
  32. data "template_file" "app_task" {
  33.    template = file("./templates/ecs/app_task.json.tpl")
  34.  
  35.    vars = {
  36.       app_name             = "app"
  37.       app_image            = var.app_image
  38.       app_port             = var.app_port
  39.       fargate_cpu          = 512
  40.       fargate_memory       = 1024
  41.       aws_region           = var.aws_region
  42.  
  43.       log_group            = aws_cloudwatch_log_group.app_log_group.name
  44.       database_url         = "postgres://${var.database_username}:${var.database_password}@${local.database_endpoint}/${var.database_name}"
  45.       ## database_url      = "postgresql://${var.database_username}:${var.database_password}@${local.database_endpoint}:5432/${var.database_name}"
  46.       database_name        = var.database_name
  47.       database_username    = var.database_username
  48.       database_password    = var.database_password
  49.       ...
  50. }
  51.  
  52. ## app_task.json.tpl
  53. [
  54.   {
  55.     "name": "${app_name}",
  56.     "image": "${app_image}",
  57.     "cpu": ${fargate_cpu},
  58.     "memory": ${fargate_memory},
  59.     "networkMode": "awsvpc",    
  60.     "memoryReservation": 512,
  61.     "logConfiguration": {
  62.         "logDriver": "awslogs",
  63.         "options": {
  64.           "awslogs-group": "${log_group}",
  65.           "awslogs-region": "${aws_region}",
  66.           "awslogs-stream-prefix": "ecs"
  67.         }
  68.     },
  69.     "portMappings": [
  70.       {
  71.         "containerPort": ${app_port},
  72.         "hostPort": ${app_port}
  73.       }
  74.     ],
  75.     "entryPoint": [
  76.       "python", "main.py"
  77.     ],
  78.     "environment": [
  79.       {
  80.         "name": "POSTGRES_URL",
  81.         "value": "${database_url}"
  82.       },
  83.       {
  84.         "name": "POSTGRES_PORT",
  85.         "value": "5432"
  86.       },
  87.       {
  88.         "name": "POSTGRES_USER",
  89.         "value": "${database_username}"
  90.       },
  91.       {
  92.         "name": "POSTGRES_PASSWORD",
  93.         "value": "${database_password}"
  94.       },
  95.       {
  96.         "name": "POSTGRES_DB",
  97.         "value": "${database_name}"
  98.       },
  99.       ...
  100.    }
  101. ]
Advertisement
RAW Paste Data Copied
Advertisement