Skip to content

Commit

Permalink
[TERRAFORM] Added the Terraform deployment module for search (#26)
Browse files Browse the repository at this point in the history
* [TERRAFORM] Added the Terraform deployment module for search

Added the terraform module with the necessary files.

* [TERRAFORM] updated some small configuration items

Also deleted the main.tf as it is not used.
  • Loading branch information
fmadjdian authored Jan 25, 2023
1 parent 7b397fa commit a83a42d
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 0 deletions.
13 changes: 13 additions & 0 deletions terraform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Terraform service generator

# Description
This Terraform module is used to create the Terraform outputs used as an input for the Infrastructure deployment using Terraform/Terragrunt.
The configuration of the service is placed inside 'modules/service_configuration/' as a template called 'services.yaml.tftpl'.

Please see the following for more info, including install instructions and complete documentation:

* [Terragrunt Website](https://terragrunt.gruntwork.io)
* [Getting started with Terragrunt](https://terragrunt.gruntwork.io/docs/getting-started/quick-start/)
* [Terragrunt Documentation](https://terragrunt.gruntwork.io/docs)
* [Contributing to Terragrunt](https://terragrunt.gruntwork.io/docs/community/contributing)
* [Commercial Support](https://terragrunt.gruntwork.io/commercial-support/)
27 changes: 27 additions & 0 deletions terraform/application_services/app.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
locals {
basicinfra_version = "v1"

ecr_repo = "028339422996.dkr.ecr.eu-west-1.amazonaws.com"

app_name = "aerius"
app_timezone = "Europe/Amsterdam"

target_groups = {
"tg1" = {name = "search", protocol = "HTTP", port = "8090", path = "/", matcher = "200-399"}
}

listener_rules = {
"rule1" = {tg = "tg1", application_type = "SEARCH", path_pattern = "/*", cognito = true}
}

ecs_ctr_fes_1_max_instance_size = "2"

ecs_capacity_providers = {
"01" = {description = "On_demand_capacity", number = "001", asg = "01"}
}

ecs_autoscaling_group = {
"01" = {description = "On_demand_capacity", number = "001", spot = false}
}

}
7 changes: 7 additions & 0 deletions terraform/application_services/ecs_services/modules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"url": "git@github.com:aerius/Cloud-infra-modules.git",
"version": "v1",
"checkout_path": "ecs_services"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#############################
# COLLECT REMOTE STATE DATA #
#############################

## Bing API KEY
data "aws_ssm_parameter" "bing_apikey_search" {
name = "/shared/keys/bing"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
output "services" {
description = "The services object containing all configuration"
value = yamldecode(templatefile("${path.module}/services.yaml.tftpl", {
APP_TIMEZONE = var.app_timezone,
APP_VERSION = var.app_version,
REGISTRY_URL = var.ecr_directory == null ? "${var.ecr_repo}/${lower(var.environment)}" : "${var.ecr_repo}/${var.ecr_directory}",

BING_APIKEY = data.aws_ssm_parameter.bing_apikey_search

})).services
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# Copyright the State of the Netherlands
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#

services:

search:
image: ${REGISTRY_URL}/search:${APP_VERSION}
cpu: 4096
memory: 8192
desired_count: 1
target_group: tg1
portmappings:
- containerPort: 8090
hostPort: 8090
environment:
- name: TZ
value: ${APP_TIMEZONE}
- name: NL_AERIUS_BING_APIKEY
value: $(BING_APIKEY)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
############################
# Terragrunt configuration
############################

# Include all settings from the root terraform.tfvars file
include {
path = find_in_parent_folders()
}


terraform {
extra_arguments "common_vars" {
commands = get_terraform_commands_that_need_vars()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
####################
# MODULE VARIABLES #
####################

#--------------------
# Standard Variables
#--------------------

variable "account_id" {
type = string
description = "The AWS account ID in which to provision the infrastructure"
}

variable "service" {
type = map(string)
description = "A map of service details, e.g.: name, type, theme etc."
}

variable "environment" {
type = string
description = "A string for the Environment used in the terragrunt repository directory structure. E.g development, test, apps_shared_service. etc"
}

variable "loc" {
type = string
description = "A string containing the region Code e.g LDN"
}

variable "tf_bucket_key_prefix" {
type = string
description = "A string containing the region Code e.g LDN"
}

#==========================
# ECS Service Variables
#==========================

variable "app_version" {
type = string
description = "The version of the application being deployed"
}

variable "app_timezone" {
type = string
description = "Timezone configuration for the application"
}

variable "ecr_repo" {
type = string
description = "Name of the ECR repository hosting the images"
}

variable "ecr_directory" {
type = string
description = "Name of the directory hosting the images in the ECR repository"
default = null
}

variable "application_host_headers" {
type = map
description = "Map containing host headers for specific applications"
}
46 changes: 46 additions & 0 deletions terraform/application_services/ecs_services/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
############################
# Terragrunt configuration
############################

# Include all settings from the root terraform.tfvars file
include {
path = find_in_parent_folders()
}

dependencies {
paths = ["../service_configuration"]
}

dependency "service_configuration" {
config_path = "../service_configuration"

mock_outputs = {
"services" = {
"nginx" = {
"image" = "myMockImage:latest"
"cpu" = 1024
"memory" = 2048
"min_capacity" = 1
"max_capacity" = 1
"desired_count" = 1
"portmappings" = [
{"containerPort" = 1337},
{"hostPort" = 1337}
]
}
}
}

mock_outputs_allowed_terraform_commands = ["init", "validate", "plan"]
}

terraform {
source = ".//services_generator"
extra_arguments "common_vars" {
commands = get_terraform_commands_that_need_vars()
}
}

inputs = {
services = dependency.service_configuration.outputs.services
}

0 comments on commit a83a42d

Please sign in to comment.