Skip to content

Latest commit

 

History

History
238 lines (188 loc) · 6.47 KB

.header.md

File metadata and controls

238 lines (188 loc) · 6.47 KB

Terraform Seqera Infrastructure Deployment Module

This Terraform code deploys infrastructure resources using the following modules:

  • VPC: Creates a Virtual Private Cloud (VPC) with subnets, routing, and networking configurations.
  • EKS: Provisions an Amazon Elastic Kubernetes Service (EKS) cluster with managed node groups.
  • Security-Group: Sets up a security group for access from the EKS cluster to the database.
  • RDS: Deploys an Amazon RDS database instance.
  • Elasticache-Redis: Creates a Redis MemoryDB cluster.
  • EC2: Creates en EC2 instance

Prerequisites

Before running this Terraform code, ensure you have the following prerequisites in place: Terraform CLI is installed on your local machine.

Usage

Follow the steps below to deploy the infrastructure:

Example EKS cluster:

## Module
module "terraform-seqera-aws" {
  source  = "github.com/seqeralabs/terraform-seqera-aws"
  region  = "eu-west-2"

  ## VPC
  vpc_name = "my-seqera-tf-vpc"

  ## EKS
  cluster_name    = "my-seqera-tf-cluster"
  cluster_version = "1.27"
  eks_managed_node_group_defaults_instance_types = ["t3.medium"]
  eks_managed_node_group_defaults_capacity_type = "ON_DEMAND"
  eks_aws_auth_roles = [
    "arn:aws:iam::1234567890123:role/MyIAMRole",
  ]

  eks_aws_auth_users = [
    "arn:aws:iam::1234567890123:user/MyIAMUSer"
  ]

  default_tags = {
    Environment = "myenvironment"
    ManagedBy   = "Terraform"
    Product     = "Seqera"
  }
}

## Outputs
output "database_url" {
  value = module.terraform-seqera-aws.database_url
}

output "redis_url" {
  value = module.terraform-seqera-aws.redis_url
}

output "seqera_irsa_role_name" {
  value = module.terraform-seqera-aws.seqera_irsa_role_name
}

Example of public EC2 instance with your local SSH public key main.tf

module "terraform-seqera-aws" {
  source  = "github.com/seqeralabs/terraform-seqera-aws"
  region  = "eu-west-2"

  ## VPC
  vpc_name = "seqera-vpc"

  ## EC2 Instance
  create_ec2_instance = true
  create_ec2_instance_local_key_pair = true
  create_ec2_public_instance = true

  default_tags = {
    Environment = "development"
    ManagedBy   = "Terraform"
    Product     = "Seqera"
    CreatedBy   = "DevOps"
  }
}

output "database_url" {
  value = module.terraform-seqera-aws.database_url
}

output "redis_url" {
  value = module.terraform-seqera-aws.redis_url
}

output "ec2_instance_public_dns_name" {
  value = module.terraform-seqera-aws.ec2_instance_public_dns_name
}

Note: To connect to the EC2 instance use the following syntax ssh ec2-user@<EC2 Instance Public DNS Name>

Example of public EC2 instance with existing AWS key pair main.tf

module "terraform-seqera-aws" {
  source  = "github.com/seqeralabs/terraform-seqera-aws"
  region  = "eu-west-2"

  ## VPC
  vpc_name = "seqera-vpc"

  ## EC2 Instance
  create_ec2_instance = true
  ec2_instance_key_name = "my-key-pair"
  create_ec2_public_instance = true

  default_tags = {
    Environment = "development"
    ManagedBy   = "Terraform"
    Product     = "Seqera"
    CreatedBy   = "DevOps"
  }
}

output "database_url" {
  value = module.terraform-seqera-aws.database_url
}

output "redis_url" {
  value = module.terraform-seqera-aws.redis_url
}

output "ec2_instance_public_dns_name" {
  value = module.terraform-seqera-aws.ec2_instance_public_dns_name
}

Example of private EC2 instance

module "terraform-seqera-aws" {
  source  = "github.com/seqeralabs/terraform-seqera-aws"
  region  = "eu-west-2"

  ## VPC
  vpc_name = "seqera-vpc"

  ## EC2 Instance
  create_ec2_instance = true
  enable_ec2_instance_session_manager_access = true

  default_tags = {
    Environment = "development"
    ManagedBy   = "Terraform"
    Product     = "Seqera"
    CreatedBy   = "DevOps"
  }
}

output "database_url" {
  value = module.terraform-seqera-aws.database_url
}

output "redis_url" {
  value = module.terraform-seqera-aws.redis_url
}

output "ec2_instance_id" {
  value = module.terraform-seqera-aws.ec2_instance_id
}

Note: To connect to the private EC2 instance, you will need to use the aws ssm plugin. the syntax is aws ssm start-session --target <EC2 Instance ID>

Example of public EC2 instance with secure SSM Session Manager access main.tf

module "terraform-seqera-aws" {
  source  = "github.com/seqeralabs/terraform-seqera-aws"
  region  = "eu-west-2"

  ## VPC
  vpc_name = "seqera-vpc"

  ## EC2 Instance
  create_ec2_instance = true
  enable_ec2_instance_session_manager_access = true
  create_ec2_public_instance = true
  ec2_instance_security_group_ingress_rules_names = ["http-80-tcp", "https-443-tcp"]

  default_tags = {
    Environment = "development"
    ManagedBy   = "Terraform"
    Product     = "Seqera"
    CreatedBy   = "DevOps"
  }
}

output "database_url" {
  value = module.terraform-seqera-aws.database_url
}

output "redis_url" {
  value = module.terraform-seqera-aws.redis_url
}

Note: To connect to the private EC2 instance, you will need to use the aws ssm`` plugin. the syntax is aws ssm start-session --target `

  1. Clone this repository to your local machine.
  2. Navigate to the project directory.
  3. Initialize the Terraform configuration by running the following command:
terraform init
  1. Review the variables in the variables.tf file and update them as per your requirements.
  2. Run the Terraform plan command to see the execution plan:
terraform plan

If the plan looks good, apply the changes by running the following command:

terraform apply
  1. Confirm the changes by typing yes when prompted. Wait for Terraform to provision the infrastructure resources.

  2. Once the deployment is complete, you will see the output values that provide information about the provisioned resources.

The following outputs will be displayed after successful deployment:

Cleanup

To destroy the provisioned infrastructure and clean up resources, run the following command:

terraform destroy

Confirm the action by typing yes when prompted.

License

This Terraform code is licensed under the Apache License