Skip to content
Snippets Groups Projects
Commit 69d40567 authored by Nuwan Rajika Kumarasiri's avatar Nuwan Rajika Kumarasiri
Browse files

Add initial terraform scripts for automating infra. for Informatica Secure Agent

Since our licensing restrict us from more than 1 instance of Secure Agent, before deploying a new instance existing instance need to be shutdown (after adjusting any resources that depends on that instance). Due to this reason terraform is not part of CI/CD.
parent b19b1b91
No related branches found
No related tags found
2 merge requests!20Add note about minimum privileges for IICS user,!2Add initial terraform scripts for automating infra. for Informatica Secure Agent
*.idea
.env .env
volumes/ volumes/
credentials.tf
*.svg
*_credentials.tf
sandbox
.DS_Store
.vscode
*.tfstate
*.tfstate.backup
.terraform
*.tfvars
.idea/
*.backup
...@@ -61,3 +61,17 @@ Minimum Hardware Specs ...@@ -61,3 +61,17 @@ Minimum Hardware Specs
## Known Issues ## Known Issues
* Doesn't seem to be able to run in host network mode because it won't be able to talk to internal ports. It would probably work if you expose those ports. * Doesn't seem to be able to run in host network mode because it won't be able to talk to internal ports. It would probably work if you expose those ports.
## Terraform
* Infrastructure is available as code in terraform.
* Before disposing and create a new instance of Informatica Secure Agent, existing live connections to various targets(for e.g. databases)
should be reviewed and terminated. Due to this reason this is not part of CI/CD pipeline and can be executed as per necessity.
* Various configurations can be overridden using `-var=`, see [variables.tf](./terraform/variables.tf) for available parameters.
```
$ cd terraform
$ terraform init
$ terraform validate
$ terraform plan -out agent.tfplan
$ terraform apply "agent.tfplan"
```
* See Terraform doc on [variables](https://www.terraform.io/docs/configuration/variables.html) to see how to pass command line arguments.
\ No newline at end of file
data "template_file" "container" { data "template_file" "container" {
template = file("./templates/container.tpl") template = file("./templates/container.tpl")
vars = { vars = {
container_name = var.container_name container_name = var.container_name
image_name = var.image_name image_name = var.image_name
fargate_cpu = var.fargate_cpu fargate_cpu = var.fargate_cpu
fargate_memory = var.fargate_memory fargate_memory = var.fargate_memory
app_port1 = var.container_app_port[0] app_port1 = var.container_app_port[0]
app_port2 = var.container_app_port[1] app_port2 = var.container_app_port[1]
app_port3 = var.container_app_port[2] app_port3 = var.container_app_port[2]
network_mode = var.container_network_mode network_mode = var.container_network_mode
} }
} }
...@@ -17,26 +17,28 @@ data "aws_iam_role" "ecs-task-execution" { ...@@ -17,26 +17,28 @@ data "aws_iam_role" "ecs-task-execution" {
} }
resource "aws_ecs_task_definition" "task" { resource "aws_ecs_task_definition" "task" {
family = var.ecs_task_name family = var.ecs_task_name
execution_role_arn = data.aws_iam_role.ecs-task-execution.arn execution_role_arn = data.aws_iam_role.ecs-task-execution.arn
network_mode = var.container_network_mode network_mode = var.container_network_mode
requires_compatibilities = ["FARGATE"] requires_compatibilities = [
cpu = var.fargate_cpu "FARGATE"]
memory = var.fargate_memory cpu = var.fargate_cpu
container_definitions = data.template_file.container.rendered memory = var.fargate_memory
container_definitions = data.template_file.container.rendered
} }
resource "aws_ecs_service" "service" { resource "aws_ecs_service" "service" {
name = var.ecs_service_name name = var.ecs_service_name
cluster = aws_ecs_cluster.cluster.id cluster = aws_ecs_cluster.cluster.id
task_definition = aws_ecs_task_definition.task.arn task_definition = aws_ecs_task_definition.task.arn
desired_count = 1 desired_count = 1
launch_type = "FARGATE" launch_type = "FARGATE"
network_configuration { network_configuration {
security_groups = [
data.aws_security_group.sec-group.id]
subnets = data.aws_subnet_ids.subnets.ids
assign_public_ip = false assign_public_ip = false
subnets = [data.aws_subnet_ids.subnet-a.id,data.aws_subnet_ids.subnet-b.id]
security_groups = [data.aws_security_group.sec-group.id]
} }
} }
......
...@@ -2,17 +2,16 @@ data "aws_vpc" "vpc" { ...@@ -2,17 +2,16 @@ data "aws_vpc" "vpc" {
tags = var.vpc_tags tags = var.vpc_tags
} }
data "aws_subnet_ids" "subnet-a" { data "aws_subnet_ids" "subnets" {
vpc_id = data.aws_vpc.vpc.id vpc_id = data.aws_vpc.vpc.id
tags = var.private_subnet_a_tags filter {
} name = "tag:Name"
values = [
data "aws_subnet_ids" "subnet-b" { var.private_subnets_filter["Name"]]
vpc_id = data.aws_vpc.vpc.id }
tags = var.private_subnet_b_tags
} }
data "aws_security_group" "sec-group" { data "aws_security_group" "sec-group" {
vpc_id = data.aws_vpc.vpc.id vpc_id = data.aws_vpc.vpc.id
tags = var.security_group tags = var.security_group
} }
\ No newline at end of file
provider "aws" { provider "aws" {
access_key = var.aws_access_key access_key = var.aws_access_key
secret_key = var.aws_secret_key secret_key = var.aws_secret_key
region = var.aws_region region = var.aws_region
allowed_account_ids = [var.aws_account_id] allowed_account_ids = [
var.aws_account_id]
} }
\ No newline at end of file
data "aws_security_group" "secgroup" { data "aws_security_group" "secgroup" {
vpc_id = data.aws_vpc.vpc.id vpc_id = data.aws_vpc.vpc.id
tags = var.security_group tags = var.security_group
} }
\ No newline at end of file
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
"hostPort": ${app_port2} "hostPort": ${app_port2}
}, },
{ {
"containerPort": ${app_port2}, "containerPort": ${app_port3},
"hostPort": ${app_port2} "hostPort": ${app_port3}
} }
] ]
} }
......
variable "aws_access_key" {} variable "aws_access_key" {}
variable "aws_secret_key" {} variable "aws_secret_key" {}
variable "aws_account_id" { variable "aws_account_id" {
default = "265723766240" default = "265723766240"
} }
variable "aws_region" { variable "aws_region" {
default = "us-east-1" # test tier default = "us-east-1"
# test tier
} }
variable "vpc_tags" { variable "vpc_tags" {
type = map(string) type = map(string)
default = { default = {
Name = "test-tier" Name = "test-tier"
tier = "test" tier = "test"
} }
} }
# needs at least two subnets # needs at least two subnets
variable "private_subnet_a_tags" { variable "private_subnets_filter" {
type = map(string) type = map(string)
default = { default = {
Name = "test-private-a" Name = "test-private-*"
tier = "test" }
network = "private"
}
}
variable "private_subnet_b_tags" {
type = map(string)
default = {
Name = "test-private-b"
tier = "test"
network = "private"
}
} }
variable "security_group" { variable "security_group" {
type = map(string) type = map(string)
default = { default = {
tier = "test" tier = "test"
Name = "internal" Name = "internal"
} }
} }
variable "image_name" { variable "image_name" {
default = "265723766240.dkr.ecr.us-east-1.amazonaws.com/enterprise-integrations/iics_secure_agent" default = "265723766240.dkr.ecr.us-east-1.amazonaws.com/enterprise-integrations/iics_secure_agent"
} }
variable "container_name" { variable "container_name" {
default = "iics-secure-agent-test" default = "iics-secure-agent-test"
} }
variable "container_network_mode" { variable "container_network_mode" {
default = "awsvpc" default = "awsvpc"
} }
variable "container_app_port" { variable "container_app_port" {
type = list(string) type = list(string)
default = [7080, 7443, 5432] default = [
7080,
7443,
5432]
} }
# note that as per our licesning model each # note that as per our licesning model each
# container would be an extran instance # container would be an extran instance
variable "container_count" { variable "container_count" {
default = 1 default = 1
} }
# https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html
# see Secure Agent resource requirements for these numbers.
variable "fargate_cpu" { variable "fargate_cpu" {
default = "4096" # 1 vCPU = 1024 CPU units # 1 vCPU = 1024 CPU units
default = "4096"
} }
variable "fargate_memory" { variable "fargate_memory" {
default = "4095" # in MiB # in MiB
default = "8192"
} }
# ecs # ecs
variable "ecs_cluster_name" { variable "ecs_cluster_name" {
default = "iics-agent-cluster" default = "iics-agent-cluster"
} }
variable "ecs_cluster_tags" { variable "ecs_cluster_tags" {
type = map(string) type = map(string)
default = { default = {
Name = "iics-agent-cluster" Name = "iics-agent-cluster"
tier = "test" tier = "test"
} }
} }
variable "ecs_task_name" { variable "ecs_task_name" {
default = "iics-secure-agent-test" default = "iics-agent-task"
} }
variable "ecs_service_name" { variable "ecs_service_name" {
default = "iics-secure-agent-test" default = "iics-agent-service"
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment